blob: 09d1d6cca173b00ab3e1a51088426c8d9e4a9bfe [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
43/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
44#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
45#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\""
46#define ANQP_IP_ADDR_TYPE_1 "060101000c"
47#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
48#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
49#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
50#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"
51#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
52
53extern char *sigma_main_ifname;
54extern char *sigma_wpas_ctrl;
55extern char *sigma_hapd_ctrl;
56extern char *ap_inet_addr;
57extern char *ap_inet_mask;
58extern char *sigma_radio_ifname[];
59
60static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
61 struct sigma_cmd *cmd);
62static int ath_ap_start_hostapd(struct sigma_dut *dut);
63static void ath_ap_set_params(struct sigma_dut *dut);
64static int kill_process(struct sigma_dut *dut, char *proc_name,
65 unsigned char is_proc_instance_one, int sig);
66
67
68static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
69 struct sigma_cmd *cmd)
70{
71 /* const char *name = get_param(cmd, "NAME"); */
72 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
73 return 0;
74}
75
76
77static int get_hwaddr(const char *ifname, unsigned char *hwaddr)
78{
79#ifndef __QNXNTO__
80 struct ifreq ifr;
81 int s;
82
83 s = socket(AF_INET, SOCK_DGRAM, 0);
84 if (s < 0)
85 return -1;
86 memset(&ifr, 0, sizeof(ifr));
87 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
88 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
89 perror("ioctl");
90 close(s);
91 return -1;
92 }
93 close(s);
94 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
95#else /* __QNXNTO__ */
96 struct ifaddrs *ifaddrshead = NULL;
97 int found = 0;
98 struct ifaddrs *temp_ifap = NULL;
99 struct sockaddr_dl *sdl = NULL;
100
101 if (getifaddrs(&ifaddrshead) != 0) {
102 perror("getifaddrs failed");
103 return -1;
104 }
105
106 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
107 ifaddrshead = ifaddrshead->ifa_next) {
108 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
109 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
110 found = 1;
111 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
112 if (sdl)
113 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
114 }
115 }
116
117 if (temp_ifap)
118 freeifaddrs(temp_ifap);
119
120 if (!found) {
121 perror("Failed to get the interface");
122 return -1;
123 }
124#endif /* __QNXNTO__ */
125 return 0;
126}
127
128
129static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
130 const char *val)
131{
132 char buf[60];
133
134 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
135 ifname, atoi(val));
136 if (system(buf) != 0) {
137 sigma_dut_print(dut, DUT_MSG_ERROR,
138 "wifitool ap_group_id failed");
139 }
140}
141
142
143void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
144 const char *val)
145{
146 char buf[60];
147
148 /* TODO: Enable support for other values */
149 if (strcasecmp(val, "40") == 0) {
150 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
151 ifname);
152 if (system(buf) != 0) {
153 sigma_dut_print(dut, DUT_MSG_ERROR,
154 "wifitool cts_width failed");
155 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800156 snprintf(buf, sizeof(buf),
157 "athdiag --set --address=0x10024 --val=0xd90b8a14");
158 if (system(buf) != 0) {
159 sigma_dut_print(dut, DUT_MSG_ERROR,
160 "disabling phy restart failed");
161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200162 } else {
163 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
164 }
165}
166
167
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800168void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
169 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200170{
171 char buf[60];
172
173 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200174 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200175 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
176 if (system(buf) != 0) {
177 sigma_dut_print(dut, DUT_MSG_ERROR,
178 "iwpriv cwmenable 1 failed");
179 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800180 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
181 ifname);
182 if (system(buf) != 0) {
183 sigma_dut_print(dut, DUT_MSG_ERROR,
184 "disabling RTS from rate control logic failed");
185 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200186 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200187 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200188 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
189 if (system(buf) != 0) {
190 sigma_dut_print(dut, DUT_MSG_ERROR,
191 "iwpriv cwmenable 0 failed");
192 }
193 } else {
194 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
195 }
196}
197
198
199static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
200 const char *val)
201{
202 char buf[60];
203
204 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200205 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
207 if (system(buf) != 0) {
208 sigma_dut_print(dut, DUT_MSG_ERROR,
209 "iwconfig rts 64 failed");
210 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800211 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
212 ifname);
213 if (system(buf) != 0) {
214 sigma_dut_print(dut, DUT_MSG_ERROR,
215 "wifitool beeliner_fw_test 100 1 failed");
216 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200217 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200218 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200219 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
220 if (system(buf) != 0) {
221 sigma_dut_print(dut, DUT_MSG_ERROR,
222 "iwpriv rts 2347 failed");
223 }
224 } else {
225 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
226 }
227}
228
229
230static enum ap_mode get_mode(const char *str)
231{
232 if (strcasecmp(str, "11a") == 0)
233 return AP_11a;
234 else if (strcasecmp(str, "11g") == 0)
235 return AP_11g;
236 else if (strcasecmp(str, "11b") == 0)
237 return AP_11b;
238 else if (strcasecmp(str, "11na") == 0)
239 return AP_11na;
240 else if (strcasecmp(str, "11ng") == 0)
241 return AP_11ng;
242 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
243 return AP_11ac;
244 else
245 return AP_inval;
246}
247
248
249static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
250{
251 char command[1000];
252 const char *bin;
253 enum driver_type drv = get_driver_type();
254
255 if (file_exists("hostapd_cli"))
256 bin = "./hostapd_cli";
257 else
258 bin = "hostapd_cli";
259
260 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
261 sigma_hapd_ctrl = "/var/run/hostapd-wifi0";
262
263 if (sigma_radio_ifname[0] &&
264 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
265 sigma_hapd_ctrl = "/var/run/hostapd-wifi1";
266 else if (sigma_radio_ifname[0] &&
267 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
268 sigma_hapd_ctrl = "/var/run/hostapd-wifi2";
269 }
270
271 if (sigma_hapd_ctrl)
272 snprintf(command, sizeof(command), "%s -p %s %s",
273 bin, sigma_hapd_ctrl, buf);
274 else
275 snprintf(command, sizeof(command), "%s %s", bin, buf);
276 return run_system(dut, command);
277}
278
279
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700280static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
281 struct sigma_cmd *cmd)
282{
283 FILE *f;
284 int i;
285
286 f = fopen("/tmp/lci_cfg.txt", "w");
287 if (!f) {
288 sigma_dut_print(dut, DUT_MSG_ERROR,
289 "Failed to open /tmp/lci_cfg.txt");
290 return -1;
291 }
292
293 for (i = 2; i < cmd->count; i++)
294 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
295 fprintf(f, "\n");
296 fclose(f);
297
298 return 0;
299}
300
301
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200302static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
303 struct sigma_cmd *cmd)
304{
305 /* const char *name = get_param(cmd, "NAME"); */
306 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200307 const char *val;
308 unsigned int wlan_tag = 1;
309 char *ifname = get_main_ifname();
310
311 val = get_param(cmd, "WLAN_TAG");
312 if (val) {
313 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700314 if (wlan_tag < 1 || wlan_tag > 3) {
315 /*
316 * The only valid WLAN Tags as of now as per the latest
317 * WFA scripts are 1, 2, and 3.
318 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200319 send_resp(dut, conn, SIGMA_INVALID,
320 "errorCode,Invalid WLAN_TAG");
321 return 0;
322 }
323 }
324
325 val = get_param(cmd, "CountryCode");
326 if (val) {
327 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
328 return -1;
329 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
330 "%s", val);
331 }
332
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530333 val = get_param(cmd, "regulatory_mode");
334 if (val) {
335 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
336 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
337 }
338
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200339 val = get_param(cmd, "SSID");
340 if (val) {
341 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
342 return -1;
343
344 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700345 /*
346 * If tag is not specified, it is deemed to be 1.
347 * Hence tag of 1 is a special case and the values
348 * corresponding to wlan-tag=1 are stored separately
349 * from the values corresponding tags 2 and 3.
350 * This approach minimises the changes to existing code
351 * since most of the sigma_dut code does not deal with
352 * WLAN-TAG CAPI variable.
353 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200354 snprintf(dut->ap_ssid,
355 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700356 } else {
357 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
358 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
359 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200360 }
361 }
362
363 val = get_param(cmd, "CHANNEL");
364 if (val) {
365 const char *pos;
366 dut->ap_channel = atoi(val);
367 pos = strchr(val, ';');
368 if (pos) {
369 pos++;
370 dut->ap_channel_1 = atoi(pos);
371 }
372 }
373
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530374 /* Overwrite the AP channel with DFS channel if configured */
375 val = get_param(cmd, "dfs_chan");
376 if (val) {
377 dut->ap_channel = atoi(val);
378 }
379
380 val = get_param(cmd, "dfs_mode");
381 if (val) {
382 if (strcasecmp(val, "Enable") == 0)
383 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
384 else if (strcasecmp(val, "Disable") == 0)
385 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
386 else
387 sigma_dut_print(dut, DUT_MSG_ERROR,
388 "Unsupported dfs_mode value: %s", val);
389 }
390
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200391 val = get_param(cmd, "MODE");
392 if (val) {
393 char *str, *pos;
394
395 str = strdup(val);
396 if (str == NULL)
397 return -1;
398 pos = strchr(str, ';');
399 if (pos)
400 *pos++ = '\0';
401
402 dut->ap_is_dual = 0;
403 dut->ap_mode = get_mode(str);
404 if (dut->ap_mode == AP_inval) {
405 send_resp(dut, conn, SIGMA_INVALID,
406 "errorCode,Unsupported MODE");
407 free(str);
408 return 0;
409 }
410 if (dut->ap_mode == AP_11ac)
411 dut->ap_chwidth = AP_80;
412
413 if (pos) {
414 dut->ap_mode_1 = get_mode(pos);
415 if (dut->ap_mode_1 == AP_inval) {
416 send_resp(dut, conn, SIGMA_INVALID,
417 "errorCode,Unsupported MODE");
418 free(str);
419 return 0;
420 }
421 if (dut->ap_mode_1 == AP_11ac)
422 dut->ap_chwidth_1 = AP_80;
423 dut->ap_is_dual = 1;
424 }
425
426 free(str);
427 } else if (dut->ap_mode == AP_inval) {
428 if (dut->ap_channel <= 11)
429 dut->ap_mode = AP_11ng;
430 else if (dut->program == PROGRAM_VHT)
431 dut->ap_mode = AP_11ac;
432 else
433 dut->ap_mode = AP_11na;
434 }
435
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530436 val = get_param(cmd, "WME");
437 if (val) {
438 if (strcasecmp(val, "on") == 0)
439 dut->ap_wme = AP_WME_ON;
440 else if (strcasecmp(val, "off") == 0)
441 dut->ap_wme = AP_WME_OFF;
442 else
443 sigma_dut_print(dut, DUT_MSG_ERROR,
444 "Unsupported WME value: %s", val);
445 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200446
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530447 val = get_param(cmd, "WMMPS");
448 if (val) {
449 if (strcasecmp(val, "on") == 0)
450 dut->ap_wmmps = AP_WMMPS_ON;
451 else if (strcasecmp(val, "off") == 0)
452 dut->ap_wmmps = AP_WMMPS_OFF;
453 else
454 sigma_dut_print(dut, DUT_MSG_ERROR,
455 "Unsupported WMMPS value: %s", val);
456 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200457
458 val = get_param(cmd, "RTS");
459 if (val)
460 dut->ap_rts = atoi(val);
461
462 val = get_param(cmd, "FRGMNT");
463 if (val)
464 dut->ap_frgmnt = atoi(val);
465
466 /* TODO: PWRSAVE */
467
468 val = get_param(cmd, "BCNINT");
469 if (val)
470 dut->ap_bcnint = atoi(val);
471
472 val = get_param(cmd, "RADIO");
473 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530474 enum driver_type drv = get_driver_type();
475
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200476 if (strcasecmp(val, "on") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200477 if (drv == DRIVER_ATHEROS)
478 ath_ap_start_hostapd(dut);
479 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
480 return 0;
481 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530482 if (drv == DRIVER_OPENWRT) {
483 run_system(dut, "wifi down");
484 sigma_dut_print(dut, DUT_MSG_INFO,
485 "wifi down on radio,off");
486 } else if (kill_process(dut, "(hostapd)", 1,
487 SIGTERM) == 0 ||
488 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200489 sigma_dut_print(dut, DUT_MSG_INFO,
490 "Killed hostapd on radio,off");
491 }
492 } else {
493 send_resp(dut, conn, SIGMA_INVALID,
494 "errorCode,Unsupported RADIO value");
495 return 0;
496 }
497 }
498
499 val = get_param(cmd, "P2PMgmtBit");
500 if (val)
501 dut->ap_p2p_mgmt = atoi(val);
502
503 /* TODO: ChannelUsage */
504
505 /* TODO: 40_INTOLERANT */
506
507 val = get_param(cmd, "ADDBA_REJECT");
508 if (val) {
509 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200510 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200511 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200512 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200513 }
514
515 val = get_param(cmd, "AMPDU");
516 if (val) {
517 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200518 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200519 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200520 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200521 }
522
523 val = get_param(cmd, "AMPDU_EXP");
524 if (val)
525 dut->ap_ampdu_exp = atoi(val);
526
527 val = get_param(cmd, "AMSDU");
528 if (val) {
529 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200530 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200531 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200532 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200533 }
534
535 val = get_param(cmd, "NoAck");
536 if (val) {
537 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200538 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200539 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200540 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200541 }
542
543 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200544 /* TODO: MCS_32 */
545
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530546 val = get_param(cmd, "OFFSET");
547 if (val) {
548 if (strcasecmp(val, "Above") == 0)
549 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
550 else if (strcasecmp(val, "Below") == 0)
551 dut->ap_chwidth_offset = SEC_CH_40BELOW;
552 }
553
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200554 val = get_param(cmd, "MCS_FIXEDRATE");
555 if (val) {
556 dut->ap_fixed_rate = 1;
557 dut->ap_mcs = atoi(val);
558 }
559
560 val = get_param(cmd, "SPATIAL_RX_STREAM");
561 if (val) {
562 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
563 dut->ap_rx_streams = 1;
564 if (dut->device_type == AP_testbed)
565 dut->ap_vhtmcs_map = 0xfffc;
566 } else if (strcasecmp(val, "2SS") == 0 ||
567 strcasecmp(val, "2") == 0) {
568 dut->ap_rx_streams = 2;
569 if (dut->device_type == AP_testbed)
570 dut->ap_vhtmcs_map = 0xfff0;
571 } else if (strcasecmp(val, "3SS") == 0 ||
572 strcasecmp(val, "3") == 0) {
573 dut->ap_rx_streams = 3;
574 if (dut->device_type == AP_testbed)
575 dut->ap_vhtmcs_map = 0xffc0;
576 } else if (strcasecmp(val, "4SS") == 0 ||
577 strcasecmp(val, "4") == 0) {
578 dut->ap_rx_streams = 4;
579 }
580 }
581
582 val = get_param(cmd, "SPATIAL_TX_STREAM");
583 if (val) {
584 if (strcasecmp(val, "1SS") == 0 ||
585 strcasecmp(val, "1") == 0) {
586 dut->ap_tx_streams = 1;
587 if (dut->device_type == AP_testbed)
588 dut->ap_vhtmcs_map = 0xfffc;
589 } else if (strcasecmp(val, "2SS") == 0 ||
590 strcasecmp(val, "2") == 0) {
591 dut->ap_tx_streams = 2;
592 if (dut->device_type == AP_testbed)
593 dut->ap_vhtmcs_map = 0xfff0;
594 } else if (strcasecmp(val, "3SS") == 0 ||
595 strcasecmp(val, "3") == 0) {
596 dut->ap_tx_streams = 3;
597 if (dut->device_type == AP_testbed)
598 dut->ap_vhtmcs_map = 0xffc0;
599 } else if (strcasecmp(val, "4SS") == 0 ||
600 strcasecmp(val, "4") == 0) {
601 dut->ap_tx_streams = 4;
602 }
603 }
604
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700605 val = get_param(cmd, "BSS_max_idle");
606 if (val) {
607 if (strncasecmp(val, "Enable", 7) == 0) {
608 dut->wnm_bss_max_feature = VALUE_ENABLED;
609 } else if (strncasecmp(val, "Disable", 8) == 0) {
610 dut->wnm_bss_max_feature = VALUE_DISABLED;
611 } else {
612 send_resp(dut, conn, SIGMA_ERROR,
613 "errorCode,Invalid value for BSS_max_Feature");
614 return 0;
615 }
616 }
617
618 val = get_param(cmd, "BSS_Idle_Protection_options");
619 if (val) {
620 int protection = (int) strtol(val, (char **) NULL, 10);
621
622 if (protection != 1 && protection != 0) {
623 send_resp(dut, conn, SIGMA_ERROR,
624 "errorCode,Invalid value for BSS_Idle_Protection_options");
625 return 0;
626 }
627 dut->wnm_bss_max_protection = protection ?
628 VALUE_ENABLED : VALUE_DISABLED;
629 }
630
631 val = get_param(cmd, "BSS_max_Idle_period");
632 if (val) {
633 int idle_time = (int) strtol(val, (char **) NULL, 10);
634
635 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
636 send_resp(dut, conn, SIGMA_ERROR,
637 "errorCode,Invalid value for BSS_max_Idle_period");
638 return 0;
639 }
640 dut->wnm_bss_max_idle_time = idle_time;
641 }
642
643 val = get_param(cmd, "PROXY_ARP");
644 if (val)
645 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
646
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200647 val = get_param(cmd, "nss_mcs_cap");
648 if (val) {
649 int nss, mcs;
650 char token[20];
651 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530652 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200653
654 if (strlen(val) >= sizeof(token))
655 return -1;
656 strcpy(token, val);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530657 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530658 if (!result) {
659 sigma_dut_print(dut, DUT_MSG_ERROR,
660 "VHT NSS not specified");
661 return 0;
662 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200663 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530664 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200665 if (result == NULL) {
666 sigma_dut_print(dut, DUT_MSG_ERROR,
667 "VHTMCS NOT SPECIFIED!");
668 return 0;
669 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530670 result = strtok_r(result, "-", &saveptr);
671 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530672 if (!result) {
673 sigma_dut_print(dut, DUT_MSG_ERROR,
674 "VHT MCS not specified");
675 return 0;
676 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200677 mcs = atoi(result);
678 switch (nss) {
679 case 1:
680 switch (mcs) {
681 case 7:
682 dut->ap_vhtmcs_map = 0xfffc;
683 break;
684 case 8:
685 dut->ap_vhtmcs_map = 0xfffd;
686 break;
687 case 9:
688 dut->ap_vhtmcs_map = 0xfffe;
689 break;
690 default:
691 dut->ap_vhtmcs_map = 0xfffe;
692 break;
693 }
694 break;
695 case 2:
696 switch (mcs) {
697 case 7:
698 dut->ap_vhtmcs_map = 0xfff0;
699 break;
700 case 8:
701 dut->ap_vhtmcs_map = 0xfff5;
702 break;
703 case 9:
704 dut->ap_vhtmcs_map = 0xfffa;
705 break;
706 default:
707 dut->ap_vhtmcs_map = 0xfffa;
708 break;
709 }
710 break;
711 case 3:
712 switch (mcs) {
713 case 7:
714 dut->ap_vhtmcs_map = 0xffc0;
715 break;
716 case 8:
717 dut->ap_vhtmcs_map = 0xffd5;
718 break;
719 case 9:
720 dut->ap_vhtmcs_map = 0xffea;
721 break;
722 default:
723 dut->ap_vhtmcs_map = 0xffea;
724 break;
725 }
726 break;
727 default:
728 dut->ap_vhtmcs_map = 0xffea;
729 break;
730 }
731 }
732
733 /* TODO: MPDU_MIN_START_SPACING */
734 /* TODO: RIFS_TEST */
735 /* TODO: SGI20 */
736
737 val = get_param(cmd, "STBC_TX");
738 if (val)
739 dut->ap_tx_stbc = atoi(val);
740
741 val = get_param(cmd, "WIDTH");
742 if (val) {
743 if (strcasecmp(val, "20") == 0)
744 dut->ap_chwidth = AP_20;
745 else if (strcasecmp(val, "40") == 0)
746 dut->ap_chwidth = AP_40;
747 else if (strcasecmp(val, "80") == 0)
748 dut->ap_chwidth = AP_80;
749 else if (strcasecmp(val, "160") == 0)
750 dut->ap_chwidth = AP_160;
751 else if (strcasecmp(val, "Auto") == 0)
752 dut->ap_chwidth = AP_AUTO;
753 else {
754 send_resp(dut, conn, SIGMA_INVALID,
755 "errorCode,Unsupported WIDTH");
756 return 0;
757 }
758 }
759
760 /* TODO: WIDTH_SCAN */
761
762 val = get_param(cmd, "TDLSProhibit");
763 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
764 val = get_param(cmd, "TDLSChswitchProhibit");
765 dut->ap_tdls_prohibit_chswitch =
766 val && strcasecmp(val, "Enabled") == 0;
767 val = get_param(cmd, "HS2");
768 if (val && wlan_tag == 1)
769 dut->ap_hs2 = atoi(val);
770 val = get_param(cmd, "P2P_CROSS_CONNECT");
771 if (val)
772 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
773
774 val = get_param(cmd, "FakePubKey");
775 dut->ap_fake_pkhash = val && atoi(val);
776
777 val = get_param(cmd, "vht_tkip");
778 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
779 val = get_param(cmd, "vht_wep");
780 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
781
782 val = get_param(cmd, "Protect_mode");
783 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
784
785 val = get_param(cmd, "DYN_BW_SGNL");
786 if (val) {
787 switch (get_driver_type()) {
788 case DRIVER_OPENWRT:
789 switch (get_openwrt_driver_type()) {
790 case OPENWRT_DRIVER_ATHEROS:
791 ath_config_dyn_bw_sig(dut, ifname, val);
792 break;
793 default:
794 send_resp(dut, conn, SIGMA_ERROR,
795 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
796 return 0;
797 }
798 break;
799 default:
800 sigma_dut_print(dut, DUT_MSG_ERROR,
801 "Unsupported DYN_BW_SGL with the current driver");
802 break;
803 }
804 }
805
806 val = get_param(cmd, "SGI80");
807 if (val) {
808 if (strcasecmp(val, "enable") == 0)
809 dut->ap_sgi80 = 1;
810 else if (strcasecmp(val, "disable") == 0)
811 dut->ap_sgi80 = 0;
812 else {
813 send_resp(dut, conn, SIGMA_INVALID,
814 "errorCode,Unsupported SGI80");
815 return 0;
816 }
817 }
818
819 val = get_param(cmd, "LDPC");
820 if (val) {
821 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200822 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200823 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200824 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200825 else {
826 send_resp(dut, conn, SIGMA_INVALID,
827 "errorCode,Unsupported LDPC");
828 return 0;
829 }
830 }
831
832 val = get_param(cmd, "BW_SGNL");
833 if (val) {
834 /*
835 * With dynamic bandwidth signaling enabled we should see
836 * RTS if the threshold is met.
837 */
838 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200839 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200840 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200841 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200842 } else {
843 send_resp(dut, conn, SIGMA_INVALID,
844 "errorCode,Unsupported BW_SGNL");
845 return 0;
846 }
847 }
848
849 val = get_param(cmd, "RTS_FORCE");
850 if (val) {
851 switch (get_driver_type()) {
852 case DRIVER_OPENWRT:
853 switch (get_openwrt_driver_type()) {
854 case OPENWRT_DRIVER_ATHEROS:
855 ath_config_rts_force(dut, ifname, val);
856 break;
857 default:
858 send_resp(dut, conn, SIGMA_ERROR,
859 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
860 return 0;
861 }
862 break;
863 default:
864 sigma_dut_print(dut, DUT_MSG_ERROR,
865 "Unsupported RTS_FORCE with the current driver");
866 break;
867 }
868 }
869
870 val = get_param(cmd, "Zero_crc");
871 if (val) {
872 switch (get_driver_type()) {
873 case DRIVER_ATHEROS:
874 ath_set_zero_crc(dut, val);
875 break;
876 case DRIVER_OPENWRT:
877 switch (get_openwrt_driver_type()) {
878 case OPENWRT_DRIVER_ATHEROS:
879 ath_set_zero_crc(dut, val);
880 break;
881 default:
882 send_resp(dut, conn, SIGMA_ERROR,
883 "errorCode,Unsupported zero_crc with the current driver");
884 return 0;
885 }
886 break;
887 default:
888 send_resp(dut, conn, SIGMA_ERROR,
889 "errorCode,Unsupported zero_crc with the current driver");
890 return 0;
891 }
892 }
893
894 val = get_param(cmd, "TxBF");
895 if (val)
896 dut->ap_txBF = strcasecmp(val, "enable") == 0;
897
898 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +0530899 if (val) {
900 if (strcasecmp(val, "enable") == 0) {
901 dut->ap_txBF = 1;
902 dut->ap_mu_txBF = 1;
903 } else if (strcasecmp(val, "disable") == 0) {
904 dut->ap_txBF = 0;
905 dut->ap_mu_txBF = 0;
906 } else {
907 sigma_dut_print(dut, DUT_MSG_ERROR,
908 "Unsupported MU_TxBF");
909 }
910 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911
912 /* UNSUPPORTED: tx_lgi_rate */
913
914 val = get_param(cmd, "wpsnfc");
915 if (val)
916 dut->ap_wpsnfc = atoi(val);
917
918 val = get_param(cmd, "GROUP_ID");
919 if (val) {
920 switch (get_driver_type()) {
921 case DRIVER_OPENWRT:
922 switch (get_openwrt_driver_type()) {
923 case OPENWRT_DRIVER_ATHEROS:
924 ath_ap_set_group_id(dut, ifname, val);
925 break;
926 default:
927 send_resp(dut, conn, SIGMA_ERROR,
928 "errorCode,Unsupported group_id with the current driver");
929 return 0;
930 }
931 break;
932 default:
933 send_resp(dut, conn, SIGMA_ERROR,
934 "errorCode,Unsupported group_id with the current driver");
935 return 0;
936 }
937 }
938
939 val = get_param(cmd, "CTS_WIDTH");
940 if (val) {
941 switch (get_driver_type()) {
942 case DRIVER_OPENWRT:
943 switch (get_openwrt_driver_type()) {
944 case OPENWRT_DRIVER_ATHEROS:
945 ath_set_cts_width(dut, ifname, val);
946 break;
947 default:
948 send_resp(dut, conn, SIGMA_ERROR,
949 "errorCode,Unsupported cts_width with the current driver");
950 return 0;
951 }
952 break;
953 default:
954 send_resp(dut, conn, SIGMA_ERROR,
955 "errorCode,Unsupported cts_width with the current driver");
956 return 0;
957 }
958 }
959
priyadharshini gowthaman264d5442016-02-25 15:52:22 -0800960 val = get_param(cmd, "MU_NDPA_FrameFormat");
961 if (val)
962 dut->ap_ndpa_frame = atoi(val);
963
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -0700964 val = get_param(cmd, "interworking");
965 if (val && strcmp(val, "1") == 0)
966 dut->ap_interworking = 1;
967
968 val = get_param(cmd, "GAS_CB_DELAY");
969 if (val)
970 dut->ap_gas_cb_delay = atoi(val);
971
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700972 val = get_param(cmd, "LCI");
973 if (val) {
974 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
975 return -1;
976 dut->ap_lci = 1;
977 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
978 ath_set_lci_config(dut, val, cmd);
979 }
980
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -0700981 val = get_param(cmd, "InfoZ");
982 if (val) {
983 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
984 return -1;
985 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
986 }
987
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700988 val = get_param(cmd, "LocCivicAddr");
989 if (val) {
990 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
991 return -1;
992 dut->ap_lcr = 1;
993 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
994 if (dut->ap_lci == 0)
995 ath_set_lci_config(dut, val, cmd);
996 }
997
998 val = get_param(cmd, "NeighAPBSSID");
999 if (val) {
1000 if (dut->ap_neighap < 3) {
1001 if (parse_mac_address(
1002 dut, val,
1003 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1004 send_resp(dut, conn, SIGMA_INVALID,
1005 "Failed to parse MAC address");
1006 return 0;
1007 }
1008 dut->ap_neighap++;
1009 if (dut->ap_lci == 1)
1010 dut->ap_scan = 1;
1011 }
1012 }
1013
1014 val = get_param(cmd, "OpChannel");
1015 if (val) {
1016 if (dut->ap_opchannel < 3) {
1017 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1018 dut->ap_opchannel++;
1019 }
1020 }
1021
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001022 val = get_param(cmd, "URI-FQDNdescriptor");
1023 if (val) {
1024 if (strcasecmp(val, "HELD") == 0) {
1025 dut->ap_fqdn_held = 1;
1026 } else if (strcasecmp(val, "SUPL") == 0) {
1027 dut->ap_fqdn_supl = 1;
1028 } else {
1029 send_resp(dut, conn, SIGMA_INVALID,
1030 "errorCode,Unsupported URI-FQDNdescriptor");
1031 return 0;
1032 }
1033 }
1034
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001035 val = get_param(cmd, "Reg_Domain");
1036 if (val) {
1037 if (strcasecmp(val, "Local") == 0) {
1038 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1039 } else if (strcasecmp(val, "Global") == 0) {
1040 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1041 } else {
1042 send_resp(dut, conn, SIGMA_ERROR,
1043 "errorCode,Wrong value for Reg_Domain");
1044 return 0;
1045 }
1046 }
1047
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001048 val = get_param(cmd, "NAME");
1049 if (val) {
1050 if (strcasecmp(val, "ap1mbo") == 0)
1051 dut->ap_name = 1;
1052 else if (strcasecmp(val, "ap2mbo") == 0)
1053 dut->ap_name = 2;
1054 else
1055 dut->ap_name = 0;
1056 }
1057
1058 val = get_param(cmd, "FT_OA");
1059 if (val) {
1060 if (strcasecmp(val, "Enable") == 0) {
1061 dut->ap_ft_oa = 1;
1062 } else if (strcasecmp(val, "Disable") == 0) {
1063 dut->ap_ft_oa = 0;
1064 } else {
1065 send_resp(dut, conn, SIGMA_ERROR,
1066 "errorCode,Wrong value for FT_OA");
1067 return 0;
1068 }
1069 }
1070
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001071 val = get_param(cmd, "Cellular_Cap_Pref");
1072 if (val)
1073 dut->ap_cell_cap_pref = atoi(val);
1074
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001075 val = get_param(cmd, "DOMAIN");
1076 if (val) {
1077 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1078 send_resp(dut, conn, SIGMA_ERROR,
1079 "errorCode,Too long DOMAIN");
1080 return 0;
1081 }
1082 snprintf(dut->ap_mobility_domain,
1083 sizeof(dut->ap_mobility_domain), "%s", val);
1084 }
1085
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001086 val = get_param(cmd, "ft_bss_list");
1087 if (val) {
1088 char *mac_str;
1089 int i;
1090 char *saveptr;
1091 char *mac_list_str;
1092
1093 mac_list_str = strdup(val);
1094 if (!mac_list_str)
1095 return -1;
1096 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1097 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1098 if (parse_mac_address(dut, mac_str,
1099 dut->ft_bss_mac_list[i]) < 0) {
1100 sigma_dut_print(dut, DUT_MSG_ERROR,
1101 "MAC Address not in proper format");
1102 break;
1103 }
1104 dut->ft_bss_mac_cnt++;
1105 mac_str = strtok_r(NULL, " ", &saveptr);
1106 }
1107 sigma_dut_print(dut, DUT_MSG_DEBUG,
1108 "Storing the following FT BSS MAC List");
1109 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1110 sigma_dut_print(dut, DUT_MSG_DEBUG,
1111 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1112 i,
1113 dut->ft_bss_mac_list[i][0],
1114 dut->ft_bss_mac_list[i][1],
1115 dut->ft_bss_mac_list[i][2],
1116 dut->ft_bss_mac_list[i][3],
1117 dut->ft_bss_mac_list[i][4],
1118 dut->ft_bss_mac_list[i][5]);
1119 }
1120 free(mac_list_str);
1121 }
1122
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001123 return 1;
1124}
1125
1126
1127static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1128{
1129 char buf[256];
1130 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1131
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301132 if (tid < 0 ||
1133 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1134 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1135 return;
1136 }
1137
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001138 snprintf(buf, sizeof(buf),
1139 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1140 ifname, VI_QOS_TMP_FILE);
1141 if (system(buf) != 0)
1142 return;
1143
1144 snprintf(buf, sizeof(buf),
1145 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1146 ifname, VI_QOS_TMP_FILE);
1147 if (system(buf) != 0)
1148 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1149
1150 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1151 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1152 if (system(buf) != 0) {
1153 sigma_dut_print(dut, DUT_MSG_ERROR,
1154 "Output redirection to VI_QOS_TMP_FILE failed");
1155 }
1156
1157 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1158 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1159 if (system(buf) != 0) {
1160 sigma_dut_print(dut, DUT_MSG_ERROR,
1161 "Append TID to VI_QOS_FILE failed ");
1162 }
1163
1164 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1165 if (system(buf) != 0)
1166 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1167}
1168
1169
1170static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1171 struct sigma_cmd *cmd)
1172{
1173 const char *val;
1174 char *ifname;
1175 char buf[256];
1176 int tid = 0;
1177
1178 ifname = get_main_ifname();
1179 val = get_param(cmd, "TID");
1180 if (val) {
1181 tid = atoi(val);
1182 if (tid)
1183 ath_inject_frame(dut, ifname, tid);
1184 }
1185
1186 /* NOTE: This is the command sequence on Peregrine for ADDBA */
1187 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
1188 if (system(buf) != 0) {
1189 sigma_dut_print(dut, DUT_MSG_ERROR,
1190 "iwpriv setaddbaoper failed");
1191 }
1192
1193 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1194 ifname, tid);
1195 if (system(buf) != 0) {
1196 sigma_dut_print(dut, DUT_MSG_ERROR,
1197 "wifitool senddelba failed");
1198 }
1199
1200 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1201 ifname, tid);
1202 if (system(buf) != 0) {
1203 sigma_dut_print(dut, DUT_MSG_ERROR,
1204 "wifitool sendaddba failed");
1205 }
1206
1207 return 1;
1208}
1209
1210
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301211static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1212 const char *sta_mac,
1213 const char *dir_path)
1214{
1215 DIR *dir;
1216 struct dirent *entry;
1217 char buf[128], path[128];
1218 int ret = 0;
1219
1220 dir = opendir(dir_path);
1221 if (!dir)
1222 return 0;
1223
1224 while ((entry = readdir(dir))) {
1225 ret = 1;
1226
1227 if (strcmp(entry->d_name, ".") == 0 ||
1228 strcmp(entry->d_name, "..") == 0)
1229 continue;
1230
1231 snprintf(path, sizeof(path) - 1, "%s/%s",
1232 dir_path, entry->d_name);
1233 path[sizeof(path) - 1] = 0;
1234
1235 if (strcmp(entry->d_name, sta_mac) == 0) {
1236 snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode",
1237 path);
1238 if (system(buf) != 0) {
1239 sigma_dut_print(dut, DUT_MSG_ERROR,
1240 "Failed to set aggr mode for ath10k");
1241 }
1242
1243 snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba",
1244 tid, path);
1245 if (system(buf) != 0) {
1246 sigma_dut_print(dut, DUT_MSG_ERROR,
1247 "Failed to set addbareq for ath10k");
1248 }
1249
1250 break;
1251 }
1252
1253 /* Recursively search subdirectories */
1254 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1255 }
1256
1257 closedir(dir);
1258
1259 return ret;
1260}
1261
1262
1263static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1264 struct sigma_cmd *cmd)
1265{
1266 const char *val;
1267 int tid = 0;
1268
1269 val = get_param(cmd, "TID");
1270 if (val)
1271 tid = atoi(val);
1272
1273 val = get_param(cmd, "sta_mac_address");
1274 if (!val) {
1275 sigma_dut_print(dut, DUT_MSG_ERROR,
1276 "Failed to parse station MAC address");
1277 return 0;
1278 }
1279
1280 return ath10k_debug_enable_addba_req(dut, tid, val,
1281 "/sys/kernel/debug/ieee80211");
1282}
1283
1284
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001285static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1286 struct sigma_cmd *cmd)
1287{
1288 /* const char *name = get_param(cmd, "NAME"); */
1289 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301290 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001291
1292 switch (get_driver_type()) {
1293 case DRIVER_ATHEROS:
1294 return ath_ap_send_addba_req(dut, conn, cmd);
1295 case DRIVER_OPENWRT:
1296 switch (get_openwrt_driver_type()) {
1297 case OPENWRT_DRIVER_ATHEROS:
1298 return ath_ap_send_addba_req(dut, conn, cmd);
1299 default:
1300 send_resp(dut, conn, SIGMA_ERROR,
1301 "errorCode,ap_send_addba_req not supported with this driver");
1302 return 0;
1303 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301304 case DRIVER_WCN:
1305 case DRIVER_LINUX_WCN:
1306 /* AP automatically sends ADDBA request after association. */
1307 sigma_dut_print(dut, DUT_MSG_INFO,
1308 "ap_send_addba_req command ignored");
1309 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301310 case DRIVER_MAC80211:
1311 if (stat("/sys/module/ath10k_core", &s) == 0)
1312 return ath10k_ap_send_addba_req(dut, cmd);
1313 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001314 default:
1315 send_resp(dut, conn, SIGMA_ERROR,
1316 "errorCode,ap_send_addba_req not supported with this driver");
1317 return 0;
1318 }
1319}
1320
1321
1322static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1323 struct sigma_cmd *cmd)
1324{
1325 /* const char *name = get_param(cmd, "NAME"); */
1326 const char *val;
1327 unsigned int wlan_tag = 1;
1328
1329 val = get_param(cmd, "WLAN_TAG");
1330 if (val)
1331 wlan_tag = atoi(val);
1332
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001333 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001334 val = get_param(cmd, "KEYMGNT");
1335 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001336 if (strcasecmp(val, "NONE") == 0) {
1337 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1338 } else if (strcasecmp(val, "OSEN") == 0 &&
1339 wlan_tag == 2) {
1340 /*
1341 * OSEN only supported on WLAN_TAG = 2 for now
1342 */
1343 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
1344 } else if (strcasecmp(val, "WPA2-PSK") == 0) {
1345 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1346 AP2_WPA2_PSK;
1347 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001348 send_resp(dut, conn, SIGMA_INVALID,
1349 "errorCode,Unsupported KEYMGNT");
1350 return 0;
1351 }
1352 return 1;
1353 }
1354 }
1355
1356 val = get_param(cmd, "KEYMGNT");
1357 if (val) {
1358 if (strcasecmp(val, "WPA2-PSK") == 0) {
1359 dut->ap_key_mgmt = AP_WPA2_PSK;
1360 dut->ap_cipher = AP_CCMP;
1361 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1362 strcasecmp(val, "WPA2-Ent") == 0) {
1363 dut->ap_key_mgmt = AP_WPA2_EAP;
1364 dut->ap_cipher = AP_CCMP;
1365 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1366 dut->ap_key_mgmt = AP_WPA_PSK;
1367 dut->ap_cipher = AP_TKIP;
1368 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1369 strcasecmp(val, "WPA-Ent") == 0) {
1370 dut->ap_key_mgmt = AP_WPA_EAP;
1371 dut->ap_cipher = AP_TKIP;
1372 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1373 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1374 dut->ap_cipher = AP_CCMP_TKIP;
1375 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1376 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1377 dut->ap_cipher = AP_CCMP_TKIP;
1378 } else if (strcasecmp(val, "NONE") == 0) {
1379 dut->ap_key_mgmt = AP_OPEN;
1380 dut->ap_cipher = AP_PLAIN;
1381 } else {
1382 send_resp(dut, conn, SIGMA_INVALID,
1383 "errorCode,Unsupported KEYMGNT");
1384 return 0;
1385 }
1386 }
1387
1388 val = get_param(cmd, "ENCRYPT");
1389 if (val) {
1390 if (strcasecmp(val, "WEP") == 0) {
1391 dut->ap_cipher = AP_WEP;
1392 } else if (strcasecmp(val, "TKIP") == 0) {
1393 dut->ap_cipher = AP_TKIP;
1394 } else if (strcasecmp(val, "AES") == 0 ||
1395 strcasecmp(val, "AES-CCMP") == 0) {
1396 dut->ap_cipher = AP_CCMP;
1397 } else {
1398 send_resp(dut, conn, SIGMA_INVALID,
1399 "errorCode,Unsupported ENCRYPT");
1400 return 0;
1401 }
1402 }
1403
1404 val = get_param(cmd, "WEPKEY");
1405 if (val) {
1406 size_t len;
1407 if (dut->ap_cipher != AP_WEP) {
1408 send_resp(dut, conn, SIGMA_INVALID,
1409 "errorCode,Unexpected WEPKEY without WEP "
1410 "configuration");
1411 return 0;
1412 }
1413 len = strlen(val);
1414 if (len != 10 && len != 26) {
1415 send_resp(dut, conn, SIGMA_INVALID,
1416 "errorCode,Unexpected WEPKEY length");
1417 return 0;
1418 }
1419 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1420 }
1421
1422 val = get_param(cmd, "PSK");
1423 if (val) {
1424 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1425 return -1;
1426 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1427 "%s", val);
1428 }
1429
1430 val = get_param(cmd, "PMF");
1431 if (val) {
1432 if (strcasecmp(val, "Disabled") == 0) {
1433 dut->ap_pmf = AP_PMF_DISABLED;
1434 } else if (strcasecmp(val, "Optional") == 0) {
1435 dut->ap_pmf = AP_PMF_OPTIONAL;
1436 } else if (strcasecmp(val, "Required") == 0) {
1437 dut->ap_pmf = AP_PMF_REQUIRED;
1438 } else {
1439 send_resp(dut, conn, SIGMA_INVALID,
1440 "errorCode,Unsupported PMF");
1441 return 0;
1442 }
1443 }
1444
1445 if (dut->ap_key_mgmt == AP_OPEN) {
1446 dut->ap_hs2 = 0;
1447 dut->ap_pmf = AP_PMF_DISABLED;
1448 }
1449
1450 dut->ap_add_sha256 = 0;
1451 val = get_param(cmd, "SHA256AD");
1452 if (val == NULL)
1453 val = get_param(cmd, "SHA256");
1454 if (val) {
1455 if (strcasecmp(val, "Disabled") == 0) {
1456 } else if (strcasecmp(val, "Enabled") == 0) {
1457 dut->ap_add_sha256 = 1;
1458 } else {
1459 send_resp(dut, conn, SIGMA_INVALID,
1460 "errorCode,Unsupported PMF");
1461 return 0;
1462 }
1463 }
1464
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301465 val = get_param(cmd, "PreAuthentication");
1466 if (val) {
1467 if (strcasecmp(val, "disabled") == 0) {
1468 dut->ap_rsn_preauth = 0;
1469 } else if (strcasecmp(val, "enabled") == 0) {
1470 dut->ap_rsn_preauth = 1;
1471 } else {
1472 send_resp(dut, conn, SIGMA_INVALID,
1473 "errorCode,Unsupported PreAuthentication value");
1474 return 0;
1475 }
1476 }
1477
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001478 return 1;
1479}
1480
1481
1482static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
1483 struct sigma_cmd *cmd)
1484{
1485 /* const char *name = get_param(cmd, "NAME"); */
1486 const char *val;
1487 unsigned int wlan_tag = 1, radius_port = 0;
1488 char *radius_ipaddr = NULL, *radius_password = NULL;
1489
1490 val = get_param(cmd, "WLAN_TAG");
1491 if (val) {
1492 wlan_tag = atoi(val);
1493 if (wlan_tag != 1 && wlan_tag != 2) {
1494 send_resp(dut, conn, SIGMA_INVALID,
1495 "errorCode,Invalid WLAN_TAG");
1496 return 0;
1497 }
1498 }
1499
1500 val = get_param(cmd, "PORT");
1501 if (val)
1502 radius_port = atoi(val);
1503
1504 if (wlan_tag == 1) {
1505 if (radius_port)
1506 dut->ap_radius_port = radius_port;
1507 radius_ipaddr = dut->ap_radius_ipaddr;
1508 radius_password = dut->ap_radius_password;
1509 } else if (wlan_tag == 2) {
1510 if (radius_port)
1511 dut->ap2_radius_port = radius_port;
1512 radius_ipaddr = dut->ap2_radius_ipaddr;
1513 radius_password = dut->ap2_radius_password;
1514 }
1515
1516 val = get_param(cmd, "IPADDR");
1517 if (val) {
1518 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
1519 return -1;
1520 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
1521 "%s", val);
1522 }
1523
1524 val = get_param(cmd, "PASSWORD");
1525 if (val) {
1526 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
1527 return -1;
1528 snprintf(radius_password,
1529 sizeof(dut->ap_radius_password), "%s", val);
1530 }
1531
1532 return 1;
1533}
1534
1535
1536static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
1537 const char *key, const char *val)
1538{
1539 char buf[100];
1540
1541 if (val == NULL) {
1542 snprintf(buf, sizeof(buf),
1543 "uci delete wireless.wifi%d.%s", id, key);
1544 run_system(dut, buf);
1545 return;
1546 }
1547
1548 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
1549 id, key, val);
1550 run_system(dut, buf);
1551}
1552
1553
1554static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
1555 const char *key, const char *val)
1556{
1557 char buf[256];
1558
1559 if (val == NULL) {
1560 snprintf(buf, sizeof(buf),
1561 "uci del_list wireless.wifi%d.%s", id, key);
1562 run_system(dut, buf);
1563 return;
1564 }
1565
1566 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
1567 id, key, val);
1568 run_system(dut, buf);
1569}
1570
1571
1572static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
1573 const char *val)
1574{
1575 char buf[256];
1576
1577 if (val == NULL) {
1578 snprintf(buf, sizeof(buf),
1579 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1580 run_system(dut, buf);
1581 return;
1582 }
1583
1584 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1585 id, key, val);
1586 run_system(dut, buf);
1587}
1588
1589
1590static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
1591 const char *key, const char *val)
1592{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07001593 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001594
1595 if (val == NULL) {
1596 snprintf(buf, sizeof(buf),
1597 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
1598 run_system(dut, buf);
1599 return;
1600 }
1601
1602 snprintf(buf, sizeof(buf),
1603 "uci add_list wireless.@wifi-iface[%d].%s=%s",
1604 id, key, val);
1605 run_system(dut, buf);
1606}
1607
1608
1609static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
1610 const char *val)
1611{
1612 char buf[256];
1613
1614 if (val == NULL) {
1615 snprintf(buf, sizeof(buf),
1616 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1617 run_system(dut, buf);
1618 return;
1619 }
1620
1621 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
1622 run_system(dut, buf);
1623 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1624 id, key, val);
1625 run_system(dut, buf);
1626 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1627 id, "network", "lan");
1628 run_system(dut, buf);
1629 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1630 id, "mode", "ap");
1631 run_system(dut, buf);
1632 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1633 id, "encryption", "none");
1634 run_system(dut, buf);
1635}
1636
1637
1638#define OPENWRT_MAX_NUM_RADIOS 3
1639static void owrt_ap_config_radio(struct sigma_dut *dut)
1640{
1641 int radio_id[MAX_RADIO] = { 0, 1 };
1642 int radio_count, radio_no;
1643 char buf[64];
1644
1645 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
1646 radio_count++) {
1647 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
1648 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
1649 if (!sigma_radio_ifname[radio_no] ||
1650 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
1651 continue;
1652 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
1653 owrt_ap_set_vap(dut, radio_count, "device", buf);
1654 radio_id[radio_no] = radio_count;
1655 }
1656 }
1657
1658 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1659 switch (dut->ap_mode) {
1660 case AP_11g:
1661 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
1662 break;
1663 case AP_11b:
1664 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
1665 break;
1666 case AP_11ng:
1667 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1668 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1669 break;
1670 case AP_11a:
1671 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
1672 break;
1673 case AP_11na:
1674 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
1675 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1676 break;
1677 case AP_11ac:
1678 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
1679 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1680 break;
1681 case AP_inval:
1682 sigma_dut_print(dut, DUT_MSG_ERROR,
1683 "MODE NOT SPECIFIED!");
1684 return;
1685 default:
1686 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1687 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1688 break;
1689 }
1690
1691 if (dut->ap_is_dual) {
1692 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1693 switch (dut->ap_mode_1) {
1694 case AP_11g:
1695 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
1696 break;
1697 case AP_11b:
1698 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
1699 break;
1700 case AP_11ng:
1701 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1702 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1703 break;
1704 case AP_11a:
1705 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
1706 break;
1707 case AP_11na:
1708 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
1709 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1710 break;
1711 case AP_11ac:
1712 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
1713 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
1714 break;
1715 case AP_inval:
1716 sigma_dut_print(dut, DUT_MSG_ERROR,
1717 "MODE NOT SPECIFIED!");
1718 return;
1719 default:
1720 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1721 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1722 break;
1723 }
1724
1725 }
1726
1727 /* Channel */
1728 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
1729 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
1730
1731 switch (dut->ap_chwidth) {
1732 case AP_20:
1733 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1734 break;
1735 case AP_40:
1736 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
1737 break;
1738 case AP_80:
1739 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1740 break;
1741 case AP_160:
1742 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
1743 break;
1744 case AP_AUTO:
1745 default:
1746 break;
1747 }
1748
1749 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
1750 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
1751 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
1752 }
1753
1754 if (dut->ap_is_dual) {
1755 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
1756 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
1757 }
1758
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001759 /* Country Code */
1760 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
1761 const char *country;
1762
1763 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
1764 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001765 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001766 } else if (dut->ap_countrycode[0]) {
1767 owrt_ap_set_radio(dut, radio_id[0], "country",
1768 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001769 }
1770
1771 if (dut->ap_disable_protection == 1) {
1772 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
1773 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
1774 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
1775 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
1776 }
1777}
1778
1779
1780static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
1781{
1782 char buf[256];
1783
1784 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
1785 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
1786 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
1787 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
1788
1789 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1790 "'eng:Wi-Fi Alliance'");
1791
1792 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1793 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
1794
1795 if (dut->ap_wan_metrics == 1)
1796 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1797 "'01:2500:384:0:0:10'");
1798 else if (dut->ap_wan_metrics == 1)
1799 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1800 "'01:1500:384:20:20:10'");
1801 else if (dut->ap_wan_metrics == 2)
1802 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1803 "'01:1500:384:20:20:10'");
1804 else if (dut->ap_wan_metrics == 3)
1805 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1806 "'01:2000:1000:20:20:10'");
1807 else if (dut->ap_wan_metrics == 4)
1808 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1809 "'01:8000:1000:20:20:10'");
1810 else if (dut->ap_wan_metrics == 5)
1811 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1812 "'01:9000:5000:20:20:10'");
1813
1814 if (dut->ap_conn_capab == 1) {
1815 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
1816 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1817 "'6:20:1'");
1818 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1819 "'6:22:0'");
1820 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1821 "'6:80:1'");
1822 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1823 "'6:443:1'");
1824 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1825 "'6:1723:0'");
1826 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1827 "'6:5060:0'");
1828 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1829 "'17:500:1'");
1830 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1831 "'17:5060:0'");
1832 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1833 "'17:4500:1'");
1834 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1835 "'50:0:1'");
1836 } else if (dut->ap_conn_capab == 2) {
1837 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1838 "'6:80:1'");
1839 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1840 "'6:443:1'");
1841 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1842 "'17:5060:1'");
1843 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1844 "'6:5060:1'");
1845 } else if (dut->ap_conn_capab == 3) {
1846 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1847 "'6:80:1'");
1848 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1849 "'6:443:1'");
1850 }
1851
1852 if (dut->ap_oper_class == 1)
1853 snprintf(buf, sizeof(buf), "%s", "51");
1854 else if (dut->ap_oper_class == 2)
1855 snprintf(buf, sizeof(buf), "%s", "73");
1856 else if (dut->ap_oper_class == 3)
1857 snprintf(buf, sizeof(buf), "%s", "5173");
1858
1859 if (dut->ap_oper_class)
1860 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
1861
1862 if (dut->ap_osu_provider_list) {
1863 char *osu_friendly_name = NULL;
1864 char *osu_icon = NULL;
1865 char *osu_ssid = NULL;
1866 char *osu_nai = NULL;
1867 char *osu_service_desc = NULL;
1868 char *hs20_icon_filename = NULL;
1869 char hs20_icon[150];
1870 int osu_method;
1871
1872 hs20_icon_filename = "icon_red_zxx.png";
1873 if (dut->ap_osu_icon_tag == 2)
1874 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1875 snprintf(hs20_icon, sizeof(hs20_icon),
1876 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
1877 hs20_icon_filename);
1878 osu_icon = "icon_red_zxx.png";
1879 osu_ssid = "OSU";
1880 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
1881 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
1882 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
1883 dut->ap_osu_method[0];
1884
1885 if (strlen(dut->ap_osu_server_uri[0]))
1886 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
1887 dut->ap_osu_server_uri[0]);
1888 else
1889 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
1890 "'https://osu-server.r2-testbed.wi-fi.org/'");
1891 switch (dut->ap_osu_provider_list) {
1892 case 1:
1893 case 101:
1894 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1895 "'eng:SP Red Test Only'");
1896 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1897 "'eng:Free service for test purpose'");
1898 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1899 hs20_icon);
1900
1901 hs20_icon_filename = "icon_red_eng.png";
1902 if (dut->ap_osu_icon_tag == 2)
1903 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1904
1905 snprintf(hs20_icon, sizeof(hs20_icon),
1906 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
1907 hs20_icon_filename);
1908 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1909 "icon_red_eng.png");
1910 break;
1911 case 2:
1912 case 102:
1913 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1914 "'eng:Wireless Broadband Alliance'");
1915 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1916 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001917 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001918 if (dut->ap_osu_icon_tag == 2)
1919 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1920
1921 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001922 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001923 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001924 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001925 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
1926 break;
1927 case 3:
1928 case 103:
1929 osu_friendly_name = "spa:SP Red Test Only";
1930 osu_service_desc = "spa:Free service for test purpose";
1931 break;
1932 case 4:
1933 case 104:
1934 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001935 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1937 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001938 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (dut->ap_osu_icon_tag == 2)
1940 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1941
1942 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001943 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944 hs20_icon_filename);
1945 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1946 hs20_icon);
1947 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
1948
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001949 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001950 if (dut->ap_osu_icon_tag == 2)
1951 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1952
1953 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001954 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001956 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001957 break;
1958 case 5:
1959 case 105:
1960 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001961 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1963 "'eng:Free service for test purpose'");
1964 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
1965
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001966 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001967 if (dut->ap_osu_icon_tag == 2)
1968 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1969
1970 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001971 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03001973 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001974 break;
1975 case 6:
1976 case 106:
1977 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1978 "'eng:SP Green Test Only'");
1979 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1980 "'kor:SP 초록 테스트 전용'");
1981
1982 hs20_icon_filename = "icon_green_zxx.png";
1983 if (dut->ap_osu_icon_tag == 2)
1984 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1985
1986 snprintf(hs20_icon, sizeof(hs20_icon),
1987 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
1988 hs20_icon_filename);
1989 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1990 hs20_icon);
1991
1992 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1993 "'icon_green_zxx.png'");
1994 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
1995 dut->ap_osu_method[0];
1996
1997 snprintf(buf, sizeof(buf), "%d", osu_method);
1998 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
1999
2000 if (strlen(dut->ap_osu_server_uri[1]))
2001 owrt_ap_set_list_vap(dut, vap_id,
2002 "osu_server_uri",
2003 dut->ap_osu_server_uri[1]);
2004 else
2005 owrt_ap_set_list_vap(dut, vap_id,
2006 "osu_server_uri",
2007 "'https://osu-server.r2-testbed.wi-fi.org/'");
2008
2009 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2010 "'eng:SP Orange Test Only'");
2011
2012 hs20_icon_filename = "icon_orange_zxx.png";
2013 if (dut->ap_osu_icon_tag == 2)
2014 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2015
2016 snprintf(hs20_icon, sizeof(hs20_icon),
2017 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2018 hs20_icon_filename);
2019
2020 osu_icon = "icon_orange_zxx.png";
2021 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2022 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2023 dut->ap_osu_method[1];
2024 osu_service_desc = NULL;
2025 break;
2026 case 7:
2027 case 107:
2028 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002029 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002030 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2031 "'eng:Free service for test purpose'");
2032
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002033 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002034 if (dut->ap_osu_icon_tag == 2)
2035 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2036
2037 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002038 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002039 hs20_icon_filename);
2040 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2041 hs20_icon);
2042
2043 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002044 "'icon_green_eng.png'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002045 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2046
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002047 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002048 if (dut->ap_osu_icon_tag == 2)
2049 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2050
2051 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002052 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002053 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002054 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002055 break;
2056 case 8:
2057 case 108:
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 osu_ssid = "OSU-Encrypted";
2063 osu_nai = "'anonymous@hotspot.net'";
2064 break;
2065 case 9:
2066 case 109:
2067 osu_ssid = "OSU-OSEN";
2068 osu_nai = "'test-anonymous@wi-fi.org'";
2069 osu_friendly_name = "'eng:SP Orange Test Only'";
2070 hs20_icon_filename = "icon_orange_zxx.png";
2071 if (dut->ap_osu_icon_tag == 2)
2072 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2073
2074 snprintf(hs20_icon, sizeof(hs20_icon),
2075 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2076 hs20_icon_filename);
2077 osu_icon = "icon_orange_zxx.png";
2078 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2079 dut->ap_osu_method[0];
2080 osu_service_desc = NULL;
2081 break;
2082 default:
2083 break;
2084 }
2085
2086 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002087 if (strcmp(dut->ap_tag_ssid[0],
2088 dut->ap_osu_ssid) != 0 &&
2089 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002090 sigma_dut_print(dut, DUT_MSG_ERROR,
2091 "OSU_SSID and WLAN_TAG2 SSID differ");
2092 return -2;
2093 }
2094
2095 snprintf(buf, sizeof(buf), "'\"%s\"'",
2096 dut->ap_osu_ssid);
2097 } else {
2098 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2099 }
2100
2101 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2102
2103
2104 if (osu_friendly_name)
2105 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2106 osu_friendly_name);
2107 if (osu_service_desc)
2108 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2109 osu_service_desc);
2110 if (osu_nai)
2111 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2112
2113 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2114
2115 if (osu_icon)
2116 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2117 osu_icon);
2118
2119 if (dut->ap_osu_provider_list > 100) {
2120 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2121 "0");
2122 } else {
2123 snprintf(buf, sizeof(buf), "%d", osu_method);
2124 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2125 buf);
2126 }
2127 }
2128
2129 return 0;
2130}
2131
2132
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002133static void set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2134 char *anqp_string, size_t str_size)
2135{
2136 unsigned char bssid[ETH_ALEN];
2137 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2138 int preference = 0xff;
2139
2140 get_hwaddr(ifname, bssid);
2141 snprintf(anqp_string, str_size,
2142 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2143 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2144 preference,
2145 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2146 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2147 preference - 1);
2148}
2149
2150
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002151static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2152 size_t str_size, int wlan_tag)
2153{
2154 char *ifname;
2155 enum driver_type drv;
2156
2157 drv = get_driver_type();
2158 if (drv == DRIVER_ATHEROS) {
2159 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2160 dut->ap_mode == AP_11ac) &&
2161 if_nametoindex("ath1") > 0)
2162 ifname = "ath1";
2163 else
2164 ifname = "ath0";
2165 } else if (drv == DRIVER_OPENWRT) {
2166 if (sigma_radio_ifname[0] &&
2167 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2168 ifname = "ath2";
2169 else if (sigma_radio_ifname[0] &&
2170 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2171 ifname = "ath1";
2172 else
2173 ifname = "ath0";
2174 } else {
2175 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2176 dut->ap_mode == AP_11ac) &&
2177 if_nametoindex("wlan1") > 0)
2178 ifname = "wlan1";
2179 else
2180 ifname = "wlan0";
2181 }
2182
2183 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2184 /* Handle tagged-ifname only on OPENWRT for now */
2185 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
2186 } else {
2187 snprintf(ifname_str, str_size, "%s", ifname);
2188 }
2189}
2190
2191
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002192static int owrt_ap_config_vap(struct sigma_dut *dut)
2193{
2194 char buf[256], *temp;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002195 int vap_id = 0, vap_count, i, j;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002196
2197 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002198 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002199
2200 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2201 if (sigma_radio_ifname[vap_id] &&
2202 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2203 break;
2204 }
2205 if (vap_id == MAX_RADIO)
2206 continue;
2207
2208 /* Single VAP configuration */
2209 if (!dut->ap_is_dual)
2210 vap_id = vap_count;
2211
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002212 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2213 /*
2214 * We keep a separate array of ap_tag_ssid and
2215 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2216 * So j=0 => WLAN_TAG = 2
2217 */
2218 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002219
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002220 if (dut->ap_tag_ssid[j][0] == '\0')
2221 continue;
2222
2223 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2224 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2225 "device", buf);
2226 /* SSID */
2227 snprintf(buf, sizeof(buf), "\"%s\"",
2228 dut->ap_tag_ssid[j]);
2229 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2230 "ssid", buf);
2231
2232 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
2233 wlan_tag == 2) {
2234 /* Only supported for WLAN_TAG=2 */
2235 owrt_ap_set_vap(dut, vap_count + 1, "osen",
2236 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002237 snprintf(buf, sizeof(buf), "wpa2");
2238 owrt_ap_set_vap(dut, vap_count + 1,
2239 "encryption", buf);
2240 snprintf(buf, sizeof(buf), "%s",
2241 dut->ap2_radius_ipaddr);
2242 owrt_ap_set_vap(dut, vap_count + 1,
2243 "auth_server", buf);
2244 snprintf(buf, sizeof(buf), "%d",
2245 dut->ap2_radius_port);
2246 owrt_ap_set_vap(dut, vap_count + 1,
2247 "auth_port", buf);
2248 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002249 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002250 owrt_ap_set_vap(dut, vap_count + 1,
2251 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002252 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
2253 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2254 "encryption", "psk2+ccmp");
2255 snprintf(buf, sizeof(buf), "\"%s\"",
2256 dut->ap_passphrase);
2257 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2258 "key", buf);
2259 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
2260 owrt_ap_set_vap(dut, vap_count + 1,
2261 "ieee80211w", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002262 }
2263 }
2264
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002265 /* Now set anqp_elem for wlan_tag = 1 */
2266 if (dut->program == PROGRAM_MBO &&
2267 get_driver_type() == DRIVER_OPENWRT) {
2268 char anqp_string[200];
2269
2270 set_anqp_elem_value(dut, sigma_radio_ifname[0],
2271 anqp_string, sizeof(anqp_string));
2272 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
2273 anqp_string);
2274 }
2275
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002276 /* SSID */
2277 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
2278 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
2279
2280 /* Encryption */
2281 switch (dut->ap_key_mgmt) {
2282 case AP_OPEN:
2283 if (dut->ap_cipher == AP_WEP) {
2284 owrt_ap_set_vap(dut, vap_count, "encryption",
2285 "wep-mixed");
2286 owrt_ap_set_vap(dut, vap_count, "key",
2287 dut->ap_wepkey);
2288 } else {
2289 owrt_ap_set_vap(dut, vap_count, "encryption",
2290 "none");
2291 }
2292 break;
2293 case AP_WPA2_PSK:
2294 case AP_WPA2_PSK_MIXED:
2295 case AP_WPA_PSK:
2296 if (dut->ap_key_mgmt == AP_WPA2_PSK) {
2297 snprintf(buf, sizeof(buf), "psk2");
2298 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
2299 snprintf(buf, sizeof(buf), "psk-mixed");
2300 } else {
2301 snprintf(buf, sizeof(buf), "psk");
2302 }
2303
2304 if (dut->ap_cipher == AP_CCMP_TKIP) {
2305 strncat(buf, "+ccmp+tkip",
Jouni Malinen0a05d502016-08-29 21:34:13 +03002306 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002307 } else if (dut->ap_cipher == AP_TKIP) {
2308 strncat(buf, "+tkip",
Jouni Malinen0a05d502016-08-29 21:34:13 +03002309 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002310 } else {
2311 strncat(buf, "+ccmp",
Jouni Malinen0a05d502016-08-29 21:34:13 +03002312 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002313 }
2314
2315 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
2316 snprintf(buf, sizeof(buf), "\"%s\"",
2317 dut->ap_passphrase);
2318 owrt_ap_set_vap(dut, vap_count, "key", buf);
2319 break;
2320 case AP_WPA2_EAP:
2321 case AP_WPA2_EAP_MIXED:
2322 case AP_WPA_EAP:
2323 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
2324 snprintf(buf, sizeof(buf), "wpa2");
2325 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
2326 snprintf(buf, sizeof(buf), "wpa-mixed");
2327 } else {
2328 snprintf(buf, sizeof(buf), "wpa");
2329 }
2330
2331 if (dut->ap_cipher == AP_CCMP_TKIP) {
Jouni Malinen0a05d502016-08-29 21:34:13 +03002332 strncat(buf, "+ccmp+tkip",
2333 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002334 } else if (dut->ap_cipher == AP_TKIP) {
Jouni Malinen0a05d502016-08-29 21:34:13 +03002335 strncat(buf, "+tkip",
2336 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002337 } else {
Jouni Malinen0a05d502016-08-29 21:34:13 +03002338 strncat(buf, "+ccmp",
2339 sizeof(buf) - strlen(buf) - 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002340 }
2341 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
2342 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
2343 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
2344 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
2345 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
2346 snprintf(buf, sizeof(buf), "%s",
2347 dut->ap_radius_password);
2348 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
2349 break;
2350 }
2351
2352 if (!dut->ap_is_dual)
2353 break;
2354 }
2355
2356 if (dut->ap_is_dual)
2357 return 1;
2358
2359 /* PMF */
2360 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
2361 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
2362
2363 /* Add SHA256 */
2364 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
2365 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
2366
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302367 /* Enable RSN preauthentication, if asked to */
2368 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
2369 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
2370
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002371 /* Hotspot 2.0 */
2372 if (dut->ap_hs2) {
2373 int ret;
2374
2375 ret = owrt_ap_config_vap_hs2(dut, vap_id);
2376 if (ret)
2377 return ret;
2378 }
2379
2380 /* Interworking */
2381 if (dut->ap_interworking) {
2382 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
2383 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
2384 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
2385 owrt_ap_set_vap(dut, vap_id, "internet", buf);
2386 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
2387 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
2388 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
2389 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
2390 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
2391 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2392
2393 if (dut->ap_gas_cb_delay > 0) {
2394 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
2395 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
2396 }
2397
2398 if (dut->ap_roaming_cons[0]) {
2399 char *rcons, *temp_ptr;
2400
2401 rcons = strdup(dut->ap_roaming_cons);
2402 if (rcons == NULL)
2403 return 0;
2404
2405 temp_ptr = strchr(rcons, ';');
2406
2407 if (temp_ptr)
2408 *temp_ptr++ = '\0';
2409
2410 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
2411 rcons);
2412
2413 if (temp_ptr)
2414 owrt_ap_set_list_vap(dut, vap_id,
2415 "roaming_consortium",
2416 temp_ptr);
2417
2418 free(rcons);
2419 }
2420 }
2421
2422 if (dut->ap_venue_name) {
2423 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
2424 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
2425 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
2426 "\'"ANQP_VENUE_NAME_1_CHI"\'");
2427 }
2428
2429 if (dut->ap_net_auth_type == 1) {
2430 owrt_ap_set_vap(dut, vap_id, "network_auth_type",
2431 "'00https://tandc-server.wi-fi.org'");
2432 } else if (dut->ap_net_auth_type == 2) {
2433 owrt_ap_set_vap(dut, vap_id, "network_auth_type", "'01'");
2434 }
2435
2436 if (dut->ap_nai_realm_list == 1) {
2437 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2438 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
2439 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2440 "'0,wi-fi.org;example.com,13[5:6]'");
2441
2442 } else if (dut->ap_nai_realm_list == 2) {
2443 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2444 "'0,wi-fi.org,21[2:4][5:7]'");
2445 } else if (dut->ap_nai_realm_list == 3) {
2446 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2447 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
2448 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2449 "'0,wi-fi.org;example.com,13[5:6]'");
2450 } else if (dut->ap_nai_realm_list == 4) {
2451 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2452 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
2453 } else if (dut->ap_nai_realm_list == 5) {
2454 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2455 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
2456 } else if (dut->ap_nai_realm_list == 6) {
2457 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2458 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
2459 } else if (dut->ap_nai_realm_list == 7) {
2460 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2461 "'0,wi-fi.org,13[5:6]'");
2462 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2463 "'0,wi-fi.org,21[2:4][5:7]'");
2464 }
2465
2466 if (dut->ap_domain_name_list[0])
2467 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
2468 dut->ap_domain_name_list);
2469
2470 if (dut->ap_ip_addr_type_avail)
2471 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
2472 "'0c'");
2473
2474 temp = buf;
2475
2476 *temp++ = '\'';
2477
2478 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
2479 if (i)
2480 *temp++ = ';';
2481
2482 snprintf(temp,
2483 sizeof(dut->ap_plmn_mcc[i]) +
2484 sizeof(dut->ap_plmn_mnc[i]) + 1,
2485 "%s,%s",
2486 dut->ap_plmn_mcc[i],
2487 dut->ap_plmn_mnc[i]);
2488
2489 temp += strlen(dut->ap_plmn_mcc[i]) +
2490 strlen(dut->ap_plmn_mnc[i]) + 1;
2491 }
2492
2493 *temp++ = '\'';
2494 *temp++ = '\0';
2495
2496 if (i)
2497 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
2498
2499 if (dut->ap_qos_map_set == 1)
2500 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
2501 else if (dut->ap_qos_map_set == 2)
2502 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
2503
2504 /* Proxy-ARP */
2505 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
2506 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
2507
2508 /* DGAF */
2509 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
2510 /* parse to hostapd */
2511 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
2512 /* parse to wifi driver */
2513 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
2514
2515 /* HCBSSLoad */
2516 if (dut->ap_bss_load) {
2517 unsigned int bssload = 0;
2518
2519 if (dut->ap_bss_load == 1) {
2520 /* STA count: 1, CU: 50, AAC: 65535 */
2521 bssload = 0x0132ffff;
2522 } else if (dut->ap_bss_load == 2) {
2523 /* STA count: 1, CU: 200, AAC: 65535 */
2524 bssload = 0x01c8ffff;
2525 } else if (dut->ap_bss_load == 3) {
2526 /* STA count: 1, CU: 75, AAC: 65535 */
2527 bssload = 0x014bffff;
2528 }
2529
2530 snprintf(buf, sizeof(buf), "%d", bssload);
2531 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
2532 }
2533
2534 /* L2TIF */
2535 if (dut->ap_l2tif)
2536 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
2537
2538 if (dut->ap_disable_protection == 1)
2539 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
2540
2541 if (dut->ap_txBF) {
2542 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
2543 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
2544 }
2545
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05302546 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002548
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05302549 if (dut->ap_tx_stbc) {
2550 /* STBC and beamforming are mutually exclusive features */
2551 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
2552 }
2553
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05302554 /* enable dfsmode */
2555 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
2556 owrt_ap_set_vap(dut, vap_id, "doth", buf);
2557
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002558 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
2559 char anqpval[1024];
2560
2561 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
2562
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002563 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05302564 snprintf(anqpval, sizeof(anqpval),
2565 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002566 dut->ap_val_lci, dut->ap_infoz);
2567 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2568 }
2569
2570 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05302571 snprintf(anqpval, sizeof(anqpval),
2572 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002573 dut->ap_val_lcr);
2574 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2575 }
2576
2577 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
2578 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
2579 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
2580 }
2581
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002582 if (dut->program == PROGRAM_MBO) {
2583 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
2584 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
2585 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07002586 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002587
2588 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
2589 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07002590 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
2591 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002592 }
2593
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07002594 if (dut->ap_ft_oa == 1) {
2595 unsigned char self_mac[ETH_ALEN];
2596 char mac_str[20];
2597
2598 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
2599 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
2600 get_hwaddr(sigma_radio_ifname[0], self_mac);
2601 snprintf(mac_str, sizeof(mac_str),
2602 "%02x:%02x:%02x:%02x:%02x:%02x",
2603 self_mac[0], self_mac[1], self_mac[2],
2604 self_mac[3], self_mac[4], self_mac[5]);
2605 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
2606 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
2607 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
2608 "000102030405060708090a0b0c0d0e0f");
2609 snprintf(mac_str, sizeof(mac_str),
2610 "%02x:%02x:%02x:%02x:%02x:%02x",
2611 dut->ft_bss_mac_list[0][0],
2612 dut->ft_bss_mac_list[0][1],
2613 dut->ft_bss_mac_list[0][2],
2614 dut->ft_bss_mac_list[0][3],
2615 dut->ft_bss_mac_list[0][4],
2616 dut->ft_bss_mac_list[0][5]);
2617 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
2618 }
2619
2620 if ((dut->ap_ft_oa == 1 && dut->ap_name == 0) ||
2621 (dut->ap_ft_oa == 1 && dut->ap_name == 2)) {
2622 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder",
2623 "00:01:02:03:04:06");
2624 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
2625 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
2626 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", "000102030405");
2627 }
2628
2629 if (dut->ap_ft_oa == 1 && dut->ap_name == 1) {
2630 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder",
2631 "00:01:02:03:04:05");
2632 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
2633 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
2634 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", "000102030406");
2635 }
2636
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07002637 if (dut->ap_mobility_domain[0])
2638 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
2639 dut->ap_mobility_domain);
2640
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002641 return 1;
2642}
2643
2644
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002645static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
2646{
2647 char anqpval[1024];
2648 unsigned char addr[6];
2649 unsigned char addr2[6];
2650 struct ifreq ifr;
2651 char *ifname;
2652 int s;
2653 int vap_id = 0;
2654
2655 s = socket(AF_INET, SOCK_DGRAM, 0);
2656 if (s < 0) {
2657 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
2658 return -1;
2659 }
2660
2661 memset(&ifr, 0, sizeof(ifr));
2662 ifname = "ath0";
2663 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
2664 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2665 perror("ioctl");
2666 close(s);
2667 return -1;
2668 }
2669 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
2670
2671 memset(&ifr, 0, sizeof(ifr));
2672 ifname = "ath01";
2673 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
2674 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2675 perror("ioctl");
2676 close(s);
2677 return -1;
2678 }
2679 close(s);
2680 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
2681
2682 snprintf(anqpval, sizeof(anqpval),
2683 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
2684 dut->ap_val_lci, dut->ap_infoz,
2685 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
2686 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
2687
2688 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2689 return 0;
2690}
2691
2692
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002693static int owrt_ap_post_config_commit(struct sigma_dut *dut,
2694 struct sigma_conn *conn,
2695 struct sigma_cmd *cmd)
2696{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002697 int ap_security = 0;
2698 int i;
2699
2700 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
2701 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
2702 ap_security = 1;
2703 }
2704 if (dut->ap_key_mgmt != AP_OPEN)
2705 ap_security = 1;
2706 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002707 /* allow some time for hostapd to start before returning
2708 * success */
2709 usleep(500000);
2710
2711 if (run_hostapd_cli(dut, "ping") != 0) {
2712 send_resp(dut, conn, SIGMA_ERROR,
2713 "errorCode,Failed to talk to hostapd");
2714 return 0;
2715 }
2716 }
2717
2718 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2719 ath_ap_set_params(dut);
2720
2721 /* Send response */
2722 return 1;
2723}
2724
2725
2726static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
2727 struct sigma_conn *conn,
2728 struct sigma_cmd *cmd)
2729{
2730 /* Stop the AP */
2731 run_system(dut, "wifi down");
2732
2733 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05302734 run_system(dut, "rm -rf /etc/config/wireless");
2735 switch (get_openwrt_driver_type()) {
2736 case OPENWRT_DRIVER_ATHEROS:
2737 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
2738 break;
2739 default:
2740 run_system(dut, "wifi detect > /etc/config/wireless");
2741 break;
2742 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743
2744 /* Configure Radio & VAP, commit the config */
2745 owrt_ap_config_radio(dut);
2746 owrt_ap_config_vap(dut);
2747 run_system(dut, "uci commit");
2748
2749 /* Start AP */
2750 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002751 if (dut->program != PROGRAM_MBO &&
2752 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002753 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002754 /*
2755 * MBO has a different ANQP element value which is set in
2756 * owrt_ap_config_vap().
2757 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002758 owrt_ap_config_vap_anqp(dut);
2759 run_system(dut, "uci commit");
2760 run_system(dut, "wifi");
2761 }
2762
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002763 return owrt_ap_post_config_commit(dut, conn, cmd);
2764}
2765
2766
2767static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
2768{
2769 unsigned char bssid[6];
2770 char buf[100];
2771 char *ifname, *radio_name;
2772 int vap_id = 0;
2773
2774 if (sigma_radio_ifname[0] &&
2775 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2776 ifname = "ath2";
2777 radio_name = "wifi2";
2778 vap_id = 2;
2779 } else if (sigma_radio_ifname[0] &&
2780 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2781 ifname = "ath1";
2782 radio_name = "wifi1";
2783 vap_id = 1;
2784 } else {
2785 ifname = "ath0";
2786 radio_name = "wifi0";
2787 vap_id = 0;
2788 }
2789
2790 if (!get_hwaddr(ifname, bssid)) {
2791 snprintf(buf, sizeof(buf), "%s", bssid);
2792 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2793 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2794 "%02x:%02x:%02x:%02x:%02x:%02x",
2795 bssid[0], bssid[1], bssid[2], bssid[3],
2796 bssid[4], bssid[5]);
2797 } else {
2798 if (!get_hwaddr(radio_name, bssid)) {
2799 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
2800 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2801 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2802 "%02x:%02x:%02x:%02x:%02x:%02x",
2803 bssid[0], bssid[1], bssid[2], bssid[3],
2804 bssid[4], bssid[5]);
2805 } else {
2806 /* Select & enable/disable radios */
2807 if (sigma_radio_ifname[0] &&
2808 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2809 /* We want to use wifi2 */
2810 owrt_ap_set_radio(dut, 0, "disabled", "1");
2811 owrt_ap_set_radio(dut, 1, "disabled", "1");
2812 owrt_ap_set_radio(dut, 2, "disabled", "0");
2813 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
2814 } else if (sigma_radio_ifname[0] &&
2815 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2816 /* We want to use wifi1 */
2817 owrt_ap_set_radio(dut, 0, "disabled", "1");
2818 owrt_ap_set_radio(dut, 1, "disabled", "0");
2819 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
2820 } else {
2821 /* We want to use wifi0 */
2822 owrt_ap_set_radio(dut, 0, "disabled", "0");
2823 owrt_ap_set_radio(dut, 1, "disabled", "1");
2824 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
2825 }
2826
2827 run_system(dut, "uci commit");
2828 run_system(dut, "wifi up");
2829
2830 if (!get_hwaddr(radio_name, bssid)) {
2831 snprintf(buf, sizeof(buf), "%s",
2832 dut->ap_hessid);
2833 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2834 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2835 "%02x:%02x:%02x:%02x:%02x:%02x",
2836 bssid[0], bssid[1], bssid[2], bssid[3],
2837 bssid[4], bssid[5]);
2838 }
2839 }
2840 }
2841}
2842
2843
2844static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
2845 struct sigma_cmd *cmd)
2846{
2847 switch (get_driver_type()) {
2848 case DRIVER_ATHEROS:
2849 run_system(dut, "apdown");
2850 sleep(1);
2851 run_system(dut, "reboot");
2852 break;
2853 case DRIVER_OPENWRT:
2854 run_system(dut, "wifi down");
2855 sleep(1);
2856 run_system(dut, "reboot");
2857 break;
2858 default:
2859 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
2860 break;
2861 }
2862
2863 return 1;
2864}
2865
2866
2867int ascii2hexstr(const char *str, char *hex)
2868{
2869 int i, length;
2870
2871 length = strlen(str);
2872
2873 for (i = 0; i < length; i++)
2874 snprintf(hex + i * 2, 3, "%X", str[i]);
2875
2876 hex[length * 2] = '\0';
2877 return 1;
2878}
2879
2880
2881static int kill_process(struct sigma_dut *dut, char *proc_name,
2882 unsigned char is_proc_instance_one, int sig)
2883{
2884#ifdef __linux__
2885 struct dirent *dp, *dp_in;
2886 const char *direc = "/proc/";
2887 char buf[100];
2888 DIR *dir = opendir(direc);
2889 DIR *dir_in;
2890 FILE *fp;
2891 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302892 char *saveptr;
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05302893 int ret = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894
2895 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05302896 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002897
2898 while ((dp = readdir(dir)) != NULL) {
2899 if (dp->d_type != DT_DIR)
2900 continue;
2901
2902 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
2903 dir_in = opendir(buf);
2904 if (dir_in == NULL)
2905 continue;
2906 dp_in = readdir(dir_in);
2907 closedir(dir_in);
2908 if (dp_in == NULL)
2909 continue;
2910 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
2911 fp = fopen(buf, "r");
2912 if (fp == NULL)
2913 continue;
2914 if (fgets(buf, 100, fp) == NULL)
2915 buf[0] = '\0';
2916 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302917 pid = strtok_r(buf, " ", &saveptr);
2918 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002919 if (pid && temp &&
2920 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
2921 sigma_dut_print(dut, DUT_MSG_INFO,
2922 "killing %s process with PID %s",
2923 proc_name, pid);
2924 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
2925 atoi(pid));
2926 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05302927 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 if (is_proc_instance_one)
2929 break;
2930 }
2931 }
2932
2933 closedir(dir);
2934
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05302935 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936#else /* __linux__ */
2937 return -1;
2938#endif /* __linux__ */
2939}
2940
2941
2942static int run_ndc(struct sigma_dut *dut, char *buf)
2943{
2944 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
2945 sleep(2);
2946 return run_system(dut, buf);
2947}
2948
2949
2950static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
2951 const char *field, const char *value)
2952{
2953 FILE *fcfg, *ftmp;
2954 char buf[MAX_CONF_LINE_LEN + 1];
2955 int len, found = 0, res;
2956
2957 /* Open the configuration file */
2958 fcfg = fopen(pfile, "r");
2959 if (!fcfg) {
2960 sigma_dut_print(dut, DUT_MSG_ERROR,
2961 "Failed to open hostapd conf file");
2962 return -1;
2963 }
2964
2965 snprintf(buf, sizeof(buf), "%s~", pfile);
2966 /* Open a temporary file */
2967 ftmp = fopen(buf, "w+");
2968 if (!ftmp) {
2969 fclose(fcfg);
2970 sigma_dut_print(dut, DUT_MSG_ERROR,
2971 "Failed to open temp buf");
2972 return -1;
2973 }
2974
2975 /* Read the values from the configuration file */
2976 len = strlen(field);
2977 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
2978 char *pline = buf;
2979
2980 /* commented line */
2981 if (buf[0] == '#')
2982 pline++;
2983
2984 /* Identify the configuration parameter to be updated */
2985 if (!found && strncmp(pline, field, len) == 0 &&
2986 pline[len] == '=') {
2987 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
2988 found = 1;
2989 sigma_dut_print(dut, DUT_MSG_INFO,
2990 "Updated hostapd conf file");
2991 }
2992
2993 fprintf(ftmp, "%s", buf);
2994 }
2995
2996 if (!found) {
2997 /* Configuration line not found */
2998 /* Add the new line at the end of file */
2999 fprintf(ftmp, "%s=%s\n", field, value);
3000 sigma_dut_print(dut, DUT_MSG_INFO,
3001 "Adding a new line in hostapd conf file");
3002 }
3003
3004 fclose(fcfg);
3005 fclose(ftmp);
3006
3007 snprintf(buf, sizeof(buf), "%s~", pfile);
3008
3009 /* Restore the updated configuration file */
3010 res = rename(buf, pfile);
3011
3012 /* Remove the temporary file. Ignore the return value */
3013 unlink(buf);
3014
3015 /* chmod is needed because open() may not set permissions properly
3016 * depending on the current umask */
3017 if (chmod(pfile, 0660) < 0) {
3018 unlink(pfile);
3019 sigma_dut_print(dut, DUT_MSG_ERROR,
3020 "Error changing permissions");
3021 return -1;
3022 }
3023
3024 if (res < 0) {
3025 sigma_dut_print(dut, DUT_MSG_ERROR,
3026 "Error restoring conf file");
3027 return -1;
3028 }
3029
3030 return 0;
3031}
3032
3033
3034static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
3035 struct sigma_conn *conn,
3036 struct sigma_cmd *cmd)
3037{
3038 char buf[100];
3039 struct stat s;
3040 int num_tries = 0, ret;
3041
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303042 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
3043 system("killall netd") == 0) {
3044 /* Avoid Error: Error connecting (Connection refused)
3045 * Wait some time to allow netd to reinitialize.
3046 */
3047 usleep(1500000);
3048 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003049
3050 while (num_tries < 10) {
3051 ret = run_ndc(dut, "ndc softap stopap");
3052 num_tries++;
3053 if (WIFEXITED(ret))
3054 ret = WEXITSTATUS(ret);
3055 /* On success, NDC exits with 0 */
3056 if (ret == 0)
3057 break;
3058 sigma_dut_print(dut, DUT_MSG_INFO,
3059 "Try No. %d: ndc softap stopap failed, exit code %d",
3060 num_tries, ret);
3061 }
3062
3063 if (ret != 0)
3064 sigma_dut_print(dut, DUT_MSG_ERROR,
3065 "ndc softap stopap command failed for 10 times - giving up");
3066
3067#ifdef ANDROID
3068 /* Unload/Load driver to cleanup the state of the driver */
3069 wifi_unload_driver();
3070 wifi_load_driver();
3071#else /* ANDROID */
3072 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
3073 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
3074#endif /* ANDROID */
3075
3076 switch (dut->ap_mode) {
3077 case AP_11g:
3078 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
3079 break;
3080 case AP_11b:
3081 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
3082 break;
3083 case AP_11ng:
3084 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3085 break;
3086 case AP_11a:
3087 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
3088 break;
3089 case AP_11na:
3090 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3091 break;
3092 case AP_11ac:
3093 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
3094 break;
3095 default:
3096 break;
3097 }
3098
3099 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
3100 dut->ap_channel);
3101 run_ndc(dut, buf);
3102
3103 /*
3104 * ndc doesn't support double quotes as SSID string, so re-write
3105 * hostapd configuration file to update SSID.
3106 */
3107 if (dut->ap_ssid[0] != '\0')
3108 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
3109
3110 switch (dut->ap_key_mgmt) {
3111 case AP_OPEN:
3112 if (dut->ap_cipher == AP_WEP) {
3113 run_ndc(dut, "ndc softap qccmd set security_mode=1");
3114 snprintf(buf, sizeof(buf),
3115 "ndc softap qccmd set wep_key0=%s",
3116 dut->ap_wepkey);
3117 run_ndc(dut, buf);
3118 } else {
3119 run_ndc(dut, "ndc softap qccmd set security_mode=0");
3120 }
3121 break;
3122 case AP_WPA2_PSK:
3123 case AP_WPA2_PSK_MIXED:
3124 case AP_WPA_PSK:
3125 if (dut->ap_key_mgmt == AP_WPA2_PSK)
3126 run_ndc(dut, "ndc softap qccmd set security_mode=3");
3127 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
3128 run_ndc(dut, "ndc softap qccmd set security_mode=4");
3129 else
3130 run_ndc(dut, "ndc softap qccmd set security_mode=2");
3131
3132 /*
3133 * ndc doesn't support some special characters as passphrase,
3134 * so re-write hostapd configuration file to update Passphrase.
3135 */
3136 if (dut->ap_passphrase[0] != '\0')
3137 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
3138 "wpa_passphrase", dut->ap_passphrase);
3139
3140 if (dut->ap_cipher == AP_CCMP_TKIP)
3141 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3142 "TKIP CCMP");
3143 else if (dut->ap_cipher == AP_TKIP)
3144 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3145 "TKIP");
3146 else
3147 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3148 "CCMP &");
3149 break;
3150 case AP_WPA2_EAP:
3151 case AP_WPA2_EAP_MIXED:
3152 case AP_WPA_EAP:
3153 /* Not supported */
3154 break;
3155 }
3156
3157 switch (dut->ap_pmf) {
3158 case AP_PMF_DISABLED:
3159 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
3160 break;
3161 case AP_PMF_OPTIONAL:
3162 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
3163 if (dut->ap_add_sha256)
3164 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
3165 else
3166 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
3167 break;
3168 case AP_PMF_REQUIRED:
3169 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
3170 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
3171 break;
3172 }
3173
3174 if (dut->ap_countrycode[0]) {
3175 snprintf(buf, sizeof(buf),
3176 "ndc softap qccmd set country_code=%s",
3177 dut->ap_countrycode);
3178 run_ndc(dut, buf);
3179 }
3180
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05303181 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
3182 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
3183
3184 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
3185 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
3186
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003187 run_ndc(dut, "ndc softap startap");
3188
3189 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
3190 num_tries = 0;
3191 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
3192 run_ndc(dut, "ndc softap stopap");
3193 run_ndc(dut, "ndc softap startap");
3194 num_tries++;
3195 }
3196
3197 if (num_tries == 10) {
3198 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
3199 "iface %s :: reboot the APDUT", buf);
3200 return ret;
3201 }
3202
3203 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
3204 ap_inet_addr, ap_inet_mask);
3205 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
3206 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
3207 if (system(buf) != 0) {
3208 sigma_dut_print(dut, DUT_MSG_ERROR,
3209 "Failed to intialize the interface");
3210 return -1;
3211 }
3212
3213 return 1;
3214}
3215
3216
3217static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
3218{
3219 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
3220 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
3221
3222 if (dut->ap_oper_name) {
3223 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
3224 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
3225 }
3226
3227 if (dut->ap_wan_metrics == 1)
3228 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
3229 else if (dut->ap_wan_metrics == 2)
3230 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
3231 else if (dut->ap_wan_metrics == 3)
3232 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
3233 else if (dut->ap_wan_metrics == 4)
3234 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
3235 else if (dut->ap_wan_metrics == 5)
3236 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
3237
3238 if (dut->ap_conn_capab == 1) {
3239 fprintf(f, "hs20_conn_capab=1:0:0\n");
3240 fprintf(f, "hs20_conn_capab=6:20:1\n");
3241 fprintf(f, "hs20_conn_capab=6:22:0\n");
3242 fprintf(f, "hs20_conn_capab=6:80:1\n");
3243 fprintf(f, "hs20_conn_capab=6:443:1\n");
3244 fprintf(f, "hs20_conn_capab=6:1723:0\n");
3245 fprintf(f, "hs20_conn_capab=6:5060:0\n");
3246 fprintf(f, "hs20_conn_capab=17:500:1\n");
3247 fprintf(f, "hs20_conn_capab=17:5060:0\n");
3248 fprintf(f, "hs20_conn_capab=17:4500:1\n");
3249 fprintf(f, "hs20_conn_capab=50:0:1\n");
3250 } else if (dut->ap_conn_capab == 2) {
3251 fprintf(f, "hs20_conn_capab=6:80:1\n");
3252 fprintf(f, "hs20_conn_capab=6:443:1\n");
3253 fprintf(f, "hs20_conn_capab=17:5060:1\n");
3254 fprintf(f, "hs20_conn_capab=6:5060:1\n");
3255 } else if (dut->ap_conn_capab == 3) {
3256 fprintf(f, "hs20_conn_capab=6:80:1\n");
3257 fprintf(f, "hs20_conn_capab=6:443:1\n");
3258 } else if (dut->ap_conn_capab == 4) {
3259 fprintf(f, "hs20_conn_capab=6:80:1\n");
3260 fprintf(f, "hs20_conn_capab=6:443:1\n");
3261 fprintf(f, "hs20_conn_capab=6:5060:1\n");
3262 fprintf(f, "hs20_conn_capab=17:5060:1\n");
3263 }
3264
3265 if (dut->ap_oper_class == 1)
3266 fprintf(f, "hs20_operating_class=51\n");
3267 else if (dut->ap_oper_class == 2)
3268 fprintf(f, "hs20_operating_class=73\n");
3269 else if (dut->ap_oper_class == 3)
3270 fprintf(f, "hs20_operating_class=5173\n");
3271
3272 if (dut->ap_osu_provider_list) {
3273 char *osu_friendly_name = NULL;
3274 char *osu_icon = NULL;
3275 char *osu_ssid = NULL;
3276 char *osu_nai = NULL;
3277 char *osu_service_desc = NULL;
3278 char *hs20_icon_filename = NULL;
3279 char hs20_icon[150];
3280 int osu_method;
3281
3282 hs20_icon_filename = "icon_red_zxx.png";
3283 if (dut->ap_osu_icon_tag == 2)
3284 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3285 snprintf(hs20_icon, sizeof(hs20_icon),
3286 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
3287 hs20_icon_filename);
3288 osu_icon = "icon_red_zxx.png";
3289 osu_ssid = "OSU";
3290 osu_friendly_name = "kor:SP 빨강 테스트 전용";
3291 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
3292 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
3293
3294 if (strlen(dut->ap_osu_server_uri[0]))
3295 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
3296 else
3297 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
3298
3299 switch (dut->ap_osu_provider_list) {
3300 case 1:
3301 case 101:
3302 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
3303 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3304 hs20_icon_filename = "icon_red_eng.png";
3305 if (dut->ap_osu_icon_tag == 2)
3306 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3307 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
3308 hs20_icon_filename);
3309 fprintf(f, "osu_icon=icon_red_eng.png\n");
3310 break;
3311 case 2:
3312 case 102:
3313 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
3314 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3315 hs20_icon_filename = "icon_orange_zxx.png";
3316 if (dut->ap_osu_icon_tag == 2)
3317 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3318 snprintf(hs20_icon, sizeof(hs20_icon),
3319 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3320 hs20_icon_filename);
3321 osu_icon = "icon_orange_zxx.png";
3322 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
3323 break;
3324 case 3:
3325 case 103:
3326 osu_friendly_name = "spa:SP Red Test Only";
3327 osu_service_desc = "spa:Free service for test purpose";
3328 break;
3329 case 4:
3330 case 104:
3331 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3332 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3333 hs20_icon_filename = "icon_orange_eng.png";
3334 if (dut->ap_osu_icon_tag == 2)
3335 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3336 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
3337 hs20_icon_filename);
3338 fprintf(f, "osu_icon=icon_orange_eng.png\n");
3339 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3340
3341 hs20_icon_filename = "icon_orange_zxx.png";
3342 if (dut->ap_osu_icon_tag == 2)
3343 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3344 snprintf(hs20_icon, sizeof(hs20_icon),
3345 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3346 hs20_icon_filename);
3347 osu_icon = "icon_orange_zxx.png";
3348 break;
3349 case 5:
3350 case 105:
3351 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3352 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3353 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3354 hs20_icon_filename = "icon_orange_zxx.png";
3355 if (dut->ap_osu_icon_tag == 2)
3356 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3357 snprintf(hs20_icon, sizeof(hs20_icon),
3358 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3359 hs20_icon_filename);
3360 osu_icon = "icon_orange_zxx.png";
3361 break;
3362 case 6:
3363 case 106:
3364 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
3365 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
3366 hs20_icon_filename = "icon_green_zxx.png";
3367 if (dut->ap_osu_icon_tag == 2)
3368 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3369 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
3370 hs20_icon_filename);
3371 fprintf(f, "osu_icon=icon_green_zxx.png\n");
3372 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
3373 fprintf(f, "osu_method_list=%d\n", osu_method);
3374
3375 if (strlen(dut->ap_osu_server_uri[1]))
3376 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
3377 else
3378 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
3379 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3380 hs20_icon_filename = "icon_orange_zxx.png";
3381 if (dut->ap_osu_icon_tag == 2)
3382 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3383 snprintf(hs20_icon, sizeof(hs20_icon),
3384 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3385 hs20_icon_filename);
3386 osu_icon = "icon_orange_zxx.png";
3387 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3388 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
3389 osu_service_desc = NULL;
3390 break;
3391 case 7:
3392 case 107:
3393 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
3394 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3395 hs20_icon_filename = "icon_green_eng.png";
3396 if (dut->ap_osu_icon_tag == 2)
3397 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3398 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
3399 hs20_icon_filename);
3400 fprintf(f, "osu_icon=icon_green_eng.png\n");
3401 osu_friendly_name = "kor:SP 초록 테스트 전용";
3402
3403 hs20_icon_filename = "icon_green_zxx.png";
3404 if (dut->ap_osu_icon_tag == 2)
3405 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3406 snprintf(hs20_icon, sizeof(hs20_icon),
3407 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
3408 hs20_icon_filename);
3409 osu_icon = "icon_green_zxx.png";
3410 break;
3411 case 8:
3412 case 108:
3413 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
3414 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3415 osu_ssid = "OSU-Encrypted";
3416 osu_nai = "anonymous@hotspot.net";
3417 break;
3418 case 9:
3419 case 109:
3420 osu_ssid = "OSU-OSEN";
3421 osu_nai = "test-anonymous@wi-fi.org";
3422 osu_friendly_name = "eng:SP Orange Test Only";
3423 hs20_icon_filename = "icon_orange_zxx.png";
3424 if (dut->ap_osu_icon_tag == 2)
3425 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3426 snprintf(hs20_icon, sizeof(hs20_icon),
3427 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3428 hs20_icon_filename);
3429 osu_icon = "icon_orange_zxx.png";
3430 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
3431 osu_service_desc = NULL;
3432 break;
3433 default:
3434 break;
3435 }
3436
3437 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003438 if (strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
3439 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003440 sigma_dut_print(dut, DUT_MSG_ERROR,
3441 "OSU_SSID and "
3442 "WLAN_TAG2 SSID differ");
3443 return -2;
3444 }
3445 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
3446 } else
3447 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
3448
3449
3450 if (osu_friendly_name)
3451 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
3452
3453 if (osu_service_desc)
3454 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
3455
3456 if (osu_nai)
3457 fprintf(f, "osu_nai=%s\n", osu_nai);
3458
3459 fprintf(f, "hs20_icon=%s\n", hs20_icon);
3460
3461 if (osu_icon)
3462 fprintf(f, "osu_icon=%s\n", osu_icon);
3463
3464 if (dut->ap_osu_provider_list > 100)
3465 fprintf(f, "osu_method_list=0\n");
3466 else
3467 fprintf(f, "osu_method_list=%d\n", osu_method);
3468 }
3469
3470 return 0;
3471}
3472
3473
3474static void write_ap_roaming_cons(FILE *f, const char *list)
3475{
3476 char *buf, *pos, *end;
3477
3478 if (list == NULL || list[0] == '\0')
3479 return;
3480
3481 buf = strdup(list);
3482 if (buf == NULL)
3483 return;
3484
3485 pos = buf;
3486 while (pos && *pos) {
3487 end = strchr(pos, ';');
3488 if (end)
3489 *end++ = '\0';
3490 fprintf(f, "roaming_consortium=%s\n", pos);
3491 pos = end;
3492 }
3493
3494 free(buf);
3495}
3496
3497
3498static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
3499{
3500 int i;
3501 char buf[100], *temp;
3502
3503 if (dut->ap_gas_cb_delay > 0)
3504 fprintf(f, "gas_comeback_delay=%d\n",
3505 dut->ap_gas_cb_delay);
3506
3507 fprintf(f, "interworking=1\n"
3508 "access_network_type=%d\n"
3509 "internet=%d\n"
3510 "asra=0\n"
3511 "esr=0\n"
3512 "uesa=0\n"
3513 "venue_group=%d\n"
3514 "venue_type=%d\n",
3515 dut->ap_access_net_type,
3516 dut->ap_internet,
3517 dut->ap_venue_group,
3518 dut->ap_venue_type);
3519 if (dut->ap_hessid[0])
3520 fprintf(f, "hessid=%s\n", dut->ap_hessid);
3521
3522 write_ap_roaming_cons(f, dut->ap_roaming_cons);
3523
3524 if (dut->ap_venue_name) {
3525 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
3526 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
3527 }
3528
3529 if (dut->ap_net_auth_type == 1)
3530 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
3531 else if (dut->ap_net_auth_type == 2)
3532 fprintf(f, "network_auth_type=01\n");
3533
3534 if (dut->ap_nai_realm_list == 1) {
3535 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
3536 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
3537 } else if (dut->ap_nai_realm_list == 2) {
3538 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
3539 } else if (dut->ap_nai_realm_list == 3) {
3540 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
3541 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
3542 } else if (dut->ap_nai_realm_list == 4) {
3543 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
3544 } else if (dut->ap_nai_realm_list == 5) {
3545 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
3546 } else if (dut->ap_nai_realm_list == 6) {
3547 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
3548 } else if (dut->ap_nai_realm_list == 7) {
3549 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
3550 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
3551 }
3552
3553 if (dut->ap_domain_name_list[0]) {
3554 fprintf(f, "domain_name=%s\n",
3555 dut->ap_domain_name_list);
3556 }
3557
3558 if (dut->ap_ip_addr_type_avail == 1) {
3559 fprintf(f, "ipaddr_type_availability=0c\n");
3560 }
3561
3562 temp = buf;
3563 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
3564 i++) {
3565 if (i)
3566 *temp++ = ';';
3567
3568 snprintf(temp,
3569 sizeof(dut->ap_plmn_mcc[i]) +
3570 sizeof(dut->ap_plmn_mnc[i]) + 1,
3571 "%s,%s",
3572 dut->ap_plmn_mcc[i],
3573 dut->ap_plmn_mnc[i]);
3574
3575 temp += strlen(dut->ap_plmn_mcc[i]) +
3576 strlen(dut->ap_plmn_mnc[i]) + 1;
3577 }
3578 if (i)
3579 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
3580
3581 if (dut->ap_qos_map_set == 1)
3582 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
3583 else if (dut->ap_qos_map_set == 2)
3584 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
3585
3586 return 0;
3587}
3588
3589
3590static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
3591{
3592 FILE *f;
3593
3594 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
3595 system("killall hostapd") == 0) {
3596 int i;
3597
3598 /* Wait some time to allow hostapd to complete cleanup before
3599 * starting a new process */
3600 for (i = 0; i < 10; i++) {
3601 usleep(500000);
3602 if (system("pidof hostapd") != 0)
3603 break;
3604 }
3605 }
3606
3607 f = fopen("/tmp/secath0", "a");
3608 if (f == NULL)
3609 return -2;
3610
3611 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
3612 fclose(f);
3613 return -2;
3614 }
3615
3616 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
3617 fclose(f);
3618 return -2;
3619 }
3620
3621 fflush(f);
3622 fclose(f);
3623 return ath_ap_start_hostapd(dut);
3624}
3625
3626
3627static int ath_ap_start_hostapd(struct sigma_dut *dut)
3628{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003629 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003630 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
3631 else
3632 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
3633
3634 return 0;
3635}
3636
3637
3638#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
3639
3640static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
3641{
3642 FILE *f;
3643 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
3644 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
3645 char buf[100];
3646 int i;
3647
3648 f = fopen("/root/anqpserver.conf", "w");
3649 if (f == NULL)
3650 return -1;
3651
3652 if (dut->ap_nai_realm_list == 1) {
3653 nai_realm = 1;
3654 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");
3655 } else if (dut->ap_nai_realm_list == 2) {
3656 nai_realm = 1;
3657 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
3658 } else if (dut->ap_nai_realm_list == 3) {
3659 nai_realm = 1;
3660 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");
3661 } else if (dut->ap_nai_realm_list == 4) {
3662 nai_realm = 1;
3663 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");
3664 } else
3665 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
3666
3667 if (dut->ap_domain_name_list[0]) {
3668 char *next, *start, *dnbuf, *dn1, *anqp_dn;
3669 int len, dn_len_max;
3670 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303671 if (dnbuf == NULL) {
3672 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003673 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303674 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003675
3676 len = strlen(dnbuf);
3677 dn_len_max = 50 + len*2;
3678 anqp_dn = malloc(dn_len_max);
3679 if (anqp_dn == NULL) {
3680 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303681 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003682 return -1;
3683 }
3684 start = dnbuf;
3685 dn1 = anqp_dn;
3686 while (start && *start) {
3687 char *hexstr;
3688
3689 next = strchr(start, ',');
3690 if (next)
3691 *next++ = '\0';
3692
3693 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05303694 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003695 if (hexstr == NULL) {
3696 free(dnbuf);
3697 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303698 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003699 return -1;
3700 }
3701 ascii2hexstr(start, hexstr);
3702 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
3703 free(hexstr);
3704 dn1 += 2 + len * 2;
3705 dn_len_max -= 2 + len * 2;
3706 start = next;
3707 }
3708 free(dnbuf);
3709 if (dut->ap_gas_cb_delay) {
3710 fprintf(f, "dyn_domain_name=0c01%04x%s",
3711 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3712 domain_name = 1;
3713 } else
3714 fprintf(f, "domain_name=0c01%04x%s",
3715 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3716 free(anqp_dn);
3717 } else
3718 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
3719
3720 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
3721
3722 if (dut->ap_oper_name) {
3723 if (dut->ap_gas_cb_delay) {
3724 fprintf(f, "dyn_oper_friendly_name="
3725 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3726 oper_name = 1;
3727 } else
3728 fprintf(f, "oper_friendly_name="
3729 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3730 } else
3731 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
3732
3733 if (dut->ap_venue_name) {
3734 if (dut->ap_gas_cb_delay) {
3735 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
3736 venue_name = 1;
3737 } else
3738 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
3739 } else
3740 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
3741
3742 if (dut->ap_wan_metrics) {
3743 if (dut->ap_gas_cb_delay) {
3744 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
3745 wan_metrics = 1;
3746 } else
3747 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
3748 "\n");
3749 } else
3750 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
3751
3752 if (dut->ap_conn_capab) {
3753 if (dut->ap_gas_cb_delay) {
3754 fprintf(f, "dyn_conn_capability="
3755 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3756 conn_cap = 1;
3757 } else
3758 fprintf(f, "conn_capability="
3759 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3760 } else
3761 sigma_dut_print(dut, DUT_MSG_ERROR,
3762 "not setting conn_capability");
3763
3764 if (dut->ap_ip_addr_type_avail) {
3765 if (dut->ap_gas_cb_delay) {
3766 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
3767 "\n");
3768 ipaddr_avail = 1;
3769 } else
3770 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
3771 } else
3772 sigma_dut_print(dut, DUT_MSG_ERROR,
3773 "not setting ipaddr_type_avail");
3774
3775 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3776 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
3777 dut->ap_plmn_mcc[i][1],
3778 dut->ap_plmn_mcc[i][0],
3779 dut->ap_plmn_mnc[i][2] == '\0' ?
3780 'f' : dut->ap_plmn_mnc[i][2],
3781 dut->ap_plmn_mcc[i][2],
3782 dut->ap_plmn_mnc[i][1],
3783 dut->ap_plmn_mnc[i][0]);
3784 }
3785 if (i) {
3786 uint16_t ie_len = (i * 3) + 5;
3787 if (dut->ap_gas_cb_delay) {
3788 fprintf(f, "dyn_cell_net=0801");
3789 cell_net = 1;
3790 } else
3791 fprintf(f, "cell_net=0801");
3792 fprintf(f, "%04x", LE16(ie_len));
3793 fprintf(f, "00"); /* version */
3794 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
3795 fprintf(f, "00"); /* plmn list */
3796 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
3797 fprintf(f, "%02x", i); /* number of plmns */
3798 fprintf(f, "%s\n", buf); /* plmns */
3799 } else
3800 sigma_dut_print(dut, DUT_MSG_ERROR,
3801 "not setting 3gpp_cellular_network");
3802
3803 if (nai_realm || domain_name || oper_name || venue_name ||
3804 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
3805 fprintf(f, "anqp_attach=");
3806 if (venue_name)
3807 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
3808 if (nai_realm)
3809 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
3810 if (cell_net)
3811 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
3812 if (domain_name)
3813 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
3814 if (oper_name)
3815 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
3816 if (wan_metrics)
3817 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
3818 if (conn_cap)
3819 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
3820 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
3821 fprintf(f, "\n");
3822 }
3823
3824 fclose(f);
3825
3826 run_system(dut, "anqpserver -i ath0 &");
3827 if (!dut->ap_anqpserver_on)
3828 run_system(dut, "killall anqpserver");
3829
3830 return 1;
3831}
3832
3833
3834static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
3835{
3836 char buf[100];
3837
3838 run_system(dut, "cfg -a AP_STARTMODE=standard");
3839
3840 if (sigma_radio_ifname[0] &&
3841 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3842 run_system(dut, "cfg -a AP_RADIO_ID=1");
3843 switch (dut->ap_mode) {
3844 case AP_11g:
3845 run_system(dut, "cfg -a AP_CHMODE_2=11G");
3846 break;
3847 case AP_11b:
3848 run_system(dut, "cfg -a AP_CHMODE_2=11B");
3849 break;
3850 case AP_11ng:
3851 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
3852 break;
3853 case AP_11a:
3854 run_system(dut, "cfg -a AP_CHMODE_2=11A");
3855 break;
3856 case AP_11na:
3857 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
3858 break;
3859 case AP_11ac:
3860 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3861 break;
3862 default:
3863 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3864 break;
3865 }
3866
3867 switch (dut->ap_rx_streams) {
3868 case 1:
3869 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
3870 break;
3871 case 2:
3872 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
3873 break;
3874 case 3:
3875 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
3876 break;
3877 }
3878
3879 switch (dut->ap_tx_streams) {
3880 case 1:
3881 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
3882 break;
3883 case 2:
3884 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
3885 break;
3886 case 3:
3887 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
3888 break;
3889 }
3890
3891 switch (dut->ap_chwidth) {
3892 case AP_20:
3893 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
3894 break;
3895 case AP_40:
3896 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
3897 break;
3898 case AP_80:
3899 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3900 break;
3901 case AP_160:
3902 case AP_AUTO:
3903 default:
3904 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3905 break;
3906 }
3907
3908 if (dut->ap_tx_stbc) {
3909 run_system(dut, "cfg -a TX_STBC_2=1");
3910 }
3911
3912 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
3913 dut->ap_channel);
3914
3915 if (dut->ap_is_dual) {
3916 switch (dut->ap_mode_1) {
3917 case AP_11g:
3918 run_system(dut, "cfg -a AP_CHMODE=11G");
3919 break;
3920 case AP_11b:
3921 run_system(dut, "cfg -a AP_CHMODE=11B");
3922 break;
3923 case AP_11ng:
3924 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3925 break;
3926 case AP_11a:
3927 run_system(dut, "cfg -a AP_CHMODE=11A");
3928 break;
3929 case AP_11na:
3930 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
3931 break;
3932 case AP_11ac:
3933 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
3934 break;
3935 default:
3936 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3937 break;
3938 }
3939 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
3940 dut->ap_channel_1);
3941 }
3942 run_system(dut, buf);
3943 } else {
3944 run_system(dut, "cfg -a AP_RADIO_ID=0");
3945 switch (dut->ap_mode) {
3946 case AP_11g:
3947 run_system(dut, "cfg -a AP_CHMODE=11G");
3948 break;
3949 case AP_11b:
3950 run_system(dut, "cfg -a AP_CHMODE=11B");
3951 break;
3952 case AP_11ng:
3953 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3954 break;
3955 case AP_11a:
3956 run_system(dut, "cfg -a AP_CHMODE=11A");
3957 break;
3958 case AP_11na:
3959 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
3960 break;
3961 case AP_11ac:
3962 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
3963 break;
3964 default:
3965 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3966 break;
3967 }
3968 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
3969 dut->ap_channel);
3970 run_system(dut, buf);
3971 }
3972
3973 if (dut->ap_sgi80 == 1) {
3974 run_system(dut, "cfg -a SHORTGI=1");
3975 run_system(dut, "cfg -a SHORTGI_2=1");
3976 } else if (dut->ap_sgi80 == 0) {
3977 run_system(dut, "cfg -a SHORTGI=0");
3978 run_system(dut, "cfg -a SHORTGI_2=0");
3979 }
3980
Jouni Malinen57fa3d82016-11-30 12:51:43 +02003981 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003982 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02003983 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003984 run_system(dut, "cfg -a LDPC=0");
3985}
3986
3987
3988void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
3989{
3990 char buf[50];
3991
3992 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
3993 if (system(buf) != 0)
3994 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
3995
3996 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
3997 if (system(buf) != 0)
3998 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
3999
4000 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
4001 if (system(buf) != 0)
4002 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
4003
4004 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
4005 if (system(buf) != 0)
4006 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
4007}
4008
4009
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004010static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
4011 const char *val)
4012{
4013 if (strcasecmp(val, "enable") == 0) {
4014 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 1", ifname);
4015 } else if (strcasecmp(val, "disable") == 0) {
4016 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 0", ifname);
4017 } else {
4018 sigma_dut_print(dut, DUT_MSG_ERROR,
4019 "Unsupported assoc_disallow");
4020 }
4021}
4022
4023
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07004024static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
4025{
4026 int i;
4027 int least_pref = 1 << 8;
4028 char ifname[20];
4029 uint8_t self_mac[ETH_ALEN];
4030 char buf[200];
4031 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
4032
4033 get_if_name(dut, ifname, sizeof(ifname), 1);
4034 get_hwaddr(ifname, self_mac);
4035
4036 /* Clear off */
4037 snprintf(buf, sizeof(buf),
4038 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
4039 ifname);
4040 run_system(dut, buf);
4041
4042 /* Find the least preference number */
4043 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
4044 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
4045
4046 ap_ne_class = 1;
4047 ap_ne_pref = 255;
4048 ap_ne_op_ch = 1;
4049 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
4050 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
4051 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
4052 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
4053 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
4054 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
4055
4056 if (ap_ne_pref < least_pref)
4057 least_pref = ap_ne_pref;
4058 snprintf(buf, sizeof(buf),
4059 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4060 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
4061 mac_addr[3], mac_addr[4], mac_addr[5],
4062 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
4063 run_system(dut, buf);
4064 }
4065
4066 /* Now add the self AP Address */
4067 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
4068 if (dut->ap_channel <= 11)
4069 ap_ne_class = 81;
4070 else
4071 ap_ne_class = 115;
4072 } else {
4073 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
4074 }
4075
4076 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
4077 ap_ne_op_ch = dut->ap_channel;
4078 else
4079 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
4080
4081 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
4082 ap_ne_pref = least_pref - 1;
4083 else
4084 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
4085
4086 snprintf(buf, sizeof(buf),
4087 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4088 ifname, self_mac[0], self_mac[1], self_mac[2],
4089 self_mac[3], self_mac[4], self_mac[5],
4090 ap_ne_pref,
4091 ap_ne_class,
4092 ap_ne_op_ch);
4093 run_system(dut, buf);
4094}
4095
4096
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004097static void ath_ap_set_params(struct sigma_dut *dut)
4098{
4099 const char *basedev = "wifi1";
4100 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
4101 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07004102 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004103
4104 if (dut->ap_countrycode[0]) {
4105 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
4106 basedev, dut->ap_countrycode);
4107 if (system(buf) != 0) {
4108 sigma_dut_print(dut, DUT_MSG_ERROR,
4109 "iwpriv setCountry failed");
4110 }
4111 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
4112 }
4113
4114 for (i = 0; i < NUM_AP_AC; i++) {
4115 if (dut->ap_qos[i].ac) {
4116 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
4117 ifname, i, dut->ap_qos[i].cwmin);
4118 if (system(buf) != 0) {
4119 sigma_dut_print(dut, DUT_MSG_ERROR,
4120 "iwpriv cwmin failed");
4121 }
4122
4123 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
4124 ifname, i, dut->ap_qos[i].cwmax);
4125 if (system(buf) != 0) {
4126 sigma_dut_print(dut, DUT_MSG_ERROR,
4127 "iwpriv cwmax failed");
4128 }
4129
4130 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
4131 ifname, i, dut->ap_qos[i].aifs);
4132 if (system(buf) != 0) {
4133 sigma_dut_print(dut, DUT_MSG_ERROR,
4134 "iwpriv aifs failed");
4135 }
4136
4137 snprintf(buf, sizeof(buf),
4138 "iwpriv %s txoplimit %d 0 %d",
4139 ifname, i, dut->ap_qos[i].txop);
4140 if (system(buf) != 0) {
4141 sigma_dut_print(dut, DUT_MSG_ERROR,
4142 "iwpriv txoplimit failed");
4143 }
4144
4145 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
4146 ifname, i, dut->ap_qos[i].acm);
4147 if (system(buf) != 0) {
4148 sigma_dut_print(dut, DUT_MSG_ERROR,
4149 "iwpriv acm failed");
4150 }
4151 }
4152 }
4153
4154 for (i = 0; i < NUM_AP_AC; i++) {
4155 if (dut->ap_sta_qos[i].ac) {
4156 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
4157 ifname, i, dut->ap_sta_qos[i].cwmin);
4158 if (system(buf) != 0) {
4159 sigma_dut_print(dut, DUT_MSG_ERROR,
4160 "iwpriv cwmin failed");
4161 }
4162
4163 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
4164 ifname, i, dut->ap_sta_qos[i].cwmax);
4165 if (system(buf) != 0) {
4166 sigma_dut_print(dut, DUT_MSG_ERROR,
4167 "iwpriv cwmax failed");
4168 }
4169
4170 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
4171 ifname, i, dut->ap_sta_qos[i].aifs);
4172 if (system(buf) != 0) {
4173 sigma_dut_print(dut, DUT_MSG_ERROR,
4174 "iwpriv aifs failed");
4175 }
4176
4177 snprintf(buf, sizeof(buf),
4178 "iwpriv %s txoplimit %d 1 %d",
4179 ifname, i, dut->ap_sta_qos[i].txop);
4180 if (system(buf) != 0) {
4181 sigma_dut_print(dut, DUT_MSG_ERROR,
4182 "iwpriv txoplimit failed");
4183 }
4184
4185 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
4186 ifname, i, dut->ap_sta_qos[i].acm);
4187 if (system(buf) != 0) {
4188 sigma_dut_print(dut, DUT_MSG_ERROR,
4189 "iwpriv acm failed");
4190 }
4191 }
4192 }
4193
4194 if (dut->ap_disable_protection == 1) {
4195 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
4196 if (system(buf) != 0) {
4197 sigma_dut_print(dut, DUT_MSG_ERROR,
4198 "iwpriv enablertscts failed");
4199 }
4200 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
4201 }
4202
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004203 if (dut->ap_ldpc == VALUE_ENABLED) {
Sarvepalli, Rajesh Babu580572a2016-11-29 22:07:14 +05304204 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 3", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004205 if (system(buf) != 0) {
4206 sigma_dut_print(dut, DUT_MSG_ERROR,
4207 "iwpriv ldpc 1 failed");
4208 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004209 } else if (dut->ap_ldpc == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004210 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
4211 if (system(buf) != 0) {
4212 sigma_dut_print(dut, DUT_MSG_ERROR,
4213 "iwpriv ldpc 0 failed");
4214 }
4215 }
4216
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004217 if (dut->ap_ampdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
4219 if (system(buf) != 0) {
4220 sigma_dut_print(dut, DUT_MSG_ERROR,
4221 "iwpriv ampdu 1 failed");
4222 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004223 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004224 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
4225 if (system(buf) != 0) {
4226 sigma_dut_print(dut, DUT_MSG_ERROR,
4227 "iwpriv ampdu 0 failed");
4228 }
4229 }
4230
4231 if (dut->ap_ampdu_exp) {
4232 if (dut->program == PROGRAM_VHT) {
4233 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
4234 ifname, dut->ap_ampdu_exp);
4235 if (system(buf) != 0) {
4236 sigma_dut_print(dut, DUT_MSG_ERROR,
4237 "iwpriv vhtmaxampdu failed");
4238 }
4239 } else {
4240 /* 11N */
4241 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
4242 ifname, dut->ap_ampdu_exp);
4243 if (system(buf) != 0) {
4244 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
4245 }
4246 }
4247 }
4248
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004249 if (dut->ap_noack == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004250 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
4251 if (system(buf) != 0) {
4252 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
4253 }
4254 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
4255 if (system(buf) != 0) {
4256 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
4257 }
4258 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
4259 if (system(buf) != 0) {
4260 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
4261 }
4262 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
4263 if (system(buf) != 0) {
4264 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
4265 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004266 } else if (dut->ap_noack == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
4268 if (system(buf) != 0) {
4269 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
4270 }
4271 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
4272 if (system(buf) != 0) {
4273 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
4274 }
4275 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
4276 if (system(buf) != 0) {
4277 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
4278 }
4279 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
4280 if (system(buf) != 0) {
4281 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
4282 }
4283 }
4284
4285 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
4286 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4287 ifname, dut->ap_vhtmcs_map);
4288 if (system(buf) != 0) {
4289 sigma_dut_print(dut, DUT_MSG_ERROR,
4290 "iwpriv vht_mcsmap failed");
4291 }
4292 }
4293
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004294 if (dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004295 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
4296 if (system(buf) != 0) {
4297 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
4298 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004299 } else if (dut->ap_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004300 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
4301 if (system(buf) != 0) {
4302 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
4303 }
4304 }
4305
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004306 if (dut->ap_rx_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004307 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
4308 if (system(buf) != 0) {
4309 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
4310 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004311 } else if (dut->ap_rx_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
4313 if (system(buf) != 0) {
4314 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
4315 }
4316 }
4317
4318 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004319 if (dut->ap_addba_reject != VALUE_NOT_SET &&
4320 dut->ap_ampdu == VALUE_DISABLED &&
4321 dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004322 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
4323 if (system(buf) != 0) {
4324 sigma_dut_print(dut, DUT_MSG_ERROR,
4325 "iwpriv setaddbaoper 1 failed");
4326 }
4327
4328 snprintf(buf, sizeof(buf),
4329 "wifitool %s senddelba 1 0 1 4", ifname);
4330 if (system(buf) != 0) {
4331 sigma_dut_print(dut, DUT_MSG_ERROR,
4332 "wifitool senddelba failed");
4333 }
4334
4335 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
4336 ifname);
4337 if (system(buf) != 0) {
4338 sigma_dut_print(dut, DUT_MSG_ERROR,
4339 "wifitool sendsingleamsdu failed");
4340 }
4341
4342 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
4343 if (system(buf) != 0) {
4344 sigma_dut_print(dut, DUT_MSG_ERROR,
4345 "iwpriv amsdu failed");
4346 }
4347 }
4348
4349 if (dut->ap_mode == AP_11ac) {
4350 int chwidth, nss;
4351
4352 switch (dut->ap_chwidth) {
4353 case AP_20:
4354 chwidth = 0;
4355 break;
4356 case AP_40:
4357 chwidth = 1;
4358 break;
4359 case AP_80:
4360 chwidth = 2;
4361 break;
4362 case AP_160:
4363 chwidth = 3;
4364 break;
4365 default:
4366 chwidth = 0;
4367 break;
4368 }
4369
4370 switch (dut->ap_tx_streams) {
4371 case 1:
4372 nss = 1;
4373 break;
4374 case 2:
4375 nss = 2;
4376 break;
4377 case 3:
4378 nss = 3;
4379 break;
4380 case 4:
4381 nss = 4;
4382 break;
4383 default:
4384 nss = 3;
4385 break;
4386 }
4387
4388 if (dut->ap_fixed_rate) {
4389 if (nss == 4)
4390 ath_disable_txbf(dut, ifname);
4391
4392 /* Set the nss */
4393 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
4394 ifname, nss);
4395 if (system(buf) != 0) {
4396 sigma_dut_print(dut, DUT_MSG_ERROR,
4397 "iwpriv nss failed");
4398 }
4399
4400 /* Set the channel width */
4401 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
4402 ifname, chwidth);
4403 if (system(buf) != 0) {
4404 sigma_dut_print(dut, DUT_MSG_ERROR,
4405 "iwpriv chwidth failed");
4406 }
4407
4408 /* Set the VHT MCS */
4409 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
4410 ifname, dut->ap_mcs);
4411 if (system(buf) != 0) {
4412 sigma_dut_print(dut, DUT_MSG_ERROR,
4413 "iwpriv vhtmcs failed");
4414 }
4415 }
4416 }
4417
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004418 if (dut->ap_dyn_bw_sig == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004419 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
4420 if (system(buf) != 0) {
4421 sigma_dut_print(dut, DUT_MSG_ERROR,
4422 "iwpriv cwmenable 1 failed");
4423 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004424 } else if (dut->ap_dyn_bw_sig == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004425 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
4426 if (system(buf) != 0) {
4427 sigma_dut_print(dut, DUT_MSG_ERROR,
4428 "iwpriv cwmenable 0 failed");
4429 }
4430 }
4431
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004432 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
4434 if (system(buf) != 0) {
4435 sigma_dut_print(dut, DUT_MSG_ERROR,
4436 "iwconfig rts 64 failed");
4437 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004438 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
4440 if (system(buf) != 0) {
4441 sigma_dut_print(dut, DUT_MSG_ERROR,
4442 "iwpriv rts 2347 failed");
4443 }
4444 }
4445
4446 if (dut->ap_hs2) {
4447 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
4448 if (system(buf) != 0) {
4449 sigma_dut_print(dut, DUT_MSG_ERROR,
4450 "iwpriv qbssload failed");
4451 }
4452 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
4453 }
4454
4455 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
4456 unsigned int bssload = 0;
4457
4458 if (dut->ap_bss_load == 1) {
4459 /* STA count: 1, CU: 50, AAC: 65535 */
4460 bssload = 0x0132ffff;
4461 } else if (dut->ap_bss_load == 2) {
4462 /* STA count: 1, CU: 200, AAC: 65535 */
4463 bssload = 0x01c8ffff;
4464 } else if (dut->ap_bss_load == 3) {
4465 /* STA count: 1, CU: 75, AAC: 65535 */
4466 bssload = 0x014bffff;
4467 }
4468
4469 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
4470 ifname, bssload);
4471 if (system(buf) != 0) {
4472 sigma_dut_print(dut, DUT_MSG_ERROR,
4473 "iwpriv hcbssload failed");
4474 }
4475 } else if (dut->ap_bss_load == 0) {
4476 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
4477 if (system(buf) != 0) {
4478 sigma_dut_print(dut, DUT_MSG_ERROR,
4479 "iwpriv qbssload failed");
4480 }
4481 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
4482 }
4483
4484 if (dut->ap_dgaf_disable) {
4485 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
4486 if (system(buf) != 0) {
4487 sigma_dut_print(dut, DUT_MSG_ERROR,
4488 "iwpriv dgaf_disable failed");
4489 }
4490 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
4491 }
4492
4493 if (dut->ap_l2tif) {
4494 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
4495 if (system(buf) != 0) {
4496 sigma_dut_print(dut, DUT_MSG_ERROR,
4497 "iwpriv l2tif failed");
4498 }
4499 snprintf(buf, sizeof(buf),
4500 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
4501 if (system(buf) != 0)
4502 sigma_dut_print(dut, DUT_MSG_ERROR,
4503 "l2tif br failed");
4504
4505 snprintf(buf, sizeof(buf),
4506 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
4507 if (system(buf) != 0)
4508 sigma_dut_print(dut, DUT_MSG_ERROR,
4509 "l2tif brif failed");
4510 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
4511 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08004512
4513 if (dut->ap_ndpa_frame == 0) {
4514 snprintf(buf, sizeof(buf),
4515 "wifitool %s beeliner_fw_test 117 192", ifname);
4516 if (system(buf) != 0) {
4517 sigma_dut_print(dut, DUT_MSG_ERROR,
4518 "wifitool beeliner_fw_test 117 192 failed");
4519 }
4520 snprintf(buf, sizeof(buf),
4521 "wifitool %s beeliner_fw_test 118 192", ifname);
4522 if (system(buf) != 0) {
4523 sigma_dut_print(dut, DUT_MSG_ERROR,
4524 "wifitool beeliner_fw_test 117 192 failed");
4525 }
4526 } else if (dut->ap_ndpa_frame == 1) {
4527 /* Driver default - no changes needed */
4528 } else if (dut->ap_ndpa_frame == 2) {
4529 snprintf(buf, sizeof(buf),
4530 "wifitool %s beeliner_fw_test 115 1", ifname);
4531 if (system(buf) != 0) {
4532 sigma_dut_print(dut, DUT_MSG_ERROR,
4533 "wifitool beeliner_fw_test 117 192 failed");
4534 }
4535 snprintf(buf, sizeof(buf),
4536 "wifitool %s beeliner_fw_test 116 1", ifname);
4537 if (system(buf) != 0) {
4538 sigma_dut_print(dut, DUT_MSG_ERROR,
4539 "wifitool beeliner_fw_test 117 192 failed");
4540 }
4541 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07004542
4543 if (dut->ap_rtt == 1) {
4544 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
4545 run_system(dut, buf);
4546 }
4547
4548 if (dut->ap_lci == 1) {
4549 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
4550 run_system(dut, buf);
4551 }
4552
4553 if (dut->ap_lcr == 1) {
4554 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
4555 run_system(dut, buf);
4556 }
4557
4558 if (dut->ap_rrm == 1) {
4559 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
4560 run_system(dut, buf);
4561 }
4562
4563 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
4564 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
4565 }
4566
4567 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
4568 FILE *f;
4569
4570 f = fopen("/tmp/nbr_report.txt", "w");
4571 if (!f) {
4572 sigma_dut_print(dut, DUT_MSG_ERROR,
4573 "Failed to open /tmp/nbr_report.txt");
4574 return;
4575 }
4576
4577 fprintf(f,
4578 "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",
4579 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
4580 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
4581 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
4582 dut->ap_val_opchannel[0]);
4583 fclose(f);
4584
4585 f = fopen("/tmp/ftmrr.txt", "w");
4586 if (!f) {
4587 sigma_dut_print(dut, DUT_MSG_ERROR,
4588 "Failed to open /tmp/ftmrr.txt");
4589 return;
4590 }
4591
4592 fprintf(f,
4593 "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",
4594 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
4595 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
4596 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
4597 dut->ap_val_opchannel[0]);
4598 fclose(f);
4599 }
4600
4601 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
4602 FILE *f;
4603
4604 f = fopen("/tmp/nbr_report.txt", "a");
4605 if (!f) {
4606 sigma_dut_print(dut, DUT_MSG_ERROR,
4607 "Failed to open /tmp/nbr_report.txt");
4608 return;
4609 }
4610 fprintf(f,
4611 "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",
4612 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
4613 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
4614 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
4615 dut->ap_val_opchannel[1]);
4616 fclose(f);
4617
4618 f = fopen("/tmp/ftmrr.txt", "a");
4619 if (!f) {
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "Failed to open /tmp/ftmrr.txt");
4622 return;
4623 }
4624 fprintf(f,
4625 "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",
4626 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
4627 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
4628 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
4629 dut->ap_val_opchannel[1]);
4630 fclose(f);
4631 }
4632
4633 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
4634 FILE *f;
4635
4636 f = fopen("/tmp/nbr_report.txt", "a");
4637 if (!f) {
4638 sigma_dut_print(dut, DUT_MSG_ERROR,
4639 "Failed to open /tmp/nbr_report.txt");
4640 return;
4641 }
4642
4643 fprintf(f,
4644 "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",
4645 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
4646 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
4647 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
4648 dut->ap_val_opchannel[2]);
4649 fclose(f);
4650
4651 f = fopen("/tmp/ftmrr.txt", "a");
4652 if (!f) {
4653 sigma_dut_print(dut, DUT_MSG_ERROR,
4654 "Failed to open /tmp/ftmrr.txt");
4655 return;
4656 }
4657
4658 fprintf(f,
4659 "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",
4660 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
4661 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
4662 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
4663 dut->ap_val_opchannel[2]);
4664 fclose(f);
4665 }
4666
4667 if (dut->ap_neighap) {
4668 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
4669 run_system(dut, buf);
4670 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
4671 run_system(dut, buf);
4672 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
4673 run_system(dut, buf);
4674 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
4675 run_system(dut, buf);
4676 }
4677
4678 if (dut->ap_scan == 1) {
4679 snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600",
4680 ifname);
4681 run_system(dut, buf);
4682 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
4683 run_system(dut, buf);
4684 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004685
4686 if (dut->ap_set_bssidpref) {
4687 snprintf(buf, sizeof(buf),
4688 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
4689 ifname);
4690 if (system(buf) != 0) {
4691 sigma_dut_print(dut, DUT_MSG_ERROR,
4692 "wifitool clear bssidpref failed");
4693 }
4694 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07004695
4696 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
4697 int feature_enable;
4698
4699 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
4700 snprintf(buf, sizeof(buf), "iwpriv %s wnm %d",
4701 ifname, feature_enable);
4702 run_system(dut, buf);
4703 snprintf(buf, sizeof(buf), "iwpriv %s wnm_bss %d",
4704 ifname, feature_enable);
4705 run_system(dut, buf);
4706 if (feature_enable) {
4707 const char *extra = "";
4708
4709 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
4710 if (dut->wnm_bss_max_protection ==
4711 VALUE_ENABLED)
4712 extra = " 1";
4713 else
4714 extra = " 0";
4715 }
4716 snprintf(buf, sizeof(buf),
4717 "wlanconfig %s wnm setbssmax %d%s",
4718 ifname, dut->wnm_bss_max_idle_time, extra);
4719 run_system(dut, buf);
4720 }
4721 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004722
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004723 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07004724 apply_mbo_pref_ap_list(dut);
4725
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004726 snprintf(buf, sizeof(buf), "iwpriv %s mbo_cel_pref %d",
4727 ifname, dut->ap_cell_cap_pref);
4728 run_system(dut, buf);
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07004729
4730 snprintf(buf, sizeof(buf), "iwpriv %s mbocap 0x40", ifname);
4731 run_system(dut, buf);
4732
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004733 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004734 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004735}
4736
4737
4738static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
4739 struct sigma_conn *conn,
4740 struct sigma_cmd *cmd)
4741{
4742 /* const char *name = get_param(cmd, "NAME"); */
4743 char buf[100];
4744 struct stat s;
4745 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
4746
4747 if (stat("/proc/athversion", &s) == 0) {
4748 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
4749 run_system(dut, "apdown");
4750 }
4751
4752 cmd_ath_ap_radio_config(dut);
4753
4754 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
4755 run_system(dut, buf);
4756
4757 switch (dut->ap_key_mgmt) {
4758 case AP_OPEN:
4759 if (dut->ap_cipher == AP_WEP) {
4760 run_system(dut, "cfg -a AP_SECMODE=WEP");
4761 run_system(dut, "cfg -a AP_SECFILE=NONE");
4762 /* shared auth mode not supported */
4763 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
4764 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
4765 snprintf(buf, sizeof(buf),
4766 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
4767 dut->ap_wepkey);
4768 run_system(dut, buf);
4769 snprintf(buf, sizeof(buf),
4770 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
4771 dut->ap_wepkey);
4772 run_system(dut, buf);
4773 } else {
4774 run_system(dut, "cfg -a AP_SECMODE=None");
4775 }
4776 break;
4777 case AP_WPA2_PSK:
4778 case AP_WPA2_PSK_MIXED:
4779 case AP_WPA_PSK:
4780 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4781 run_system(dut, "cfg -a AP_WPA=2");
4782 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4783 run_system(dut, "cfg -a AP_WPA=3");
4784 else
4785 run_system(dut, "cfg -a AP_WPA=1");
4786 run_system(dut, "cfg -a AP_SECMODE=WPA");
4787 run_system(dut, "cfg -a AP_SECFILE=PSK");
4788 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
4789 dut->ap_passphrase);
4790 run_system(dut, buf);
4791 if (dut->ap_cipher == AP_CCMP_TKIP)
4792 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
4793 else if (dut->ap_cipher == AP_TKIP)
4794 run_system(dut, "cfg -a AP_CYPHER=TKIP");
4795 else
4796 run_system(dut, "cfg -a AP_CYPHER=CCMP");
4797 break;
4798 case AP_WPA2_EAP:
4799 case AP_WPA2_EAP_MIXED:
4800 case AP_WPA_EAP:
4801 if (dut->ap_key_mgmt == AP_WPA2_EAP)
4802 run_system(dut, "cfg -a AP_WPA=2");
4803 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
4804 run_system(dut, "cfg -a AP_WPA=3");
4805 else
4806 run_system(dut, "cfg -a AP_WPA=1");
4807 run_system(dut, "cfg -a AP_SECMODE=WPA");
4808 run_system(dut, "cfg -a AP_SECFILE=EAP");
4809 if (dut->ap_cipher == AP_CCMP_TKIP)
4810 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
4811 else if (dut->ap_cipher == AP_TKIP)
4812 run_system(dut, "cfg -a AP_CYPHER=TKIP");
4813 else
4814 run_system(dut, "cfg -a AP_CYPHER=CCMP");
4815 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
4816 dut->ap_radius_ipaddr);
4817 run_system(dut, buf);
4818 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
4819 dut->ap_radius_port);
4820 run_system(dut, buf);
4821 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
4822 dut->ap_radius_password);
4823 run_system(dut, buf);
4824 break;
4825 }
4826
4827 if (dut->ap_is_dual) {
4828 /* ath1 settings in case of dual */
4829 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
4830 dut->ap_ssid);
4831 run_system(dut, buf);
4832
4833 switch (dut->ap_key_mgmt) {
4834 case AP_OPEN:
4835 if (dut->ap_cipher == AP_WEP) {
4836 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
4837 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
4838 /* shared auth mode not supported */
4839 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
4840 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
4841 snprintf(buf, sizeof(buf),
4842 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
4843 dut->ap_wepkey);
4844 run_system(dut, buf);
4845 snprintf(buf, sizeof(buf),
4846 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
4847 dut->ap_wepkey);
4848 run_system(dut, buf);
4849 } else {
4850 run_system(dut, "cfg -a AP_SECMODE_2=None");
4851 }
4852 break;
4853 case AP_WPA2_PSK:
4854 case AP_WPA2_PSK_MIXED:
4855 case AP_WPA_PSK:
4856 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4857 run_system(dut, "cfg -a AP_WPA_2=2");
4858 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4859 run_system(dut, "cfg -a AP_WPA_2=3");
4860 else
4861 run_system(dut, "cfg -a AP_WPA_2=1");
4862 // run_system(dut, "cfg -a AP_WPA_2=2");
4863 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
4864 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
4865 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
4866 dut->ap_passphrase);
4867 run_system(dut, buf);
4868 if (dut->ap_cipher == AP_CCMP_TKIP)
4869 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
4870 else if (dut->ap_cipher == AP_TKIP)
4871 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
4872 else
4873 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
4874 break;
4875 case AP_WPA2_EAP:
4876 case AP_WPA2_EAP_MIXED:
4877 case AP_WPA_EAP:
4878 if (dut->ap_key_mgmt == AP_WPA2_EAP)
4879 run_system(dut, "cfg -a AP_WPA_2=2");
4880 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
4881 run_system(dut, "cfg -a AP_WPA_2=3");
4882 else
4883 run_system(dut, "cfg -a AP_WPA_2=1");
4884 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
4885 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
4886 if (dut->ap_cipher == AP_CCMP_TKIP)
4887 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
4888 else if (dut->ap_cipher == AP_TKIP)
4889 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
4890 else
4891 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
4892
4893 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
4894 dut->ap_radius_ipaddr);
4895 run_system(dut, buf);
4896 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
4897 dut->ap_radius_port);
4898 run_system(dut, buf);
4899 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
4900 dut->ap_radius_password);
4901 run_system(dut, buf);
4902 break;
4903 }
4904
4905 /* wifi0 settings in case of dual */
4906 run_system(dut, "cfg -a AP_RADIO_ID=0");
4907 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
4908 run_system(dut, "cfg -a AP_STARTMODE=dual");
4909 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
4910 run_system(dut, "cfg -a TX_CHAINMASK=7");
4911 run_system(dut, "cfg -a RX_CHAINMASK=7");
4912 }
4913
4914 switch (dut->ap_pmf) {
4915 case AP_PMF_DISABLED:
4916 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
4917 run_system(dut, buf);
4918 break;
4919 case AP_PMF_OPTIONAL:
4920 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
4921 run_system(dut, buf);
4922 break;
4923 case AP_PMF_REQUIRED:
4924 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
4925 run_system(dut, buf);
4926 break;
4927 }
4928 if (dut->ap_add_sha256) {
4929 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
4930 run_system(dut, buf);
4931 } else {
4932 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
4933 run_system(dut, buf);
4934 }
4935
4936 if (dut->ap_hs2)
4937 run_system(dut, "cfg -a AP_HOTSPOT=1");
4938 else
4939 run_system(dut, "cfg -r AP_HOTSPOT");
4940
4941 if (dut->ap_interworking) {
4942 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
4943 dut->ap_access_net_type);
4944 run_system(dut, buf);
4945 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
4946 dut->ap_internet);
4947 run_system(dut, buf);
4948 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
4949 dut->ap_venue_group);
4950 run_system(dut, buf);
4951 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
4952 dut->ap_venue_type);
4953 run_system(dut, buf);
4954 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
4955 dut->ap_hessid);
4956 run_system(dut, buf);
4957
4958 if (dut->ap_roaming_cons[0]) {
4959 char *second, *rc;
4960 rc = strdup(dut->ap_roaming_cons);
4961 if (rc == NULL)
4962 return 0;
4963
4964 second = strchr(rc, ';');
4965 if (second)
4966 *second++ = '\0';
4967
4968 snprintf(buf, sizeof(buf),
4969 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
4970 run_system(dut, buf);
4971
4972 if (second) {
4973 snprintf(buf, sizeof(buf),
4974 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
4975 "=%s", second);
4976 run_system(dut, buf);
4977 }
4978 free(rc);
4979 } else {
4980 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
4981 run_system(dut,
4982 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
4983 }
4984 } else {
4985 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
4986 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
4987 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
4988 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
4989 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
4990 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
4991 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
4992 }
4993
4994 if (dut->ap_proxy_arp)
4995 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
4996 else
4997 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
4998 if (dut->ap_dgaf_disable)
4999 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
5000 else
5001 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
5002
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005003 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005004 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005005 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006 run_system(dut, buf);
5007
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005008 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005009 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5010 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
5011
5012 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
5013 dut->ap2_radius_ipaddr);
5014 run_system(dut, buf);
5015
5016 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
5017 dut->ap2_radius_port);
5018 run_system(dut, buf);
5019
5020 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
5021 dut->ap2_radius_password);
5022 run_system(dut, buf);
5023 } else {
5024 run_system(dut, "cfg -a AP_SECMODE_2=None");
5025 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
5026 run_system(dut, "cfg -r AP_AUTH_PORT_2");
5027 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
5028 }
5029
5030 run_system(dut, "cfg -a AP_STARTMODE=multi");
5031 }
5032
5033 run_system(dut, "cfg -c");
5034
5035 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
5036 if (system("apup") != 0) {
5037 /* to be debugged why apup returns error
5038 send_resp(dut, conn, SIGMA_ERROR,
5039 "errorCode,apup failed");
5040 return 0;
5041 */
5042 }
5043 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
5044
5045 if (dut->ap_key_mgmt != AP_OPEN) {
5046 int res;
5047 /* allow some time for hostapd to start before returning
5048 * success */
5049 usleep(500000);
5050 if (run_hostapd_cli(dut, "ping") != 0) {
5051 send_resp(dut, conn, SIGMA_ERROR,
5052 "errorCode,Failed to talk to hostapd");
5053 return 0;
5054 }
5055
5056 if (dut->ap_hs2 && !dut->ap_anqpserver) {
5057 /* the cfg app doesn't like ";" in the variables */
5058 res = ath_ap_append_hostapd_conf(dut);
5059 if (res < 0)
5060 return res;
5061
5062 /* wait for hostapd to be ready */
5063 usleep(500000);
5064 if (run_hostapd_cli(dut, "ping") != 0) {
5065 send_resp(dut, conn, SIGMA_ERROR,
5066 "errorCode,Failed to talk to "
5067 "hostapd");
5068 return 0;
5069 }
5070 }
5071 }
5072
5073 ath_ap_set_params(dut);
5074
5075 if (dut->ap_anqpserver)
5076 return cmd_ath_ap_anqpserver_start(dut);
5077
5078 if (dut->ap2_proxy_arp)
5079 run_system(dut, "iwpriv ath1 proxy_arp 1");
5080
5081 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
5082 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
5083 if (system(buf) != 0) {
5084 sigma_dut_print(dut, DUT_MSG_ERROR,
5085 "iwpriv htweptkip failed");
5086 }
5087 }
5088
5089 return 1;
5090}
5091
5092
5093static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
5094 const char *ifname)
5095{
5096 char buf[200];
5097
5098 if (!chain || !ifname)
5099 return -2;
5100
5101 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
5102 if (system(buf) != 0) {
5103 sigma_dut_print(dut, DUT_MSG_ERROR,
5104 "Failed to set ebtables rules, RULE-1, %s",
5105 chain);
5106 return -2;
5107 }
5108
5109 snprintf(buf, sizeof(buf),
5110 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
5111 chain, ifname);
5112 if (system(buf) != 0) {
5113 sigma_dut_print(dut, DUT_MSG_ERROR,
5114 "Failed to set ebtables rules, RULE-2, %s",
5115 chain);
5116 return -2;
5117 }
5118
5119 snprintf(buf, sizeof(buf),
5120 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
5121 chain, ifname);
5122 if (system(buf) != 0) {
5123 sigma_dut_print(dut, DUT_MSG_ERROR,
5124 "Failed to set ebtables rules, RULE-3, %s",
5125 chain);
5126 return -2;
5127 }
5128
5129 snprintf(buf, sizeof(buf),
5130 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
5131 chain, ifname);
5132 if (system(buf) != 0) {
5133 sigma_dut_print(dut, DUT_MSG_ERROR,
5134 "Failed to set ebtables rules, RULE-4, %s",
5135 chain);
5136 return -2;
5137 }
5138
5139 return 0;
5140}
5141
5142
5143static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
5144 const char *chain,
5145 const char *ifname)
5146{
5147 char buf[200];
5148
5149 if (!chain || !ifname)
5150 return -2;
5151
5152 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
5153 if (system(buf) != 0) {
5154 sigma_dut_print(dut, DUT_MSG_ERROR,
5155 "Failed to set ebtables rules, RULE-5, %s",
5156 chain);
5157 return -2;
5158 }
5159
5160 snprintf(buf, sizeof(buf),
5161 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
5162 chain, ifname);
5163 if (system(buf) != 0) {
5164 sigma_dut_print(dut, DUT_MSG_ERROR,
5165 "Failed to set ebtables rules, RULE-6, %s",
5166 chain);
5167 return -2;
5168 }
5169
5170 snprintf(buf, sizeof(buf),
5171 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
5172 chain, ifname);
5173 if (system(buf) != 0) {
5174 sigma_dut_print(dut, DUT_MSG_ERROR,
5175 "Failed to set ebtables rules, RULE-7, %s",
5176 chain);
5177 return -2;
5178 }
5179
5180 snprintf(buf, sizeof(buf),
5181 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
5182 chain, ifname);
5183 if (system(buf) != 0) {
5184 sigma_dut_print(dut, DUT_MSG_ERROR,
5185 "Failed to set ebtables rules, RULE-8, %s",
5186 chain);
5187 return -2;
5188 }
5189
5190 return 0;
5191}
5192
5193
5194static int check_channel(int channel)
5195{
5196 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
5197 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
5198 161, 165 };
5199 int num_chan = sizeof(channel_list) / sizeof(int);
5200 int i;
5201
5202 for (i = 0; i < num_chan; i++) {
5203 if (channel == channel_list[i])
5204 return i;
5205 }
5206
5207 return -1;
5208}
5209
5210
5211static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
5212{
5213 int ch_base;
5214 int period;
5215
5216 if (check_channel(channel) < 0)
5217 return -1;
5218
5219 if (channel >= 36 && channel <= 64)
5220 ch_base = 36;
5221 else if (channel >= 100 && channel <= 144)
5222 ch_base = 100;
5223 else
5224 ch_base = 149;
5225
5226 period = channel % ch_base * 5 / chwidth;
5227 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
5228}
5229
5230
5231static int is_ht40plus_chan(int chan)
5232{
5233 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
5234 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
5235 chan == 132 || chan == 149 || chan == 157;
5236}
5237
5238
5239static int is_ht40minus_chan(int chan)
5240{
5241 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
5242 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
5243 chan == 136 || chan == 153 || chan == 161;
5244}
5245
5246
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05305247static int get_5g_channel_freq(int chan)
5248{
5249 return 5000 + chan * 5;
5250}
5251
5252
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005253static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
5254 struct sigma_cmd *cmd)
5255{
5256 /* const char *name = get_param(cmd, "NAME"); */
5257 FILE *f;
5258 const char *ifname;
5259 char buf[500];
5260 char path[100];
5261 enum driver_type drv;
5262
5263 drv = get_driver_type();
5264
5265 if (dut->mode == SIGMA_MODE_STATION) {
5266 stop_sta_mode(dut);
5267 sleep(1);
5268 }
5269
5270 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
5271 snprintf(buf, sizeof(buf), "ifconfig %s down",
5272 dut->sniffer_ifname);
5273 if (system(buf) != 0) {
5274 sigma_dut_print(dut, DUT_MSG_INFO,
5275 "Failed to run '%s'", buf);
5276 }
5277 snprintf(buf, sizeof(buf), "iw dev %s set type station",
5278 dut->sniffer_ifname);
5279 if (system(buf) != 0) {
5280 sigma_dut_print(dut, DUT_MSG_INFO,
5281 "Failed to run '%s'", buf);
5282 }
5283 }
5284
5285 dut->mode = SIGMA_MODE_AP;
5286
5287 if (drv == DRIVER_ATHEROS)
5288 return cmd_ath_ap_config_commit(dut, conn, cmd);
5289 if (drv == DRIVER_WCN)
5290 return cmd_wcn_ap_config_commit(dut, conn, cmd);
5291 if (drv == DRIVER_OPENWRT)
5292 return cmd_owrt_ap_config_commit(dut, conn, cmd);
5293
5294 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
5295 if (f == NULL) {
5296 sigma_dut_print(dut, DUT_MSG_ERROR,
5297 "%s: Failed to open sigma_dut-ap.conf",
5298 __func__);
5299 return -2;
5300 }
5301 switch (dut->ap_mode) {
5302 case AP_11g:
5303 case AP_11b:
5304 case AP_11ng:
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305305 ifname = (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) ?
5306 "wlan0" : "ath0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005307 if (drv == DRIVER_QNXNTO && sigma_main_ifname)
5308 ifname = sigma_main_ifname;
5309 fprintf(f, "hw_mode=g\n");
5310 break;
5311 case AP_11a:
5312 case AP_11na:
5313 case AP_11ac:
5314 if (drv == DRIVER_QNXNTO) {
5315 if (sigma_main_ifname)
5316 ifname = sigma_main_ifname;
5317 else
5318 ifname = "wlan0";
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305319 } else if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005320 if (if_nametoindex("wlan1") > 0)
5321 ifname = "wlan1";
5322 else
5323 ifname = "wlan0";
5324 } else {
5325 ifname = get_main_ifname();
5326 }
5327 fprintf(f, "hw_mode=a\n");
5328 break;
5329 default:
5330 fclose(f);
5331 return -1;
5332 }
5333
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305334 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005335 fprintf(f, "driver=nl80211\n");
5336
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305337 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5338 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005339 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05305340 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
5341
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005342 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05305343 if (dut->ap_mode == AP_11ng &&
5344 (dut->ap_chwidth == AP_40 ||
5345 (dut->ap_chwidth == AP_AUTO &&
5346 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005347 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305348 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005349 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305350 ht40minus = 1;
5351 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005352 }
5353
5354 /* configure ht_capab based on channel width */
5355 if (dut->ap_mode == AP_11na &&
5356 (dut->ap_chwidth == AP_40 ||
5357 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05305358 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005359 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05305360 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005361 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05305362 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005363 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05305364
5365 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305366 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05305367
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05305368 /* Overwrite the ht_capab with offset value if configured */
5369 if (dut->ap_chwidth == AP_40 &&
5370 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
5371 ht40plus = 1;
5372 ht40minus = 0;
5373 } else if (dut->ap_chwidth == AP_40 &&
5374 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
5375 ht40minus = 1;
5376 ht40plus = 0;
5377 }
5378
Tamizh chelvam431c6002017-03-07 17:07:16 +05305379 fprintf(f, "ht_capab=%s%s%s\n",
5380 ht40plus ? "[HT40+]" : "",
5381 ht40minus ? "[HT40-]" : "",
5382 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005383 }
5384
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305385 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5386 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005387 dut->ap_mode == AP_11ac) {
5388 fprintf(f, "ieee80211ac=1\n"
5389 "ieee80211n=1\n"
5390 "ht_capab=[HT40+]\n");
5391 }
5392
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305393 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5394 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005395 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
5396 if (dut->ap_countrycode[0]) {
5397 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
5398 fprintf(f, "ieee80211d=1\n");
5399 fprintf(f, "ieee80211h=1\n");
5400 }
5401 }
5402
5403 fprintf(f, "interface=%s\n", ifname);
5404 if (dut->bridge)
5405 fprintf(f, "bridge=%s\n", dut->bridge);
5406 fprintf(f, "channel=%d\n", dut->ap_channel);
5407
5408 if (sigma_hapd_ctrl)
5409 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
5410 else
5411 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
5412
5413 if (dut->ap_ssid[0])
5414 fprintf(f, "ssid=%s\n", dut->ap_ssid);
5415 else
5416 fprintf(f, "ssid=QCA AP OOB\n");
5417 if (dut->ap_bcnint)
5418 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
5419
5420 switch (dut->ap_key_mgmt) {
5421 case AP_OPEN:
5422 if (dut->ap_cipher == AP_WEP)
5423 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
5424 break;
5425 case AP_WPA2_PSK:
5426 case AP_WPA2_PSK_MIXED:
5427 case AP_WPA_PSK:
5428 if (dut->ap_key_mgmt == AP_WPA2_PSK)
5429 fprintf(f, "wpa=2\n");
5430 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5431 fprintf(f, "wpa=3\n");
5432 else
5433 fprintf(f, "wpa=1\n");
5434 fprintf(f, "wpa_key_mgmt=WPA-PSK\n");
5435 switch (dut->ap_pmf) {
5436 case AP_PMF_DISABLED:
5437 fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n",
5438 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
5439 break;
5440 case AP_PMF_OPTIONAL:
5441 fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n",
5442 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
5443 break;
5444 case AP_PMF_REQUIRED:
5445 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
5446 break;
5447 }
5448 if (dut->ap_cipher == AP_CCMP_TKIP)
5449 fprintf(f, "wpa_pairwise=CCMP TKIP\n");
5450 else if (dut->ap_cipher == AP_TKIP)
5451 fprintf(f, "wpa_pairwise=TKIP\n");
5452 else
5453 fprintf(f, "wpa_pairwise=CCMP\n");
5454 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
5455 break;
5456 case AP_WPA2_EAP:
5457 case AP_WPA2_EAP_MIXED:
5458 case AP_WPA_EAP:
5459 fprintf(f, "ieee8021x=1\n");
5460 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5461 fprintf(f, "wpa=2\n");
5462 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5463 fprintf(f, "wpa=3\n");
5464 else
5465 fprintf(f, "wpa=1\n");
5466 switch (dut->ap_pmf) {
5467 case AP_PMF_DISABLED:
5468 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
5469 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
5470 break;
5471 case AP_PMF_OPTIONAL:
5472 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
5473 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
5474 break;
5475 case AP_PMF_REQUIRED:
5476 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
5477 break;
5478 }
5479 if (dut->ap_cipher == AP_CCMP_TKIP)
5480 fprintf(f, "wpa_pairwise=CCMP TKIP\n");
5481 else if (dut->ap_cipher == AP_TKIP)
5482 fprintf(f, "wpa_pairwise=TKIP\n");
5483 else
5484 fprintf(f, "wpa_pairwise=CCMP\n");
5485 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
5486 if (dut->ap_radius_port)
5487 fprintf(f, "auth_server_port=%d\n",
5488 dut->ap_radius_port);
5489 fprintf(f, "auth_server_shared_secret=%s\n",
5490 dut->ap_radius_password);
5491 break;
5492 }
5493
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05305494 if (dut->ap_rsn_preauth)
5495 fprintf(f, "rsn_preauth=1\n");
5496
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005497 switch (dut->ap_pmf) {
5498 case AP_PMF_DISABLED:
5499 break;
5500 case AP_PMF_OPTIONAL:
5501 fprintf(f, "ieee80211w=1\n");
5502 break;
5503 case AP_PMF_REQUIRED:
5504 fprintf(f, "ieee80211w=2\n");
5505 break;
5506 }
5507
5508 if (dut->ap_p2p_mgmt)
5509 fprintf(f, "manage_p2p=1\n");
5510
5511 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
5512 fprintf(f, "tdls_prohibit=1\n");
5513 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
5514 fprintf(f, "tdls_prohibit_chan_switch=1\n");
5515 if (dut->ap_p2p_cross_connect >= 0) {
5516 fprintf(f, "manage_p2p=1\n"
5517 "allow_cross_connection=%d\n",
5518 dut->ap_p2p_cross_connect);
5519 }
5520
5521 if (dut->ap_l2tif || dut->ap_proxy_arp) {
5522 if (!dut->bridge) {
5523 sigma_dut_print(dut, DUT_MSG_ERROR,
5524 "Bridge must be configured. Run with -b <brname>.");
5525 fclose(f);
5526 return -2;
5527 }
5528 fprintf(f, "ap_isolate=1\n");
5529 }
5530
5531 if (dut->ap_proxy_arp)
5532 fprintf(f, "proxy_arp=1\n");
5533
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05305534 if (dut->ap_wme)
5535 fprintf(f, "wmm_enabled=1\n");
5536
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05305537 if (dut->ap_wmmps == AP_WMMPS_ON)
5538 fprintf(f, "uapsd_advertisement_enabled=1\n");
5539
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005540 if (dut->ap_hs2) {
5541 if (dut->ap_bss_load) {
5542 char *bss_load;
5543
5544 switch (dut->ap_bss_load) {
5545 case -1:
5546 bss_load = "bss_load_update_period=10";
5547 break;
5548 case 1:
5549 /* STA count: 1, CU: 50, AAC: 65535 */
5550 bss_load = "bss_load_test=1:50:65535";
5551 break;
5552 case 2:
5553 /* STA count: 1, CU: 200, AAC: 65535 */
5554 bss_load = "bss_load_test=1:200:65535";
5555 break;
5556 case 3:
5557 /* STA count: 1, CU: 75, AAC: 65535 */
5558 bss_load = "bss_load_test=1:75:65535";
5559 break;
5560 default:
5561 bss_load = NULL;
5562 break;
5563 }
5564
5565 if (!bss_load) {
5566 fclose(f);
5567 return -2;
5568 }
5569 fprintf(f, "%s\n", bss_load);
5570 }
5571
5572 if (append_hostapd_conf_hs2(dut, f)) {
5573 fclose(f);
5574 return -2;
5575 }
5576 }
5577
5578 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
5579 fclose(f);
5580 return -2;
5581 }
5582
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005583 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584 unsigned char bssid[6];
5585 char ifname2[50];
5586
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305587 if (get_hwaddr(ifname, bssid)) {
5588 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305590 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591 bssid[0] |= 0x02;
5592
5593 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
5594 fprintf(f, "bss=%s_1\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005595 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005596 if (dut->bridge)
5597 fprintf(f, "bridge=%s\n", dut->bridge);
5598 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
5599 bssid[0], bssid[1], bssid[2], bssid[3],
5600 bssid[4], bssid[5]);
5601
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005602 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005603 fprintf(f, "osen=1\n");
5604 if (strlen(dut->ap2_radius_ipaddr))
5605 fprintf(f, "auth_server_addr=%s\n",
5606 dut->ap2_radius_ipaddr);
5607 if (dut->ap2_radius_port)
5608 fprintf(f, "auth_server_port=%d\n",
5609 dut->ap2_radius_port);
5610 if (strlen(dut->ap2_radius_password))
5611 fprintf(f, "auth_server_shared_secret=%s\n",
5612 dut->ap2_radius_password);
5613 }
5614
5615 if (dut->ap2_proxy_arp) {
5616 if (!dut->bridge) {
5617 sigma_dut_print(dut, DUT_MSG_ERROR,
5618 "Bridge must be configured. Run with -b <brname>.");
5619 fclose(f);
5620 return -2;
5621 }
5622 fprintf(f, "ap_isolate=1\n");
5623 fprintf(f, "proxy_arp=1\n");
5624
5625 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
5626 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
5627 fclose(f);
5628 return -2;
5629 }
5630
5631 }
5632 }
5633
5634 if (dut->program == PROGRAM_WPS) {
5635 fprintf(f, "eap_server=1\n"
5636 "wps_state=1\n"
5637 "device_name=QCA AP\n"
5638 "manufacturer=QCA\n"
5639 "device_type=6-0050F204-1\n"
5640 "config_methods=label virtual_display "
5641 "virtual_push_button keypad%s\n"
5642 "ap_pin=12345670\n"
5643 "friendly_name=QCA Access Point\n"
5644 "upnp_iface=%s\n",
5645 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
5646 dut->bridge ? dut->bridge : ifname);
5647 }
5648
5649 if (dut->program == PROGRAM_VHT) {
5650 int vht_oper_centr_freq_idx;
5651
5652 if (check_channel(dut->ap_channel) < 0) {
5653 send_resp(dut, conn, SIGMA_INVALID,
5654 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305655 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005656 return 0;
5657 }
5658
5659 switch (dut->ap_chwidth) {
5660 case AP_20:
5661 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
5662 vht_oper_centr_freq_idx =
5663 get_oper_centr_freq_seq_idx(20,
5664 dut->ap_channel);
5665 break;
5666 case AP_40:
5667 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
5668 vht_oper_centr_freq_idx =
5669 get_oper_centr_freq_seq_idx(40,
5670 dut->ap_channel);
5671 break;
5672 case AP_80:
5673 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
5674 vht_oper_centr_freq_idx =
5675 get_oper_centr_freq_seq_idx(80,
5676 dut->ap_channel);
5677 break;
5678 case AP_160:
5679 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
5680 vht_oper_centr_freq_idx =
5681 get_oper_centr_freq_seq_idx(160,
5682 dut->ap_channel);
5683 break;
5684 default:
5685 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
5686 vht_oper_centr_freq_idx =
5687 get_oper_centr_freq_seq_idx(80,
5688 dut->ap_channel);
5689 break;
5690 }
5691 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
5692 vht_oper_centr_freq_idx);
5693 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
5694
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005695 if (dut->ap_sgi80 || dut->ap_txBF ||
5696 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05305697 dut->ap_tx_stbc || dut->ap_mu_txBF) {
5698 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005699 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05305700 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05305701 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005702 (dut->ap_ldpc == VALUE_ENABLED) ?
5703 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05305704 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
5705 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 }
5707 }
5708
5709 fclose(f);
5710#ifdef __QNXNTO__
5711 if (system("slay hostapd") == 0)
5712#else /* __QNXNTO__ */
5713 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
5714 system("killall hostapd") == 0)
5715#endif /* __QNXNTO__ */
5716 {
5717 int i;
5718 /* Wait some time to allow hostapd to complete cleanup before
5719 * starting a new process */
5720 for (i = 0; i < 10; i++) {
5721 usleep(500000);
5722#ifdef __QNXNTO__
5723 if (system("pidin | grep hostapd") != 0)
5724 break;
5725#else /* __QNXNTO__ */
5726 if (system("pidof hostapd") != 0)
5727 break;
5728#endif /* __QNXNTO__ */
5729 }
5730 }
5731
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05305732#ifdef ANDROID
5733 /* Set proper conf file permissions so that hostapd process
5734 * can access it.
5735 */
5736 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
5737 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
5738 sigma_dut_print(dut, DUT_MSG_ERROR,
5739 "Error changing permissions");
5740
5741 if (chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, AID_WIFI) < 0)
5742 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
5743#endif /* ANDROID */
5744
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005745 if (drv == DRIVER_QNXNTO) {
5746 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05305747 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005748 "/sigma_dut-ap.conf",
5749 dut->hostapd_debug_log ? "-ddKt -f " : "",
5750 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005751 dut->hostapd_entropy_log ? " -e" : "",
5752 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
5753 "");
5754 } else {
5755 /*
5756 * It looks like a monitor interface can cause some issues for
5757 * beaconing, so remove it (if injection was used) before
5758 * starting hostapd.
5759 */
5760 if (if_nametoindex("sigmadut") > 0 &&
5761 system("iw dev sigmadut del") != 0)
5762 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
5763 "monitor interface");
5764
5765 snprintf(buf, sizeof(buf), "%shostapd -B%s%s%s%s " SIGMA_TMPDIR
5766 "/sigma_dut-ap.conf",
5767 file_exists("hostapd") ? "./" : "",
5768 dut->hostapd_debug_log ? " -ddKt -f" : "",
5769 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
5770 dut->hostapd_entropy_log ? " -e" : "",
5771 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
5772 "");
5773 }
5774
5775 if (system(buf) != 0) {
5776 send_resp(dut, conn, SIGMA_ERROR,
5777 "errorCode,Failed to start hostapd");
5778 return 0;
5779 }
5780
5781 /* allow some time for hostapd to start before returning success */
5782 usleep(500000);
5783 if (run_hostapd_cli(dut, "ping") != 0) {
5784 send_resp(dut, conn, SIGMA_ERROR,
5785 "errorCode,Failed to talk to hostapd");
5786 return 0;
5787 }
5788
5789 if (dut->ap_l2tif) {
5790 snprintf(path, sizeof(path),
5791 "/sys/class/net/%s/brport/hairpin_mode",
5792 ifname);
5793 if (!file_exists(path)) {
5794 sigma_dut_print(dut, DUT_MSG_ERROR,
5795 "%s must be binded to the bridge for L2TIF",
5796 ifname);
5797 return -2;
5798 }
5799
5800 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
5801 if (system(buf) != 0) {
5802 sigma_dut_print(dut, DUT_MSG_ERROR,
5803 "Failed to enable hairpin_mode for L2TIF");
5804 return -2;
5805 }
5806
5807 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
5808 if (system(buf) != 0) {
5809 sigma_dut_print(dut, DUT_MSG_ERROR,
5810 "Failed to set ebtables rules, RULE-9");
5811 return -2;
5812 }
5813
5814 snprintf(buf, sizeof(buf),
5815 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
5816 ifname);
5817 if (system(buf) != 0) {
5818 sigma_dut_print(dut, DUT_MSG_ERROR,
5819 "Failed to set ebtables rules, RULE-11");
5820 return -2;
5821 }
5822 }
5823
5824 if (dut->ap_proxy_arp) {
5825 if (dut->ap_dgaf_disable) {
5826 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
5827 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
5828 return -2;
5829 } else {
5830 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
5831 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
5832 return -2;
5833 }
5834
5835 /* For 4.5-(c) */
5836 snprintf(buf, sizeof(buf),
5837 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
5838 ifname);
5839 if (system(buf) != 0) {
5840 sigma_dut_print(dut, DUT_MSG_ERROR,
5841 "Failed to set ebtables rules, RULE-10");
5842 return -2;
5843 }
5844 }
5845
5846 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
5847 /* Drop TDLS frames */
5848 snprintf(buf, sizeof(buf),
5849 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
5850 if (system(buf) != 0) {
5851 sigma_dut_print(dut, DUT_MSG_ERROR,
5852 "Failed to set ebtables rules, RULE-13");
5853 return -2;
5854 }
5855 }
5856
5857 if (dut->ap_fake_pkhash &&
5858 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
5859 send_resp(dut, conn, SIGMA_ERROR,
5860 "errorCode,Could not enable FakePubKey");
5861 return 0;
5862 }
5863
5864 return 1;
5865}
5866
5867
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305868static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
5869 struct qos_params *qos, const char *cwmin,
5870 const char *cwmax, const char *aifs,
5871 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305873 int val;
5874
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005875 if (cwmin) {
5876 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305877 val = atoi(cwmin);
5878 if (val < 0 || val > 15) {
5879 send_resp(dut, conn, SIGMA_INVALID,
5880 "errorCode,Invalid cwMin");
5881 return 0;
5882 }
5883 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005884 }
5885
5886 if (cwmax) {
5887 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305888 val = atoi(cwmax);
5889 if (val < 0 || val > 15) {
5890 send_resp(dut, conn, SIGMA_INVALID,
5891 "errorCode,Invalid cwMax");
5892 return 0;
5893 }
5894 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005895 }
5896
5897 if (aifs) {
5898 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305899 val = atoi(aifs);
5900 if (val < 1 || val > 255) {
5901 send_resp(dut, conn, SIGMA_INVALID,
5902 "errorCode,Invalid AIFS");
5903 return 0;
5904 }
5905 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005906 }
5907
5908 if (txop) {
5909 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305910 val = atoi(txop);
5911 if (val < 0 || val > 0xffff) {
5912 send_resp(dut, conn, SIGMA_INVALID,
5913 "errorCode,Invalid txop");
5914 return 0;
5915 }
5916 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005917 }
5918
5919 if (acm) {
5920 qos->ac = 1;
5921 qos->acm = strcasecmp(acm, "on") == 0;
5922 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305923
5924 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005925}
5926
5927
5928static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
5929 struct sigma_cmd *cmd)
5930{
5931 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305932 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
5933 get_param(cmd, "cwmin_VO"),
5934 get_param(cmd, "cwmax_VO"),
5935 get_param(cmd, "AIFS_VO"),
5936 get_param(cmd, "TXOP_VO"),
5937 get_param(cmd, "ACM_VO")) ||
5938 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
5939 get_param(cmd, "cwmin_VI"),
5940 get_param(cmd, "cwmax_VI"),
5941 get_param(cmd, "AIFS_VI"),
5942 get_param(cmd, "TXOP_VI"),
5943 get_param(cmd, "ACM_VI")) ||
5944 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
5945 get_param(cmd, "cwmin_BE"),
5946 get_param(cmd, "cwmax_BE"),
5947 get_param(cmd, "AIFS_BE"),
5948 get_param(cmd, "TXOP_BE"),
5949 get_param(cmd, "ACM_BE")) ||
5950 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
5951 get_param(cmd, "cwmin_BK"),
5952 get_param(cmd, "cwmax_BK"),
5953 get_param(cmd, "AIFS_BK"),
5954 get_param(cmd, "TXOP_BK"),
5955 get_param(cmd, "ACM_BK")))
5956 return 0;
5957
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005958 return 1;
5959}
5960
5961
5962static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
5963 struct sigma_cmd *cmd)
5964{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05305965 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
5966 get_param(cmd, "cwmin_VO"),
5967 get_param(cmd, "cwmax_VO"),
5968 get_param(cmd, "AIFS_VO"),
5969 get_param(cmd, "TXOP_VO"),
5970 get_param(cmd, "ACM_VO")) ||
5971 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
5972 get_param(cmd, "cwmin_VI"),
5973 get_param(cmd, "cwmax_VI"),
5974 get_param(cmd, "AIFS_VI"),
5975 get_param(cmd, "TXOP_VI"),
5976 get_param(cmd, "ACM_VI")) ||
5977 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
5978 get_param(cmd, "cwmin_BE"),
5979 get_param(cmd, "cwmax_BE"),
5980 get_param(cmd, "AIFS_BE"),
5981 get_param(cmd, "TXOP_BE"),
5982 get_param(cmd, "ACM_BE")) ||
5983 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
5984 get_param(cmd, "cwmin_BK"),
5985 get_param(cmd, "cwmax_BK"),
5986 get_param(cmd, "AIFS_BK"),
5987 get_param(cmd, "TXOP_BK"),
5988 get_param(cmd, "ACM_BK")))
5989 return 0;
5990
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005991 return 1;
5992}
5993
5994
5995static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
5996{
5997 unsigned char bssid[6];
5998 char buf[100];
5999 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
6000 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
6001 run_system(dut, "cfg -a AP_SECMODE=WPA");
6002 run_system(dut, "cfg -a AP_SECFILE=EAP");
6003 run_system(dut, "cfg -a AP_WPA=2");
6004 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6005 run_system(dut, "cfg -a AP_HOTSPOT=1");
6006 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
6007 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
6008 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
6009 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
6010 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
6011 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
6012 if (!get_hwaddr("ath0", bssid)) {
6013 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
6014 "%02x:%02x:%02x:%02x:%02x:%02x",
6015 bssid[0], bssid[1], bssid[2], bssid[3],
6016 bssid[4], bssid[5]);
6017 run_system(dut, buf);
6018 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
6019 "%02x:%02x:%02x:%02x:%02x:%02x",
6020 bssid[0], bssid[1], bssid[2], bssid[3],
6021 bssid[4], bssid[5]);
6022 } else {
6023 if (!get_hwaddr("wifi0", bssid)) {
6024 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
6025 "%02x:%02x:%02x:%02x:%02x:%02x",
6026 bssid[0], bssid[1], bssid[2], bssid[3],
6027 bssid[4], bssid[5]);
6028 run_system(dut, buf);
6029 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
6030 "%02x:%02x:%02x:%02x:%02x:%02x",
6031 bssid[0], bssid[1], bssid[2], bssid[3],
6032 bssid[4], bssid[5]);
6033 } else {
6034 /* load the driver and try again */
6035 run_system(dut, "/etc/rc.d/rc.wlan up");
6036
6037 if (!get_hwaddr("wifi0", bssid)) {
6038 snprintf(buf, sizeof(buf),
6039 "cfg -a AP_HOTSPOT_HESSID="
6040 "%02x:%02x:%02x:%02x:%02x:%02x",
6041 bssid[0], bssid[1], bssid[2],
6042 bssid[3], bssid[4], bssid[5]);
6043 run_system(dut, buf);
6044 snprintf(dut->ap_hessid,
6045 sizeof(dut->ap_hessid),
6046 "%02x:%02x:%02x:%02x:%02x:%02x",
6047 bssid[0], bssid[1], bssid[2],
6048 bssid[3], bssid[4], bssid[5]);
6049 }
6050 }
6051 }
6052
6053 run_system(dut, "cfg -r AP_SSID_2");
6054 run_system(dut, "cfg -c");
6055 /* run_system(dut, "cfg -s"); */
6056}
6057
6058
6059static void ath_reset_vht_defaults(struct sigma_dut *dut)
6060{
6061 run_system(dut, "cfg -x");
6062 run_system(dut, "cfg -a AP_RADIO_ID=1");
6063 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
6064 run_system(dut, "cfg -a AP_STARTMODE=standard");
6065 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
6066 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
6067 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
6068 run_system(dut, "cfg -a ATH_countrycode=0x348");
6069 /* NOTE: For Beeliner we have to turn off MU-MIMO */
6070 if (system("rm /tmp/secath*") != 0) {
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to remove secath file");
6073 }
6074}
6075
6076
6077static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
6078 struct sigma_cmd *cmd)
6079{
6080 const char *type;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306081 enum driver_type drv;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006082 int i;
6083
6084 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
6085 /*
6086 * Reset all tagged SSIDs to NULL-string and all key management
6087 * to open.
6088 */
6089 dut->ap_tag_ssid[i][0] = '\0';
6090 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
6091 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006092
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306093 drv = get_driver_type();
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006094 dut->program = sigma_program_to_enum(get_param(cmd, "PROGRAM"));
6095 dut->device_type = AP_unknown;
6096 type = get_param(cmd, "type");
6097 if (type && strcasecmp(type, "Testbed") == 0)
6098 dut->device_type = AP_testbed;
6099 if (type && strcasecmp(type, "DUT") == 0)
6100 dut->device_type = AP_dut;
6101
6102 dut->ap_rts = 0;
6103 dut->ap_frgmnt = 0;
6104 dut->ap_bcnint = 0;
6105 dut->ap_key_mgmt = AP_OPEN;
6106 dut->ap_ssid[0] = '\0';
6107 dut->ap_fake_pkhash = 0;
6108 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
6109 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006110 dut->ap_addba_reject = VALUE_NOT_SET;
6111 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006112 dut->ap_is_dual = 0;
6113 dut->ap_mode = AP_inval;
6114 dut->ap_mode_1 = AP_inval;
6115
6116 dut->ap_allow_vht_wep = 0;
6117 dut->ap_allow_vht_tkip = 0;
6118 dut->ap_disable_protection = 0;
6119 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006120 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
6121 dut->ap_ldpc = VALUE_NOT_SET;
6122 dut->ap_sig_rts = VALUE_NOT_SET;
6123 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05306125 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006126 dut->ap_chwidth = AP_AUTO;
6127
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05306128 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006129 dut->ap_wpsnfc = 0;
6130 dut->ap_bss_load = -1;
6131 dut->ap_p2p_cross_connect = -1;
6132
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05306133 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
6134 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306135 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05306136
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006137 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07006138 dut->ft_bss_mac_cnt = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006139
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306140 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306141 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306142 dut->ap_wmmps = AP_WMMPS_ON;
6143 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306144 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306145 dut->ap_wmmps = AP_WMMPS_OFF;
6146 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306147
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006148 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6149 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006150 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006151
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006152 if (drv == DRIVER_ATHEROS)
6153 cmd_ath_ap_hs2_reset(dut);
6154 else if (drv == DRIVER_OPENWRT)
6155 cmd_owrt_ap_hs2_reset(dut);
6156
6157 dut->ap_interworking = 1;
6158 dut->ap_access_net_type = 2;
6159 dut->ap_internet = 0;
6160 dut->ap_venue_group = 2;
6161 dut->ap_venue_type = 8;
6162 dut->ap_domain_name_list[0] = '\0';
6163 dut->ap_hs2 = 1;
6164 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
6165 "506f9a;001bc504bd");
6166 dut->ap_l2tif = 0;
6167 dut->ap_proxy_arp = 0;
6168 if (dut->bridge) {
6169 char buf[50];
6170
6171 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
6172 dut->bridge);
6173 if (system(buf) != 0) {
6174 sigma_dut_print(dut, DUT_MSG_DEBUG,
6175 "%s ip neigh table flushing failed",
6176 dut->bridge);
6177 }
6178
6179 snprintf(buf, sizeof(buf), "ebtables -F");
6180 if (system(buf) != 0) {
6181 sigma_dut_print(dut, DUT_MSG_DEBUG,
6182 "%s ebtables flushing failed",
6183 dut->bridge);
6184 }
6185 }
6186 dut->ap_dgaf_disable = 0;
6187 dut->ap_p2p_cross_connect = 0;
6188 dut->ap_gas_cb_delay = 0;
6189 dut->ap_nai_realm_list = 0;
6190 dut->ap_oper_name = 0;
6191 dut->ap_venue_name = 0;
6192 for (i = 0; i < 10; i++) {
6193 dut->ap_plmn_mcc[i][0] = '\0';
6194 dut->ap_plmn_mnc[i][0] = '\0';
6195 }
6196 dut->ap_wan_metrics = 0;
6197 dut->ap_conn_capab = 0;
6198 dut->ap_ip_addr_type_avail = 0;
6199 dut->ap_net_auth_type = 0;
6200 dut->ap_oper_class = 0;
6201 dut->ap_pmf = 0;
6202 dut->ap_add_sha256 = 0;
6203 }
6204
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006205 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006206 int i;
6207 const char hessid[] = "50:6f:9a:00:11:22";
6208
6209 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
6210 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211 dut->ap_pmf = 1;
6212 dut->ap_osu_provider_list = 0;
6213 for (i = 0; i < 10; i++) {
6214 dut->ap_osu_server_uri[i][0] = '\0';
6215 dut->ap_osu_method[i] = 0xFF;
6216 }
6217 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006218 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006219 dut->ap2_proxy_arp = 0;
6220 dut->ap_osu_icon_tag = 0;
6221 }
6222
6223 if (dut->program == PROGRAM_VHT) {
6224 /* Set up the defaults */
6225 dut->ap_mode = AP_11ac;
6226 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006227 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08006228 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006229 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006230 dut->ap_amsdu = VALUE_DISABLED;
6231 dut->ap_ldpc = VALUE_DISABLED;
6232 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006233 dut->ap_sgi80 = 0;
6234 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006235 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306236 /*
6237 * As LDPC is optional, don't enable this by default
6238 * for LINUX-WCN driver. The ap_set_wireless command
6239 * can be used to enable LDPC, when needed.
6240 */
6241 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006242 dut->ap_ldpc = VALUE_ENABLED;
6243 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006244 dut->ap_sgi80 = 1;
6245 }
6246 dut->ap_fixed_rate = 0;
6247 dut->ap_rx_streams = 3;
6248 dut->ap_tx_streams = 3;
6249 dut->ap_vhtmcs_map = 0;
6250 dut->ap_chwidth = AP_80;
6251 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006252 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05306253 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
6254 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006255 if (get_driver_type() == DRIVER_ATHEROS)
6256 ath_reset_vht_defaults(dut);
6257 }
6258
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006259 if (dut->program == PROGRAM_IOTLP) {
6260 dut->wnm_bss_max_feature = VALUE_DISABLED;
6261 dut->wnm_bss_max_idle_time = 0;
6262 dut->wnm_bss_max_protection = VALUE_NOT_SET;
6263 dut->ap_proxy_arp = 1;
6264 } else {
6265 /*
6266 * Do not touch the BSS-MAX Idle time feature
6267 * if the program is not IOTLP.
6268 */
6269 dut->wnm_bss_max_feature = VALUE_NOT_SET;
6270 dut->wnm_bss_max_idle_time = 0;
6271 dut->wnm_bss_max_protection = VALUE_NOT_SET;
6272 }
6273
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006274 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006275 dut->ap_rrm = 1;
6276 dut->ap_rtt = 1;
6277 dut->ap_lci = 0;
6278 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07006279 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006280 dut->ap_lcr = 0;
6281 dut->ap_val_lcr[0] = '\0';
6282 dut->ap_neighap = 0;
6283 dut->ap_opchannel = 0;
6284 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07006285 dut->ap_fqdn_held = 0;
6286 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07006287 dut->ap_interworking = 0;
6288 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006289 dut->ap_msnt_type = 0;
6290 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07006291 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07006292 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07006293 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006294
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006295 if (dut->program == PROGRAM_MBO) {
6296 dut->ap_mbo = 1;
6297 dut->ap_interworking = 1;
6298 dut->ap_ne_class = 0;
6299 dut->ap_ne_op_ch = 0;
6300 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07006301 dut->ap_btmreq_disassoc_imnt = 0;
6302 dut->ap_btmreq_term_bit = 0;
6303 dut->ap_disassoc_timer = 0;
6304 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07006305 dut->ap_channel = 36;
6306 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006307 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07006308 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006309 dut->mbo_self_ap_tuple.ap_ne_class = -1;
6310 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
6311 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
6312
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006313 }
6314
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006315 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
6316 system("killall hostapd") == 0) {
6317 int i;
6318 /* Wait some time to allow hostapd to complete cleanup before
6319 * starting a new process */
6320 for (i = 0; i < 10; i++) {
6321 usleep(500000);
6322 if (system("pidof hostapd") != 0)
6323 break;
6324 }
6325 }
6326
6327 if (if_nametoindex("sigmadut") > 0 &&
6328 system("iw dev sigmadut del") != 0)
6329 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
6330 "monitor interface");
6331
6332 return 1;
6333}
6334
6335
6336static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
6337 struct sigma_cmd *cmd)
6338{
6339 /* const char *name = get_param(cmd, "NAME"); */
6340 struct stat s;
6341 char resp[200];
6342 FILE *f;
6343 enum driver_type drv = get_driver_type();
6344
6345 switch (drv) {
6346 case DRIVER_ATHEROS: {
6347 /* Atheros AP */
6348 struct utsname uts;
6349 char *version, athver[100];
6350
6351 if (stat("/proc/athversion", &s) != 0) {
6352 if (system("/etc/rc.d/rc.wlan up") != 0) {
6353 }
6354 }
6355
6356 athver[0] = '\0';
6357 f = fopen("/proc/athversion", "r");
6358 if (f) {
6359 if (fgets(athver, sizeof(athver), f)) {
6360 char *pos = strchr(athver, '\n');
6361 if (pos)
6362 *pos = '\0';
6363 }
6364 fclose(f);
6365 }
6366
6367 if (uname(&uts) == 0)
6368 version = uts.release;
6369 else
6370 version = "Unknown";
6371
6372 if (if_nametoindex("ath1") > 0)
6373 snprintf(resp, sizeof(resp), "interface,ath0_24G "
6374 "ath1_5G,agent,1.0,version,%s/drv:%s",
6375 version, athver);
6376 else
6377 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
6378 "agent,1.0,version,%s/drv:%s",
6379 version, athver);
6380
6381 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6382 return 0;
6383 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306384 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006385 case DRIVER_MAC80211: {
6386 struct utsname uts;
6387 char *version;
6388
6389 if (uname(&uts) == 0)
6390 version = uts.release;
6391 else
6392 version = "Unknown";
6393
6394 if (if_nametoindex("wlan1") > 0)
6395 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
6396 "wlan1_5G,agent,1.0,version,%s", version);
6397 else
6398 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
6399 "agent,1.0,version,%s", version);
6400
6401 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6402 return 0;
6403 }
6404 case DRIVER_QNXNTO: {
6405 struct utsname uts;
6406 char *version;
6407
6408 if (uname(&uts) == 0)
6409 version = uts.release;
6410 else
6411 version = "Unknown";
6412 snprintf(resp, sizeof(resp),
6413 "interface,%s_any,agent,1.0,version,%s",
6414 sigma_main_ifname ? sigma_main_ifname : "NA",
6415 version);
6416 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6417 return 0;
6418 }
6419 case DRIVER_OPENWRT: {
6420 switch (get_openwrt_driver_type()) {
6421 case OPENWRT_DRIVER_ATHEROS: {
6422 struct utsname uts;
6423 char *version;
6424
6425 if (uname(&uts) == 0)
6426 version = uts.release;
6427 else
6428 version = "Unknown";
6429
6430 if (if_nametoindex("ath1") > 0)
6431 snprintf(resp, sizeof(resp),
6432 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
6433 version);
6434 else
6435 snprintf(resp, sizeof(resp),
6436 "interface,ath0_any,agent,1.0,version,%s",
6437 version);
6438
6439 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6440 return 0;
6441 }
6442 default:
6443 send_resp(dut, conn, SIGMA_ERROR,
6444 "errorCode,Unsupported openwrt driver");
6445 return 0;
6446 }
6447 }
6448 default:
6449 send_resp(dut, conn, SIGMA_ERROR,
6450 "errorCode,Unsupported driver");
6451 return 0;
6452 }
6453}
6454
6455
6456static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6457 struct sigma_cmd *cmd)
6458{
6459 /* const char *name = get_param(cmd, "NAME"); */
6460 /* const char *ifname = get_param(cmd, "INTERFACE"); */
6461 const char *val;
6462 char buf[100];
6463
6464 val = get_param(cmd, "MinorCode");
6465 if (val) {
6466 /* TODO: add support for P2P minor code */
6467 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
6468 "yet supported");
6469 return 0;
6470 }
6471
6472 val = get_param(cmd, "STA_MAC_ADDRESS");
6473 if (val == NULL)
6474 return -1;
6475 snprintf(buf, sizeof(buf), "deauth %s", val);
6476 if (run_hostapd_cli(dut, buf) != 0)
6477 return -2;
6478
6479 return 1;
6480}
6481
6482
6483#ifdef __linux__
6484int inject_frame(int s, const void *data, size_t len, int encrypt);
6485int open_monitor(const char *ifname);
6486int hwaddr_aton(const char *txt, unsigned char *addr);
6487#endif /* __linux__ */
6488
6489enum send_frame_type {
6490 DISASSOC, DEAUTH, SAQUERY
6491};
6492enum send_frame_protection {
6493 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6494};
6495
6496
6497static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6498 enum send_frame_type frame,
6499 enum send_frame_protection protected,
6500 const char *sta_addr)
6501{
6502#ifdef __linux__
6503 unsigned char buf[1000], *pos;
6504 int s, res;
6505 unsigned char addr_sta[6], addr_own[6];
6506 char *ifname;
6507 char cbuf[100];
6508 struct ifreq ifr;
6509
6510 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
6511 dut->ap_mode == AP_11ac) &&
6512 if_nametoindex("wlan1") > 0)
6513 ifname = "wlan1";
6514 else
6515 ifname = "wlan0";
6516
6517 if (hwaddr_aton(sta_addr, addr_sta) < 0)
6518 return -1;
6519
6520 s = socket(AF_INET, SOCK_DGRAM, 0);
6521 if (s < 0)
6522 return -1;
6523 memset(&ifr, 0, sizeof(ifr));
6524 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
6525 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
6526 perror("ioctl");
6527 close(s);
6528 return -1;
6529 }
6530 close(s);
6531 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
6532
6533 if (if_nametoindex("sigmadut") == 0) {
6534 snprintf(cbuf, sizeof(cbuf),
6535 "iw dev %s interface add sigmadut type monitor",
6536 ifname);
6537 if (system(cbuf) != 0 ||
6538 if_nametoindex("sigmadut") == 0) {
6539 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6540 "monitor interface with '%s'", cbuf);
6541 return -2;
6542 }
6543 }
6544
6545 if (system("ifconfig sigmadut up") != 0) {
6546 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6547 "monitor interface up");
6548 return -2;
6549 }
6550
6551 pos = buf;
6552
6553 /* Frame Control */
6554 switch (frame) {
6555 case DISASSOC:
6556 *pos++ = 0xa0;
6557 break;
6558 case DEAUTH:
6559 *pos++ = 0xc0;
6560 break;
6561 case SAQUERY:
6562 *pos++ = 0xd0;
6563 break;
6564 }
6565
6566 if (protected == INCORRECT_KEY)
6567 *pos++ = 0x40; /* Set Protected field to 1 */
6568 else
6569 *pos++ = 0x00;
6570
6571 /* Duration */
6572 *pos++ = 0x00;
6573 *pos++ = 0x00;
6574
6575 /* addr1 = DA (station) */
6576 memcpy(pos, addr_sta, 6);
6577 pos += 6;
6578 /* addr2 = SA (own address) */
6579 memcpy(pos, addr_own, 6);
6580 pos += 6;
6581 /* addr3 = BSSID (own address) */
6582 memcpy(pos, addr_own, 6);
6583 pos += 6;
6584
6585 /* Seq# (to be filled by driver/mac80211) */
6586 *pos++ = 0x00;
6587 *pos++ = 0x00;
6588
6589 if (protected == INCORRECT_KEY) {
6590 /* CCMP parameters */
6591 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6592 pos += 8;
6593 }
6594
6595 if (protected == INCORRECT_KEY) {
6596 switch (frame) {
6597 case DEAUTH:
6598 /* Reason code (encrypted) */
6599 memcpy(pos, "\xa7\x39", 2);
6600 pos += 2;
6601 break;
6602 case DISASSOC:
6603 /* Reason code (encrypted) */
6604 memcpy(pos, "\xa7\x39", 2);
6605 pos += 2;
6606 break;
6607 case SAQUERY:
6608 /* Category|Action|TransID (encrypted) */
6609 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6610 pos += 4;
6611 break;
6612 default:
6613 return -1;
6614 }
6615
6616 /* CCMP MIC */
6617 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6618 pos += 8;
6619 } else {
6620 switch (frame) {
6621 case DEAUTH:
6622 /* reason code = 8 */
6623 *pos++ = 0x08;
6624 *pos++ = 0x00;
6625 break;
6626 case DISASSOC:
6627 /* reason code = 8 */
6628 *pos++ = 0x08;
6629 *pos++ = 0x00;
6630 break;
6631 case SAQUERY:
6632 /* Category - SA Query */
6633 *pos++ = 0x08;
6634 /* SA query Action - Request */
6635 *pos++ = 0x00;
6636 /* Transaction ID */
6637 *pos++ = 0x12;
6638 *pos++ = 0x34;
6639 break;
6640 }
6641 }
6642
6643 s = open_monitor("sigmadut");
6644 if (s < 0) {
6645 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6646 "monitor socket");
6647 return 0;
6648 }
6649
6650 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
6651 if (res < 0) {
6652 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6653 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306654 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 return 0;
6656 }
6657 if (res < pos - buf) {
6658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
6659 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306660 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006661 return 0;
6662 }
6663
6664 close(s);
6665
6666 return 1;
6667#else /* __linux__ */
6668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
6669 "yet supported");
6670 return 0;
6671#endif /* __linux__ */
6672}
6673
6674
6675int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
6676 struct sigma_cmd *cmd)
6677{
6678 const char *val, *dest;
6679 char buf[100];
6680
6681 val = get_param(cmd, "FrameName");
6682 if (val == NULL)
6683 return -1;
6684
6685 if (strcasecmp(val, "QoSMapConfigure") == 0) {
6686 dest = get_param(cmd, "Dest");
6687 if (!dest)
6688 return -1;
6689
6690 val = get_param(cmd, "QoS_MAP_SET");
6691 if (val) {
6692 dut->ap_qos_map_set = atoi(val);
6693 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
6694 dut->ap_qos_map_set);
6695 }
6696
6697 if (dut->ap_qos_map_set == 1)
6698 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
6699 else if (dut->ap_qos_map_set == 2)
6700 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
6701
6702 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
6703 if (run_hostapd_cli(dut, buf) != 0)
6704 return -1;
6705 }
6706
6707 return 1;
6708}
6709
6710
6711static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
6712 struct sigma_cmd *cmd)
6713{
6714 const char *val;
6715 char *ifname;
6716 char buf[100];
6717 int chwidth, nss;
6718
6719 val = get_param(cmd, "FrameName");
6720 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
6721 send_resp(dut, conn, SIGMA_ERROR,
6722 "errorCode,Unsupported FrameName");
6723 return 0;
6724 }
6725
6726 /*
6727 * Sequence of commands for Opmode notification on
6728 * Peregrine based products
6729 */
6730 ifname = get_main_ifname();
6731
6732 /* Disable STBC */
6733 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
6734 if (system(buf) != 0) {
6735 sigma_dut_print(dut, DUT_MSG_ERROR,
6736 "iwpriv tx_stbc 0 failed!");
6737 }
6738
6739 /* Check whether optional arg channel width was passed */
6740 val = get_param(cmd, "Channel_width");
6741 if (val) {
6742 switch (atoi(val)) {
6743 case 20:
6744 chwidth = 0;
6745 break;
6746 case 40:
6747 chwidth = 1;
6748 break;
6749 case 80:
6750 chwidth = 2;
6751 break;
6752 case 160:
6753 chwidth = 3;
6754 break;
6755 default:
6756 chwidth = 2;
6757 break;
6758 }
6759 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6760 ifname, chwidth);
6761 if (system(buf) != 0) {
6762 sigma_dut_print(dut, DUT_MSG_ERROR,
6763 "iwpriv chwidth failed!");
6764 }
6765 }
6766
6767 /* Check whether optional arg NSS was passed */
6768 val = get_param(cmd, "NSS");
6769 if (val) {
6770 /* Convert nss to chainmask */
6771 switch (atoi(val)) {
6772 case 1:
6773 nss = 1;
6774 break;
6775 case 2:
6776 nss = 3;
6777 break;
6778 case 3:
6779 nss = 7;
6780 break;
6781 default:
6782 /* We do not support NSS > 3 */
6783 nss = 3;
6784 break;
6785 }
6786 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6787 ifname, nss);
6788 if (system(buf) != 0) {
6789 sigma_dut_print(dut, DUT_MSG_ERROR,
6790 "iwpriv rxchainmask failed!");
6791 }
6792 }
6793
6794 /* Send the opmode notification */
6795 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
6796 if (system(buf) != 0) {
6797 sigma_dut_print(dut, DUT_MSG_ERROR,
6798 "iwpriv opmode_notify failed!");
6799 }
6800
6801 return 1;
6802}
6803
6804
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006805static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
6806 struct sigma_cmd *cmd)
6807{
6808 const char *val;
6809 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07006810 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006811
6812 val = get_param(cmd, "MsntType");
6813 if (val) {
6814 if (dut->ap_msnt_type == 0)
6815 dut->ap_msnt_type = atoi(val);
6816
6817 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
6818 dut->ap_msnt_type = atoi(val);
6819 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07006820 val = get_param(cmd, "RandInterval");
6821 if (val)
6822 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006823 f = fopen("/tmp/ftmrr.txt", "a");
6824 if (!f) {
6825 sigma_dut_print(dut, DUT_MSG_ERROR,
6826 "Failed to open /tmp/ftmrr.txt");
6827 return -1;
6828 }
6829
6830 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07006831 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",
6832 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006833 fclose(f);
6834 dut->ap_msnt_type = 5;
6835 run_system(dut, "wpc -f /tmp/ftmrr.txt");
6836 }
6837 } else if (dut->ap_msnt_type == 5) {
6838 run_system(dut, "wpc -f /tmp/ftmrr.txt");
6839 } else if (dut->ap_msnt_type == 2) {
6840 f = fopen("/tmp/wru.txt", "w");
6841 if (!f) {
6842 sigma_dut_print(dut, DUT_MSG_ERROR,
6843 "Failed to open /tmp/wru.txt");
6844 return -1;
6845 }
6846
6847 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
6848 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
6849 fclose(f);
6850 run_system(dut, "wpc -w /tmp/wru.txt");
6851 }
6852 }
6853 return 1;
6854}
6855
6856
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07006857/*
6858 * The following functions parse_send_frame_params_int(),
6859 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
6860 * are used by ath_ap_send_frame_bcn_rpt_req().
6861 * Beacon Report Request is a frame used as part of the MBO program.
6862 * The command for sending beacon report has a lot of
6863 * arguments and having these functions reduces code size.
6864 *
6865 */
6866static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
6867 struct sigma_dut *dut,
6868 char *buf, size_t buf_size)
6869{
6870 const char *str_val;
6871 int int_val;
6872 char temp[100];
6873
6874 str_val = get_param(cmd, param);
6875 if (!str_val) {
6876 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
6877 return -1;
6878 }
6879 int_val = atoi(str_val);
6880 snprintf(temp, sizeof(temp), " %d", int_val);
6881 strncat(buf, temp, buf_size - strlen(buf) - 1);
6882 return 0;
6883}
6884
6885
6886static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
6887 struct sigma_dut *dut,
6888 char *buf, size_t buf_size)
6889{
6890 const char *str_val;
6891 char temp[100];
6892
6893 str_val = get_param(cmd, param);
6894 if (!str_val) {
6895 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
6896 return -1;
6897 }
6898 snprintf(temp, sizeof(temp), " %s", str_val);
6899 temp[sizeof(temp) - 1] = '\0';
6900 strncat(buf, temp, buf_size - strlen(buf) - 1);
6901 return 0;
6902}
6903
6904
6905static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
6906 struct sigma_dut *dut,
6907 char *buf, size_t buf_size)
6908{
6909 const char *str_val;
6910 unsigned char mac[6];
6911 char temp[100];
6912
6913 str_val = get_param(cmd, param);
6914 if (!str_val) {
6915 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
6916 return -1;
6917 }
6918
6919 if (parse_mac_address(dut, str_val, mac) < 0) {
6920 sigma_dut_print(dut, DUT_MSG_ERROR,
6921 "MAC Address not in proper format");
6922 return -1;
6923 }
6924 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
6925 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
6926 strncat(buf, temp, buf_size - strlen(temp) - 1);
6927 return 0;
6928}
6929
6930
6931static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
6932 char *buf, size_t buf_size)
6933{
6934 const char *str_val;
6935 char *value = " 1";
6936
6937 str_val = get_param(cmd, param);
6938 if (!str_val || str_val[0] == '\0')
6939 value = " 0";
6940 strncat(buf, value, buf_size - strlen(buf) - 1);
6941
6942}
6943
6944
6945/*
6946 * wifitool athN sendbcnrpt
6947 * <STA MAC - Plugs in from Dest_MAC>
6948 * <regclass - Plugs in from RegClass - int>
6949 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
6950 * <rand_ivl - Plugs in from RandInt - string>
6951 * <duration - Plugs in from MeaDur - integer>
6952 * <mode - Plugs in from MeaMode - string>
6953 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
6954 * <rep_cond - Plugs in from RptCond - integer>
6955 * <rpt_detail - Plugs in from RptDet - integer>
6956 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
6957 * <chanrpt_mode - Plugs in from APChanRpt - integer>
6958 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
6959 * [AP channel numbers]
6960 */
6961static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
6962 struct sigma_cmd *cmd,
6963 const char *ifname)
6964{
6965 char buf[100];
6966 int rpt_det;
6967 const char *str_val;
6968 const char *mea_mode;
6969
6970 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
6971
6972 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
6973 return -1;
6974 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
6975 return -1;
6976 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
6977 return -1;
6978 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
6979 return -1;
6980 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
6981 return -1;
6982
6983 str_val = get_param(cmd, "MeaMode");
6984 if (!str_val) {
6985 sigma_dut_print(dut, DUT_MSG_ERROR,
6986 "MeaMode parameter not present in send bcn-rpt-req");
6987 return -1;
6988 }
6989 if (strcasecmp(str_val, "passive") == 0) {
6990 mea_mode = " 0";
6991 } else if (strcasecmp(str_val, "active") == 0) {
6992 mea_mode = " 1";
6993 } else if (strcasecmp(str_val, "table") == 0) {
6994 mea_mode = " 2";
6995 } else {
6996 sigma_dut_print(dut, DUT_MSG_ERROR,
6997 "MEA-MODE Value not correctly given");
6998 return -1;
6999 }
7000 strncat(buf, mea_mode, sizeof(buf) - strlen(buf) - 1);
7001
7002 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
7003
7004 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
7005 return -1;
7006
7007 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
7008 return -1;
7009 str_val = get_param(cmd, "RptDet");
7010 rpt_det = str_val ? atoi(str_val) : 0;
7011
7012 if (rpt_det)
7013 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
7014 else
7015 strncat(buf, " 0", sizeof(buf) - strlen(buf) - 1);
7016
7017 if (rpt_det)
7018 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
7019 sizeof(buf));
7020 else
7021 strncat(buf, " 0", sizeof(buf) - strlen(buf) - 1);
7022
7023 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
7024 return -1;
7025
7026 run_system(dut, buf);
7027 return 0;
7028}
7029
7030
7031static void inform_and_sleep(struct sigma_dut *dut, int seconds)
7032{
7033 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
7034 sleep(seconds);
7035 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
7036 seconds);
7037}
7038
7039
7040static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
7041 struct sigma_cmd *cmd, const char *ifname)
7042{
7043 unsigned char mac_addr[ETH_ALEN];
7044 int disassoc_timer;
7045 char buf[100];
7046 const char *val;
7047 int cand_list = 1;
7048 int tsf = 2;
7049
7050 val = get_param(cmd, "Dest_MAC");
7051 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
7052 sigma_dut_print(dut, DUT_MSG_ERROR,
7053 "MAC Address not in proper format");
7054 return -1;
7055 }
7056
7057 val = get_param(cmd, "Disassoc_Timer");
7058 if (val)
7059 disassoc_timer = atoi(val);
7060 else
7061 disassoc_timer = dut->ap_disassoc_timer;
7062
7063 val = get_param(cmd, "Cand_List");
7064 if (val && val[0])
7065 cand_list = atoi(val);
7066
7067 val = get_param(cmd, "BTMQuery_Reason_Code");
7068 if (val) {
7069 snprintf(buf, sizeof(buf), "iwpriv %s mbo_trans_rs %s",
7070 ifname, val);
7071 run_system(dut, buf);
7072 }
7073
7074 snprintf(buf, sizeof(buf),
7075 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 3 %d %d %d %d",
7076 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
7077 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
7078 dut->ap_btmreq_disassoc_imnt,
7079 dut->ap_btmreq_term_bit,
7080 tsf,
7081 dut->ap_btmreq_bss_term_dur);
7082 run_system(dut, buf);
7083
7084 if (dut->ap_btmreq_term_bit) {
7085 inform_and_sleep(dut, 3);
7086 run_system_wrapper(dut, "ifconfig %s down", ifname);
7087 inform_and_sleep(dut, dut->ap_btmreq_bss_term_dur * 60);
7088 run_system_wrapper(dut, "ifconfig %s up", ifname);
7089 } else if (dut->ap_btmreq_disassoc_imnt) {
7090 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
7091 run_system_wrapper(dut,
7092 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
7093 ifname,
7094 mac_addr[0], mac_addr[1], mac_addr[2],
7095 mac_addr[3], mac_addr[4], mac_addr[5]);
7096 }
7097 return 0;
7098}
7099
7100
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007101static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
7102 struct sigma_cmd *cmd)
7103{
7104 const char *val;
7105 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007106
7107 ifname = get_main_ifname();
7108
7109 val = get_param(cmd, "FrameName");
7110 if (!val)
7111 return -1;
7112
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007113 if (strcasecmp(val, "BTMReq") == 0)
7114 ath_ap_send_frame_btm_req(dut, cmd, ifname);
7115 else if (strcasecmp(val, "BcnRptReq") == 0)
7116 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
7117 else
7118 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007119
7120 return 1;
7121}
7122
7123
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007124static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
7125 struct sigma_cmd *cmd)
7126{
7127 switch (get_driver_type()) {
7128 case DRIVER_ATHEROS:
7129 return ath_ap_send_frame_vht(dut, conn, cmd);
7130 break;
7131 case DRIVER_OPENWRT:
7132 switch (get_openwrt_driver_type()) {
7133 case OPENWRT_DRIVER_ATHEROS:
7134 return ath_ap_send_frame_vht(dut, conn, cmd);
7135 default:
7136 send_resp(dut, conn, SIGMA_ERROR,
7137 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
7138 return 0;
7139 }
7140 default:
7141 send_resp(dut, conn, SIGMA_ERROR,
7142 "errorCode,Unsupported ap_send_frame with the current driver");
7143 return 0;
7144 }
7145}
7146
7147
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007148static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
7149 struct sigma_cmd *cmd)
7150{
7151 switch (get_driver_type()) {
7152 case DRIVER_ATHEROS:
7153 return ath_ap_send_frame_loc(dut, conn, cmd);
7154 case DRIVER_OPENWRT:
7155 switch (get_openwrt_driver_type()) {
7156 case OPENWRT_DRIVER_ATHEROS:
7157 return ath_ap_send_frame_loc(dut, conn, cmd);
7158 default:
7159 send_resp(dut, conn, SIGMA_ERROR,
7160 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
7161 return 0;
7162 }
7163 default:
7164 send_resp(dut, conn, SIGMA_ERROR,
7165 "errorCode,Unsupported ap_send_frame_loc with the current driver");
7166 return 0;
7167 }
7168}
7169
7170
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007171static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
7172 struct sigma_cmd *cmd)
7173{
7174 switch (get_driver_type()) {
7175 case DRIVER_ATHEROS:
7176 return ath_ap_send_frame_mbo(dut, conn, cmd);
7177 case DRIVER_OPENWRT:
7178 switch (get_openwrt_driver_type()) {
7179 case OPENWRT_DRIVER_ATHEROS:
7180 return ath_ap_send_frame_mbo(dut, conn, cmd);
7181 default:
7182 send_resp(dut, conn, SIGMA_ERROR,
7183 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
7184 return 0;
7185 }
7186 default:
7187 send_resp(dut, conn, SIGMA_ERROR,
7188 "errorCode,Unsupported ap_send_frame with the current driver");
7189 return 0;
7190 }
7191}
7192
7193
Lior David0fe101e2017-03-09 16:09:50 +02007194static int ap_send_frame_60g(struct sigma_dut *dut,
7195 struct sigma_conn *conn,
7196 struct sigma_cmd *cmd)
7197{
7198 switch (get_driver_type()) {
7199#ifdef __linux__
7200 case DRIVER_WIL6210:
7201 return wil6210_send_frame_60g(dut, conn, cmd);
7202#endif /* __linux__ */
7203 default:
7204 send_resp(dut, conn, SIGMA_ERROR,
7205 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7206 return 0;
7207 }
7208}
7209
7210
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007211int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7212 struct sigma_cmd *cmd)
7213{
7214 /* const char *name = get_param(cmd, "NAME"); */
7215 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7216 const char *val;
7217 enum send_frame_type frame;
7218 enum send_frame_protection protected;
7219 char buf[100];
7220
7221 val = get_param(cmd, "Program");
7222 if (val) {
7223 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007224 strcasecmp(val, "HS2-R2") == 0 ||
7225 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007226 return ap_send_frame_hs2(dut, conn, cmd);
7227 if (strcasecmp(val, "VHT") == 0)
7228 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007229 if (strcasecmp(val, "LOC") == 0)
7230 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007231 if (strcasecmp(val, "MBO") == 0)
7232 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007233 if (strcasecmp(val, "60GHz") == 0)
7234 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007235 }
7236
7237 val = get_param(cmd, "PMFFrameType");
7238 if (val == NULL)
7239 val = get_param(cmd, "FrameName");
7240 if (val == NULL)
7241 val = get_param(cmd, "Type");
7242 if (val == NULL)
7243 return -1;
7244 if (strcasecmp(val, "disassoc") == 0)
7245 frame = DISASSOC;
7246 else if (strcasecmp(val, "deauth") == 0)
7247 frame = DEAUTH;
7248 else if (strcasecmp(val, "saquery") == 0)
7249 frame = SAQUERY;
7250 else {
7251 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7252 "PMFFrameType");
7253 return 0;
7254 }
7255
7256 val = get_param(cmd, "PMFProtected");
7257 if (val == NULL)
7258 val = get_param(cmd, "Protected");
7259 if (val == NULL)
7260 return -1;
7261 if (strcasecmp(val, "Correct-key") == 0 ||
7262 strcasecmp(val, "CorrectKey") == 0)
7263 protected = CORRECT_KEY;
7264 else if (strcasecmp(val, "IncorrectKey") == 0)
7265 protected = INCORRECT_KEY;
7266 else if (strcasecmp(val, "Unprotected") == 0)
7267 protected = UNPROTECTED;
7268 else {
7269 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7270 "PMFProtected");
7271 return 0;
7272 }
7273
7274 val = get_param(cmd, "stationID");
7275 if (val == NULL)
7276 return -1;
7277
7278 if (protected == INCORRECT_KEY ||
7279 (protected == UNPROTECTED && frame == SAQUERY))
7280 return ap_inject_frame(dut, conn, frame, protected, val);
7281
7282 switch (frame) {
7283 case DISASSOC:
7284 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
7285 val, protected == CORRECT_KEY);
7286 break;
7287 case DEAUTH:
7288 snprintf(buf, sizeof(buf), "deauth %s test=%d",
7289 val, protected == CORRECT_KEY);
7290 break;
7291 case SAQUERY:
7292 snprintf(buf, sizeof(buf), "sa_query %s", val);
7293 break;
7294 }
7295
7296 if (run_hostapd_cli(dut, buf) != 0)
7297 return -2;
7298
7299 return 1;
7300}
7301
7302
7303static int cmd_ap_get_mac_address(struct sigma_dut *dut,
7304 struct sigma_conn *conn,
7305 struct sigma_cmd *cmd)
7306{
7307#if defined( __linux__)
7308 /* const char *name = get_param(cmd, "NAME"); */
7309 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7310 char resp[50];
7311 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007312 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007313 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007314 int s, wlan_tag = 1;
7315 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007316
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007317 val = get_param(cmd, "WLAN_TAG");
7318 if (val) {
7319 wlan_tag = atoi(val);
7320 if (wlan_tag < 1 || wlan_tag > 3) {
7321 /*
7322 * The only valid WLAN Tags as of now as per the latest
7323 * WFA scripts are 1, 2, and 3.
7324 */
7325 send_resp(dut, conn, SIGMA_INVALID,
7326 "errorCode,Unsupported WLAN_TAG");
7327 return 0;
7328 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007329 }
7330
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007331 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
7332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007333 s = socket(AF_INET, SOCK_DGRAM, 0);
7334 if (s < 0)
7335 return -1;
7336 memset(&ifr, 0, sizeof(ifr));
7337 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7338 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
7339 perror("ioctl");
7340 close(s);
7341 return -1;
7342 }
7343 close(s);
7344 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
7345
7346 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
7347 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
7348 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7349 return 0;
7350#elif defined( __QNXNTO__)
7351 char resp[50];
7352 unsigned char addr[6];
7353
7354 if (!sigma_main_ifname) {
7355 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
7356 return 0;
7357 }
7358
7359 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
7360 send_resp(dut, conn, SIGMA_ERROR,
7361 "errorCode,Failed to get address");
7362 return 0;
7363 }
7364 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
7365 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
7366 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7367 return 0;
7368#else /* __linux__ */
7369 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
7370 "yet supported");
7371 return 0;
7372#endif /* __linux__ */
7373}
7374
7375
7376static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
7377 struct sigma_cmd *cmd)
7378{
7379 /*
7380 * Ignore the command since the parameters are already handled through
7381 * ap_set_security.
7382 */
7383
7384 return 1;
7385}
7386
7387
7388static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
7389 struct sigma_cmd *cmd)
7390{
7391 /* const char *name = get_param(cmd, "NAME"); */
7392 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7393 const char *val, *dest;
7394 char *pos, buf[100];
7395 int i, wlan_tag = 1;
7396
7397 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
7398 "following parameters");
7399 for (i = 0; i < cmd->count; i++) {
7400 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
7401 (cmd->values[i] ? cmd->values[i] : "NULL"));
7402 }
7403
7404 val = get_param(cmd, "ICMPv4_ECHO");
7405 if (val && atoi(val)) {
7406 snprintf(buf, sizeof(buf), "ebtables -F");
7407 if (system(buf) != 0) {
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "Failed to set ebtables rules, RULE-12");
7410 }
7411 return 1;
7412 }
7413
7414 val = get_param(cmd, "WLAN_TAG");
7415 if (val) {
7416 wlan_tag = atoi(val);
7417 if (wlan_tag != 1 && wlan_tag != 2) {
7418 send_resp(dut, conn, SIGMA_INVALID,
7419 "errorCode,Invalid WLAN_TAG");
7420 return 0;
7421 }
7422 }
7423
7424 if (wlan_tag == 2) {
7425 val = get_param(cmd, "PROXY_ARP");
7426 if (val)
7427 dut->ap2_proxy_arp = atoi(val);
7428 return 1;
7429 }
7430
7431 dest = get_param(cmd, "STA_MAC");
7432 if (dest) {
7433 /* This is a special/ugly way of using this command.
7434 * If "Dest" MAC is included, assume that this command
7435 * is being issued after ap_config_commit for dynamically
7436 * setting the QoS Map Set.
7437 */
7438 val = get_param(cmd, "QoS_MAP_SET");
7439 if (val) {
7440 dut->ap_qos_map_set = atoi(val);
7441 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
7442 dut->ap_qos_map_set);
7443 }
7444
7445 if (dut->ap_qos_map_set == 1)
7446 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
7447 else if (dut->ap_qos_map_set == 2)
7448 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
7449
7450 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
7451 if (run_hostapd_cli(dut, buf) != 0)
7452 return -1;
7453 }
7454
7455 val = get_param(cmd, "DGAF_DISABLE");
7456 if (val)
7457 dut->ap_dgaf_disable = atoi(val);
7458
7459 dut->ap_interworking = 1;
7460
7461 val = get_param(cmd, "INTERWORKING");
7462 if (val == NULL)
7463 val = get_param(cmd, "INTERNETWORKING");
7464 if (val != NULL && atoi(val) == 0) {
7465 dut->ap_interworking = 0;
7466 dut->ap_hs2 = 0;
7467 return 1;
7468 }
7469
7470 val = get_param(cmd, "ACCS_NET_TYPE");
7471 if (val) {
7472 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
7473 strcasecmp(val, "Chargable_Public_Network") == 0 ||
7474 strcasecmp(val, "Chargable Public Network") == 0)
7475 dut->ap_access_net_type = 2;
7476 else
7477 dut->ap_access_net_type = atoi(val);
7478 }
7479
7480 val = get_param(cmd, "INTERNET");
7481 if (val)
7482 dut->ap_internet = atoi(val);
7483
7484 val = get_param(cmd, "VENUE_GRP");
7485 if (val) {
7486 if (strcasecmp(val, "Business") == 0)
7487 dut->ap_venue_group = 2;
7488 else
7489 dut->ap_venue_group = atoi(val);
7490 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
7491 dut->ap_venue_name);
7492 }
7493
7494 val = get_param(cmd, "VENUE_TYPE");
7495 if (val) {
7496 if (strcasecmp(val, "R&D") == 0)
7497 dut->ap_venue_type = 8;
7498 else
7499 dut->ap_venue_type = atoi(val);
7500 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
7501 dut->ap_venue_type);
7502 }
7503
7504 val = get_param(cmd, "HESSID");
7505 if (val) {
7506 if (strlen(val) >= sizeof(dut->ap_hessid)) {
7507 send_resp(dut, conn, SIGMA_ERROR,
7508 "errorCode,Invalid HESSID");
7509 return 0;
7510 }
7511 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
7512 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
7513 dut->ap_hessid);
7514 }
7515
7516 val = get_param(cmd, "ROAMING_CONS");
7517 if (val) {
7518 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
7519 send_resp(dut, conn, SIGMA_ERROR,
7520 "errorCode,Invalid ROAMING_CONS");
7521 return 0;
7522 }
7523 if (strcasecmp(val, "Disabled") == 0) {
7524 dut->ap_roaming_cons[0] = '\0';
7525 } else {
7526 snprintf(dut->ap_roaming_cons,
7527 sizeof(dut->ap_roaming_cons), "%s", val);
7528 }
7529 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
7530 dut->ap_roaming_cons);
7531 }
7532
7533 val = get_param(cmd, "ANQP");
7534 if (val)
7535 dut->ap_anqpserver_on = atoi(val);
7536
7537 val = get_param(cmd, "NAI_REALM_LIST");
7538 if (val) {
7539 dut->ap_nai_realm_list = atoi(val);
7540 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
7541 dut->ap_nai_realm_list);
7542 }
7543
7544 val = get_param(cmd, "3GPP_INFO");
7545 if (val) {
7546 /* What kind of encoding format is used?! */
7547 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
7548 "not yet supported (contents not fully defined)");
7549 return 0;
7550 }
7551
7552 val = get_param(cmd, "DOMAIN_LIST");
7553 if (val) {
7554 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
7555 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
7556 "DOMAIN_LIST");
7557 return 0;
7558 }
7559 snprintf(dut->ap_domain_name_list,
7560 sizeof(dut->ap_domain_name_list), "%s", val);
7561 pos = dut->ap_domain_name_list;
7562 while (*pos) {
7563 if (*pos == ';')
7564 *pos = ',';
7565 pos++;
7566 }
7567 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
7568 dut->ap_domain_name_list);
7569 }
7570
7571 val = get_param(cmd, "OPER_NAME");
7572 if (val) {
7573 dut->ap_oper_name = atoi(val);
7574 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
7575 dut->ap_oper_name);
7576 }
7577
7578 val = get_param(cmd, "VENUE_NAME");
7579 if (val) {
7580 dut->ap_venue_name = atoi(val);
7581 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
7582 dut->ap_venue_name);
7583 }
7584
7585 val = get_param(cmd, "GAS_CB_DELAY");
7586 if (val) {
7587 dut->ap_gas_cb_delay = atoi(val);
7588 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
7589 dut->ap_gas_cb_delay);
7590 }
7591
7592 val = get_param(cmd, "MIH");
7593 if (val && atoi(val) > 0) {
7594 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
7595 "supported");
7596 return 0;
7597 }
7598
7599 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
7600 if (val) {
7601 dut->ap_l2tif = atoi(val);
7602 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
7603 dut->ap_l2tif);
7604 }
7605
7606 val = get_param(cmd, "BCST_UNCST");
7607 if (val) {
7608 send_resp(dut, conn, SIGMA_ERROR,
7609 "errorCode,BCST_UNCST not yet supported");
7610 return 0;
7611 }
7612
7613 val = get_param(cmd, "PLMN_MCC");
7614 if (val) {
7615 char mcc[100], *start, *end;
7616 int i = 0;
7617 if (strlen(val) >= sizeof(mcc)) {
7618 send_resp(dut, conn, SIGMA_ERROR,
7619 "errorCode,PLMN_MCC too long");
7620 return 0;
7621 }
7622 strncpy(mcc, val, sizeof(mcc));
7623 start = mcc;
7624 while ((end = strchr(start, ';'))) {
7625 /* process all except the last */
7626 *end = '\0';
7627 if (strlen(start) != 3) {
7628 send_resp(dut, conn, SIGMA_ERROR,
7629 "errorCode,Invalid PLMN_MCC");
7630 return 0;
7631 }
7632 snprintf(dut->ap_plmn_mcc[i],
7633 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
7634 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
7635 dut->ap_plmn_mcc[i]);
7636 i++;
7637 start = end + 1;
7638 *end = ';';
7639 }
7640 if (strlen(start) != 3) {
7641 send_resp(dut, conn, SIGMA_ERROR,
7642 "errorCode,Invalid PLMN_MCC");
7643 return 0;
7644 }
7645 /* process last or only one */
7646 snprintf(dut->ap_plmn_mcc[i],
7647 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
7648 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
7649 dut->ap_plmn_mcc[i]);
7650 }
7651
7652 val = get_param(cmd, "PLMN_MNC");
7653 if (val) {
7654 char mnc[100], *start, *end;
7655 int i = 0;
7656 if (strlen(val) >= sizeof(mnc)) {
7657 send_resp(dut, conn, SIGMA_ERROR,
7658 "errorCode,PLMN_MNC too long");
7659 return 0;
7660 }
7661 strncpy(mnc, val, sizeof(mnc));
7662 start = mnc;
7663 while ((end = strchr(start, ';'))) {
7664 *end = '\0';
7665 if (strlen(start) != 2 && strlen(start) != 3) {
7666 send_resp(dut, conn, SIGMA_ERROR,
7667 "errorCode,Invalid PLMN_MNC");
7668 return 0;
7669 }
7670 snprintf(dut->ap_plmn_mnc[i],
7671 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
7672 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
7673 dut->ap_plmn_mnc[i]);
7674 i++;
7675 start = end + 1;
7676 *end = ';';
7677 }
7678 if (strlen(start) != 2 && strlen(start) != 3) {
7679 send_resp(dut, conn, SIGMA_ERROR,
7680 "errorCode,Invalid PLMN_MNC");
7681 return 0;
7682 }
7683 snprintf(dut->ap_plmn_mnc[i],
7684 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
7685 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
7686 dut->ap_plmn_mnc[i]);
7687 }
7688
7689 val = get_param(cmd, "PROXY_ARP");
7690 if (val) {
7691 dut->ap_proxy_arp = atoi(val);
7692 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
7693 dut->ap_proxy_arp);
7694 }
7695
7696 val = get_param(cmd, "WAN_METRICS");
7697 if (val) {
7698 dut->ap_wan_metrics = atoi(val);
7699 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
7700 dut->ap_wan_metrics);
7701 }
7702
7703 val = get_param(cmd, "CONN_CAP");
7704 if (val) {
7705 dut->ap_conn_capab = atoi(val);
7706 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
7707 dut->ap_conn_capab);
7708 }
7709
7710 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
7711 if (val) {
7712 dut->ap_ip_addr_type_avail = atoi(val);
7713 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
7714 dut->ap_ip_addr_type_avail);
7715 }
7716
7717 val = get_param(cmd, "NET_AUTH_TYPE");
7718 if (val) {
7719 dut->ap_net_auth_type = atoi(val);
7720 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
7721 dut->ap_net_auth_type);
7722 }
7723
7724 val = get_param(cmd, "OP_CLASS");
7725 if (val == NULL)
7726 val = get_param(cmd, "OPER_CLASS");
7727 if (val) {
7728 dut->ap_oper_class = atoi(val);
7729 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
7730 dut->ap_oper_class);
7731 }
7732
7733 val = get_param(cmd, "OSU_PROVIDER_LIST");
7734 if (val) {
7735 dut->ap_osu_provider_list = atoi(val);
7736 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
7737 dut->ap_osu_provider_list);
7738 }
7739
7740 val = get_param(cmd, "OSU_SERVER_URI");
7741 if (val) {
7742 i = 0;
7743 do {
7744 int len;
7745 const char *uri = val;
7746 val = strchr(val, ' ');
7747 len = val ? (val++ - uri) : (int) strlen(uri);
7748 if (len > 0 && len < 256) {
7749 memcpy(dut->ap_osu_server_uri[i], uri, len);
7750 dut->ap_osu_server_uri[i][len] = '\0';
7751 sigma_dut_print(dut, DUT_MSG_INFO,
7752 "ap_osu_server_uri[%d] %s", i,
7753 dut->ap_osu_server_uri[i]);
7754 }
7755 } while (val && ++i < 10);
7756 }
7757
7758 val = get_param(cmd, "OSU_METHOD");
7759 if (val) {
7760 i = 0;
7761 do {
7762 int len;
7763 const char *method = val;
7764 val = strchr(val, ' ');
7765 len = val ? (val++ - method) : (int) strlen(method);
7766 if (len > 0) {
7767 if (strncasecmp(method, "SOAP", len) == 0)
7768 dut->ap_osu_method[i] = 1;
7769 else if (strncasecmp(method, "OMADM", len) == 0)
7770 dut->ap_osu_method[i] = 0;
7771 else
7772 return -2;
7773 }
7774 } while (val && ++i < 10);
7775 }
7776
7777 val = get_param(cmd, "OSU_SSID");
7778 if (val) {
7779 if (strlen(val) > 0 && strlen(val) <= 32) {
7780 strncpy(dut->ap_osu_ssid, val,
7781 sizeof(dut->ap_osu_ssid));
7782 sigma_dut_print(dut, DUT_MSG_INFO,
7783 "ap_osu_ssid %s",
7784 dut->ap_osu_ssid);
7785 }
7786 }
7787
7788 val = get_param(cmd, "OSU_ICON_TAG");
7789 if (val)
7790 dut->ap_osu_icon_tag = atoi(val);
7791
7792 val = get_param(cmd, "QoS_MAP_SET");
7793 if (val) {
7794 dut->ap_qos_map_set = atoi(val);
7795 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
7796 dut->ap_qos_map_set);
7797 }
7798
7799 val = get_param(cmd, "BSS_LOAD");
7800 if (val) {
7801 dut->ap_bss_load = atoi(val);
7802 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
7803 dut->ap_bss_load);
7804 }
7805
7806 return 1;
7807}
7808
7809
7810void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
7811{
7812 char buf[100];
7813
7814 if (!file_exists("nfc-status"))
7815 return;
7816
7817 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
7818 run_system(dut, buf);
7819}
7820
7821
7822static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
7823 const char *info)
7824{
7825 int res;
7826
7827 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
7828 printf("%s\n\n", info);
7829
7830 nfc_status(dut, "START", info);
7831 res = run_system(dut, cmd);
7832 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
7833 if (res) {
7834 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
7835 cmd, res);
7836 return res;
7837 }
7838
7839 return 0;
7840}
7841
7842
7843static int ap_nfc_write_config_token(struct sigma_dut *dut,
7844 struct sigma_conn *conn,
7845 struct sigma_cmd *cmd)
7846{
7847 int res;
7848 char buf[300];
7849
7850 run_system(dut, "killall wps-ap-nfc.py");
7851 unlink("nfc-success");
7852 snprintf(buf, sizeof(buf),
7853 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
7854 dut->summary_log ? "--summary " : "",
7855 dut->summary_log ? dut->summary_log : "");
7856 res = run_nfc_command(dut, buf,
7857 "Touch NFC Tag to write WPS configuration token");
7858 if (res || !file_exists("nfc-success")) {
7859 send_resp(dut, conn, SIGMA_ERROR,
7860 "ErrorCode,Failed to write tag");
7861 return 0;
7862 }
7863
7864 return 1;
7865}
7866
7867
7868static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
7869 struct sigma_conn *conn,
7870 struct sigma_cmd *cmd)
7871{
7872 int res;
7873 char buf[300];
7874
7875 run_system(dut, "killall wps-ap-nfc.py");
7876
7877 unlink("nfc-success");
7878 snprintf(buf, sizeof(buf),
7879 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
7880 dut->summary_log ? "--summary " : "",
7881 dut->summary_log ? dut->summary_log : "");
7882 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
7883 if (res || !file_exists("nfc-success")) {
7884 send_resp(dut, conn, SIGMA_ERROR,
7885 "ErrorCode,Failed to read tag");
7886 return 0;
7887 }
7888
7889 return 1;
7890}
7891
7892
7893static int ap_nfc_write_password_token(struct sigma_dut *dut,
7894 struct sigma_conn *conn,
7895 struct sigma_cmd *cmd)
7896{
7897 int res;
7898 char buf[300];
7899
7900 run_system(dut, "killall wps-ap-nfc.py");
7901 unlink("nfc-success");
7902 snprintf(buf, sizeof(buf),
7903 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
7904 dut->summary_log ? "--summary " : "",
7905 dut->summary_log ? dut->summary_log : "");
7906 res = run_nfc_command(dut, buf,
7907 "Touch NFC Tag to write WPS password token");
7908 if (res || !file_exists("nfc-success")) {
7909 send_resp(dut, conn, SIGMA_ERROR,
7910 "ErrorCode,Failed to write tag");
7911 return 0;
7912 }
7913
7914 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
7915 send_resp(dut, conn, SIGMA_ERROR,
7916 "ErrorCode,Failed to enable NFC password token");
7917 return 0;
7918 }
7919
7920 return 1;
7921}
7922
7923
7924static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
7925 struct sigma_conn *conn,
7926 struct sigma_cmd *cmd)
7927{
7928 int res;
7929 char buf[300];
7930
7931 run_system(dut, "killall wps-ap-nfc.py");
7932 unlink("nfc-success");
7933 snprintf(buf, sizeof(buf),
7934 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
7935 dut->summary_log ? "--summary " : "",
7936 dut->summary_log ? dut->summary_log : "");
7937 res = run_nfc_command(dut, buf,
7938 "Touch NFC Device to respond to WPS connection handover");
7939 if (res) {
7940 send_resp(dut, conn, SIGMA_ERROR,
7941 "ErrorCode,Failed to enable NFC for connection "
7942 "handover");
7943 return 0;
7944 }
7945 if (!file_exists("nfc-success")) {
7946 send_resp(dut, conn, SIGMA_ERROR,
7947 "ErrorCode,Failed to complete NFC connection handover");
7948 return 0;
7949 }
7950
7951 return 1;
7952}
7953
7954
7955static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
7956 struct sigma_cmd *cmd)
7957{
7958 /* const char *name = get_param(cmd, "Name"); */
7959 /* const char *intf = get_param(cmd, "Interface"); */
7960 const char *oper = get_param(cmd, "Operation");
7961
7962 if (oper == NULL)
7963 return -1;
7964
7965 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
7966 return ap_nfc_write_config_token(dut, conn, cmd);
7967 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
7968 return ap_nfc_write_password_token(dut, conn, cmd);
7969 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
7970 return ap_nfc_wps_read_passwd(dut, conn, cmd);
7971 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
7972 return ap_nfc_wps_connection_handover(dut, conn, cmd);
7973
7974 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
7975 return 0;
7976}
7977
7978
7979static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
7980 struct sigma_cmd *cmd)
7981{
7982 char *pin = "12345670"; /* TODO: use random PIN */
7983 char resp[100];
7984
7985 snprintf(resp, sizeof(resp), "PIN,%s", pin);
7986 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7987
7988 return 0;
7989}
7990
7991
7992static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
7993 const char *val)
7994{
7995 char *token, *result;
7996 int nss = 0, chwidth = 0;
7997 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307998 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007999
8000 /*
8001 * The following commands should be invoked to generate
8002 * VHT op mode notification
8003 */
8004
8005 /* Extract the NSS info */
8006 token = strdup(val);
8007 if (!token)
8008 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308009 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008010 if (result) {
8011 int count = atoi(result);
8012
8013 /* We do not support NSS > 3 */
8014 if (count < 0 || count > 3) {
8015 free(token);
8016 return -1;
8017 }
8018
8019 /* Convert nss to chainmask */
8020 while (count--)
8021 nss = (nss << 1) | 1;
8022
8023 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
8024 ifname, nss);
8025 if (system(buf) != 0) {
8026 sigma_dut_print(dut, DUT_MSG_ERROR,
8027 "iwpriv wifi1 rxchainmask failed!");
8028 }
8029 }
8030
8031 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308032 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008033 if (result) {
8034 switch (atoi(result)) {
8035 case 20:
8036 chwidth = 0;
8037 break;
8038 case 40:
8039 chwidth = 1;
8040 break;
8041 case 80:
8042 chwidth = 2;
8043 break;
8044 case 160:
8045 chwidth = 3;
8046 break;
8047 default:
8048 chwidth = 2;
8049 break;
8050 }
8051 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8052 ifname, chwidth);
8053 if (system(buf) != 0) {
8054 sigma_dut_print(dut, DUT_MSG_ERROR,
8055 "iwpriv chwidth failed!");
8056 }
8057 }
8058
8059 /* Send the opmode notification */
8060 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
8061 if (system(buf) != 0) {
8062 sigma_dut_print(dut, DUT_MSG_ERROR,
8063 "iwpriv opmode_notify failed!");
8064 }
8065 free(token);
8066
8067 return 0;
8068}
8069
8070
8071static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
8072 const char *val)
8073{
8074 /* String (nss_operating_mode; mcs_operating_mode) */
8075 int nss, mcs;
8076 char *token, *result;
8077 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308078 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008079
8080 token = strdup(val);
8081 if (!token)
8082 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308083 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308084 if (!result) {
8085 sigma_dut_print(dut, DUT_MSG_ERROR,
8086 "VHT NSS not specified");
8087 goto end;
8088 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008089 if (strcasecmp(result, "def") != 0) {
8090 nss = atoi(result);
8091
8092 if (nss == 4)
8093 ath_disable_txbf(dut, ifname);
8094
8095 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
8096 if (system(buf) != 0) {
8097 sigma_dut_print(dut, DUT_MSG_ERROR,
8098 "iwpriv nss failed");
8099 }
8100 } else {
8101 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
8102 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
8103 if (system(buf) != 0) {
8104 sigma_dut_print(dut, DUT_MSG_ERROR,
8105 "iwpriv nss failed");
8106 }
8107 }
8108 }
8109
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308110 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308111 if (!result) {
8112 sigma_dut_print(dut, DUT_MSG_ERROR,
8113 "VHT MCS not specified");
8114 goto end;
8115 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008116 if (strcasecmp(result, "def") == 0) {
8117 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
8118 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
8119 ifname);
8120 if (system(buf) != 0) {
8121 sigma_dut_print(dut, DUT_MSG_ERROR,
8122 "iwpriv vhtmcs failed");
8123 }
8124 } else {
8125 snprintf(buf, sizeof(buf),
8126 "iwpriv %s set11NRates 0", ifname);
8127 if (system(buf) != 0) {
8128 sigma_dut_print(dut, DUT_MSG_ERROR,
8129 "iwpriv set11NRates failed");
8130 }
8131 }
8132 } else {
8133 mcs = atoi(result);
8134 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
8135 if (system(buf) != 0) {
8136 sigma_dut_print(dut, DUT_MSG_ERROR,
8137 "iwpriv vhtmcs failed");
8138 }
8139 }
8140
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308141end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008142 free(token);
8143 return 0;
8144}
8145
8146
8147static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8148 const char *val)
8149{
8150 char *token, *result;
8151 int channel = 36;
8152 int chwidth = 80;
8153 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308154 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008155
8156 /* Extract the channel info */
8157 token = strdup(val);
8158 if (!token)
8159 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308160 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008161 if (result)
8162 channel = atoi(result);
8163
8164 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308165 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008166 if (result)
8167 chwidth = atoi(result);
8168
8169 /* Issue the channel switch command */
8170 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
8171 ifname, channel, chwidth);
8172 if (system(buf) != 0) {
8173 sigma_dut_print(dut, DUT_MSG_ERROR,
8174 "iwpriv doth_ch_chwidth failed!");
8175 }
8176
8177 free(token);
8178 return 0;
8179}
8180
8181
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008182static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
8183 const char *val)
8184{
8185 char buf[80];
8186 unsigned char mac_addr[6];
8187
8188 if (parse_mac_address(dut, val, mac_addr) < 0)
8189 return -1;
8190
8191 snprintf(buf, sizeof(buf),
8192 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
8193 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
8194 run_system(dut, buf);
8195
8196 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
8197 ifname, mac_addr[4], mac_addr[5]);
8198 run_system(dut, buf);
8199
8200 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
8201 run_system(dut, buf);
8202
8203 return 0;
8204}
8205
8206
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008207void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08008208{
8209 char buf[60];
8210
8211 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
8212 if (system(buf) != 0) {
8213 sigma_dut_print(dut, DUT_MSG_ERROR,
8214 "disabling novap reset failed");
8215 }
8216}
8217
8218
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008219struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
8220 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008221{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008222 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008223
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008224 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
8225 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
8226 ETH_ALEN) == 0)
8227 return &dut->mbo_pref_aps[i];
8228 }
8229 return NULL;
8230}
8231
8232
8233static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
8234 int ap_ne_class, int ap_ne_op_ch,
8235 int ap_ne_pref)
8236{
8237 struct mbo_pref_ap *entry;
8238 uint8_t self_mac[ETH_ALEN];
8239 char ifname[50];
8240
8241 get_if_name(dut, ifname, sizeof(ifname), 1);
8242 get_hwaddr(ifname, self_mac);
8243
8244 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
8245 entry = &dut->mbo_self_ap_tuple;
8246 else
8247 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
8248
8249 if (!entry) {
8250 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "Nebor AP List is full. Not adding");
8253 return;
8254 }
8255 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
8256 dut->mbo_pref_ap_cnt++;
8257 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
8258 entry->ap_ne_class = -1;
8259 entry->ap_ne_op_ch = -1;
8260 entry->ap_ne_pref = -1;
8261 }
8262 if (ap_ne_class != -1)
8263 entry->ap_ne_class = ap_ne_class;
8264 if (ap_ne_op_ch != -1)
8265 entry->ap_ne_op_ch = ap_ne_op_ch;
8266 if (ap_ne_pref != -1)
8267 entry->ap_ne_pref = ap_ne_pref;
8268}
8269
8270
8271static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
8272 struct sigma_cmd *cmd)
8273{
8274 unsigned char mac_addr[ETH_ALEN];
8275 const char *val;
8276 /*
8277 * -1 is invalid value for the following
8278 * to differentiate between unset and set values
8279 * -1 => implies not set by CAPI
8280 */
8281 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
8282 int list_offset = dut->mbo_pref_ap_cnt;
8283
8284 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
8285 sigma_dut_print(dut, DUT_MSG_ERROR,
8286 "AP Pref Entry list is full");
8287 return -1;
8288 }
8289
8290 val = get_param(cmd, "Nebor_Op_Class");
8291 if (val)
8292 ap_ne_class = atoi(val);
8293
8294 val = get_param(cmd, "Nebor_Op_Ch");
8295 if (val)
8296 ap_ne_op_ch = atoi(val);
8297
8298 val = get_param(cmd, "Nebor_Pref");
8299 if (val)
8300 ap_ne_pref = atoi(val);
8301
8302 val = get_param(cmd, "Nebor_BSSID");
8303 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008304 return -1;
8305
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008306 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
8307 ap_ne_pref);
8308 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008309 return 0;
8310}
8311
8312
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008313static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8314 struct sigma_cmd *cmd)
8315{
8316 const char *val;
8317 char *ifname;
8318
8319 ifname = get_main_ifname();
8320
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08008321 /* Disable vap reset between the commands */
8322 novap_reset(dut, ifname);
8323
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008324 val = get_param(cmd, "Opt_md_notif_ie");
8325 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
8326 return -1;
8327
8328 /* TODO: Optional arguments */
8329
8330 val = get_param(cmd, "nss_mcs_opt");
8331 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
8332 return -1;
8333
8334 val = get_param(cmd, "chnum_band");
8335 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
8336 return -1;
8337
8338 val = get_param(cmd, "RTS_FORCE");
8339 if (val)
8340 ath_config_rts_force(dut, ifname, val);
8341
8342 val = get_param(cmd, "DYN_BW_SGNL");
8343 if (val)
8344 ath_config_dyn_bw_sig(dut, ifname, val);
8345
8346 val = get_param(cmd, "CTS_WIDTH");
8347 if (val)
8348 ath_set_cts_width(dut, ifname, val);
8349
8350 val = get_param(cmd, "Ndpa_stainfo_mac");
8351 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
8352 return -1;
8353
8354 val = get_param(cmd, "txBandwidth");
8355 if (val && ath_set_width(dut, conn, ifname, val) < 0)
8356 return -1;
8357
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008358 val = get_param(cmd, "Assoc_Disallow");
8359 if (val)
8360 ath_set_assoc_disallow(dut, ifname, val);
8361
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008362
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008363 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008364 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
8365 if (val)
8366 dut->ap_btmreq_disassoc_imnt = atoi(val);
8367
8368 val = get_param(cmd, "BTMReq_Term_Bit");
8369 if (val)
8370 dut->ap_btmreq_term_bit = atoi(val);
8371
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -07008372 val = get_param(cmd, "Assoc_Delay");
8373 if (val)
8374 run_system_wrapper(dut, "iwpriv %s mbo_asoc_ret %s",
8375 ifname, val);
8376
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008377 val = get_param(cmd, "Disassoc_Timer");
8378 if (val)
8379 dut->ap_disassoc_timer = atoi(val);
8380
8381 val = get_param(cmd, "BSS_Term_Duration");
8382 if (val)
8383 dut->ap_btmreq_bss_term_dur = atoi(val);
8384
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008385 return 1;
8386}
8387
8388
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308389static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8390 const char *val)
8391{
8392 char *token, *result;
8393 int channel = 36;
8394 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308395 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308396
8397 /* Extract the channel info */
8398 token = strdup(val);
8399 if (!token)
8400 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308401 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308402 if (result)
8403 channel = atoi(result);
8404
8405 /* Issue the channel switch command */
8406 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
8407 ifname, channel);
8408 if (system(buf) != 0) {
8409 sigma_dut_print(dut, DUT_MSG_ERROR,
8410 "iwpriv setChanChange failed!");
8411 }
8412
8413 free(token);
8414 return 0;
8415}
8416
8417
8418static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8419 struct sigma_cmd *cmd)
8420{
8421 const char *val;
8422 char *ifname;
8423
8424 ifname = get_main_ifname();
8425
8426 val = get_param(cmd, "chnum_band");
8427 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
8428 return -1;
8429
8430 return 1;
8431}
8432
8433
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05308434static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8435 const char *val)
8436{
8437 char *token, *result;
8438 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
8439 channel_freq;
8440 char buf[100];
8441 char *saveptr;
8442
8443 /* Extract the channel info */
8444 token = strdup(val);
8445 if (!token)
8446 return -1;
8447 result = strtok_r(token, ";", &saveptr);
8448 if (result)
8449 channel = atoi(result);
8450
8451 /* Extract the channel width info */
8452 result = strtok_r(NULL, ";", &saveptr);
8453 if (result)
8454 chwidth = atoi(result);
8455
8456 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
8457 if (center_freq_idx < 0) {
8458 free(token);
8459 return -1;
8460 }
8461
8462 center_freq = get_5g_channel_freq(center_freq_idx);
8463 channel_freq = get_5g_channel_freq(channel);
8464
8465 /* Issue the channel switch command */
8466 snprintf(buf, sizeof(buf),
8467 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
8468 ifname, channel_freq, center_freq, chwidth);
8469 if (run_hostapd_cli(dut,buf) != 0) {
8470 sigma_dut_print(dut, DUT_MSG_ERROR,
8471 "hostapd_cli chan_switch failed");
8472 }
8473
8474 free(token);
8475 return 0;
8476}
8477
8478
8479static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
8480 struct sigma_conn *conn,
8481 struct sigma_cmd *cmd)
8482{
8483 const char *val;
8484 char *ifname;
8485
8486 ifname = get_main_ifname();
8487 val = get_param(cmd, "chnum_band");
8488 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
8489 return -1;
8490
8491 return 1;
8492}
8493
8494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008495static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8496 struct sigma_cmd *cmd)
8497{
8498 /* const char *name = get_param(cmd, "NAME"); */
8499 /* const char *type = get_param(cmd, "Type"); */
8500
8501 switch (get_driver_type()) {
8502 case DRIVER_ATHEROS:
8503 return ath_ap_set_rfeature(dut, conn, cmd);
8504 case DRIVER_OPENWRT:
8505 switch (get_openwrt_driver_type()) {
8506 case OPENWRT_DRIVER_ATHEROS:
8507 return ath_ap_set_rfeature(dut, conn, cmd);
8508 default:
8509 send_resp(dut, conn, SIGMA_ERROR,
8510 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
8511 return 0;
8512 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +05308513 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308514 case DRIVER_WCN:
8515 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05308516 case DRIVER_MAC80211:
8517 return mac80211_ap_set_rfeature(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008518 default:
8519 send_resp(dut, conn, SIGMA_ERROR,
8520 "errorCode,Unsupported ap_set_rfeature with the current driver");
8521 return 0;
8522 }
8523}
8524
8525
8526static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
8527 struct sigma_cmd *cmd)
8528{
8529 /* const char *name = get_param(cmd, "NAME"); */
8530 return 1;
8531}
8532
8533
8534void ap_register_cmds(void)
8535{
8536 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
8537 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
8538 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
8539 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
8540 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
8541 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308542 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008543 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
8544 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
8545 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
8546 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
8547 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
8548 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
8549 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
8550 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
8551 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
8552 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
8553 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
8554 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
8555 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
8556 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
8557 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
8558 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
8559 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
8560}