blob: 7957a44c0e990ca6c01919a5a736ca62d2b4e543 [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__
15#include <dirent.h>
16#include <string.h>
17#include <sys/types.h>
18#include <unistd.h>
19#endif /* __linux__ */
20#ifdef __QNXNTO__
21#include <ifaddrs.h>
22#include <net/if_dl.h>
23#endif /* __QNXNTO__ */
24#include "wpa_helpers.h"
25#ifdef ANDROID
26#include <hardware_legacy/wifi.h>
27#endif /* ANDROID */
28
29/* Temporary files for ap_send_addba_req */
30#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
31#define VI_QOS_FILE "/tmp/vi-qos.txt"
32#define VI_QOS_REFFILE "/etc/vi-qos.txt"
33
34/* Configuration file name on Android */
35#ifndef ANDROID_CONFIG_FILE
36#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
37#endif /* ANDROID_CONFIG_FILE */
38/* Maximum length of the line in the configuration file */
39#define MAX_CONF_LINE_LEN (156)
40
41/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
42#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
43#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\""
44#define ANQP_IP_ADDR_TYPE_1 "060101000c"
45#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
46#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
47#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
48#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"
49#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
50
51extern char *sigma_main_ifname;
52extern char *sigma_wpas_ctrl;
53extern char *sigma_hapd_ctrl;
54extern char *ap_inet_addr;
55extern char *ap_inet_mask;
56extern char *sigma_radio_ifname[];
57
58static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
59 struct sigma_cmd *cmd);
60static int ath_ap_start_hostapd(struct sigma_dut *dut);
61static void ath_ap_set_params(struct sigma_dut *dut);
62static int kill_process(struct sigma_dut *dut, char *proc_name,
63 unsigned char is_proc_instance_one, int sig);
64
65
66static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
67 struct sigma_cmd *cmd)
68{
69 /* const char *name = get_param(cmd, "NAME"); */
70 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
71 return 0;
72}
73
74
75static int get_hwaddr(const char *ifname, unsigned char *hwaddr)
76{
77#ifndef __QNXNTO__
78 struct ifreq ifr;
79 int s;
80
81 s = socket(AF_INET, SOCK_DGRAM, 0);
82 if (s < 0)
83 return -1;
84 memset(&ifr, 0, sizeof(ifr));
85 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
86 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
87 perror("ioctl");
88 close(s);
89 return -1;
90 }
91 close(s);
92 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
93#else /* __QNXNTO__ */
94 struct ifaddrs *ifaddrshead = NULL;
95 int found = 0;
96 struct ifaddrs *temp_ifap = NULL;
97 struct sockaddr_dl *sdl = NULL;
98
99 if (getifaddrs(&ifaddrshead) != 0) {
100 perror("getifaddrs failed");
101 return -1;
102 }
103
104 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
105 ifaddrshead = ifaddrshead->ifa_next) {
106 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
107 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
108 found = 1;
109 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
110 if (sdl)
111 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
112 }
113 }
114
115 if (temp_ifap)
116 freeifaddrs(temp_ifap);
117
118 if (!found) {
119 perror("Failed to get the interface");
120 return -1;
121 }
122#endif /* __QNXNTO__ */
123 return 0;
124}
125
126
127static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
128 const char *val)
129{
130 char buf[60];
131
132 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
133 ifname, atoi(val));
134 if (system(buf) != 0) {
135 sigma_dut_print(dut, DUT_MSG_ERROR,
136 "wifitool ap_group_id failed");
137 }
138}
139
140
141void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
142 const char *val)
143{
144 char buf[60];
145
146 /* TODO: Enable support for other values */
147 if (strcasecmp(val, "40") == 0) {
148 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
149 ifname);
150 if (system(buf) != 0) {
151 sigma_dut_print(dut, DUT_MSG_ERROR,
152 "wifitool cts_width failed");
153 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800154 snprintf(buf, sizeof(buf),
155 "athdiag --set --address=0x10024 --val=0xd90b8a14");
156 if (system(buf) != 0) {
157 sigma_dut_print(dut, DUT_MSG_ERROR,
158 "disabling phy restart failed");
159 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200160 } else {
161 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
162 }
163}
164
165
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800166void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
167 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200168{
169 char buf[60];
170
171 if (strcasecmp(val, "enable") == 0) {
172 dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_ENABLED;
173 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
174 if (system(buf) != 0) {
175 sigma_dut_print(dut, DUT_MSG_ERROR,
176 "iwpriv cwmenable 1 failed");
177 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800178 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
179 ifname);
180 if (system(buf) != 0) {
181 sigma_dut_print(dut, DUT_MSG_ERROR,
182 "disabling RTS from rate control logic failed");
183 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200184 } else if (strcasecmp(val, "disable") == 0) {
185 dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_DISABLED;
186 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
187 if (system(buf) != 0) {
188 sigma_dut_print(dut, DUT_MSG_ERROR,
189 "iwpriv cwmenable 0 failed");
190 }
191 } else {
192 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
193 }
194}
195
196
197static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
198 const char *val)
199{
200 char buf[60];
201
202 if (strcasecmp(val, "enable") == 0) {
203 dut->ap_sig_rts = 1;
204 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
205 if (system(buf) != 0) {
206 sigma_dut_print(dut, DUT_MSG_ERROR,
207 "iwconfig rts 64 failed");
208 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800209 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
210 ifname);
211 if (system(buf) != 0) {
212 sigma_dut_print(dut, DUT_MSG_ERROR,
213 "wifitool beeliner_fw_test 100 1 failed");
214 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200215 } else if (strcasecmp(val, "disable") == 0) {
216 dut->ap_sig_rts = 2;
217 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
218 if (system(buf) != 0) {
219 sigma_dut_print(dut, DUT_MSG_ERROR,
220 "iwpriv rts 2347 failed");
221 }
222 } else {
223 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
224 }
225}
226
227
228static enum ap_mode get_mode(const char *str)
229{
230 if (strcasecmp(str, "11a") == 0)
231 return AP_11a;
232 else if (strcasecmp(str, "11g") == 0)
233 return AP_11g;
234 else if (strcasecmp(str, "11b") == 0)
235 return AP_11b;
236 else if (strcasecmp(str, "11na") == 0)
237 return AP_11na;
238 else if (strcasecmp(str, "11ng") == 0)
239 return AP_11ng;
240 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
241 return AP_11ac;
242 else
243 return AP_inval;
244}
245
246
247static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
248{
249 char command[1000];
250 const char *bin;
251 enum driver_type drv = get_driver_type();
252
253 if (file_exists("hostapd_cli"))
254 bin = "./hostapd_cli";
255 else
256 bin = "hostapd_cli";
257
258 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
259 sigma_hapd_ctrl = "/var/run/hostapd-wifi0";
260
261 if (sigma_radio_ifname[0] &&
262 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
263 sigma_hapd_ctrl = "/var/run/hostapd-wifi1";
264 else if (sigma_radio_ifname[0] &&
265 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
266 sigma_hapd_ctrl = "/var/run/hostapd-wifi2";
267 }
268
269 if (sigma_hapd_ctrl)
270 snprintf(command, sizeof(command), "%s -p %s %s",
271 bin, sigma_hapd_ctrl, buf);
272 else
273 snprintf(command, sizeof(command), "%s %s", bin, buf);
274 return run_system(dut, command);
275}
276
277
278static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
279 struct sigma_cmd *cmd)
280{
281 /* const char *name = get_param(cmd, "NAME"); */
282 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200283 const char *val;
284 unsigned int wlan_tag = 1;
285 char *ifname = get_main_ifname();
286
287 val = get_param(cmd, "WLAN_TAG");
288 if (val) {
289 wlan_tag = atoi(val);
290 if (wlan_tag != 1 && wlan_tag != 2) {
291 send_resp(dut, conn, SIGMA_INVALID,
292 "errorCode,Invalid WLAN_TAG");
293 return 0;
294 }
295 }
296
297 val = get_param(cmd, "CountryCode");
298 if (val) {
299 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
300 return -1;
301 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
302 "%s", val);
303 }
304
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530305 val = get_param(cmd, "regulatory_mode");
306 if (val) {
307 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
308 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
309 }
310
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200311 val = get_param(cmd, "SSID");
312 if (val) {
313 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
314 return -1;
315
316 if (wlan_tag == 1) {
317 snprintf(dut->ap_ssid,
318 sizeof(dut->ap_ssid), "%s", val);
319 } else if (wlan_tag == 2) {
320 snprintf(dut->ap2_ssid,
321 sizeof(dut->ap2_ssid), "%s", val);
322 }
323 }
324
325 val = get_param(cmd, "CHANNEL");
326 if (val) {
327 const char *pos;
328 dut->ap_channel = atoi(val);
329 pos = strchr(val, ';');
330 if (pos) {
331 pos++;
332 dut->ap_channel_1 = atoi(pos);
333 }
334 }
335
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530336 /* Overwrite the AP channel with DFS channel if configured */
337 val = get_param(cmd, "dfs_chan");
338 if (val) {
339 dut->ap_channel = atoi(val);
340 }
341
342 val = get_param(cmd, "dfs_mode");
343 if (val) {
344 if (strcasecmp(val, "Enable") == 0)
345 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
346 else if (strcasecmp(val, "Disable") == 0)
347 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
348 else
349 sigma_dut_print(dut, DUT_MSG_ERROR,
350 "Unsupported dfs_mode value: %s", val);
351 }
352
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200353 val = get_param(cmd, "MODE");
354 if (val) {
355 char *str, *pos;
356
357 str = strdup(val);
358 if (str == NULL)
359 return -1;
360 pos = strchr(str, ';');
361 if (pos)
362 *pos++ = '\0';
363
364 dut->ap_is_dual = 0;
365 dut->ap_mode = get_mode(str);
366 if (dut->ap_mode == AP_inval) {
367 send_resp(dut, conn, SIGMA_INVALID,
368 "errorCode,Unsupported MODE");
369 free(str);
370 return 0;
371 }
372 if (dut->ap_mode == AP_11ac)
373 dut->ap_chwidth = AP_80;
374
375 if (pos) {
376 dut->ap_mode_1 = get_mode(pos);
377 if (dut->ap_mode_1 == AP_inval) {
378 send_resp(dut, conn, SIGMA_INVALID,
379 "errorCode,Unsupported MODE");
380 free(str);
381 return 0;
382 }
383 if (dut->ap_mode_1 == AP_11ac)
384 dut->ap_chwidth_1 = AP_80;
385 dut->ap_is_dual = 1;
386 }
387
388 free(str);
389 } else if (dut->ap_mode == AP_inval) {
390 if (dut->ap_channel <= 11)
391 dut->ap_mode = AP_11ng;
392 else if (dut->program == PROGRAM_VHT)
393 dut->ap_mode = AP_11ac;
394 else
395 dut->ap_mode = AP_11na;
396 }
397
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530398 val = get_param(cmd, "WME");
399 if (val) {
400 if (strcasecmp(val, "on") == 0)
401 dut->ap_wme = AP_WME_ON;
402 else if (strcasecmp(val, "off") == 0)
403 dut->ap_wme = AP_WME_OFF;
404 else
405 sigma_dut_print(dut, DUT_MSG_ERROR,
406 "Unsupported WME value: %s", val);
407 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200408
409 /* TODO: WMMPS */
410
411 val = get_param(cmd, "RTS");
412 if (val)
413 dut->ap_rts = atoi(val);
414
415 val = get_param(cmd, "FRGMNT");
416 if (val)
417 dut->ap_frgmnt = atoi(val);
418
419 /* TODO: PWRSAVE */
420
421 val = get_param(cmd, "BCNINT");
422 if (val)
423 dut->ap_bcnint = atoi(val);
424
425 val = get_param(cmd, "RADIO");
426 if (val) {
427 if (strcasecmp(val, "on") == 0) {
428 enum driver_type drv = get_driver_type();
429 if (drv == DRIVER_ATHEROS)
430 ath_ap_start_hostapd(dut);
431 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
432 return 0;
433 } else if (strcasecmp(val, "off") == 0) {
434 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
435 system("killall hostapd") == 0) {
436 sigma_dut_print(dut, DUT_MSG_INFO,
437 "Killed hostapd on radio,off");
438 }
439 } else {
440 send_resp(dut, conn, SIGMA_INVALID,
441 "errorCode,Unsupported RADIO value");
442 return 0;
443 }
444 }
445
446 val = get_param(cmd, "P2PMgmtBit");
447 if (val)
448 dut->ap_p2p_mgmt = atoi(val);
449
450 /* TODO: ChannelUsage */
451
452 /* TODO: 40_INTOLERANT */
453
454 val = get_param(cmd, "ADDBA_REJECT");
455 if (val) {
456 if (strcasecmp(val, "Enable") == 0)
457 dut->ap_addba_reject = 1;
458 else if (strcasecmp(val, "Disable") == 0)
459 dut->ap_addba_reject = 2;
460 }
461
462 val = get_param(cmd, "AMPDU");
463 if (val) {
464 if (strcasecmp(val, "Enable") == 0)
465 dut->ap_ampdu = 1;
466 else if (strcasecmp(val, "Disable") == 0)
467 dut->ap_ampdu = 2;
468 }
469
470 val = get_param(cmd, "AMPDU_EXP");
471 if (val)
472 dut->ap_ampdu_exp = atoi(val);
473
474 val = get_param(cmd, "AMSDU");
475 if (val) {
476 if (strcasecmp(val, "Enable") == 0)
477 dut->ap_amsdu = 1;
478 else if (strcasecmp(val, "Disable") == 0)
479 dut->ap_amsdu = 2;
480 }
481
482 val = get_param(cmd, "NoAck");
483 if (val) {
484 if (strcasecmp(val, "on") == 0)
485 dut->ap_noack = AP_NOACK_ENABLED;
486 else if (strcasecmp(val, "off") == 0)
487 dut->ap_noack = AP_NOACK_DISABLED;
488 }
489
490 /* TODO: GREENFIELD */
491 /* TODO: OFFSET */
492 /* TODO: MCS_32 */
493
494 val = get_param(cmd, "MCS_FIXEDRATE");
495 if (val) {
496 dut->ap_fixed_rate = 1;
497 dut->ap_mcs = atoi(val);
498 }
499
500 val = get_param(cmd, "SPATIAL_RX_STREAM");
501 if (val) {
502 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
503 dut->ap_rx_streams = 1;
504 if (dut->device_type == AP_testbed)
505 dut->ap_vhtmcs_map = 0xfffc;
506 } else if (strcasecmp(val, "2SS") == 0 ||
507 strcasecmp(val, "2") == 0) {
508 dut->ap_rx_streams = 2;
509 if (dut->device_type == AP_testbed)
510 dut->ap_vhtmcs_map = 0xfff0;
511 } else if (strcasecmp(val, "3SS") == 0 ||
512 strcasecmp(val, "3") == 0) {
513 dut->ap_rx_streams = 3;
514 if (dut->device_type == AP_testbed)
515 dut->ap_vhtmcs_map = 0xffc0;
516 } else if (strcasecmp(val, "4SS") == 0 ||
517 strcasecmp(val, "4") == 0) {
518 dut->ap_rx_streams = 4;
519 }
520 }
521
522 val = get_param(cmd, "SPATIAL_TX_STREAM");
523 if (val) {
524 if (strcasecmp(val, "1SS") == 0 ||
525 strcasecmp(val, "1") == 0) {
526 dut->ap_tx_streams = 1;
527 if (dut->device_type == AP_testbed)
528 dut->ap_vhtmcs_map = 0xfffc;
529 } else if (strcasecmp(val, "2SS") == 0 ||
530 strcasecmp(val, "2") == 0) {
531 dut->ap_tx_streams = 2;
532 if (dut->device_type == AP_testbed)
533 dut->ap_vhtmcs_map = 0xfff0;
534 } else if (strcasecmp(val, "3SS") == 0 ||
535 strcasecmp(val, "3") == 0) {
536 dut->ap_tx_streams = 3;
537 if (dut->device_type == AP_testbed)
538 dut->ap_vhtmcs_map = 0xffc0;
539 } else if (strcasecmp(val, "4SS") == 0 ||
540 strcasecmp(val, "4") == 0) {
541 dut->ap_tx_streams = 4;
542 }
543 }
544
545 val = get_param(cmd, "nss_mcs_cap");
546 if (val) {
547 int nss, mcs;
548 char token[20];
549 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530550 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200551
552 if (strlen(val) >= sizeof(token))
553 return -1;
554 strcpy(token, val);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530555 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200556 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530557 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200558 if (result == NULL) {
559 sigma_dut_print(dut, DUT_MSG_ERROR,
560 "VHTMCS NOT SPECIFIED!");
561 return 0;
562 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530563 result = strtok_r(result, "-", &saveptr);
564 result = strtok_r(NULL, "-", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200565 mcs = atoi(result);
566 switch (nss) {
567 case 1:
568 switch (mcs) {
569 case 7:
570 dut->ap_vhtmcs_map = 0xfffc;
571 break;
572 case 8:
573 dut->ap_vhtmcs_map = 0xfffd;
574 break;
575 case 9:
576 dut->ap_vhtmcs_map = 0xfffe;
577 break;
578 default:
579 dut->ap_vhtmcs_map = 0xfffe;
580 break;
581 }
582 break;
583 case 2:
584 switch (mcs) {
585 case 7:
586 dut->ap_vhtmcs_map = 0xfff0;
587 break;
588 case 8:
589 dut->ap_vhtmcs_map = 0xfff5;
590 break;
591 case 9:
592 dut->ap_vhtmcs_map = 0xfffa;
593 break;
594 default:
595 dut->ap_vhtmcs_map = 0xfffa;
596 break;
597 }
598 break;
599 case 3:
600 switch (mcs) {
601 case 7:
602 dut->ap_vhtmcs_map = 0xffc0;
603 break;
604 case 8:
605 dut->ap_vhtmcs_map = 0xffd5;
606 break;
607 case 9:
608 dut->ap_vhtmcs_map = 0xffea;
609 break;
610 default:
611 dut->ap_vhtmcs_map = 0xffea;
612 break;
613 }
614 break;
615 default:
616 dut->ap_vhtmcs_map = 0xffea;
617 break;
618 }
619 }
620
621 /* TODO: MPDU_MIN_START_SPACING */
622 /* TODO: RIFS_TEST */
623 /* TODO: SGI20 */
624
625 val = get_param(cmd, "STBC_TX");
626 if (val)
627 dut->ap_tx_stbc = atoi(val);
628
629 val = get_param(cmd, "WIDTH");
630 if (val) {
631 if (strcasecmp(val, "20") == 0)
632 dut->ap_chwidth = AP_20;
633 else if (strcasecmp(val, "40") == 0)
634 dut->ap_chwidth = AP_40;
635 else if (strcasecmp(val, "80") == 0)
636 dut->ap_chwidth = AP_80;
637 else if (strcasecmp(val, "160") == 0)
638 dut->ap_chwidth = AP_160;
639 else if (strcasecmp(val, "Auto") == 0)
640 dut->ap_chwidth = AP_AUTO;
641 else {
642 send_resp(dut, conn, SIGMA_INVALID,
643 "errorCode,Unsupported WIDTH");
644 return 0;
645 }
646 }
647
648 /* TODO: WIDTH_SCAN */
649
650 val = get_param(cmd, "TDLSProhibit");
651 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
652 val = get_param(cmd, "TDLSChswitchProhibit");
653 dut->ap_tdls_prohibit_chswitch =
654 val && strcasecmp(val, "Enabled") == 0;
655 val = get_param(cmd, "HS2");
656 if (val && wlan_tag == 1)
657 dut->ap_hs2 = atoi(val);
658 val = get_param(cmd, "P2P_CROSS_CONNECT");
659 if (val)
660 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
661
662 val = get_param(cmd, "FakePubKey");
663 dut->ap_fake_pkhash = val && atoi(val);
664
665 val = get_param(cmd, "vht_tkip");
666 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
667 val = get_param(cmd, "vht_wep");
668 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
669
670 val = get_param(cmd, "Protect_mode");
671 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
672
673 val = get_param(cmd, "DYN_BW_SGNL");
674 if (val) {
675 switch (get_driver_type()) {
676 case DRIVER_OPENWRT:
677 switch (get_openwrt_driver_type()) {
678 case OPENWRT_DRIVER_ATHEROS:
679 ath_config_dyn_bw_sig(dut, ifname, val);
680 break;
681 default:
682 send_resp(dut, conn, SIGMA_ERROR,
683 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
684 return 0;
685 }
686 break;
687 default:
688 sigma_dut_print(dut, DUT_MSG_ERROR,
689 "Unsupported DYN_BW_SGL with the current driver");
690 break;
691 }
692 }
693
694 val = get_param(cmd, "SGI80");
695 if (val) {
696 if (strcasecmp(val, "enable") == 0)
697 dut->ap_sgi80 = 1;
698 else if (strcasecmp(val, "disable") == 0)
699 dut->ap_sgi80 = 0;
700 else {
701 send_resp(dut, conn, SIGMA_INVALID,
702 "errorCode,Unsupported SGI80");
703 return 0;
704 }
705 }
706
707 val = get_param(cmd, "LDPC");
708 if (val) {
709 if (strcasecmp(val, "enable") == 0)
710 dut->ap_ldpc = 1;
711 else if (strcasecmp(val, "disable") == 0)
712 dut->ap_ldpc = 2;
713 else {
714 send_resp(dut, conn, SIGMA_INVALID,
715 "errorCode,Unsupported LDPC");
716 return 0;
717 }
718 }
719
720 val = get_param(cmd, "BW_SGNL");
721 if (val) {
722 /*
723 * With dynamic bandwidth signaling enabled we should see
724 * RTS if the threshold is met.
725 */
726 if (strcasecmp(val, "enable") == 0) {
727 dut->ap_sig_rts = 1;
728 } else if (strcasecmp(val, "disable") == 0) {
729 dut->ap_sig_rts = 2;
730 } else {
731 send_resp(dut, conn, SIGMA_INVALID,
732 "errorCode,Unsupported BW_SGNL");
733 return 0;
734 }
735 }
736
737 val = get_param(cmd, "RTS_FORCE");
738 if (val) {
739 switch (get_driver_type()) {
740 case DRIVER_OPENWRT:
741 switch (get_openwrt_driver_type()) {
742 case OPENWRT_DRIVER_ATHEROS:
743 ath_config_rts_force(dut, ifname, val);
744 break;
745 default:
746 send_resp(dut, conn, SIGMA_ERROR,
747 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
748 return 0;
749 }
750 break;
751 default:
752 sigma_dut_print(dut, DUT_MSG_ERROR,
753 "Unsupported RTS_FORCE with the current driver");
754 break;
755 }
756 }
757
758 val = get_param(cmd, "Zero_crc");
759 if (val) {
760 switch (get_driver_type()) {
761 case DRIVER_ATHEROS:
762 ath_set_zero_crc(dut, val);
763 break;
764 case DRIVER_OPENWRT:
765 switch (get_openwrt_driver_type()) {
766 case OPENWRT_DRIVER_ATHEROS:
767 ath_set_zero_crc(dut, val);
768 break;
769 default:
770 send_resp(dut, conn, SIGMA_ERROR,
771 "errorCode,Unsupported zero_crc with the current driver");
772 return 0;
773 }
774 break;
775 default:
776 send_resp(dut, conn, SIGMA_ERROR,
777 "errorCode,Unsupported zero_crc with the current driver");
778 return 0;
779 }
780 }
781
782 val = get_param(cmd, "TxBF");
783 if (val)
784 dut->ap_txBF = strcasecmp(val, "enable") == 0;
785
786 val = get_param(cmd, "MU_TxBF");
787 if (val)
788 dut->ap_mu_txBF = strcasecmp(val, "enable") == 0;
789
790 /* UNSUPPORTED: tx_lgi_rate */
791
792 val = get_param(cmd, "wpsnfc");
793 if (val)
794 dut->ap_wpsnfc = atoi(val);
795
796 val = get_param(cmd, "GROUP_ID");
797 if (val) {
798 switch (get_driver_type()) {
799 case DRIVER_OPENWRT:
800 switch (get_openwrt_driver_type()) {
801 case OPENWRT_DRIVER_ATHEROS:
802 ath_ap_set_group_id(dut, ifname, val);
803 break;
804 default:
805 send_resp(dut, conn, SIGMA_ERROR,
806 "errorCode,Unsupported group_id with the current driver");
807 return 0;
808 }
809 break;
810 default:
811 send_resp(dut, conn, SIGMA_ERROR,
812 "errorCode,Unsupported group_id with the current driver");
813 return 0;
814 }
815 }
816
817 val = get_param(cmd, "CTS_WIDTH");
818 if (val) {
819 switch (get_driver_type()) {
820 case DRIVER_OPENWRT:
821 switch (get_openwrt_driver_type()) {
822 case OPENWRT_DRIVER_ATHEROS:
823 ath_set_cts_width(dut, ifname, val);
824 break;
825 default:
826 send_resp(dut, conn, SIGMA_ERROR,
827 "errorCode,Unsupported cts_width with the current driver");
828 return 0;
829 }
830 break;
831 default:
832 send_resp(dut, conn, SIGMA_ERROR,
833 "errorCode,Unsupported cts_width with the current driver");
834 return 0;
835 }
836 }
837
priyadharshini gowthaman264d5442016-02-25 15:52:22 -0800838 val = get_param(cmd, "MU_NDPA_FrameFormat");
839 if (val)
840 dut->ap_ndpa_frame = atoi(val);
841
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200842 return 1;
843}
844
845
846static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
847{
848 char buf[256];
849 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
850
851 snprintf(buf, sizeof(buf),
852 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
853 ifname, VI_QOS_TMP_FILE);
854 if (system(buf) != 0)
855 return;
856
857 snprintf(buf, sizeof(buf),
858 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
859 ifname, VI_QOS_TMP_FILE);
860 if (system(buf) != 0)
861 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
862
863 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
864 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
865 if (system(buf) != 0) {
866 sigma_dut_print(dut, DUT_MSG_ERROR,
867 "Output redirection to VI_QOS_TMP_FILE failed");
868 }
869
870 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
871 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
872 if (system(buf) != 0) {
873 sigma_dut_print(dut, DUT_MSG_ERROR,
874 "Append TID to VI_QOS_FILE failed ");
875 }
876
877 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
878 if (system(buf) != 0)
879 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
880}
881
882
883static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
884 struct sigma_cmd *cmd)
885{
886 const char *val;
887 char *ifname;
888 char buf[256];
889 int tid = 0;
890
891 ifname = get_main_ifname();
892 val = get_param(cmd, "TID");
893 if (val) {
894 tid = atoi(val);
895 if (tid)
896 ath_inject_frame(dut, ifname, tid);
897 }
898
899 /* NOTE: This is the command sequence on Peregrine for ADDBA */
900 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
901 if (system(buf) != 0) {
902 sigma_dut_print(dut, DUT_MSG_ERROR,
903 "iwpriv setaddbaoper failed");
904 }
905
906 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
907 ifname, tid);
908 if (system(buf) != 0) {
909 sigma_dut_print(dut, DUT_MSG_ERROR,
910 "wifitool senddelba failed");
911 }
912
913 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
914 ifname, tid);
915 if (system(buf) != 0) {
916 sigma_dut_print(dut, DUT_MSG_ERROR,
917 "wifitool sendaddba failed");
918 }
919
920 return 1;
921}
922
923
924static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
925 struct sigma_cmd *cmd)
926{
927 /* const char *name = get_param(cmd, "NAME"); */
928 /* const char *ifname = get_param(cmd, "INTERFACE"); */
929
930 switch (get_driver_type()) {
931 case DRIVER_ATHEROS:
932 return ath_ap_send_addba_req(dut, conn, cmd);
933 case DRIVER_OPENWRT:
934 switch (get_openwrt_driver_type()) {
935 case OPENWRT_DRIVER_ATHEROS:
936 return ath_ap_send_addba_req(dut, conn, cmd);
937 default:
938 send_resp(dut, conn, SIGMA_ERROR,
939 "errorCode,ap_send_addba_req not supported with this driver");
940 return 0;
941 }
942 default:
943 send_resp(dut, conn, SIGMA_ERROR,
944 "errorCode,ap_send_addba_req not supported with this driver");
945 return 0;
946 }
947}
948
949
950static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
951 struct sigma_cmd *cmd)
952{
953 /* const char *name = get_param(cmd, "NAME"); */
954 const char *val;
955 unsigned int wlan_tag = 1;
956
957 val = get_param(cmd, "WLAN_TAG");
958 if (val)
959 wlan_tag = atoi(val);
960
961 if (wlan_tag == 2) {
962 val = get_param(cmd, "KEYMGNT");
963 if (val) {
964 if (strcasecmp(val, "NONE") == 0)
965 dut->ap2_key_mgmt = AP2_OPEN;
966 else if (strcasecmp(val, "OSEN") == 0)
967 dut->ap2_key_mgmt = AP2_OSEN;
968 else {
969 send_resp(dut, conn, SIGMA_INVALID,
970 "errorCode,Unsupported KEYMGNT");
971 return 0;
972 }
973 return 1;
974 }
975 }
976
977 val = get_param(cmd, "KEYMGNT");
978 if (val) {
979 if (strcasecmp(val, "WPA2-PSK") == 0) {
980 dut->ap_key_mgmt = AP_WPA2_PSK;
981 dut->ap_cipher = AP_CCMP;
982 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
983 strcasecmp(val, "WPA2-Ent") == 0) {
984 dut->ap_key_mgmt = AP_WPA2_EAP;
985 dut->ap_cipher = AP_CCMP;
986 } else if (strcasecmp(val, "WPA-PSK") == 0) {
987 dut->ap_key_mgmt = AP_WPA_PSK;
988 dut->ap_cipher = AP_TKIP;
989 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
990 strcasecmp(val, "WPA-Ent") == 0) {
991 dut->ap_key_mgmt = AP_WPA_EAP;
992 dut->ap_cipher = AP_TKIP;
993 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
994 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
995 dut->ap_cipher = AP_CCMP_TKIP;
996 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
997 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
998 dut->ap_cipher = AP_CCMP_TKIP;
999 } else if (strcasecmp(val, "NONE") == 0) {
1000 dut->ap_key_mgmt = AP_OPEN;
1001 dut->ap_cipher = AP_PLAIN;
1002 } else {
1003 send_resp(dut, conn, SIGMA_INVALID,
1004 "errorCode,Unsupported KEYMGNT");
1005 return 0;
1006 }
1007 }
1008
1009 val = get_param(cmd, "ENCRYPT");
1010 if (val) {
1011 if (strcasecmp(val, "WEP") == 0) {
1012 dut->ap_cipher = AP_WEP;
1013 } else if (strcasecmp(val, "TKIP") == 0) {
1014 dut->ap_cipher = AP_TKIP;
1015 } else if (strcasecmp(val, "AES") == 0 ||
1016 strcasecmp(val, "AES-CCMP") == 0) {
1017 dut->ap_cipher = AP_CCMP;
1018 } else {
1019 send_resp(dut, conn, SIGMA_INVALID,
1020 "errorCode,Unsupported ENCRYPT");
1021 return 0;
1022 }
1023 }
1024
1025 val = get_param(cmd, "WEPKEY");
1026 if (val) {
1027 size_t len;
1028 if (dut->ap_cipher != AP_WEP) {
1029 send_resp(dut, conn, SIGMA_INVALID,
1030 "errorCode,Unexpected WEPKEY without WEP "
1031 "configuration");
1032 return 0;
1033 }
1034 len = strlen(val);
1035 if (len != 10 && len != 26) {
1036 send_resp(dut, conn, SIGMA_INVALID,
1037 "errorCode,Unexpected WEPKEY length");
1038 return 0;
1039 }
1040 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1041 }
1042
1043 val = get_param(cmd, "PSK");
1044 if (val) {
1045 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1046 return -1;
1047 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1048 "%s", val);
1049 }
1050
1051 val = get_param(cmd, "PMF");
1052 if (val) {
1053 if (strcasecmp(val, "Disabled") == 0) {
1054 dut->ap_pmf = AP_PMF_DISABLED;
1055 } else if (strcasecmp(val, "Optional") == 0) {
1056 dut->ap_pmf = AP_PMF_OPTIONAL;
1057 } else if (strcasecmp(val, "Required") == 0) {
1058 dut->ap_pmf = AP_PMF_REQUIRED;
1059 } else {
1060 send_resp(dut, conn, SIGMA_INVALID,
1061 "errorCode,Unsupported PMF");
1062 return 0;
1063 }
1064 }
1065
1066 if (dut->ap_key_mgmt == AP_OPEN) {
1067 dut->ap_hs2 = 0;
1068 dut->ap_pmf = AP_PMF_DISABLED;
1069 }
1070
1071 dut->ap_add_sha256 = 0;
1072 val = get_param(cmd, "SHA256AD");
1073 if (val == NULL)
1074 val = get_param(cmd, "SHA256");
1075 if (val) {
1076 if (strcasecmp(val, "Disabled") == 0) {
1077 } else if (strcasecmp(val, "Enabled") == 0) {
1078 dut->ap_add_sha256 = 1;
1079 } else {
1080 send_resp(dut, conn, SIGMA_INVALID,
1081 "errorCode,Unsupported PMF");
1082 return 0;
1083 }
1084 }
1085
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301086 val = get_param(cmd, "PreAuthentication");
1087 if (val) {
1088 if (strcasecmp(val, "disabled") == 0) {
1089 dut->ap_rsn_preauth = 0;
1090 } else if (strcasecmp(val, "enabled") == 0) {
1091 dut->ap_rsn_preauth = 1;
1092 } else {
1093 send_resp(dut, conn, SIGMA_INVALID,
1094 "errorCode,Unsupported PreAuthentication value");
1095 return 0;
1096 }
1097 }
1098
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001099 return 1;
1100}
1101
1102
1103static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
1104 struct sigma_cmd *cmd)
1105{
1106 /* const char *name = get_param(cmd, "NAME"); */
1107 const char *val;
1108 unsigned int wlan_tag = 1, radius_port = 0;
1109 char *radius_ipaddr = NULL, *radius_password = NULL;
1110
1111 val = get_param(cmd, "WLAN_TAG");
1112 if (val) {
1113 wlan_tag = atoi(val);
1114 if (wlan_tag != 1 && wlan_tag != 2) {
1115 send_resp(dut, conn, SIGMA_INVALID,
1116 "errorCode,Invalid WLAN_TAG");
1117 return 0;
1118 }
1119 }
1120
1121 val = get_param(cmd, "PORT");
1122 if (val)
1123 radius_port = atoi(val);
1124
1125 if (wlan_tag == 1) {
1126 if (radius_port)
1127 dut->ap_radius_port = radius_port;
1128 radius_ipaddr = dut->ap_radius_ipaddr;
1129 radius_password = dut->ap_radius_password;
1130 } else if (wlan_tag == 2) {
1131 if (radius_port)
1132 dut->ap2_radius_port = radius_port;
1133 radius_ipaddr = dut->ap2_radius_ipaddr;
1134 radius_password = dut->ap2_radius_password;
1135 }
1136
1137 val = get_param(cmd, "IPADDR");
1138 if (val) {
1139 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
1140 return -1;
1141 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
1142 "%s", val);
1143 }
1144
1145 val = get_param(cmd, "PASSWORD");
1146 if (val) {
1147 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
1148 return -1;
1149 snprintf(radius_password,
1150 sizeof(dut->ap_radius_password), "%s", val);
1151 }
1152
1153 return 1;
1154}
1155
1156
1157static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
1158 const char *key, const char *val)
1159{
1160 char buf[100];
1161
1162 if (val == NULL) {
1163 snprintf(buf, sizeof(buf),
1164 "uci delete wireless.wifi%d.%s", id, key);
1165 run_system(dut, buf);
1166 return;
1167 }
1168
1169 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
1170 id, key, val);
1171 run_system(dut, buf);
1172}
1173
1174
1175static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
1176 const char *key, const char *val)
1177{
1178 char buf[256];
1179
1180 if (val == NULL) {
1181 snprintf(buf, sizeof(buf),
1182 "uci del_list wireless.wifi%d.%s", id, key);
1183 run_system(dut, buf);
1184 return;
1185 }
1186
1187 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
1188 id, key, val);
1189 run_system(dut, buf);
1190}
1191
1192
1193static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
1194 const char *val)
1195{
1196 char buf[256];
1197
1198 if (val == NULL) {
1199 snprintf(buf, sizeof(buf),
1200 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1201 run_system(dut, buf);
1202 return;
1203 }
1204
1205 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1206 id, key, val);
1207 run_system(dut, buf);
1208}
1209
1210
1211static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
1212 const char *key, const char *val)
1213{
1214 char buf[256];
1215
1216 if (val == NULL) {
1217 snprintf(buf, sizeof(buf),
1218 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
1219 run_system(dut, buf);
1220 return;
1221 }
1222
1223 snprintf(buf, sizeof(buf),
1224 "uci add_list wireless.@wifi-iface[%d].%s=%s",
1225 id, key, val);
1226 run_system(dut, buf);
1227}
1228
1229
1230static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
1231 const char *val)
1232{
1233 char buf[256];
1234
1235 if (val == NULL) {
1236 snprintf(buf, sizeof(buf),
1237 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1238 run_system(dut, buf);
1239 return;
1240 }
1241
1242 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
1243 run_system(dut, buf);
1244 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1245 id, key, val);
1246 run_system(dut, buf);
1247 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1248 id, "network", "lan");
1249 run_system(dut, buf);
1250 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1251 id, "mode", "ap");
1252 run_system(dut, buf);
1253 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1254 id, "encryption", "none");
1255 run_system(dut, buf);
1256}
1257
1258
1259#define OPENWRT_MAX_NUM_RADIOS 3
1260static void owrt_ap_config_radio(struct sigma_dut *dut)
1261{
1262 int radio_id[MAX_RADIO] = { 0, 1 };
1263 int radio_count, radio_no;
1264 char buf[64];
1265
1266 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
1267 radio_count++) {
1268 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
1269 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
1270 if (!sigma_radio_ifname[radio_no] ||
1271 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
1272 continue;
1273 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
1274 owrt_ap_set_vap(dut, radio_count, "device", buf);
1275 radio_id[radio_no] = radio_count;
1276 }
1277 }
1278
1279 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1280 switch (dut->ap_mode) {
1281 case AP_11g:
1282 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
1283 break;
1284 case AP_11b:
1285 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
1286 break;
1287 case AP_11ng:
1288 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1289 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1290 break;
1291 case AP_11a:
1292 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
1293 break;
1294 case AP_11na:
1295 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
1296 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1297 break;
1298 case AP_11ac:
1299 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
1300 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1301 break;
1302 case AP_inval:
1303 sigma_dut_print(dut, DUT_MSG_ERROR,
1304 "MODE NOT SPECIFIED!");
1305 return;
1306 default:
1307 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1308 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1309 break;
1310 }
1311
1312 if (dut->ap_is_dual) {
1313 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1314 switch (dut->ap_mode_1) {
1315 case AP_11g:
1316 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
1317 break;
1318 case AP_11b:
1319 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
1320 break;
1321 case AP_11ng:
1322 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1323 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1324 break;
1325 case AP_11a:
1326 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
1327 break;
1328 case AP_11na:
1329 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
1330 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1331 break;
1332 case AP_11ac:
1333 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
1334 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
1335 break;
1336 case AP_inval:
1337 sigma_dut_print(dut, DUT_MSG_ERROR,
1338 "MODE NOT SPECIFIED!");
1339 return;
1340 default:
1341 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1342 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1343 break;
1344 }
1345
1346 }
1347
1348 /* Channel */
1349 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
1350 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
1351
1352 switch (dut->ap_chwidth) {
1353 case AP_20:
1354 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1355 break;
1356 case AP_40:
1357 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
1358 break;
1359 case AP_80:
1360 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1361 break;
1362 case AP_160:
1363 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
1364 break;
1365 case AP_AUTO:
1366 default:
1367 break;
1368 }
1369
1370 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
1371 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
1372 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
1373 }
1374
1375 if (dut->ap_is_dual) {
1376 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
1377 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
1378 }
1379
1380 if (dut->ap_countrycode[0]) {
1381 /* Country Code */
1382 snprintf(buf, sizeof(buf), "%s", dut->ap_countrycode);
1383 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
1384 }
1385
1386 if (dut->ap_disable_protection == 1) {
1387 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
1388 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
1389 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
1390 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
1391 }
1392}
1393
1394
1395static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
1396{
1397 char buf[256];
1398
1399 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
1400 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
1401 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
1402 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
1403
1404 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1405 "'eng:Wi-Fi Alliance'");
1406
1407 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1408 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
1409
1410 if (dut->ap_wan_metrics == 1)
1411 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1412 "'01:2500:384:0:0:10'");
1413 else if (dut->ap_wan_metrics == 1)
1414 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1415 "'01:1500:384:20:20:10'");
1416 else if (dut->ap_wan_metrics == 2)
1417 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1418 "'01:1500:384:20:20:10'");
1419 else if (dut->ap_wan_metrics == 3)
1420 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1421 "'01:2000:1000:20:20:10'");
1422 else if (dut->ap_wan_metrics == 4)
1423 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1424 "'01:8000:1000:20:20:10'");
1425 else if (dut->ap_wan_metrics == 5)
1426 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1427 "'01:9000:5000:20:20:10'");
1428
1429 if (dut->ap_conn_capab == 1) {
1430 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
1431 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1432 "'6:20:1'");
1433 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1434 "'6:22:0'");
1435 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1436 "'6:80:1'");
1437 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1438 "'6:443:1'");
1439 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1440 "'6:1723:0'");
1441 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1442 "'6:5060:0'");
1443 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1444 "'17:500:1'");
1445 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1446 "'17:5060:0'");
1447 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1448 "'17:4500:1'");
1449 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1450 "'50:0:1'");
1451 } else if (dut->ap_conn_capab == 2) {
1452 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1453 "'6:80:1'");
1454 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1455 "'6:443:1'");
1456 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1457 "'17:5060:1'");
1458 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1459 "'6:5060:1'");
1460 } else if (dut->ap_conn_capab == 3) {
1461 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1462 "'6:80:1'");
1463 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1464 "'6:443:1'");
1465 }
1466
1467 if (dut->ap_oper_class == 1)
1468 snprintf(buf, sizeof(buf), "%s", "51");
1469 else if (dut->ap_oper_class == 2)
1470 snprintf(buf, sizeof(buf), "%s", "73");
1471 else if (dut->ap_oper_class == 3)
1472 snprintf(buf, sizeof(buf), "%s", "5173");
1473
1474 if (dut->ap_oper_class)
1475 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
1476
1477 if (dut->ap_osu_provider_list) {
1478 char *osu_friendly_name = NULL;
1479 char *osu_icon = NULL;
1480 char *osu_ssid = NULL;
1481 char *osu_nai = NULL;
1482 char *osu_service_desc = NULL;
1483 char *hs20_icon_filename = NULL;
1484 char hs20_icon[150];
1485 int osu_method;
1486
1487 hs20_icon_filename = "icon_red_zxx.png";
1488 if (dut->ap_osu_icon_tag == 2)
1489 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1490 snprintf(hs20_icon, sizeof(hs20_icon),
1491 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
1492 hs20_icon_filename);
1493 osu_icon = "icon_red_zxx.png";
1494 osu_ssid = "OSU";
1495 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
1496 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
1497 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
1498 dut->ap_osu_method[0];
1499
1500 if (strlen(dut->ap_osu_server_uri[0]))
1501 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
1502 dut->ap_osu_server_uri[0]);
1503 else
1504 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
1505 "'https://osu-server.r2-testbed.wi-fi.org/'");
1506 switch (dut->ap_osu_provider_list) {
1507 case 1:
1508 case 101:
1509 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1510 "'eng:SP Red Test Only'");
1511 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1512 "'eng:Free service for test purpose'");
1513 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1514 hs20_icon);
1515
1516 hs20_icon_filename = "icon_red_eng.png";
1517 if (dut->ap_osu_icon_tag == 2)
1518 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1519
1520 snprintf(hs20_icon, sizeof(hs20_icon),
1521 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
1522 hs20_icon_filename);
1523 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1524 "icon_red_eng.png");
1525 break;
1526 case 2:
1527 case 102:
1528 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1529 "'eng:Wireless Broadband Alliance'");
1530 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1531 "'eng:Free service for test purpose'");
1532 hs20_icon_filename = "icon_green_zxx.png";
1533 if (dut->ap_osu_icon_tag == 2)
1534 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1535
1536 snprintf(hs20_icon, sizeof(hs20_icon),
1537 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
1538 hs20_icon_filename);
1539 osu_icon = "icon_green_zxx.png";
1540 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
1541 break;
1542 case 3:
1543 case 103:
1544 osu_friendly_name = "spa:SP Red Test Only";
1545 osu_service_desc = "spa:Free service for test purpose";
1546 break;
1547 case 4:
1548 case 104:
1549 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1550 "'eng:SP Blue Test Only'");
1551 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1552 "'eng:Free service for test purpose'");
1553 hs20_icon_filename = "icon_blue_eng.png";
1554 if (dut->ap_osu_icon_tag == 2)
1555 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1556
1557 snprintf(hs20_icon, sizeof(hs20_icon),
1558 "'160:76:eng:image/png:icon_blue_eng.png:/etc/ath/%s'",
1559 hs20_icon_filename);
1560 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1561 hs20_icon);
1562 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
1563
1564 hs20_icon_filename = "icon_blue_zxx.png";
1565 if (dut->ap_osu_icon_tag == 2)
1566 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1567
1568 snprintf(hs20_icon, sizeof(hs20_icon),
1569 "'128:61:zxx:image/png:icon_blue_zxx.png:/etc/ath/%s'",
1570 hs20_icon_filename);
1571 osu_icon = "icon_blue_zxx.png";
1572 break;
1573 case 5:
1574 case 105:
1575 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1576 "'eng:SP Blue Test Only'");
1577 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1578 "'eng:Free service for test purpose'");
1579 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
1580
1581 hs20_icon_filename = "icon_blue_zxx.png";
1582 if (dut->ap_osu_icon_tag == 2)
1583 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1584
1585 snprintf(hs20_icon, sizeof(hs20_icon),
1586 "'128:61:zxx:image/png:icon_blue_zxx.png:/etc/ath/%s'",
1587 hs20_icon_filename);
1588 osu_icon = "icon_blue_zxx.png";
1589 break;
1590 case 6:
1591 case 106:
1592 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1593 "'eng:SP Green Test Only'");
1594 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1595 "'kor:SP 초록 테스트 전용'");
1596
1597 hs20_icon_filename = "icon_green_zxx.png";
1598 if (dut->ap_osu_icon_tag == 2)
1599 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1600
1601 snprintf(hs20_icon, sizeof(hs20_icon),
1602 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
1603 hs20_icon_filename);
1604 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1605 hs20_icon);
1606
1607 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1608 "'icon_green_zxx.png'");
1609 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
1610 dut->ap_osu_method[0];
1611
1612 snprintf(buf, sizeof(buf), "%d", osu_method);
1613 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
1614
1615 if (strlen(dut->ap_osu_server_uri[1]))
1616 owrt_ap_set_list_vap(dut, vap_id,
1617 "osu_server_uri",
1618 dut->ap_osu_server_uri[1]);
1619 else
1620 owrt_ap_set_list_vap(dut, vap_id,
1621 "osu_server_uri",
1622 "'https://osu-server.r2-testbed.wi-fi.org/'");
1623
1624 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1625 "'eng:SP Orange Test Only'");
1626
1627 hs20_icon_filename = "icon_orange_zxx.png";
1628 if (dut->ap_osu_icon_tag == 2)
1629 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1630
1631 snprintf(hs20_icon, sizeof(hs20_icon),
1632 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
1633 hs20_icon_filename);
1634
1635 osu_icon = "icon_orange_zxx.png";
1636 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
1637 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
1638 dut->ap_osu_method[1];
1639 osu_service_desc = NULL;
1640 break;
1641 case 7:
1642 case 107:
1643 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1644 "'eng:SP Orange Test Only'");
1645 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1646 "'eng:Free service for test purpose'");
1647
1648 hs20_icon_filename = "icon_orange_eng.png";
1649 if (dut->ap_osu_icon_tag == 2)
1650 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1651
1652 snprintf(hs20_icon, sizeof(hs20_icon),
1653 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
1654 hs20_icon_filename);
1655 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
1656 hs20_icon);
1657
1658 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1659 "'icon_orange_eng.png'");
1660 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
1661
1662 hs20_icon_filename = "icon_orange_zxx.png";
1663 if (dut->ap_osu_icon_tag == 2)
1664 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1665
1666 snprintf(hs20_icon, sizeof(hs20_icon),
1667 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
1668 hs20_icon_filename);
1669 osu_icon = "icon_orange_zxx.png";
1670 break;
1671 case 8:
1672 case 108:
1673 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1674 "'eng:SP Red Test Only'");
1675 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1676 "'eng:Free service for test purpose'");
1677 osu_ssid = "OSU-Encrypted";
1678 osu_nai = "'anonymous@hotspot.net'";
1679 break;
1680 case 9:
1681 case 109:
1682 osu_ssid = "OSU-OSEN";
1683 osu_nai = "'test-anonymous@wi-fi.org'";
1684 osu_friendly_name = "'eng:SP Orange Test Only'";
1685 hs20_icon_filename = "icon_orange_zxx.png";
1686 if (dut->ap_osu_icon_tag == 2)
1687 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
1688
1689 snprintf(hs20_icon, sizeof(hs20_icon),
1690 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
1691 hs20_icon_filename);
1692 osu_icon = "icon_orange_zxx.png";
1693 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
1694 dut->ap_osu_method[0];
1695 osu_service_desc = NULL;
1696 break;
1697 default:
1698 break;
1699 }
1700
1701 if (strlen(dut->ap_osu_ssid)) {
1702 if (strcmp(dut->ap2_ssid, dut->ap_osu_ssid) != 0 &&
1703 strcmp(dut->ap2_ssid, osu_ssid) != 0) {
1704 sigma_dut_print(dut, DUT_MSG_ERROR,
1705 "OSU_SSID and WLAN_TAG2 SSID differ");
1706 return -2;
1707 }
1708
1709 snprintf(buf, sizeof(buf), "'\"%s\"'",
1710 dut->ap_osu_ssid);
1711 } else {
1712 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
1713 }
1714
1715 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
1716
1717
1718 if (osu_friendly_name)
1719 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
1720 osu_friendly_name);
1721 if (osu_service_desc)
1722 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
1723 osu_service_desc);
1724 if (osu_nai)
1725 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
1726
1727 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
1728
1729 if (osu_icon)
1730 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
1731 osu_icon);
1732
1733 if (dut->ap_osu_provider_list > 100) {
1734 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
1735 "0");
1736 } else {
1737 snprintf(buf, sizeof(buf), "%d", osu_method);
1738 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
1739 buf);
1740 }
1741 }
1742
1743 return 0;
1744}
1745
1746
1747static int owrt_ap_config_vap(struct sigma_dut *dut)
1748{
1749 char buf[256], *temp;
1750 int vap_id = 0, vap_count, i;
1751
1752 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
1753 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
1754
1755 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
1756 if (sigma_radio_ifname[vap_id] &&
1757 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
1758 break;
1759 }
1760 if (vap_id == MAX_RADIO)
1761 continue;
1762
1763 /* Single VAP configuration */
1764 if (!dut->ap_is_dual)
1765 vap_id = vap_count;
1766
1767 if (strlen(dut->ap2_ssid)) {
1768 owrt_ap_add_vap(dut, vap_count + 1, "device", buf);
1769 /* SSID */
1770 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap2_ssid);
1771 owrt_ap_set_vap(dut, vap_count + 1, "ssid", buf);
1772
1773 if (dut->ap2_key_mgmt == AP2_OSEN) {
1774 owrt_ap_set_vap(dut, vap_count + 1,
1775 "osen", "1");
1776 snprintf(buf, sizeof(buf), "wpa2");
1777 owrt_ap_set_vap(dut, vap_count + 1,
1778 "encryption", buf);
1779 snprintf(buf, sizeof(buf), "%s",
1780 dut->ap2_radius_ipaddr);
1781 owrt_ap_set_vap(dut, vap_count + 1,
1782 "auth_server", buf);
1783 snprintf(buf, sizeof(buf), "%d",
1784 dut->ap2_radius_port);
1785 owrt_ap_set_vap(dut, vap_count + 1,
1786 "auth_port", buf);
1787 snprintf(buf, sizeof(buf), "%s",
1788 dut->ap2_radius_password);
1789 owrt_ap_set_vap(dut, vap_count + 1,
1790 "auth_secret", buf);
1791 }
1792 }
1793
1794 /* SSID */
1795 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
1796 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
1797
1798 /* Encryption */
1799 switch (dut->ap_key_mgmt) {
1800 case AP_OPEN:
1801 if (dut->ap_cipher == AP_WEP) {
1802 owrt_ap_set_vap(dut, vap_count, "encryption",
1803 "wep-mixed");
1804 owrt_ap_set_vap(dut, vap_count, "key",
1805 dut->ap_wepkey);
1806 } else {
1807 owrt_ap_set_vap(dut, vap_count, "encryption",
1808 "none");
1809 }
1810 break;
1811 case AP_WPA2_PSK:
1812 case AP_WPA2_PSK_MIXED:
1813 case AP_WPA_PSK:
1814 if (dut->ap_key_mgmt == AP_WPA2_PSK) {
1815 snprintf(buf, sizeof(buf), "psk2");
1816 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
1817 snprintf(buf, sizeof(buf), "psk-mixed");
1818 } else {
1819 snprintf(buf, sizeof(buf), "psk");
1820 }
1821
1822 if (dut->ap_cipher == AP_CCMP_TKIP) {
1823 strncat(buf, "+ccmp+tkip",
1824 sizeof(buf) - sizeof("+ccmp+tkip"));
1825 } else if (dut->ap_cipher == AP_TKIP) {
1826 strncat(buf, "+tkip",
1827 sizeof(buf) - sizeof("+tkip"));
1828 } else {
1829 strncat(buf, "+ccmp",
1830 sizeof(buf) - sizeof("+ccmp"));
1831 }
1832
1833 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
1834 snprintf(buf, sizeof(buf), "\"%s\"",
1835 dut->ap_passphrase);
1836 owrt_ap_set_vap(dut, vap_count, "key", buf);
1837 break;
1838 case AP_WPA2_EAP:
1839 case AP_WPA2_EAP_MIXED:
1840 case AP_WPA_EAP:
1841 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
1842 snprintf(buf, sizeof(buf), "wpa2");
1843 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
1844 snprintf(buf, sizeof(buf), "wpa-mixed");
1845 } else {
1846 snprintf(buf, sizeof(buf), "wpa");
1847 }
1848
1849 if (dut->ap_cipher == AP_CCMP_TKIP) {
1850 strncat(buf, "+ccmp+tkip", sizeof(buf));
1851 } else if (dut->ap_cipher == AP_TKIP) {
1852 strncat(buf, "+tkip", sizeof(buf));
1853 } else {
1854 strncat(buf, "+ccmp", sizeof(buf));
1855 }
1856 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
1857 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
1858 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
1859 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
1860 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
1861 snprintf(buf, sizeof(buf), "%s",
1862 dut->ap_radius_password);
1863 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
1864 break;
1865 }
1866
1867 if (!dut->ap_is_dual)
1868 break;
1869 }
1870
1871 if (dut->ap_is_dual)
1872 return 1;
1873
1874 /* PMF */
1875 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
1876 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
1877
1878 /* Add SHA256 */
1879 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
1880 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
1881
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301882 /* Enable RSN preauthentication, if asked to */
1883 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
1884 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
1885
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001886 /* Hotspot 2.0 */
1887 if (dut->ap_hs2) {
1888 int ret;
1889
1890 ret = owrt_ap_config_vap_hs2(dut, vap_id);
1891 if (ret)
1892 return ret;
1893 }
1894
1895 /* Interworking */
1896 if (dut->ap_interworking) {
1897 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
1898 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
1899 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
1900 owrt_ap_set_vap(dut, vap_id, "internet", buf);
1901 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
1902 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
1903 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
1904 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
1905 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
1906 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
1907
1908 if (dut->ap_gas_cb_delay > 0) {
1909 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
1910 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
1911 }
1912
1913 if (dut->ap_roaming_cons[0]) {
1914 char *rcons, *temp_ptr;
1915
1916 rcons = strdup(dut->ap_roaming_cons);
1917 if (rcons == NULL)
1918 return 0;
1919
1920 temp_ptr = strchr(rcons, ';');
1921
1922 if (temp_ptr)
1923 *temp_ptr++ = '\0';
1924
1925 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
1926 rcons);
1927
1928 if (temp_ptr)
1929 owrt_ap_set_list_vap(dut, vap_id,
1930 "roaming_consortium",
1931 temp_ptr);
1932
1933 free(rcons);
1934 }
1935 }
1936
1937 if (dut->ap_venue_name) {
1938 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
1939 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
1940 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
1941 "\'"ANQP_VENUE_NAME_1_CHI"\'");
1942 }
1943
1944 if (dut->ap_net_auth_type == 1) {
1945 owrt_ap_set_vap(dut, vap_id, "network_auth_type",
1946 "'00https://tandc-server.wi-fi.org'");
1947 } else if (dut->ap_net_auth_type == 2) {
1948 owrt_ap_set_vap(dut, vap_id, "network_auth_type", "'01'");
1949 }
1950
1951 if (dut->ap_nai_realm_list == 1) {
1952 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1953 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
1954 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1955 "'0,wi-fi.org;example.com,13[5:6]'");
1956
1957 } else if (dut->ap_nai_realm_list == 2) {
1958 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1959 "'0,wi-fi.org,21[2:4][5:7]'");
1960 } else if (dut->ap_nai_realm_list == 3) {
1961 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1962 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
1963 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1964 "'0,wi-fi.org;example.com,13[5:6]'");
1965 } else if (dut->ap_nai_realm_list == 4) {
1966 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1967 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
1968 } else if (dut->ap_nai_realm_list == 5) {
1969 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1970 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
1971 } else if (dut->ap_nai_realm_list == 6) {
1972 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1973 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
1974 } else if (dut->ap_nai_realm_list == 7) {
1975 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1976 "'0,wi-fi.org,13[5:6]'");
1977 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
1978 "'0,wi-fi.org,21[2:4][5:7]'");
1979 }
1980
1981 if (dut->ap_domain_name_list[0])
1982 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
1983 dut->ap_domain_name_list);
1984
1985 if (dut->ap_ip_addr_type_avail)
1986 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
1987 "'0c'");
1988
1989 temp = buf;
1990
1991 *temp++ = '\'';
1992
1993 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
1994 if (i)
1995 *temp++ = ';';
1996
1997 snprintf(temp,
1998 sizeof(dut->ap_plmn_mcc[i]) +
1999 sizeof(dut->ap_plmn_mnc[i]) + 1,
2000 "%s,%s",
2001 dut->ap_plmn_mcc[i],
2002 dut->ap_plmn_mnc[i]);
2003
2004 temp += strlen(dut->ap_plmn_mcc[i]) +
2005 strlen(dut->ap_plmn_mnc[i]) + 1;
2006 }
2007
2008 *temp++ = '\'';
2009 *temp++ = '\0';
2010
2011 if (i)
2012 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
2013
2014 if (dut->ap_qos_map_set == 1)
2015 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
2016 else if (dut->ap_qos_map_set == 2)
2017 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
2018
2019 /* Proxy-ARP */
2020 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
2021 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
2022
2023 /* DGAF */
2024 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
2025 /* parse to hostapd */
2026 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
2027 /* parse to wifi driver */
2028 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
2029
2030 /* HCBSSLoad */
2031 if (dut->ap_bss_load) {
2032 unsigned int bssload = 0;
2033
2034 if (dut->ap_bss_load == 1) {
2035 /* STA count: 1, CU: 50, AAC: 65535 */
2036 bssload = 0x0132ffff;
2037 } else if (dut->ap_bss_load == 2) {
2038 /* STA count: 1, CU: 200, AAC: 65535 */
2039 bssload = 0x01c8ffff;
2040 } else if (dut->ap_bss_load == 3) {
2041 /* STA count: 1, CU: 75, AAC: 65535 */
2042 bssload = 0x014bffff;
2043 }
2044
2045 snprintf(buf, sizeof(buf), "%d", bssload);
2046 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
2047 }
2048
2049 /* L2TIF */
2050 if (dut->ap_l2tif)
2051 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
2052
2053 if (dut->ap_disable_protection == 1)
2054 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
2055
2056 if (dut->ap_txBF) {
2057 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
2058 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
2059 }
2060
2061 if (dut->ap_mu_txBF) {
2062 owrt_ap_set_vap(dut, vap_id, "vhtmubfee", "1");
2063 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
2064 }
2065
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05302066 if (dut->ap_tx_stbc) {
2067 /* STBC and beamforming are mutually exclusive features */
2068 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
2069 }
2070
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05302071 /* enable dfsmode */
2072 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
2073 owrt_ap_set_vap(dut, vap_id, "doth", buf);
2074
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002075 return 1;
2076}
2077
2078
2079static int owrt_ap_post_config_commit(struct sigma_dut *dut,
2080 struct sigma_conn *conn,
2081 struct sigma_cmd *cmd)
2082{
2083 if (dut->ap_key_mgmt != AP_OPEN) {
2084 /* allow some time for hostapd to start before returning
2085 * success */
2086 usleep(500000);
2087
2088 if (run_hostapd_cli(dut, "ping") != 0) {
2089 send_resp(dut, conn, SIGMA_ERROR,
2090 "errorCode,Failed to talk to hostapd");
2091 return 0;
2092 }
2093 }
2094
2095 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2096 ath_ap_set_params(dut);
2097
2098 /* Send response */
2099 return 1;
2100}
2101
2102
2103static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
2104 struct sigma_conn *conn,
2105 struct sigma_cmd *cmd)
2106{
2107 /* Stop the AP */
2108 run_system(dut, "wifi down");
2109
2110 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05302111 run_system(dut, "rm -rf /etc/config/wireless");
2112 switch (get_openwrt_driver_type()) {
2113 case OPENWRT_DRIVER_ATHEROS:
2114 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
2115 break;
2116 default:
2117 run_system(dut, "wifi detect > /etc/config/wireless");
2118 break;
2119 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 /* Configure Radio & VAP, commit the config */
2122 owrt_ap_config_radio(dut);
2123 owrt_ap_config_vap(dut);
2124 run_system(dut, "uci commit");
2125
2126 /* Start AP */
2127 run_system(dut, "wifi up");
2128
2129 return owrt_ap_post_config_commit(dut, conn, cmd);
2130}
2131
2132
2133static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
2134{
2135 unsigned char bssid[6];
2136 char buf[100];
2137 char *ifname, *radio_name;
2138 int vap_id = 0;
2139
2140 if (sigma_radio_ifname[0] &&
2141 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2142 ifname = "ath2";
2143 radio_name = "wifi2";
2144 vap_id = 2;
2145 } else if (sigma_radio_ifname[0] &&
2146 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2147 ifname = "ath1";
2148 radio_name = "wifi1";
2149 vap_id = 1;
2150 } else {
2151 ifname = "ath0";
2152 radio_name = "wifi0";
2153 vap_id = 0;
2154 }
2155
2156 if (!get_hwaddr(ifname, bssid)) {
2157 snprintf(buf, sizeof(buf), "%s", bssid);
2158 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2159 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2160 "%02x:%02x:%02x:%02x:%02x:%02x",
2161 bssid[0], bssid[1], bssid[2], bssid[3],
2162 bssid[4], bssid[5]);
2163 } else {
2164 if (!get_hwaddr(radio_name, bssid)) {
2165 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
2166 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2167 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2168 "%02x:%02x:%02x:%02x:%02x:%02x",
2169 bssid[0], bssid[1], bssid[2], bssid[3],
2170 bssid[4], bssid[5]);
2171 } else {
2172 /* Select & enable/disable radios */
2173 if (sigma_radio_ifname[0] &&
2174 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2175 /* We want to use wifi2 */
2176 owrt_ap_set_radio(dut, 0, "disabled", "1");
2177 owrt_ap_set_radio(dut, 1, "disabled", "1");
2178 owrt_ap_set_radio(dut, 2, "disabled", "0");
2179 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
2180 } else if (sigma_radio_ifname[0] &&
2181 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2182 /* We want to use wifi1 */
2183 owrt_ap_set_radio(dut, 0, "disabled", "1");
2184 owrt_ap_set_radio(dut, 1, "disabled", "0");
2185 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
2186 } else {
2187 /* We want to use wifi0 */
2188 owrt_ap_set_radio(dut, 0, "disabled", "0");
2189 owrt_ap_set_radio(dut, 1, "disabled", "1");
2190 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
2191 }
2192
2193 run_system(dut, "uci commit");
2194 run_system(dut, "wifi up");
2195
2196 if (!get_hwaddr(radio_name, bssid)) {
2197 snprintf(buf, sizeof(buf), "%s",
2198 dut->ap_hessid);
2199 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2200 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2201 "%02x:%02x:%02x:%02x:%02x:%02x",
2202 bssid[0], bssid[1], bssid[2], bssid[3],
2203 bssid[4], bssid[5]);
2204 }
2205 }
2206 }
2207}
2208
2209
2210static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
2211 struct sigma_cmd *cmd)
2212{
2213 switch (get_driver_type()) {
2214 case DRIVER_ATHEROS:
2215 run_system(dut, "apdown");
2216 sleep(1);
2217 run_system(dut, "reboot");
2218 break;
2219 case DRIVER_OPENWRT:
2220 run_system(dut, "wifi down");
2221 sleep(1);
2222 run_system(dut, "reboot");
2223 break;
2224 default:
2225 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
2226 break;
2227 }
2228
2229 return 1;
2230}
2231
2232
2233int ascii2hexstr(const char *str, char *hex)
2234{
2235 int i, length;
2236
2237 length = strlen(str);
2238
2239 for (i = 0; i < length; i++)
2240 snprintf(hex + i * 2, 3, "%X", str[i]);
2241
2242 hex[length * 2] = '\0';
2243 return 1;
2244}
2245
2246
2247static int kill_process(struct sigma_dut *dut, char *proc_name,
2248 unsigned char is_proc_instance_one, int sig)
2249{
2250#ifdef __linux__
2251 struct dirent *dp, *dp_in;
2252 const char *direc = "/proc/";
2253 char buf[100];
2254 DIR *dir = opendir(direc);
2255 DIR *dir_in;
2256 FILE *fp;
2257 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302258 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002259
2260 if (dir == NULL)
2261 return -1;
2262
2263 while ((dp = readdir(dir)) != NULL) {
2264 if (dp->d_type != DT_DIR)
2265 continue;
2266
2267 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
2268 dir_in = opendir(buf);
2269 if (dir_in == NULL)
2270 continue;
2271 dp_in = readdir(dir_in);
2272 closedir(dir_in);
2273 if (dp_in == NULL)
2274 continue;
2275 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
2276 fp = fopen(buf, "r");
2277 if (fp == NULL)
2278 continue;
2279 if (fgets(buf, 100, fp) == NULL)
2280 buf[0] = '\0';
2281 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302282 pid = strtok_r(buf, " ", &saveptr);
2283 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002284 if (pid && temp &&
2285 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
2286 sigma_dut_print(dut, DUT_MSG_INFO,
2287 "killing %s process with PID %s",
2288 proc_name, pid);
2289 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
2290 atoi(pid));
2291 run_system(dut, buf);
2292 if (is_proc_instance_one)
2293 break;
2294 }
2295 }
2296
2297 closedir(dir);
2298
2299 return 0;
2300#else /* __linux__ */
2301 return -1;
2302#endif /* __linux__ */
2303}
2304
2305
2306static int run_ndc(struct sigma_dut *dut, char *buf)
2307{
2308 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
2309 sleep(2);
2310 return run_system(dut, buf);
2311}
2312
2313
2314static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
2315 const char *field, const char *value)
2316{
2317 FILE *fcfg, *ftmp;
2318 char buf[MAX_CONF_LINE_LEN + 1];
2319 int len, found = 0, res;
2320
2321 /* Open the configuration file */
2322 fcfg = fopen(pfile, "r");
2323 if (!fcfg) {
2324 sigma_dut_print(dut, DUT_MSG_ERROR,
2325 "Failed to open hostapd conf file");
2326 return -1;
2327 }
2328
2329 snprintf(buf, sizeof(buf), "%s~", pfile);
2330 /* Open a temporary file */
2331 ftmp = fopen(buf, "w+");
2332 if (!ftmp) {
2333 fclose(fcfg);
2334 sigma_dut_print(dut, DUT_MSG_ERROR,
2335 "Failed to open temp buf");
2336 return -1;
2337 }
2338
2339 /* Read the values from the configuration file */
2340 len = strlen(field);
2341 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
2342 char *pline = buf;
2343
2344 /* commented line */
2345 if (buf[0] == '#')
2346 pline++;
2347
2348 /* Identify the configuration parameter to be updated */
2349 if (!found && strncmp(pline, field, len) == 0 &&
2350 pline[len] == '=') {
2351 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
2352 found = 1;
2353 sigma_dut_print(dut, DUT_MSG_INFO,
2354 "Updated hostapd conf file");
2355 }
2356
2357 fprintf(ftmp, "%s", buf);
2358 }
2359
2360 if (!found) {
2361 /* Configuration line not found */
2362 /* Add the new line at the end of file */
2363 fprintf(ftmp, "%s=%s\n", field, value);
2364 sigma_dut_print(dut, DUT_MSG_INFO,
2365 "Adding a new line in hostapd conf file");
2366 }
2367
2368 fclose(fcfg);
2369 fclose(ftmp);
2370
2371 snprintf(buf, sizeof(buf), "%s~", pfile);
2372
2373 /* Restore the updated configuration file */
2374 res = rename(buf, pfile);
2375
2376 /* Remove the temporary file. Ignore the return value */
2377 unlink(buf);
2378
2379 /* chmod is needed because open() may not set permissions properly
2380 * depending on the current umask */
2381 if (chmod(pfile, 0660) < 0) {
2382 unlink(pfile);
2383 sigma_dut_print(dut, DUT_MSG_ERROR,
2384 "Error changing permissions");
2385 return -1;
2386 }
2387
2388 if (res < 0) {
2389 sigma_dut_print(dut, DUT_MSG_ERROR,
2390 "Error restoring conf file");
2391 return -1;
2392 }
2393
2394 return 0;
2395}
2396
2397
2398static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
2399 struct sigma_conn *conn,
2400 struct sigma_cmd *cmd)
2401{
2402 char buf[100];
2403 struct stat s;
2404 int num_tries = 0, ret;
2405
2406 kill_process(dut, "(netd)", 1, SIGKILL);
2407
2408 while (num_tries < 10) {
2409 ret = run_ndc(dut, "ndc softap stopap");
2410 num_tries++;
2411 if (WIFEXITED(ret))
2412 ret = WEXITSTATUS(ret);
2413 /* On success, NDC exits with 0 */
2414 if (ret == 0)
2415 break;
2416 sigma_dut_print(dut, DUT_MSG_INFO,
2417 "Try No. %d: ndc softap stopap failed, exit code %d",
2418 num_tries, ret);
2419 }
2420
2421 if (ret != 0)
2422 sigma_dut_print(dut, DUT_MSG_ERROR,
2423 "ndc softap stopap command failed for 10 times - giving up");
2424
2425#ifdef ANDROID
2426 /* Unload/Load driver to cleanup the state of the driver */
2427 wifi_unload_driver();
2428 wifi_load_driver();
2429#else /* ANDROID */
2430 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
2431 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
2432#endif /* ANDROID */
2433
2434 switch (dut->ap_mode) {
2435 case AP_11g:
2436 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
2437 break;
2438 case AP_11b:
2439 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
2440 break;
2441 case AP_11ng:
2442 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
2443 break;
2444 case AP_11a:
2445 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
2446 break;
2447 case AP_11na:
2448 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
2449 break;
2450 case AP_11ac:
2451 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
2452 break;
2453 default:
2454 break;
2455 }
2456
2457 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
2458 dut->ap_channel);
2459 run_ndc(dut, buf);
2460
2461 /*
2462 * ndc doesn't support double quotes as SSID string, so re-write
2463 * hostapd configuration file to update SSID.
2464 */
2465 if (dut->ap_ssid[0] != '\0')
2466 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
2467
2468 switch (dut->ap_key_mgmt) {
2469 case AP_OPEN:
2470 if (dut->ap_cipher == AP_WEP) {
2471 run_ndc(dut, "ndc softap qccmd set security_mode=1");
2472 snprintf(buf, sizeof(buf),
2473 "ndc softap qccmd set wep_key0=%s",
2474 dut->ap_wepkey);
2475 run_ndc(dut, buf);
2476 } else {
2477 run_ndc(dut, "ndc softap qccmd set security_mode=0");
2478 }
2479 break;
2480 case AP_WPA2_PSK:
2481 case AP_WPA2_PSK_MIXED:
2482 case AP_WPA_PSK:
2483 if (dut->ap_key_mgmt == AP_WPA2_PSK)
2484 run_ndc(dut, "ndc softap qccmd set security_mode=3");
2485 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
2486 run_ndc(dut, "ndc softap qccmd set security_mode=4");
2487 else
2488 run_ndc(dut, "ndc softap qccmd set security_mode=2");
2489
2490 /*
2491 * ndc doesn't support some special characters as passphrase,
2492 * so re-write hostapd configuration file to update Passphrase.
2493 */
2494 if (dut->ap_passphrase[0] != '\0')
2495 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
2496 "wpa_passphrase", dut->ap_passphrase);
2497
2498 if (dut->ap_cipher == AP_CCMP_TKIP)
2499 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
2500 "TKIP CCMP");
2501 else if (dut->ap_cipher == AP_TKIP)
2502 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
2503 "TKIP");
2504 else
2505 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
2506 "CCMP &");
2507 break;
2508 case AP_WPA2_EAP:
2509 case AP_WPA2_EAP_MIXED:
2510 case AP_WPA_EAP:
2511 /* Not supported */
2512 break;
2513 }
2514
2515 switch (dut->ap_pmf) {
2516 case AP_PMF_DISABLED:
2517 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
2518 break;
2519 case AP_PMF_OPTIONAL:
2520 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
2521 if (dut->ap_add_sha256)
2522 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
2523 else
2524 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
2525 break;
2526 case AP_PMF_REQUIRED:
2527 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
2528 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
2529 break;
2530 }
2531
2532 if (dut->ap_countrycode[0]) {
2533 snprintf(buf, sizeof(buf),
2534 "ndc softap qccmd set country_code=%s",
2535 dut->ap_countrycode);
2536 run_ndc(dut, buf);
2537 }
2538
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05302539 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
2540 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
2541
2542 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
2543 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
2544
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 run_ndc(dut, "ndc softap startap");
2546
2547 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
2548 num_tries = 0;
2549 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
2550 run_ndc(dut, "ndc softap stopap");
2551 run_ndc(dut, "ndc softap startap");
2552 num_tries++;
2553 }
2554
2555 if (num_tries == 10) {
2556 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
2557 "iface %s :: reboot the APDUT", buf);
2558 return ret;
2559 }
2560
2561 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
2562 ap_inet_addr, ap_inet_mask);
2563 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
2564 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
2565 if (system(buf) != 0) {
2566 sigma_dut_print(dut, DUT_MSG_ERROR,
2567 "Failed to intialize the interface");
2568 return -1;
2569 }
2570
2571 return 1;
2572}
2573
2574
2575static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
2576{
2577 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
2578 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
2579
2580 if (dut->ap_oper_name) {
2581 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
2582 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
2583 }
2584
2585 if (dut->ap_wan_metrics == 1)
2586 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
2587 else if (dut->ap_wan_metrics == 2)
2588 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
2589 else if (dut->ap_wan_metrics == 3)
2590 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
2591 else if (dut->ap_wan_metrics == 4)
2592 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
2593 else if (dut->ap_wan_metrics == 5)
2594 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
2595
2596 if (dut->ap_conn_capab == 1) {
2597 fprintf(f, "hs20_conn_capab=1:0:0\n");
2598 fprintf(f, "hs20_conn_capab=6:20:1\n");
2599 fprintf(f, "hs20_conn_capab=6:22:0\n");
2600 fprintf(f, "hs20_conn_capab=6:80:1\n");
2601 fprintf(f, "hs20_conn_capab=6:443:1\n");
2602 fprintf(f, "hs20_conn_capab=6:1723:0\n");
2603 fprintf(f, "hs20_conn_capab=6:5060:0\n");
2604 fprintf(f, "hs20_conn_capab=17:500:1\n");
2605 fprintf(f, "hs20_conn_capab=17:5060:0\n");
2606 fprintf(f, "hs20_conn_capab=17:4500:1\n");
2607 fprintf(f, "hs20_conn_capab=50:0:1\n");
2608 } else if (dut->ap_conn_capab == 2) {
2609 fprintf(f, "hs20_conn_capab=6:80:1\n");
2610 fprintf(f, "hs20_conn_capab=6:443:1\n");
2611 fprintf(f, "hs20_conn_capab=17:5060:1\n");
2612 fprintf(f, "hs20_conn_capab=6:5060:1\n");
2613 } else if (dut->ap_conn_capab == 3) {
2614 fprintf(f, "hs20_conn_capab=6:80:1\n");
2615 fprintf(f, "hs20_conn_capab=6:443:1\n");
2616 } else if (dut->ap_conn_capab == 4) {
2617 fprintf(f, "hs20_conn_capab=6:80:1\n");
2618 fprintf(f, "hs20_conn_capab=6:443:1\n");
2619 fprintf(f, "hs20_conn_capab=6:5060:1\n");
2620 fprintf(f, "hs20_conn_capab=17:5060:1\n");
2621 }
2622
2623 if (dut->ap_oper_class == 1)
2624 fprintf(f, "hs20_operating_class=51\n");
2625 else if (dut->ap_oper_class == 2)
2626 fprintf(f, "hs20_operating_class=73\n");
2627 else if (dut->ap_oper_class == 3)
2628 fprintf(f, "hs20_operating_class=5173\n");
2629
2630 if (dut->ap_osu_provider_list) {
2631 char *osu_friendly_name = NULL;
2632 char *osu_icon = NULL;
2633 char *osu_ssid = NULL;
2634 char *osu_nai = NULL;
2635 char *osu_service_desc = NULL;
2636 char *hs20_icon_filename = NULL;
2637 char hs20_icon[150];
2638 int osu_method;
2639
2640 hs20_icon_filename = "icon_red_zxx.png";
2641 if (dut->ap_osu_icon_tag == 2)
2642 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2643 snprintf(hs20_icon, sizeof(hs20_icon),
2644 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
2645 hs20_icon_filename);
2646 osu_icon = "icon_red_zxx.png";
2647 osu_ssid = "OSU";
2648 osu_friendly_name = "kor:SP 빨강 테스트 전용";
2649 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
2650 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
2651
2652 if (strlen(dut->ap_osu_server_uri[0]))
2653 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
2654 else
2655 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
2656
2657 switch (dut->ap_osu_provider_list) {
2658 case 1:
2659 case 101:
2660 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
2661 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2662 hs20_icon_filename = "icon_red_eng.png";
2663 if (dut->ap_osu_icon_tag == 2)
2664 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2665 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
2666 hs20_icon_filename);
2667 fprintf(f, "osu_icon=icon_red_eng.png\n");
2668 break;
2669 case 2:
2670 case 102:
2671 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
2672 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2673 hs20_icon_filename = "icon_orange_zxx.png";
2674 if (dut->ap_osu_icon_tag == 2)
2675 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2676 snprintf(hs20_icon, sizeof(hs20_icon),
2677 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
2678 hs20_icon_filename);
2679 osu_icon = "icon_orange_zxx.png";
2680 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
2681 break;
2682 case 3:
2683 case 103:
2684 osu_friendly_name = "spa:SP Red Test Only";
2685 osu_service_desc = "spa:Free service for test purpose";
2686 break;
2687 case 4:
2688 case 104:
2689 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
2690 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2691 hs20_icon_filename = "icon_orange_eng.png";
2692 if (dut->ap_osu_icon_tag == 2)
2693 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2694 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
2695 hs20_icon_filename);
2696 fprintf(f, "osu_icon=icon_orange_eng.png\n");
2697 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
2698
2699 hs20_icon_filename = "icon_orange_zxx.png";
2700 if (dut->ap_osu_icon_tag == 2)
2701 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2702 snprintf(hs20_icon, sizeof(hs20_icon),
2703 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
2704 hs20_icon_filename);
2705 osu_icon = "icon_orange_zxx.png";
2706 break;
2707 case 5:
2708 case 105:
2709 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
2710 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2711 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
2712 hs20_icon_filename = "icon_orange_zxx.png";
2713 if (dut->ap_osu_icon_tag == 2)
2714 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2715 snprintf(hs20_icon, sizeof(hs20_icon),
2716 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
2717 hs20_icon_filename);
2718 osu_icon = "icon_orange_zxx.png";
2719 break;
2720 case 6:
2721 case 106:
2722 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
2723 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
2724 hs20_icon_filename = "icon_green_zxx.png";
2725 if (dut->ap_osu_icon_tag == 2)
2726 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2727 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
2728 hs20_icon_filename);
2729 fprintf(f, "osu_icon=icon_green_zxx.png\n");
2730 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
2731 fprintf(f, "osu_method_list=%d\n", osu_method);
2732
2733 if (strlen(dut->ap_osu_server_uri[1]))
2734 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
2735 else
2736 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
2737 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
2738 hs20_icon_filename = "icon_orange_zxx.png";
2739 if (dut->ap_osu_icon_tag == 2)
2740 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2741 snprintf(hs20_icon, sizeof(hs20_icon),
2742 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
2743 hs20_icon_filename);
2744 osu_icon = "icon_orange_zxx.png";
2745 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
2746 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
2747 osu_service_desc = NULL;
2748 break;
2749 case 7:
2750 case 107:
2751 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
2752 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2753 hs20_icon_filename = "icon_green_eng.png";
2754 if (dut->ap_osu_icon_tag == 2)
2755 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2756 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
2757 hs20_icon_filename);
2758 fprintf(f, "osu_icon=icon_green_eng.png\n");
2759 osu_friendly_name = "kor:SP 초록 테스트 전용";
2760
2761 hs20_icon_filename = "icon_green_zxx.png";
2762 if (dut->ap_osu_icon_tag == 2)
2763 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2764 snprintf(hs20_icon, sizeof(hs20_icon),
2765 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
2766 hs20_icon_filename);
2767 osu_icon = "icon_green_zxx.png";
2768 break;
2769 case 8:
2770 case 108:
2771 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
2772 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
2773 osu_ssid = "OSU-Encrypted";
2774 osu_nai = "anonymous@hotspot.net";
2775 break;
2776 case 9:
2777 case 109:
2778 osu_ssid = "OSU-OSEN";
2779 osu_nai = "test-anonymous@wi-fi.org";
2780 osu_friendly_name = "eng:SP Orange Test Only";
2781 hs20_icon_filename = "icon_orange_zxx.png";
2782 if (dut->ap_osu_icon_tag == 2)
2783 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2784 snprintf(hs20_icon, sizeof(hs20_icon),
2785 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
2786 hs20_icon_filename);
2787 osu_icon = "icon_orange_zxx.png";
2788 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
2789 osu_service_desc = NULL;
2790 break;
2791 default:
2792 break;
2793 }
2794
2795 if (strlen(dut->ap_osu_ssid)) {
2796 if (strcmp(dut->ap2_ssid, dut->ap_osu_ssid) &&
2797 strcmp(dut->ap2_ssid, osu_ssid)) {
2798 sigma_dut_print(dut, DUT_MSG_ERROR,
2799 "OSU_SSID and "
2800 "WLAN_TAG2 SSID differ");
2801 return -2;
2802 }
2803 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
2804 } else
2805 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
2806
2807
2808 if (osu_friendly_name)
2809 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
2810
2811 if (osu_service_desc)
2812 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
2813
2814 if (osu_nai)
2815 fprintf(f, "osu_nai=%s\n", osu_nai);
2816
2817 fprintf(f, "hs20_icon=%s\n", hs20_icon);
2818
2819 if (osu_icon)
2820 fprintf(f, "osu_icon=%s\n", osu_icon);
2821
2822 if (dut->ap_osu_provider_list > 100)
2823 fprintf(f, "osu_method_list=0\n");
2824 else
2825 fprintf(f, "osu_method_list=%d\n", osu_method);
2826 }
2827
2828 return 0;
2829}
2830
2831
2832static void write_ap_roaming_cons(FILE *f, const char *list)
2833{
2834 char *buf, *pos, *end;
2835
2836 if (list == NULL || list[0] == '\0')
2837 return;
2838
2839 buf = strdup(list);
2840 if (buf == NULL)
2841 return;
2842
2843 pos = buf;
2844 while (pos && *pos) {
2845 end = strchr(pos, ';');
2846 if (end)
2847 *end++ = '\0';
2848 fprintf(f, "roaming_consortium=%s\n", pos);
2849 pos = end;
2850 }
2851
2852 free(buf);
2853}
2854
2855
2856static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
2857{
2858 int i;
2859 char buf[100], *temp;
2860
2861 if (dut->ap_gas_cb_delay > 0)
2862 fprintf(f, "gas_comeback_delay=%d\n",
2863 dut->ap_gas_cb_delay);
2864
2865 fprintf(f, "interworking=1\n"
2866 "access_network_type=%d\n"
2867 "internet=%d\n"
2868 "asra=0\n"
2869 "esr=0\n"
2870 "uesa=0\n"
2871 "venue_group=%d\n"
2872 "venue_type=%d\n",
2873 dut->ap_access_net_type,
2874 dut->ap_internet,
2875 dut->ap_venue_group,
2876 dut->ap_venue_type);
2877 if (dut->ap_hessid[0])
2878 fprintf(f, "hessid=%s\n", dut->ap_hessid);
2879
2880 write_ap_roaming_cons(f, dut->ap_roaming_cons);
2881
2882 if (dut->ap_venue_name) {
2883 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
2884 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
2885 }
2886
2887 if (dut->ap_net_auth_type == 1)
2888 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
2889 else if (dut->ap_net_auth_type == 2)
2890 fprintf(f, "network_auth_type=01\n");
2891
2892 if (dut->ap_nai_realm_list == 1) {
2893 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
2894 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
2895 } else if (dut->ap_nai_realm_list == 2) {
2896 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
2897 } else if (dut->ap_nai_realm_list == 3) {
2898 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
2899 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
2900 } else if (dut->ap_nai_realm_list == 4) {
2901 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
2902 } else if (dut->ap_nai_realm_list == 5) {
2903 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
2904 } else if (dut->ap_nai_realm_list == 6) {
2905 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
2906 } else if (dut->ap_nai_realm_list == 7) {
2907 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
2908 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
2909 }
2910
2911 if (dut->ap_domain_name_list[0]) {
2912 fprintf(f, "domain_name=%s\n",
2913 dut->ap_domain_name_list);
2914 }
2915
2916 if (dut->ap_ip_addr_type_avail == 1) {
2917 fprintf(f, "ipaddr_type_availability=0c\n");
2918 }
2919
2920 temp = buf;
2921 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
2922 i++) {
2923 if (i)
2924 *temp++ = ';';
2925
2926 snprintf(temp,
2927 sizeof(dut->ap_plmn_mcc[i]) +
2928 sizeof(dut->ap_plmn_mnc[i]) + 1,
2929 "%s,%s",
2930 dut->ap_plmn_mcc[i],
2931 dut->ap_plmn_mnc[i]);
2932
2933 temp += strlen(dut->ap_plmn_mcc[i]) +
2934 strlen(dut->ap_plmn_mnc[i]) + 1;
2935 }
2936 if (i)
2937 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
2938
2939 if (dut->ap_qos_map_set == 1)
2940 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
2941 else if (dut->ap_qos_map_set == 2)
2942 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
2943
2944 return 0;
2945}
2946
2947
2948static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
2949{
2950 FILE *f;
2951
2952 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
2953 system("killall hostapd") == 0) {
2954 int i;
2955
2956 /* Wait some time to allow hostapd to complete cleanup before
2957 * starting a new process */
2958 for (i = 0; i < 10; i++) {
2959 usleep(500000);
2960 if (system("pidof hostapd") != 0)
2961 break;
2962 }
2963 }
2964
2965 f = fopen("/tmp/secath0", "a");
2966 if (f == NULL)
2967 return -2;
2968
2969 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
2970 fclose(f);
2971 return -2;
2972 }
2973
2974 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
2975 fclose(f);
2976 return -2;
2977 }
2978
2979 fflush(f);
2980 fclose(f);
2981 return ath_ap_start_hostapd(dut);
2982}
2983
2984
2985static int ath_ap_start_hostapd(struct sigma_dut *dut)
2986{
2987 if (dut->ap2_key_mgmt == AP2_OSEN)
2988 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
2989 else
2990 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
2991
2992 return 0;
2993}
2994
2995
2996#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
2997
2998static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
2999{
3000 FILE *f;
3001 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
3002 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
3003 char buf[100];
3004 int i;
3005
3006 f = fopen("/root/anqpserver.conf", "w");
3007 if (f == NULL)
3008 return -1;
3009
3010 if (dut->ap_nai_realm_list == 1) {
3011 nai_realm = 1;
3012 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");
3013 } else if (dut->ap_nai_realm_list == 2) {
3014 nai_realm = 1;
3015 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
3016 } else if (dut->ap_nai_realm_list == 3) {
3017 nai_realm = 1;
3018 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");
3019 } else if (dut->ap_nai_realm_list == 4) {
3020 nai_realm = 1;
3021 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");
3022 } else
3023 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
3024
3025 if (dut->ap_domain_name_list[0]) {
3026 char *next, *start, *dnbuf, *dn1, *anqp_dn;
3027 int len, dn_len_max;
3028 dnbuf = strdup(dut->ap_domain_name_list);
3029 if (dnbuf == NULL)
3030 return 0;
3031
3032 len = strlen(dnbuf);
3033 dn_len_max = 50 + len*2;
3034 anqp_dn = malloc(dn_len_max);
3035 if (anqp_dn == NULL) {
3036 free(dnbuf);
3037 return -1;
3038 }
3039 start = dnbuf;
3040 dn1 = anqp_dn;
3041 while (start && *start) {
3042 char *hexstr;
3043
3044 next = strchr(start, ',');
3045 if (next)
3046 *next++ = '\0';
3047
3048 len = strlen(start);
3049 hexstr = malloc(len * 2);
3050 if (hexstr == NULL) {
3051 free(dnbuf);
3052 free(anqp_dn);
3053 return -1;
3054 }
3055 ascii2hexstr(start, hexstr);
3056 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
3057 free(hexstr);
3058 dn1 += 2 + len * 2;
3059 dn_len_max -= 2 + len * 2;
3060 start = next;
3061 }
3062 free(dnbuf);
3063 if (dut->ap_gas_cb_delay) {
3064 fprintf(f, "dyn_domain_name=0c01%04x%s",
3065 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3066 domain_name = 1;
3067 } else
3068 fprintf(f, "domain_name=0c01%04x%s",
3069 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3070 free(anqp_dn);
3071 } else
3072 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
3073
3074 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
3075
3076 if (dut->ap_oper_name) {
3077 if (dut->ap_gas_cb_delay) {
3078 fprintf(f, "dyn_oper_friendly_name="
3079 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3080 oper_name = 1;
3081 } else
3082 fprintf(f, "oper_friendly_name="
3083 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3084 } else
3085 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
3086
3087 if (dut->ap_venue_name) {
3088 if (dut->ap_gas_cb_delay) {
3089 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
3090 venue_name = 1;
3091 } else
3092 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
3093 } else
3094 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
3095
3096 if (dut->ap_wan_metrics) {
3097 if (dut->ap_gas_cb_delay) {
3098 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
3099 wan_metrics = 1;
3100 } else
3101 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
3102 "\n");
3103 } else
3104 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
3105
3106 if (dut->ap_conn_capab) {
3107 if (dut->ap_gas_cb_delay) {
3108 fprintf(f, "dyn_conn_capability="
3109 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3110 conn_cap = 1;
3111 } else
3112 fprintf(f, "conn_capability="
3113 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3114 } else
3115 sigma_dut_print(dut, DUT_MSG_ERROR,
3116 "not setting conn_capability");
3117
3118 if (dut->ap_ip_addr_type_avail) {
3119 if (dut->ap_gas_cb_delay) {
3120 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
3121 "\n");
3122 ipaddr_avail = 1;
3123 } else
3124 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
3125 } else
3126 sigma_dut_print(dut, DUT_MSG_ERROR,
3127 "not setting ipaddr_type_avail");
3128
3129 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3130 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
3131 dut->ap_plmn_mcc[i][1],
3132 dut->ap_plmn_mcc[i][0],
3133 dut->ap_plmn_mnc[i][2] == '\0' ?
3134 'f' : dut->ap_plmn_mnc[i][2],
3135 dut->ap_plmn_mcc[i][2],
3136 dut->ap_plmn_mnc[i][1],
3137 dut->ap_plmn_mnc[i][0]);
3138 }
3139 if (i) {
3140 uint16_t ie_len = (i * 3) + 5;
3141 if (dut->ap_gas_cb_delay) {
3142 fprintf(f, "dyn_cell_net=0801");
3143 cell_net = 1;
3144 } else
3145 fprintf(f, "cell_net=0801");
3146 fprintf(f, "%04x", LE16(ie_len));
3147 fprintf(f, "00"); /* version */
3148 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
3149 fprintf(f, "00"); /* plmn list */
3150 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
3151 fprintf(f, "%02x", i); /* number of plmns */
3152 fprintf(f, "%s\n", buf); /* plmns */
3153 } else
3154 sigma_dut_print(dut, DUT_MSG_ERROR,
3155 "not setting 3gpp_cellular_network");
3156
3157 if (nai_realm || domain_name || oper_name || venue_name ||
3158 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
3159 fprintf(f, "anqp_attach=");
3160 if (venue_name)
3161 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
3162 if (nai_realm)
3163 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
3164 if (cell_net)
3165 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
3166 if (domain_name)
3167 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
3168 if (oper_name)
3169 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
3170 if (wan_metrics)
3171 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
3172 if (conn_cap)
3173 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
3174 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
3175 fprintf(f, "\n");
3176 }
3177
3178 fclose(f);
3179
3180 run_system(dut, "anqpserver -i ath0 &");
3181 if (!dut->ap_anqpserver_on)
3182 run_system(dut, "killall anqpserver");
3183
3184 return 1;
3185}
3186
3187
3188static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
3189{
3190 char buf[100];
3191
3192 run_system(dut, "cfg -a AP_STARTMODE=standard");
3193
3194 if (sigma_radio_ifname[0] &&
3195 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3196 run_system(dut, "cfg -a AP_RADIO_ID=1");
3197 switch (dut->ap_mode) {
3198 case AP_11g:
3199 run_system(dut, "cfg -a AP_CHMODE_2=11G");
3200 break;
3201 case AP_11b:
3202 run_system(dut, "cfg -a AP_CHMODE_2=11B");
3203 break;
3204 case AP_11ng:
3205 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
3206 break;
3207 case AP_11a:
3208 run_system(dut, "cfg -a AP_CHMODE_2=11A");
3209 break;
3210 case AP_11na:
3211 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
3212 break;
3213 case AP_11ac:
3214 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3215 break;
3216 default:
3217 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3218 break;
3219 }
3220
3221 switch (dut->ap_rx_streams) {
3222 case 1:
3223 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
3224 break;
3225 case 2:
3226 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
3227 break;
3228 case 3:
3229 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
3230 break;
3231 }
3232
3233 switch (dut->ap_tx_streams) {
3234 case 1:
3235 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
3236 break;
3237 case 2:
3238 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
3239 break;
3240 case 3:
3241 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
3242 break;
3243 }
3244
3245 switch (dut->ap_chwidth) {
3246 case AP_20:
3247 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
3248 break;
3249 case AP_40:
3250 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
3251 break;
3252 case AP_80:
3253 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3254 break;
3255 case AP_160:
3256 case AP_AUTO:
3257 default:
3258 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
3259 break;
3260 }
3261
3262 if (dut->ap_tx_stbc) {
3263 run_system(dut, "cfg -a TX_STBC_2=1");
3264 }
3265
3266 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
3267 dut->ap_channel);
3268
3269 if (dut->ap_is_dual) {
3270 switch (dut->ap_mode_1) {
3271 case AP_11g:
3272 run_system(dut, "cfg -a AP_CHMODE=11G");
3273 break;
3274 case AP_11b:
3275 run_system(dut, "cfg -a AP_CHMODE=11B");
3276 break;
3277 case AP_11ng:
3278 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3279 break;
3280 case AP_11a:
3281 run_system(dut, "cfg -a AP_CHMODE=11A");
3282 break;
3283 case AP_11na:
3284 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
3285 break;
3286 case AP_11ac:
3287 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
3288 break;
3289 default:
3290 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3291 break;
3292 }
3293 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
3294 dut->ap_channel_1);
3295 }
3296 run_system(dut, buf);
3297 } else {
3298 run_system(dut, "cfg -a AP_RADIO_ID=0");
3299 switch (dut->ap_mode) {
3300 case AP_11g:
3301 run_system(dut, "cfg -a AP_CHMODE=11G");
3302 break;
3303 case AP_11b:
3304 run_system(dut, "cfg -a AP_CHMODE=11B");
3305 break;
3306 case AP_11ng:
3307 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3308 break;
3309 case AP_11a:
3310 run_system(dut, "cfg -a AP_CHMODE=11A");
3311 break;
3312 case AP_11na:
3313 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
3314 break;
3315 case AP_11ac:
3316 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
3317 break;
3318 default:
3319 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
3320 break;
3321 }
3322 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
3323 dut->ap_channel);
3324 run_system(dut, buf);
3325 }
3326
3327 if (dut->ap_sgi80 == 1) {
3328 run_system(dut, "cfg -a SHORTGI=1");
3329 run_system(dut, "cfg -a SHORTGI_2=1");
3330 } else if (dut->ap_sgi80 == 0) {
3331 run_system(dut, "cfg -a SHORTGI=0");
3332 run_system(dut, "cfg -a SHORTGI_2=0");
3333 }
3334
3335 if (dut->ap_ldpc == 1)
3336 run_system(dut, "cfg -a LDPC=1");
3337 else if (dut->ap_ldpc == 2)
3338 run_system(dut, "cfg -a LDPC=0");
3339}
3340
3341
3342void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
3343{
3344 char buf[50];
3345
3346 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
3347 if (system(buf) != 0)
3348 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
3349
3350 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
3351 if (system(buf) != 0)
3352 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
3353
3354 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
3355 if (system(buf) != 0)
3356 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
3357
3358 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
3359 if (system(buf) != 0)
3360 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
3361}
3362
3363
3364static void ath_ap_set_params(struct sigma_dut *dut)
3365{
3366 const char *basedev = "wifi1";
3367 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
3368 int i;
3369 char buf[100];
3370
3371 if (dut->ap_countrycode[0]) {
3372 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
3373 basedev, dut->ap_countrycode);
3374 if (system(buf) != 0) {
3375 sigma_dut_print(dut, DUT_MSG_ERROR,
3376 "iwpriv setCountry failed");
3377 }
3378 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
3379 }
3380
3381 for (i = 0; i < NUM_AP_AC; i++) {
3382 if (dut->ap_qos[i].ac) {
3383 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
3384 ifname, i, dut->ap_qos[i].cwmin);
3385 if (system(buf) != 0) {
3386 sigma_dut_print(dut, DUT_MSG_ERROR,
3387 "iwpriv cwmin failed");
3388 }
3389
3390 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
3391 ifname, i, dut->ap_qos[i].cwmax);
3392 if (system(buf) != 0) {
3393 sigma_dut_print(dut, DUT_MSG_ERROR,
3394 "iwpriv cwmax failed");
3395 }
3396
3397 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
3398 ifname, i, dut->ap_qos[i].aifs);
3399 if (system(buf) != 0) {
3400 sigma_dut_print(dut, DUT_MSG_ERROR,
3401 "iwpriv aifs failed");
3402 }
3403
3404 snprintf(buf, sizeof(buf),
3405 "iwpriv %s txoplimit %d 0 %d",
3406 ifname, i, dut->ap_qos[i].txop);
3407 if (system(buf) != 0) {
3408 sigma_dut_print(dut, DUT_MSG_ERROR,
3409 "iwpriv txoplimit failed");
3410 }
3411
3412 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
3413 ifname, i, dut->ap_qos[i].acm);
3414 if (system(buf) != 0) {
3415 sigma_dut_print(dut, DUT_MSG_ERROR,
3416 "iwpriv acm failed");
3417 }
3418 }
3419 }
3420
3421 for (i = 0; i < NUM_AP_AC; i++) {
3422 if (dut->ap_sta_qos[i].ac) {
3423 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
3424 ifname, i, dut->ap_sta_qos[i].cwmin);
3425 if (system(buf) != 0) {
3426 sigma_dut_print(dut, DUT_MSG_ERROR,
3427 "iwpriv cwmin failed");
3428 }
3429
3430 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
3431 ifname, i, dut->ap_sta_qos[i].cwmax);
3432 if (system(buf) != 0) {
3433 sigma_dut_print(dut, DUT_MSG_ERROR,
3434 "iwpriv cwmax failed");
3435 }
3436
3437 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
3438 ifname, i, dut->ap_sta_qos[i].aifs);
3439 if (system(buf) != 0) {
3440 sigma_dut_print(dut, DUT_MSG_ERROR,
3441 "iwpriv aifs failed");
3442 }
3443
3444 snprintf(buf, sizeof(buf),
3445 "iwpriv %s txoplimit %d 1 %d",
3446 ifname, i, dut->ap_sta_qos[i].txop);
3447 if (system(buf) != 0) {
3448 sigma_dut_print(dut, DUT_MSG_ERROR,
3449 "iwpriv txoplimit failed");
3450 }
3451
3452 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
3453 ifname, i, dut->ap_sta_qos[i].acm);
3454 if (system(buf) != 0) {
3455 sigma_dut_print(dut, DUT_MSG_ERROR,
3456 "iwpriv acm failed");
3457 }
3458 }
3459 }
3460
3461 if (dut->ap_disable_protection == 1) {
3462 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
3463 if (system(buf) != 0) {
3464 sigma_dut_print(dut, DUT_MSG_ERROR,
3465 "iwpriv enablertscts failed");
3466 }
3467 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
3468 }
3469
3470 if (dut->ap_ldpc == 1) {
3471 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", ifname);
3472 if (system(buf) != 0) {
3473 sigma_dut_print(dut, DUT_MSG_ERROR,
3474 "iwpriv ldpc 1 failed");
3475 }
3476 } else if (dut->ap_ldpc == 2) {
3477 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
3478 if (system(buf) != 0) {
3479 sigma_dut_print(dut, DUT_MSG_ERROR,
3480 "iwpriv ldpc 0 failed");
3481 }
3482 }
3483
3484 if (dut->ap_ampdu == 1) {
3485 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
3486 if (system(buf) != 0) {
3487 sigma_dut_print(dut, DUT_MSG_ERROR,
3488 "iwpriv ampdu 1 failed");
3489 }
3490 } else if (dut->ap_ampdu == 2) {
3491 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
3492 if (system(buf) != 0) {
3493 sigma_dut_print(dut, DUT_MSG_ERROR,
3494 "iwpriv ampdu 0 failed");
3495 }
3496 }
3497
3498 if (dut->ap_ampdu_exp) {
3499 if (dut->program == PROGRAM_VHT) {
3500 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
3501 ifname, dut->ap_ampdu_exp);
3502 if (system(buf) != 0) {
3503 sigma_dut_print(dut, DUT_MSG_ERROR,
3504 "iwpriv vhtmaxampdu failed");
3505 }
3506 } else {
3507 /* 11N */
3508 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
3509 ifname, dut->ap_ampdu_exp);
3510 if (system(buf) != 0) {
3511 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
3512 }
3513 }
3514 }
3515
3516 if (dut->ap_noack == AP_NOACK_ENABLED) {
3517 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
3518 if (system(buf) != 0) {
3519 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
3520 }
3521 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
3522 if (system(buf) != 0) {
3523 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
3524 }
3525 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
3526 if (system(buf) != 0) {
3527 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
3528 }
3529 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
3530 if (system(buf) != 0) {
3531 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
3532 }
3533 } else if (dut->ap_noack == AP_NOACK_DISABLED) {
3534 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
3535 if (system(buf) != 0) {
3536 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
3537 }
3538 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
3539 if (system(buf) != 0) {
3540 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
3541 }
3542 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
3543 if (system(buf) != 0) {
3544 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
3545 }
3546 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
3547 if (system(buf) != 0) {
3548 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
3549 }
3550 }
3551
3552 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
3553 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3554 ifname, dut->ap_vhtmcs_map);
3555 if (system(buf) != 0) {
3556 sigma_dut_print(dut, DUT_MSG_ERROR,
3557 "iwpriv vht_mcsmap failed");
3558 }
3559 }
3560
3561 if (dut->ap_amsdu == 1) {
3562 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
3563 if (system(buf) != 0) {
3564 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
3565 }
3566 } else if (dut->ap_amsdu == 2) {
3567 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
3568 if (system(buf) != 0) {
3569 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
3570 }
3571 }
3572
3573 if (dut->ap_rx_amsdu == 1) {
3574 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
3575 if (system(buf) != 0) {
3576 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
3577 }
3578 } else if (dut->ap_rx_amsdu == 2) {
3579 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
3580 if (system(buf) != 0) {
3581 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
3582 }
3583 }
3584
3585 /* Command sequence to generate single VHT AMSDU and MPDU */
3586 if (dut->ap_addba_reject && dut->ap_ampdu == 2 && dut->ap_amsdu == 1) {
3587 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
3588 if (system(buf) != 0) {
3589 sigma_dut_print(dut, DUT_MSG_ERROR,
3590 "iwpriv setaddbaoper 1 failed");
3591 }
3592
3593 snprintf(buf, sizeof(buf),
3594 "wifitool %s senddelba 1 0 1 4", ifname);
3595 if (system(buf) != 0) {
3596 sigma_dut_print(dut, DUT_MSG_ERROR,
3597 "wifitool senddelba failed");
3598 }
3599
3600 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
3601 ifname);
3602 if (system(buf) != 0) {
3603 sigma_dut_print(dut, DUT_MSG_ERROR,
3604 "wifitool sendsingleamsdu failed");
3605 }
3606
3607 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
3608 if (system(buf) != 0) {
3609 sigma_dut_print(dut, DUT_MSG_ERROR,
3610 "iwpriv amsdu failed");
3611 }
3612 }
3613
3614 if (dut->ap_mode == AP_11ac) {
3615 int chwidth, nss;
3616
3617 switch (dut->ap_chwidth) {
3618 case AP_20:
3619 chwidth = 0;
3620 break;
3621 case AP_40:
3622 chwidth = 1;
3623 break;
3624 case AP_80:
3625 chwidth = 2;
3626 break;
3627 case AP_160:
3628 chwidth = 3;
3629 break;
3630 default:
3631 chwidth = 0;
3632 break;
3633 }
3634
3635 switch (dut->ap_tx_streams) {
3636 case 1:
3637 nss = 1;
3638 break;
3639 case 2:
3640 nss = 2;
3641 break;
3642 case 3:
3643 nss = 3;
3644 break;
3645 case 4:
3646 nss = 4;
3647 break;
3648 default:
3649 nss = 3;
3650 break;
3651 }
3652
3653 if (dut->ap_fixed_rate) {
3654 if (nss == 4)
3655 ath_disable_txbf(dut, ifname);
3656
3657 /* Set the nss */
3658 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
3659 ifname, nss);
3660 if (system(buf) != 0) {
3661 sigma_dut_print(dut, DUT_MSG_ERROR,
3662 "iwpriv nss failed");
3663 }
3664
3665 /* Set the channel width */
3666 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
3667 ifname, chwidth);
3668 if (system(buf) != 0) {
3669 sigma_dut_print(dut, DUT_MSG_ERROR,
3670 "iwpriv chwidth failed");
3671 }
3672
3673 /* Set the VHT MCS */
3674 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
3675 ifname, dut->ap_mcs);
3676 if (system(buf) != 0) {
3677 sigma_dut_print(dut, DUT_MSG_ERROR,
3678 "iwpriv vhtmcs failed");
3679 }
3680 }
3681 }
3682
3683 if (dut->ap_dyn_bw_sig == AP_DYN_BW_SGNL_ENABLED) {
3684 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
3685 if (system(buf) != 0) {
3686 sigma_dut_print(dut, DUT_MSG_ERROR,
3687 "iwpriv cwmenable 1 failed");
3688 }
3689 } else if (dut->ap_dyn_bw_sig == AP_DYN_BW_SGNL_DISABLED) {
3690 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
3691 if (system(buf) != 0) {
3692 sigma_dut_print(dut, DUT_MSG_ERROR,
3693 "iwpriv cwmenable 0 failed");
3694 }
3695 }
3696
3697 if (dut->ap_sig_rts == 1) {
3698 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
3699 if (system(buf) != 0) {
3700 sigma_dut_print(dut, DUT_MSG_ERROR,
3701 "iwconfig rts 64 failed");
3702 }
3703 } else if (dut->ap_sig_rts == 2) {
3704 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
3705 if (system(buf) != 0) {
3706 sigma_dut_print(dut, DUT_MSG_ERROR,
3707 "iwpriv rts 2347 failed");
3708 }
3709 }
3710
3711 if (dut->ap_hs2) {
3712 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
3713 if (system(buf) != 0) {
3714 sigma_dut_print(dut, DUT_MSG_ERROR,
3715 "iwpriv qbssload failed");
3716 }
3717 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
3718 }
3719
3720 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
3721 unsigned int bssload = 0;
3722
3723 if (dut->ap_bss_load == 1) {
3724 /* STA count: 1, CU: 50, AAC: 65535 */
3725 bssload = 0x0132ffff;
3726 } else if (dut->ap_bss_load == 2) {
3727 /* STA count: 1, CU: 200, AAC: 65535 */
3728 bssload = 0x01c8ffff;
3729 } else if (dut->ap_bss_load == 3) {
3730 /* STA count: 1, CU: 75, AAC: 65535 */
3731 bssload = 0x014bffff;
3732 }
3733
3734 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
3735 ifname, bssload);
3736 if (system(buf) != 0) {
3737 sigma_dut_print(dut, DUT_MSG_ERROR,
3738 "iwpriv hcbssload failed");
3739 }
3740 } else if (dut->ap_bss_load == 0) {
3741 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
3742 if (system(buf) != 0) {
3743 sigma_dut_print(dut, DUT_MSG_ERROR,
3744 "iwpriv qbssload failed");
3745 }
3746 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
3747 }
3748
3749 if (dut->ap_dgaf_disable) {
3750 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
3751 if (system(buf) != 0) {
3752 sigma_dut_print(dut, DUT_MSG_ERROR,
3753 "iwpriv dgaf_disable failed");
3754 }
3755 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
3756 }
3757
3758 if (dut->ap_l2tif) {
3759 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
3760 if (system(buf) != 0) {
3761 sigma_dut_print(dut, DUT_MSG_ERROR,
3762 "iwpriv l2tif failed");
3763 }
3764 snprintf(buf, sizeof(buf),
3765 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
3766 if (system(buf) != 0)
3767 sigma_dut_print(dut, DUT_MSG_ERROR,
3768 "l2tif br failed");
3769
3770 snprintf(buf, sizeof(buf),
3771 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
3772 if (system(buf) != 0)
3773 sigma_dut_print(dut, DUT_MSG_ERROR,
3774 "l2tif brif failed");
3775 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
3776 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08003777
3778 if (dut->ap_ndpa_frame == 0) {
3779 snprintf(buf, sizeof(buf),
3780 "wifitool %s beeliner_fw_test 117 192", ifname);
3781 if (system(buf) != 0) {
3782 sigma_dut_print(dut, DUT_MSG_ERROR,
3783 "wifitool beeliner_fw_test 117 192 failed");
3784 }
3785 snprintf(buf, sizeof(buf),
3786 "wifitool %s beeliner_fw_test 118 192", ifname);
3787 if (system(buf) != 0) {
3788 sigma_dut_print(dut, DUT_MSG_ERROR,
3789 "wifitool beeliner_fw_test 117 192 failed");
3790 }
3791 } else if (dut->ap_ndpa_frame == 1) {
3792 /* Driver default - no changes needed */
3793 } else if (dut->ap_ndpa_frame == 2) {
3794 snprintf(buf, sizeof(buf),
3795 "wifitool %s beeliner_fw_test 115 1", ifname);
3796 if (system(buf) != 0) {
3797 sigma_dut_print(dut, DUT_MSG_ERROR,
3798 "wifitool beeliner_fw_test 117 192 failed");
3799 }
3800 snprintf(buf, sizeof(buf),
3801 "wifitool %s beeliner_fw_test 116 1", ifname);
3802 if (system(buf) != 0) {
3803 sigma_dut_print(dut, DUT_MSG_ERROR,
3804 "wifitool beeliner_fw_test 117 192 failed");
3805 }
3806 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003807}
3808
3809
3810static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
3811 struct sigma_conn *conn,
3812 struct sigma_cmd *cmd)
3813{
3814 /* const char *name = get_param(cmd, "NAME"); */
3815 char buf[100];
3816 struct stat s;
3817 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
3818
3819 if (stat("/proc/athversion", &s) == 0) {
3820 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
3821 run_system(dut, "apdown");
3822 }
3823
3824 cmd_ath_ap_radio_config(dut);
3825
3826 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
3827 run_system(dut, buf);
3828
3829 switch (dut->ap_key_mgmt) {
3830 case AP_OPEN:
3831 if (dut->ap_cipher == AP_WEP) {
3832 run_system(dut, "cfg -a AP_SECMODE=WEP");
3833 run_system(dut, "cfg -a AP_SECFILE=NONE");
3834 /* shared auth mode not supported */
3835 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
3836 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
3837 snprintf(buf, sizeof(buf),
3838 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
3839 dut->ap_wepkey);
3840 run_system(dut, buf);
3841 snprintf(buf, sizeof(buf),
3842 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
3843 dut->ap_wepkey);
3844 run_system(dut, buf);
3845 } else {
3846 run_system(dut, "cfg -a AP_SECMODE=None");
3847 }
3848 break;
3849 case AP_WPA2_PSK:
3850 case AP_WPA2_PSK_MIXED:
3851 case AP_WPA_PSK:
3852 if (dut->ap_key_mgmt == AP_WPA2_PSK)
3853 run_system(dut, "cfg -a AP_WPA=2");
3854 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
3855 run_system(dut, "cfg -a AP_WPA=3");
3856 else
3857 run_system(dut, "cfg -a AP_WPA=1");
3858 run_system(dut, "cfg -a AP_SECMODE=WPA");
3859 run_system(dut, "cfg -a AP_SECFILE=PSK");
3860 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
3861 dut->ap_passphrase);
3862 run_system(dut, buf);
3863 if (dut->ap_cipher == AP_CCMP_TKIP)
3864 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
3865 else if (dut->ap_cipher == AP_TKIP)
3866 run_system(dut, "cfg -a AP_CYPHER=TKIP");
3867 else
3868 run_system(dut, "cfg -a AP_CYPHER=CCMP");
3869 break;
3870 case AP_WPA2_EAP:
3871 case AP_WPA2_EAP_MIXED:
3872 case AP_WPA_EAP:
3873 if (dut->ap_key_mgmt == AP_WPA2_EAP)
3874 run_system(dut, "cfg -a AP_WPA=2");
3875 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
3876 run_system(dut, "cfg -a AP_WPA=3");
3877 else
3878 run_system(dut, "cfg -a AP_WPA=1");
3879 run_system(dut, "cfg -a AP_SECMODE=WPA");
3880 run_system(dut, "cfg -a AP_SECFILE=EAP");
3881 if (dut->ap_cipher == AP_CCMP_TKIP)
3882 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
3883 else if (dut->ap_cipher == AP_TKIP)
3884 run_system(dut, "cfg -a AP_CYPHER=TKIP");
3885 else
3886 run_system(dut, "cfg -a AP_CYPHER=CCMP");
3887 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
3888 dut->ap_radius_ipaddr);
3889 run_system(dut, buf);
3890 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
3891 dut->ap_radius_port);
3892 run_system(dut, buf);
3893 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
3894 dut->ap_radius_password);
3895 run_system(dut, buf);
3896 break;
3897 }
3898
3899 if (dut->ap_is_dual) {
3900 /* ath1 settings in case of dual */
3901 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
3902 dut->ap_ssid);
3903 run_system(dut, buf);
3904
3905 switch (dut->ap_key_mgmt) {
3906 case AP_OPEN:
3907 if (dut->ap_cipher == AP_WEP) {
3908 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
3909 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
3910 /* shared auth mode not supported */
3911 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
3912 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
3913 snprintf(buf, sizeof(buf),
3914 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
3915 dut->ap_wepkey);
3916 run_system(dut, buf);
3917 snprintf(buf, sizeof(buf),
3918 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
3919 dut->ap_wepkey);
3920 run_system(dut, buf);
3921 } else {
3922 run_system(dut, "cfg -a AP_SECMODE_2=None");
3923 }
3924 break;
3925 case AP_WPA2_PSK:
3926 case AP_WPA2_PSK_MIXED:
3927 case AP_WPA_PSK:
3928 if (dut->ap_key_mgmt == AP_WPA2_PSK)
3929 run_system(dut, "cfg -a AP_WPA_2=2");
3930 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
3931 run_system(dut, "cfg -a AP_WPA_2=3");
3932 else
3933 run_system(dut, "cfg -a AP_WPA_2=1");
3934 // run_system(dut, "cfg -a AP_WPA_2=2");
3935 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
3936 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
3937 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
3938 dut->ap_passphrase);
3939 run_system(dut, buf);
3940 if (dut->ap_cipher == AP_CCMP_TKIP)
3941 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
3942 else if (dut->ap_cipher == AP_TKIP)
3943 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
3944 else
3945 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
3946 break;
3947 case AP_WPA2_EAP:
3948 case AP_WPA2_EAP_MIXED:
3949 case AP_WPA_EAP:
3950 if (dut->ap_key_mgmt == AP_WPA2_EAP)
3951 run_system(dut, "cfg -a AP_WPA_2=2");
3952 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
3953 run_system(dut, "cfg -a AP_WPA_2=3");
3954 else
3955 run_system(dut, "cfg -a AP_WPA_2=1");
3956 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
3957 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
3958 if (dut->ap_cipher == AP_CCMP_TKIP)
3959 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
3960 else if (dut->ap_cipher == AP_TKIP)
3961 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
3962 else
3963 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
3964
3965 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
3966 dut->ap_radius_ipaddr);
3967 run_system(dut, buf);
3968 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
3969 dut->ap_radius_port);
3970 run_system(dut, buf);
3971 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
3972 dut->ap_radius_password);
3973 run_system(dut, buf);
3974 break;
3975 }
3976
3977 /* wifi0 settings in case of dual */
3978 run_system(dut, "cfg -a AP_RADIO_ID=0");
3979 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
3980 run_system(dut, "cfg -a AP_STARTMODE=dual");
3981 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
3982 run_system(dut, "cfg -a TX_CHAINMASK=7");
3983 run_system(dut, "cfg -a RX_CHAINMASK=7");
3984 }
3985
3986 switch (dut->ap_pmf) {
3987 case AP_PMF_DISABLED:
3988 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
3989 run_system(dut, buf);
3990 break;
3991 case AP_PMF_OPTIONAL:
3992 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
3993 run_system(dut, buf);
3994 break;
3995 case AP_PMF_REQUIRED:
3996 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
3997 run_system(dut, buf);
3998 break;
3999 }
4000 if (dut->ap_add_sha256) {
4001 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
4002 run_system(dut, buf);
4003 } else {
4004 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
4005 run_system(dut, buf);
4006 }
4007
4008 if (dut->ap_hs2)
4009 run_system(dut, "cfg -a AP_HOTSPOT=1");
4010 else
4011 run_system(dut, "cfg -r AP_HOTSPOT");
4012
4013 if (dut->ap_interworking) {
4014 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
4015 dut->ap_access_net_type);
4016 run_system(dut, buf);
4017 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
4018 dut->ap_internet);
4019 run_system(dut, buf);
4020 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
4021 dut->ap_venue_group);
4022 run_system(dut, buf);
4023 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
4024 dut->ap_venue_type);
4025 run_system(dut, buf);
4026 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
4027 dut->ap_hessid);
4028 run_system(dut, buf);
4029
4030 if (dut->ap_roaming_cons[0]) {
4031 char *second, *rc;
4032 rc = strdup(dut->ap_roaming_cons);
4033 if (rc == NULL)
4034 return 0;
4035
4036 second = strchr(rc, ';');
4037 if (second)
4038 *second++ = '\0';
4039
4040 snprintf(buf, sizeof(buf),
4041 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
4042 run_system(dut, buf);
4043
4044 if (second) {
4045 snprintf(buf, sizeof(buf),
4046 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
4047 "=%s", second);
4048 run_system(dut, buf);
4049 }
4050 free(rc);
4051 } else {
4052 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
4053 run_system(dut,
4054 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
4055 }
4056 } else {
4057 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
4058 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
4059 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
4060 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
4061 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
4062 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
4063 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
4064 }
4065
4066 if (dut->ap_proxy_arp)
4067 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
4068 else
4069 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
4070 if (dut->ap_dgaf_disable)
4071 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
4072 else
4073 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
4074
4075 if (strlen(dut->ap2_ssid)) {
4076 snprintf(buf, sizeof(buf),
4077 "cfg -a AP_SSID_2=%s", dut->ap2_ssid);
4078 run_system(dut, buf);
4079
4080 if (dut->ap2_key_mgmt == AP2_OSEN) {
4081 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
4082 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
4083
4084 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
4085 dut->ap2_radius_ipaddr);
4086 run_system(dut, buf);
4087
4088 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
4089 dut->ap2_radius_port);
4090 run_system(dut, buf);
4091
4092 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
4093 dut->ap2_radius_password);
4094 run_system(dut, buf);
4095 } else {
4096 run_system(dut, "cfg -a AP_SECMODE_2=None");
4097 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
4098 run_system(dut, "cfg -r AP_AUTH_PORT_2");
4099 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
4100 }
4101
4102 run_system(dut, "cfg -a AP_STARTMODE=multi");
4103 }
4104
4105 run_system(dut, "cfg -c");
4106
4107 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
4108 if (system("apup") != 0) {
4109 /* to be debugged why apup returns error
4110 send_resp(dut, conn, SIGMA_ERROR,
4111 "errorCode,apup failed");
4112 return 0;
4113 */
4114 }
4115 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
4116
4117 if (dut->ap_key_mgmt != AP_OPEN) {
4118 int res;
4119 /* allow some time for hostapd to start before returning
4120 * success */
4121 usleep(500000);
4122 if (run_hostapd_cli(dut, "ping") != 0) {
4123 send_resp(dut, conn, SIGMA_ERROR,
4124 "errorCode,Failed to talk to hostapd");
4125 return 0;
4126 }
4127
4128 if (dut->ap_hs2 && !dut->ap_anqpserver) {
4129 /* the cfg app doesn't like ";" in the variables */
4130 res = ath_ap_append_hostapd_conf(dut);
4131 if (res < 0)
4132 return res;
4133
4134 /* wait for hostapd to be ready */
4135 usleep(500000);
4136 if (run_hostapd_cli(dut, "ping") != 0) {
4137 send_resp(dut, conn, SIGMA_ERROR,
4138 "errorCode,Failed to talk to "
4139 "hostapd");
4140 return 0;
4141 }
4142 }
4143 }
4144
4145 ath_ap_set_params(dut);
4146
4147 if (dut->ap_anqpserver)
4148 return cmd_ath_ap_anqpserver_start(dut);
4149
4150 if (dut->ap2_proxy_arp)
4151 run_system(dut, "iwpriv ath1 proxy_arp 1");
4152
4153 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
4154 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
4155 if (system(buf) != 0) {
4156 sigma_dut_print(dut, DUT_MSG_ERROR,
4157 "iwpriv htweptkip failed");
4158 }
4159 }
4160
4161 return 1;
4162}
4163
4164
4165static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
4166 const char *ifname)
4167{
4168 char buf[200];
4169
4170 if (!chain || !ifname)
4171 return -2;
4172
4173 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
4174 if (system(buf) != 0) {
4175 sigma_dut_print(dut, DUT_MSG_ERROR,
4176 "Failed to set ebtables rules, RULE-1, %s",
4177 chain);
4178 return -2;
4179 }
4180
4181 snprintf(buf, sizeof(buf),
4182 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
4183 chain, ifname);
4184 if (system(buf) != 0) {
4185 sigma_dut_print(dut, DUT_MSG_ERROR,
4186 "Failed to set ebtables rules, RULE-2, %s",
4187 chain);
4188 return -2;
4189 }
4190
4191 snprintf(buf, sizeof(buf),
4192 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
4193 chain, ifname);
4194 if (system(buf) != 0) {
4195 sigma_dut_print(dut, DUT_MSG_ERROR,
4196 "Failed to set ebtables rules, RULE-3, %s",
4197 chain);
4198 return -2;
4199 }
4200
4201 snprintf(buf, sizeof(buf),
4202 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
4203 chain, ifname);
4204 if (system(buf) != 0) {
4205 sigma_dut_print(dut, DUT_MSG_ERROR,
4206 "Failed to set ebtables rules, RULE-4, %s",
4207 chain);
4208 return -2;
4209 }
4210
4211 return 0;
4212}
4213
4214
4215static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
4216 const char *chain,
4217 const char *ifname)
4218{
4219 char buf[200];
4220
4221 if (!chain || !ifname)
4222 return -2;
4223
4224 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
4225 if (system(buf) != 0) {
4226 sigma_dut_print(dut, DUT_MSG_ERROR,
4227 "Failed to set ebtables rules, RULE-5, %s",
4228 chain);
4229 return -2;
4230 }
4231
4232 snprintf(buf, sizeof(buf),
4233 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
4234 chain, ifname);
4235 if (system(buf) != 0) {
4236 sigma_dut_print(dut, DUT_MSG_ERROR,
4237 "Failed to set ebtables rules, RULE-6, %s",
4238 chain);
4239 return -2;
4240 }
4241
4242 snprintf(buf, sizeof(buf),
4243 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
4244 chain, ifname);
4245 if (system(buf) != 0) {
4246 sigma_dut_print(dut, DUT_MSG_ERROR,
4247 "Failed to set ebtables rules, RULE-7, %s",
4248 chain);
4249 return -2;
4250 }
4251
4252 snprintf(buf, sizeof(buf),
4253 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
4254 chain, ifname);
4255 if (system(buf) != 0) {
4256 sigma_dut_print(dut, DUT_MSG_ERROR,
4257 "Failed to set ebtables rules, RULE-8, %s",
4258 chain);
4259 return -2;
4260 }
4261
4262 return 0;
4263}
4264
4265
4266static int check_channel(int channel)
4267{
4268 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
4269 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
4270 161, 165 };
4271 int num_chan = sizeof(channel_list) / sizeof(int);
4272 int i;
4273
4274 for (i = 0; i < num_chan; i++) {
4275 if (channel == channel_list[i])
4276 return i;
4277 }
4278
4279 return -1;
4280}
4281
4282
4283static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
4284{
4285 int ch_base;
4286 int period;
4287
4288 if (check_channel(channel) < 0)
4289 return -1;
4290
4291 if (channel >= 36 && channel <= 64)
4292 ch_base = 36;
4293 else if (channel >= 100 && channel <= 144)
4294 ch_base = 100;
4295 else
4296 ch_base = 149;
4297
4298 period = channel % ch_base * 5 / chwidth;
4299 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
4300}
4301
4302
4303static int is_ht40plus_chan(int chan)
4304{
4305 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
4306 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
4307 chan == 132 || chan == 149 || chan == 157;
4308}
4309
4310
4311static int is_ht40minus_chan(int chan)
4312{
4313 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
4314 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
4315 chan == 136 || chan == 153 || chan == 161;
4316}
4317
4318
4319static int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
4320 struct sigma_cmd *cmd)
4321{
4322 /* const char *name = get_param(cmd, "NAME"); */
4323 FILE *f;
4324 const char *ifname;
4325 char buf[500];
4326 char path[100];
4327 enum driver_type drv;
4328
4329 drv = get_driver_type();
4330
4331 if (dut->mode == SIGMA_MODE_STATION) {
4332 stop_sta_mode(dut);
4333 sleep(1);
4334 }
4335
4336 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
4337 snprintf(buf, sizeof(buf), "ifconfig %s down",
4338 dut->sniffer_ifname);
4339 if (system(buf) != 0) {
4340 sigma_dut_print(dut, DUT_MSG_INFO,
4341 "Failed to run '%s'", buf);
4342 }
4343 snprintf(buf, sizeof(buf), "iw dev %s set type station",
4344 dut->sniffer_ifname);
4345 if (system(buf) != 0) {
4346 sigma_dut_print(dut, DUT_MSG_INFO,
4347 "Failed to run '%s'", buf);
4348 }
4349 }
4350
4351 dut->mode = SIGMA_MODE_AP;
4352
4353 if (drv == DRIVER_ATHEROS)
4354 return cmd_ath_ap_config_commit(dut, conn, cmd);
4355 if (drv == DRIVER_WCN)
4356 return cmd_wcn_ap_config_commit(dut, conn, cmd);
4357 if (drv == DRIVER_OPENWRT)
4358 return cmd_owrt_ap_config_commit(dut, conn, cmd);
4359
4360 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
4361 if (f == NULL) {
4362 sigma_dut_print(dut, DUT_MSG_ERROR,
4363 "%s: Failed to open sigma_dut-ap.conf",
4364 __func__);
4365 return -2;
4366 }
4367 switch (dut->ap_mode) {
4368 case AP_11g:
4369 case AP_11b:
4370 case AP_11ng:
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304371 ifname = (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) ?
4372 "wlan0" : "ath0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004373 if (drv == DRIVER_QNXNTO && sigma_main_ifname)
4374 ifname = sigma_main_ifname;
4375 fprintf(f, "hw_mode=g\n");
4376 break;
4377 case AP_11a:
4378 case AP_11na:
4379 case AP_11ac:
4380 if (drv == DRIVER_QNXNTO) {
4381 if (sigma_main_ifname)
4382 ifname = sigma_main_ifname;
4383 else
4384 ifname = "wlan0";
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304385 } else if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004386 if (if_nametoindex("wlan1") > 0)
4387 ifname = "wlan1";
4388 else
4389 ifname = "wlan0";
4390 } else {
4391 ifname = get_main_ifname();
4392 }
4393 fprintf(f, "hw_mode=a\n");
4394 break;
4395 default:
4396 fclose(f);
4397 return -1;
4398 }
4399
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304400 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004401 fprintf(f, "driver=nl80211\n");
4402
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304403 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
4404 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
4406 fprintf(f, "ieee80211n=1\n");
4407 if (dut->ap_mode == AP_11ng && dut->ap_chwidth == AP_40) {
4408 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
4409 fprintf(f, "ht_capab=[HT40+]\n");
4410 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
4411 fprintf(f, "ht_capab=[HT40-]\n");
4412 }
4413
4414 /* configure ht_capab based on channel width */
4415 if (dut->ap_mode == AP_11na &&
4416 (dut->ap_chwidth == AP_40 ||
4417 (dut->ap_chwidth == AP_AUTO &&
4418 dut->default_ap_chwidth == AP_40))) {
4419 if (is_ht40plus_chan(dut->ap_channel))
4420 fprintf(f, "ht_capab=[HT40+]\n");
4421 else if (is_ht40minus_chan(dut->ap_channel))
4422 fprintf(f, "ht_capab=[HT40-]\n");
4423 }
4424 }
4425
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304426 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
4427 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004428 dut->ap_mode == AP_11ac) {
4429 fprintf(f, "ieee80211ac=1\n"
4430 "ieee80211n=1\n"
4431 "ht_capab=[HT40+]\n");
4432 }
4433
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05304434 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
4435 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004436 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
4437 if (dut->ap_countrycode[0]) {
4438 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
4439 fprintf(f, "ieee80211d=1\n");
4440 fprintf(f, "ieee80211h=1\n");
4441 }
4442 }
4443
4444 fprintf(f, "interface=%s\n", ifname);
4445 if (dut->bridge)
4446 fprintf(f, "bridge=%s\n", dut->bridge);
4447 fprintf(f, "channel=%d\n", dut->ap_channel);
4448
4449 if (sigma_hapd_ctrl)
4450 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
4451 else
4452 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
4453
4454 if (dut->ap_ssid[0])
4455 fprintf(f, "ssid=%s\n", dut->ap_ssid);
4456 else
4457 fprintf(f, "ssid=QCA AP OOB\n");
4458 if (dut->ap_bcnint)
4459 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
4460
4461 switch (dut->ap_key_mgmt) {
4462 case AP_OPEN:
4463 if (dut->ap_cipher == AP_WEP)
4464 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
4465 break;
4466 case AP_WPA2_PSK:
4467 case AP_WPA2_PSK_MIXED:
4468 case AP_WPA_PSK:
4469 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4470 fprintf(f, "wpa=2\n");
4471 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4472 fprintf(f, "wpa=3\n");
4473 else
4474 fprintf(f, "wpa=1\n");
4475 fprintf(f, "wpa_key_mgmt=WPA-PSK\n");
4476 switch (dut->ap_pmf) {
4477 case AP_PMF_DISABLED:
4478 fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n",
4479 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
4480 break;
4481 case AP_PMF_OPTIONAL:
4482 fprintf(f, "wpa_key_mgmt=WPA-PSK%s\n",
4483 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
4484 break;
4485 case AP_PMF_REQUIRED:
4486 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
4487 break;
4488 }
4489 if (dut->ap_cipher == AP_CCMP_TKIP)
4490 fprintf(f, "wpa_pairwise=CCMP TKIP\n");
4491 else if (dut->ap_cipher == AP_TKIP)
4492 fprintf(f, "wpa_pairwise=TKIP\n");
4493 else
4494 fprintf(f, "wpa_pairwise=CCMP\n");
4495 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
4496 break;
4497 case AP_WPA2_EAP:
4498 case AP_WPA2_EAP_MIXED:
4499 case AP_WPA_EAP:
4500 fprintf(f, "ieee8021x=1\n");
4501 if (dut->ap_key_mgmt == AP_WPA2_EAP)
4502 fprintf(f, "wpa=2\n");
4503 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
4504 fprintf(f, "wpa=3\n");
4505 else
4506 fprintf(f, "wpa=1\n");
4507 switch (dut->ap_pmf) {
4508 case AP_PMF_DISABLED:
4509 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
4510 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
4511 break;
4512 case AP_PMF_OPTIONAL:
4513 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
4514 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
4515 break;
4516 case AP_PMF_REQUIRED:
4517 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
4518 break;
4519 }
4520 if (dut->ap_cipher == AP_CCMP_TKIP)
4521 fprintf(f, "wpa_pairwise=CCMP TKIP\n");
4522 else if (dut->ap_cipher == AP_TKIP)
4523 fprintf(f, "wpa_pairwise=TKIP\n");
4524 else
4525 fprintf(f, "wpa_pairwise=CCMP\n");
4526 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
4527 if (dut->ap_radius_port)
4528 fprintf(f, "auth_server_port=%d\n",
4529 dut->ap_radius_port);
4530 fprintf(f, "auth_server_shared_secret=%s\n",
4531 dut->ap_radius_password);
4532 break;
4533 }
4534
4535 switch (dut->ap_pmf) {
4536 case AP_PMF_DISABLED:
4537 break;
4538 case AP_PMF_OPTIONAL:
4539 fprintf(f, "ieee80211w=1\n");
4540 break;
4541 case AP_PMF_REQUIRED:
4542 fprintf(f, "ieee80211w=2\n");
4543 break;
4544 }
4545
4546 if (dut->ap_p2p_mgmt)
4547 fprintf(f, "manage_p2p=1\n");
4548
4549 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
4550 fprintf(f, "tdls_prohibit=1\n");
4551 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
4552 fprintf(f, "tdls_prohibit_chan_switch=1\n");
4553 if (dut->ap_p2p_cross_connect >= 0) {
4554 fprintf(f, "manage_p2p=1\n"
4555 "allow_cross_connection=%d\n",
4556 dut->ap_p2p_cross_connect);
4557 }
4558
4559 if (dut->ap_l2tif || dut->ap_proxy_arp) {
4560 if (!dut->bridge) {
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Bridge must be configured. Run with -b <brname>.");
4563 fclose(f);
4564 return -2;
4565 }
4566 fprintf(f, "ap_isolate=1\n");
4567 }
4568
4569 if (dut->ap_proxy_arp)
4570 fprintf(f, "proxy_arp=1\n");
4571
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05304572 if (dut->ap_wme)
4573 fprintf(f, "wmm_enabled=1\n");
4574
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004575 if (dut->ap_hs2) {
4576 if (dut->ap_bss_load) {
4577 char *bss_load;
4578
4579 switch (dut->ap_bss_load) {
4580 case -1:
4581 bss_load = "bss_load_update_period=10";
4582 break;
4583 case 1:
4584 /* STA count: 1, CU: 50, AAC: 65535 */
4585 bss_load = "bss_load_test=1:50:65535";
4586 break;
4587 case 2:
4588 /* STA count: 1, CU: 200, AAC: 65535 */
4589 bss_load = "bss_load_test=1:200:65535";
4590 break;
4591 case 3:
4592 /* STA count: 1, CU: 75, AAC: 65535 */
4593 bss_load = "bss_load_test=1:75:65535";
4594 break;
4595 default:
4596 bss_load = NULL;
4597 break;
4598 }
4599
4600 if (!bss_load) {
4601 fclose(f);
4602 return -2;
4603 }
4604 fprintf(f, "%s\n", bss_load);
4605 }
4606
4607 if (append_hostapd_conf_hs2(dut, f)) {
4608 fclose(f);
4609 return -2;
4610 }
4611 }
4612
4613 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4614 fclose(f);
4615 return -2;
4616 }
4617
4618 if (dut->ap_hs2 && strlen(dut->ap2_ssid)) {
4619 unsigned char bssid[6];
4620 char ifname2[50];
4621
4622 if (get_hwaddr(ifname, bssid))
4623 return -2;
4624 bssid[0] |= 0x02;
4625
4626 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
4627 fprintf(f, "bss=%s_1\n", ifname2);
4628 fprintf(f, "ssid=%s\n", dut->ap2_ssid);
4629 if (dut->bridge)
4630 fprintf(f, "bridge=%s\n", dut->bridge);
4631 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
4632 bssid[0], bssid[1], bssid[2], bssid[3],
4633 bssid[4], bssid[5]);
4634
4635 if (dut->ap2_key_mgmt == AP2_OSEN) {
4636 fprintf(f, "osen=1\n");
4637 if (strlen(dut->ap2_radius_ipaddr))
4638 fprintf(f, "auth_server_addr=%s\n",
4639 dut->ap2_radius_ipaddr);
4640 if (dut->ap2_radius_port)
4641 fprintf(f, "auth_server_port=%d\n",
4642 dut->ap2_radius_port);
4643 if (strlen(dut->ap2_radius_password))
4644 fprintf(f, "auth_server_shared_secret=%s\n",
4645 dut->ap2_radius_password);
4646 }
4647
4648 if (dut->ap2_proxy_arp) {
4649 if (!dut->bridge) {
4650 sigma_dut_print(dut, DUT_MSG_ERROR,
4651 "Bridge must be configured. Run with -b <brname>.");
4652 fclose(f);
4653 return -2;
4654 }
4655 fprintf(f, "ap_isolate=1\n");
4656 fprintf(f, "proxy_arp=1\n");
4657
4658 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
4659 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
4660 fclose(f);
4661 return -2;
4662 }
4663
4664 }
4665 }
4666
4667 if (dut->program == PROGRAM_WPS) {
4668 fprintf(f, "eap_server=1\n"
4669 "wps_state=1\n"
4670 "device_name=QCA AP\n"
4671 "manufacturer=QCA\n"
4672 "device_type=6-0050F204-1\n"
4673 "config_methods=label virtual_display "
4674 "virtual_push_button keypad%s\n"
4675 "ap_pin=12345670\n"
4676 "friendly_name=QCA Access Point\n"
4677 "upnp_iface=%s\n",
4678 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
4679 dut->bridge ? dut->bridge : ifname);
4680 }
4681
4682 if (dut->program == PROGRAM_VHT) {
4683 int vht_oper_centr_freq_idx;
4684
4685 if (check_channel(dut->ap_channel) < 0) {
4686 send_resp(dut, conn, SIGMA_INVALID,
4687 "errorCode,Invalid channel");
4688 return 0;
4689 }
4690
4691 switch (dut->ap_chwidth) {
4692 case AP_20:
4693 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
4694 vht_oper_centr_freq_idx =
4695 get_oper_centr_freq_seq_idx(20,
4696 dut->ap_channel);
4697 break;
4698 case AP_40:
4699 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
4700 vht_oper_centr_freq_idx =
4701 get_oper_centr_freq_seq_idx(40,
4702 dut->ap_channel);
4703 break;
4704 case AP_80:
4705 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
4706 vht_oper_centr_freq_idx =
4707 get_oper_centr_freq_seq_idx(80,
4708 dut->ap_channel);
4709 break;
4710 case AP_160:
4711 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
4712 vht_oper_centr_freq_idx =
4713 get_oper_centr_freq_seq_idx(160,
4714 dut->ap_channel);
4715 break;
4716 default:
4717 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
4718 vht_oper_centr_freq_idx =
4719 get_oper_centr_freq_seq_idx(80,
4720 dut->ap_channel);
4721 break;
4722 }
4723 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
4724 vht_oper_centr_freq_idx);
4725 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
4726
4727 if (dut->ap_sgi80 || dut->ap_txBF || dut->ap_ldpc ||
4728 dut->ap_tx_stbc) {
4729 fprintf(f, "vht_capab=%s%s%s%s\n",
4730 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
4731 dut->ap_txBF ? "[SU-BEAMFORMER]" : "",
4732 dut->ap_ldpc ? "[RXLDPC]" : "",
4733 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "");
4734 }
4735 }
4736
4737 fclose(f);
4738#ifdef __QNXNTO__
4739 if (system("slay hostapd") == 0)
4740#else /* __QNXNTO__ */
4741 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4742 system("killall hostapd") == 0)
4743#endif /* __QNXNTO__ */
4744 {
4745 int i;
4746 /* Wait some time to allow hostapd to complete cleanup before
4747 * starting a new process */
4748 for (i = 0; i < 10; i++) {
4749 usleep(500000);
4750#ifdef __QNXNTO__
4751 if (system("pidin | grep hostapd") != 0)
4752 break;
4753#else /* __QNXNTO__ */
4754 if (system("pidof hostapd") != 0)
4755 break;
4756#endif /* __QNXNTO__ */
4757 }
4758 }
4759
4760 if (drv == DRIVER_QNXNTO) {
4761 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05304762 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004763 "/sigma_dut-ap.conf",
4764 dut->hostapd_debug_log ? "-ddKt -f " : "",
4765 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004766 dut->hostapd_entropy_log ? " -e" : "",
4767 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
4768 "");
4769 } else {
4770 /*
4771 * It looks like a monitor interface can cause some issues for
4772 * beaconing, so remove it (if injection was used) before
4773 * starting hostapd.
4774 */
4775 if (if_nametoindex("sigmadut") > 0 &&
4776 system("iw dev sigmadut del") != 0)
4777 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
4778 "monitor interface");
4779
4780 snprintf(buf, sizeof(buf), "%shostapd -B%s%s%s%s " SIGMA_TMPDIR
4781 "/sigma_dut-ap.conf",
4782 file_exists("hostapd") ? "./" : "",
4783 dut->hostapd_debug_log ? " -ddKt -f" : "",
4784 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
4785 dut->hostapd_entropy_log ? " -e" : "",
4786 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
4787 "");
4788 }
4789
4790 if (system(buf) != 0) {
4791 send_resp(dut, conn, SIGMA_ERROR,
4792 "errorCode,Failed to start hostapd");
4793 return 0;
4794 }
4795
4796 /* allow some time for hostapd to start before returning success */
4797 usleep(500000);
4798 if (run_hostapd_cli(dut, "ping") != 0) {
4799 send_resp(dut, conn, SIGMA_ERROR,
4800 "errorCode,Failed to talk to hostapd");
4801 return 0;
4802 }
4803
4804 if (dut->ap_l2tif) {
4805 snprintf(path, sizeof(path),
4806 "/sys/class/net/%s/brport/hairpin_mode",
4807 ifname);
4808 if (!file_exists(path)) {
4809 sigma_dut_print(dut, DUT_MSG_ERROR,
4810 "%s must be binded to the bridge for L2TIF",
4811 ifname);
4812 return -2;
4813 }
4814
4815 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
4816 if (system(buf) != 0) {
4817 sigma_dut_print(dut, DUT_MSG_ERROR,
4818 "Failed to enable hairpin_mode for L2TIF");
4819 return -2;
4820 }
4821
4822 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
4823 if (system(buf) != 0) {
4824 sigma_dut_print(dut, DUT_MSG_ERROR,
4825 "Failed to set ebtables rules, RULE-9");
4826 return -2;
4827 }
4828
4829 snprintf(buf, sizeof(buf),
4830 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
4831 ifname);
4832 if (system(buf) != 0) {
4833 sigma_dut_print(dut, DUT_MSG_ERROR,
4834 "Failed to set ebtables rules, RULE-11");
4835 return -2;
4836 }
4837 }
4838
4839 if (dut->ap_proxy_arp) {
4840 if (dut->ap_dgaf_disable) {
4841 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
4842 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
4843 return -2;
4844 } else {
4845 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
4846 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
4847 return -2;
4848 }
4849
4850 /* For 4.5-(c) */
4851 snprintf(buf, sizeof(buf),
4852 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
4853 ifname);
4854 if (system(buf) != 0) {
4855 sigma_dut_print(dut, DUT_MSG_ERROR,
4856 "Failed to set ebtables rules, RULE-10");
4857 return -2;
4858 }
4859 }
4860
4861 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
4862 /* Drop TDLS frames */
4863 snprintf(buf, sizeof(buf),
4864 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
4865 if (system(buf) != 0) {
4866 sigma_dut_print(dut, DUT_MSG_ERROR,
4867 "Failed to set ebtables rules, RULE-13");
4868 return -2;
4869 }
4870 }
4871
4872 if (dut->ap_fake_pkhash &&
4873 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
4874 send_resp(dut, conn, SIGMA_ERROR,
4875 "errorCode,Could not enable FakePubKey");
4876 return 0;
4877 }
4878
4879 return 1;
4880}
4881
4882
4883static void parse_qos_params(struct qos_params *qos, const char *cwmin,
4884 const char *cwmax, const char *aifs,
4885 const char *txop, const char *acm)
4886{
4887 if (cwmin) {
4888 qos->ac = 1;
4889 qos->cwmin = atoi(cwmin);
4890 }
4891
4892 if (cwmax) {
4893 qos->ac = 1;
4894 qos->cwmax = atoi(cwmax);
4895 }
4896
4897 if (aifs) {
4898 qos->ac = 1;
4899 qos->aifs = atoi(aifs);
4900 }
4901
4902 if (txop) {
4903 qos->ac = 1;
4904 qos->txop = atoi(txop) * 32;
4905 }
4906
4907 if (acm) {
4908 qos->ac = 1;
4909 qos->acm = strcasecmp(acm, "on") == 0;
4910 }
4911}
4912
4913
4914static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
4915 struct sigma_cmd *cmd)
4916{
4917 /* TXOP: The values provided here for VHT5G only */
4918 parse_qos_params(&dut->ap_qos[AP_AC_VO], get_param(cmd, "cwmin_VO"),
4919 get_param(cmd, "cwmax_VO"), get_param(cmd, "AIFS_VO"),
4920 get_param(cmd, "TXOP_VO"), get_param(cmd, "ACM_VO"));
4921 parse_qos_params(&dut->ap_qos[AP_AC_VI], get_param(cmd, "cwmin_VI"),
4922 get_param(cmd, "cwmax_VI"), get_param(cmd, "AIFS_VI"),
4923 get_param(cmd, "TXOP_VI"), get_param(cmd, "ACM_VI"));
4924 parse_qos_params(&dut->ap_qos[AP_AC_BE], get_param(cmd, "cwmin_BE"),
4925 get_param(cmd, "cwmax_BE"), get_param(cmd, "AIFS_BE"),
4926 get_param(cmd, "TXOP_BE"), get_param(cmd, "ACM_BE"));
4927 parse_qos_params(&dut->ap_qos[AP_AC_BK], get_param(cmd, "cwmin_BK"),
4928 get_param(cmd, "cwmax_BK"), get_param(cmd, "AIFS_BK"),
4929 get_param(cmd, "TXOP_BK"), get_param(cmd, "ACM_BK"));
4930 return 1;
4931}
4932
4933
4934static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
4935 struct sigma_cmd *cmd)
4936{
4937 parse_qos_params(&dut->ap_sta_qos[AP_AC_VO], get_param(cmd, "cwmin_VO"),
4938 get_param(cmd, "cwmax_VO"), get_param(cmd, "AIFS_VO"),
4939 get_param(cmd, "TXOP_VO"), get_param(cmd, "ACM_VO"));
4940 parse_qos_params(&dut->ap_sta_qos[AP_AC_VI], get_param(cmd, "cwmin_VI"),
4941 get_param(cmd, "cwmax_VI"), get_param(cmd, "AIFS_VI"),
4942 get_param(cmd, "TXOP_VI"), get_param(cmd, "ACM_VI"));
4943 parse_qos_params(&dut->ap_sta_qos[AP_AC_BE], get_param(cmd, "cwmin_BE"),
4944 get_param(cmd, "cwmax_BE"), get_param(cmd, "AIFS_BE"),
4945 get_param(cmd, "TXOP_BE"), get_param(cmd, "ACM_BE"));
4946 parse_qos_params(&dut->ap_sta_qos[AP_AC_BK], get_param(cmd, "cwmin_BK"),
4947 get_param(cmd, "cwmax_BK"), get_param(cmd, "AIFS_BK"),
4948 get_param(cmd, "TXOP_BK"), get_param(cmd, "ACM_BK"));
4949 return 1;
4950}
4951
4952
4953static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
4954{
4955 unsigned char bssid[6];
4956 char buf[100];
4957 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
4958 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
4959 run_system(dut, "cfg -a AP_SECMODE=WPA");
4960 run_system(dut, "cfg -a AP_SECFILE=EAP");
4961 run_system(dut, "cfg -a AP_WPA=2");
4962 run_system(dut, "cfg -a AP_CYPHER=CCMP");
4963 run_system(dut, "cfg -a AP_HOTSPOT=1");
4964 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
4965 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
4966 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
4967 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
4968 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
4969 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
4970 if (!get_hwaddr("ath0", bssid)) {
4971 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
4972 "%02x:%02x:%02x:%02x:%02x:%02x",
4973 bssid[0], bssid[1], bssid[2], bssid[3],
4974 bssid[4], bssid[5]);
4975 run_system(dut, buf);
4976 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4977 "%02x:%02x:%02x:%02x:%02x:%02x",
4978 bssid[0], bssid[1], bssid[2], bssid[3],
4979 bssid[4], bssid[5]);
4980 } else {
4981 if (!get_hwaddr("wifi0", bssid)) {
4982 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
4983 "%02x:%02x:%02x:%02x:%02x:%02x",
4984 bssid[0], bssid[1], bssid[2], bssid[3],
4985 bssid[4], bssid[5]);
4986 run_system(dut, buf);
4987 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4988 "%02x:%02x:%02x:%02x:%02x:%02x",
4989 bssid[0], bssid[1], bssid[2], bssid[3],
4990 bssid[4], bssid[5]);
4991 } else {
4992 /* load the driver and try again */
4993 run_system(dut, "/etc/rc.d/rc.wlan up");
4994
4995 if (!get_hwaddr("wifi0", bssid)) {
4996 snprintf(buf, sizeof(buf),
4997 "cfg -a AP_HOTSPOT_HESSID="
4998 "%02x:%02x:%02x:%02x:%02x:%02x",
4999 bssid[0], bssid[1], bssid[2],
5000 bssid[3], bssid[4], bssid[5]);
5001 run_system(dut, buf);
5002 snprintf(dut->ap_hessid,
5003 sizeof(dut->ap_hessid),
5004 "%02x:%02x:%02x:%02x:%02x:%02x",
5005 bssid[0], bssid[1], bssid[2],
5006 bssid[3], bssid[4], bssid[5]);
5007 }
5008 }
5009 }
5010
5011 run_system(dut, "cfg -r AP_SSID_2");
5012 run_system(dut, "cfg -c");
5013 /* run_system(dut, "cfg -s"); */
5014}
5015
5016
5017static void ath_reset_vht_defaults(struct sigma_dut *dut)
5018{
5019 run_system(dut, "cfg -x");
5020 run_system(dut, "cfg -a AP_RADIO_ID=1");
5021 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
5022 run_system(dut, "cfg -a AP_STARTMODE=standard");
5023 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5024 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5025 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5026 run_system(dut, "cfg -a ATH_countrycode=0x348");
5027 /* NOTE: For Beeliner we have to turn off MU-MIMO */
5028 if (system("rm /tmp/secath*") != 0) {
5029 sigma_dut_print(dut, DUT_MSG_ERROR,
5030 "Failed to remove secath file");
5031 }
5032}
5033
5034
5035static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
5036 struct sigma_cmd *cmd)
5037{
5038 const char *type;
5039
5040 dut->program = sigma_program_to_enum(get_param(cmd, "PROGRAM"));
5041 dut->device_type = AP_unknown;
5042 type = get_param(cmd, "type");
5043 if (type && strcasecmp(type, "Testbed") == 0)
5044 dut->device_type = AP_testbed;
5045 if (type && strcasecmp(type, "DUT") == 0)
5046 dut->device_type = AP_dut;
5047
5048 dut->ap_rts = 0;
5049 dut->ap_frgmnt = 0;
5050 dut->ap_bcnint = 0;
5051 dut->ap_key_mgmt = AP_OPEN;
5052 dut->ap_ssid[0] = '\0';
5053 dut->ap_fake_pkhash = 0;
5054 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
5055 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
5056 dut->ap_addba_reject = 0;
5057 dut->ap_noack = AP_NOACK_NOT_SET;
5058 dut->ap_is_dual = 0;
5059 dut->ap_mode = AP_inval;
5060 dut->ap_mode_1 = AP_inval;
5061
5062 dut->ap_allow_vht_wep = 0;
5063 dut->ap_allow_vht_tkip = 0;
5064 dut->ap_disable_protection = 0;
5065 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
5066 dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_NOT_SET;
5067 dut->ap_ldpc = 0;
5068 dut->ap_sig_rts = 0;
5069 dut->ap_rx_amsdu = 0;
5070 dut->ap_txBF = 0;
5071 dut->ap_chwidth = AP_AUTO;
5072
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05305073 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005074 dut->ap_wpsnfc = 0;
5075 dut->ap_bss_load = -1;
5076 dut->ap_p2p_cross_connect = -1;
5077
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05305078 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
5079 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
5080
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05305081 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT)
5082 dut->ap_wme = AP_WME_ON;
5083 else
5084 dut->ap_wme = AP_WME_OFF;
5085
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005086 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5087 int i;
5088 enum driver_type drv;
5089
5090 drv = get_driver_type();
5091 if (drv == DRIVER_ATHEROS)
5092 cmd_ath_ap_hs2_reset(dut);
5093 else if (drv == DRIVER_OPENWRT)
5094 cmd_owrt_ap_hs2_reset(dut);
5095
5096 dut->ap_interworking = 1;
5097 dut->ap_access_net_type = 2;
5098 dut->ap_internet = 0;
5099 dut->ap_venue_group = 2;
5100 dut->ap_venue_type = 8;
5101 dut->ap_domain_name_list[0] = '\0';
5102 dut->ap_hs2 = 1;
5103 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
5104 "506f9a;001bc504bd");
5105 dut->ap_l2tif = 0;
5106 dut->ap_proxy_arp = 0;
5107 if (dut->bridge) {
5108 char buf[50];
5109
5110 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
5111 dut->bridge);
5112 if (system(buf) != 0) {
5113 sigma_dut_print(dut, DUT_MSG_DEBUG,
5114 "%s ip neigh table flushing failed",
5115 dut->bridge);
5116 }
5117
5118 snprintf(buf, sizeof(buf), "ebtables -F");
5119 if (system(buf) != 0) {
5120 sigma_dut_print(dut, DUT_MSG_DEBUG,
5121 "%s ebtables flushing failed",
5122 dut->bridge);
5123 }
5124 }
5125 dut->ap_dgaf_disable = 0;
5126 dut->ap_p2p_cross_connect = 0;
5127 dut->ap_gas_cb_delay = 0;
5128 dut->ap_nai_realm_list = 0;
5129 dut->ap_oper_name = 0;
5130 dut->ap_venue_name = 0;
5131 for (i = 0; i < 10; i++) {
5132 dut->ap_plmn_mcc[i][0] = '\0';
5133 dut->ap_plmn_mnc[i][0] = '\0';
5134 }
5135 dut->ap_wan_metrics = 0;
5136 dut->ap_conn_capab = 0;
5137 dut->ap_ip_addr_type_avail = 0;
5138 dut->ap_net_auth_type = 0;
5139 dut->ap_oper_class = 0;
5140 dut->ap_pmf = 0;
5141 dut->ap_add_sha256 = 0;
5142 }
5143
5144 if (dut->program == PROGRAM_HS2_R2) {
5145 int i;
5146 const char hessid[] = "50:6f:9a:00:11:22";
5147
5148 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
5149 dut->ap_osu_ssid[0] = '\0';
5150 dut->ap2_ssid[0] = '\0';
5151 dut->ap_pmf = 1;
5152 dut->ap_osu_provider_list = 0;
5153 for (i = 0; i < 10; i++) {
5154 dut->ap_osu_server_uri[i][0] = '\0';
5155 dut->ap_osu_method[i] = 0xFF;
5156 }
5157 dut->ap_qos_map_set = 0;
5158 dut->ap2_key_mgmt = AP2_OPEN;
5159 dut->ap2_proxy_arp = 0;
5160 dut->ap_osu_icon_tag = 0;
5161 }
5162
5163 if (dut->program == PROGRAM_VHT) {
5164 /* Set up the defaults */
5165 dut->ap_mode = AP_11ac;
5166 dut->ap_channel = 36;
5167 dut->ap_ampdu = 0;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005168 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005169 if (dut->device_type == AP_testbed) {
5170 dut->ap_amsdu = 2;
5171 dut->ap_ldpc = 2;
5172 dut->ap_rx_amsdu = 2;
5173 dut->ap_sgi80 = 0;
5174 } else {
5175 dut->ap_amsdu = 1;
5176 dut->ap_ldpc = 1;
5177 dut->ap_rx_amsdu = 1;
5178 dut->ap_sgi80 = 1;
5179 }
5180 dut->ap_fixed_rate = 0;
5181 dut->ap_rx_streams = 3;
5182 dut->ap_tx_streams = 3;
5183 dut->ap_vhtmcs_map = 0;
5184 dut->ap_chwidth = AP_80;
5185 dut->ap_tx_stbc = 1;
5186 dut->ap_dyn_bw_sig = AP_DYN_BW_SGNL_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05305187 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
5188 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005189 if (get_driver_type() == DRIVER_ATHEROS)
5190 ath_reset_vht_defaults(dut);
5191 }
5192
5193 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
5194 system("killall hostapd") == 0) {
5195 int i;
5196 /* Wait some time to allow hostapd to complete cleanup before
5197 * starting a new process */
5198 for (i = 0; i < 10; i++) {
5199 usleep(500000);
5200 if (system("pidof hostapd") != 0)
5201 break;
5202 }
5203 }
5204
5205 if (if_nametoindex("sigmadut") > 0 &&
5206 system("iw dev sigmadut del") != 0)
5207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
5208 "monitor interface");
5209
5210 return 1;
5211}
5212
5213
5214static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
5215 struct sigma_cmd *cmd)
5216{
5217 /* const char *name = get_param(cmd, "NAME"); */
5218 struct stat s;
5219 char resp[200];
5220 FILE *f;
5221 enum driver_type drv = get_driver_type();
5222
5223 switch (drv) {
5224 case DRIVER_ATHEROS: {
5225 /* Atheros AP */
5226 struct utsname uts;
5227 char *version, athver[100];
5228
5229 if (stat("/proc/athversion", &s) != 0) {
5230 if (system("/etc/rc.d/rc.wlan up") != 0) {
5231 }
5232 }
5233
5234 athver[0] = '\0';
5235 f = fopen("/proc/athversion", "r");
5236 if (f) {
5237 if (fgets(athver, sizeof(athver), f)) {
5238 char *pos = strchr(athver, '\n');
5239 if (pos)
5240 *pos = '\0';
5241 }
5242 fclose(f);
5243 }
5244
5245 if (uname(&uts) == 0)
5246 version = uts.release;
5247 else
5248 version = "Unknown";
5249
5250 if (if_nametoindex("ath1") > 0)
5251 snprintf(resp, sizeof(resp), "interface,ath0_24G "
5252 "ath1_5G,agent,1.0,version,%s/drv:%s",
5253 version, athver);
5254 else
5255 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
5256 "agent,1.0,version,%s/drv:%s",
5257 version, athver);
5258
5259 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5260 return 0;
5261 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305262 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 case DRIVER_MAC80211: {
5264 struct utsname uts;
5265 char *version;
5266
5267 if (uname(&uts) == 0)
5268 version = uts.release;
5269 else
5270 version = "Unknown";
5271
5272 if (if_nametoindex("wlan1") > 0)
5273 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
5274 "wlan1_5G,agent,1.0,version,%s", version);
5275 else
5276 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
5277 "agent,1.0,version,%s", version);
5278
5279 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5280 return 0;
5281 }
5282 case DRIVER_QNXNTO: {
5283 struct utsname uts;
5284 char *version;
5285
5286 if (uname(&uts) == 0)
5287 version = uts.release;
5288 else
5289 version = "Unknown";
5290 snprintf(resp, sizeof(resp),
5291 "interface,%s_any,agent,1.0,version,%s",
5292 sigma_main_ifname ? sigma_main_ifname : "NA",
5293 version);
5294 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5295 return 0;
5296 }
5297 case DRIVER_OPENWRT: {
5298 switch (get_openwrt_driver_type()) {
5299 case OPENWRT_DRIVER_ATHEROS: {
5300 struct utsname uts;
5301 char *version;
5302
5303 if (uname(&uts) == 0)
5304 version = uts.release;
5305 else
5306 version = "Unknown";
5307
5308 if (if_nametoindex("ath1") > 0)
5309 snprintf(resp, sizeof(resp),
5310 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
5311 version);
5312 else
5313 snprintf(resp, sizeof(resp),
5314 "interface,ath0_any,agent,1.0,version,%s",
5315 version);
5316
5317 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5318 return 0;
5319 }
5320 default:
5321 send_resp(dut, conn, SIGMA_ERROR,
5322 "errorCode,Unsupported openwrt driver");
5323 return 0;
5324 }
5325 }
5326 default:
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "errorCode,Unsupported driver");
5329 return 0;
5330 }
5331}
5332
5333
5334static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5335 struct sigma_cmd *cmd)
5336{
5337 /* const char *name = get_param(cmd, "NAME"); */
5338 /* const char *ifname = get_param(cmd, "INTERFACE"); */
5339 const char *val;
5340 char buf[100];
5341
5342 val = get_param(cmd, "MinorCode");
5343 if (val) {
5344 /* TODO: add support for P2P minor code */
5345 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
5346 "yet supported");
5347 return 0;
5348 }
5349
5350 val = get_param(cmd, "STA_MAC_ADDRESS");
5351 if (val == NULL)
5352 return -1;
5353 snprintf(buf, sizeof(buf), "deauth %s", val);
5354 if (run_hostapd_cli(dut, buf) != 0)
5355 return -2;
5356
5357 return 1;
5358}
5359
5360
5361#ifdef __linux__
5362int inject_frame(int s, const void *data, size_t len, int encrypt);
5363int open_monitor(const char *ifname);
5364int hwaddr_aton(const char *txt, unsigned char *addr);
5365#endif /* __linux__ */
5366
5367enum send_frame_type {
5368 DISASSOC, DEAUTH, SAQUERY
5369};
5370enum send_frame_protection {
5371 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
5372};
5373
5374
5375static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
5376 enum send_frame_type frame,
5377 enum send_frame_protection protected,
5378 const char *sta_addr)
5379{
5380#ifdef __linux__
5381 unsigned char buf[1000], *pos;
5382 int s, res;
5383 unsigned char addr_sta[6], addr_own[6];
5384 char *ifname;
5385 char cbuf[100];
5386 struct ifreq ifr;
5387
5388 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
5389 dut->ap_mode == AP_11ac) &&
5390 if_nametoindex("wlan1") > 0)
5391 ifname = "wlan1";
5392 else
5393 ifname = "wlan0";
5394
5395 if (hwaddr_aton(sta_addr, addr_sta) < 0)
5396 return -1;
5397
5398 s = socket(AF_INET, SOCK_DGRAM, 0);
5399 if (s < 0)
5400 return -1;
5401 memset(&ifr, 0, sizeof(ifr));
5402 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
5403 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
5404 perror("ioctl");
5405 close(s);
5406 return -1;
5407 }
5408 close(s);
5409 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
5410
5411 if (if_nametoindex("sigmadut") == 0) {
5412 snprintf(cbuf, sizeof(cbuf),
5413 "iw dev %s interface add sigmadut type monitor",
5414 ifname);
5415 if (system(cbuf) != 0 ||
5416 if_nametoindex("sigmadut") == 0) {
5417 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
5418 "monitor interface with '%s'", cbuf);
5419 return -2;
5420 }
5421 }
5422
5423 if (system("ifconfig sigmadut up") != 0) {
5424 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5425 "monitor interface up");
5426 return -2;
5427 }
5428
5429 pos = buf;
5430
5431 /* Frame Control */
5432 switch (frame) {
5433 case DISASSOC:
5434 *pos++ = 0xa0;
5435 break;
5436 case DEAUTH:
5437 *pos++ = 0xc0;
5438 break;
5439 case SAQUERY:
5440 *pos++ = 0xd0;
5441 break;
5442 }
5443
5444 if (protected == INCORRECT_KEY)
5445 *pos++ = 0x40; /* Set Protected field to 1 */
5446 else
5447 *pos++ = 0x00;
5448
5449 /* Duration */
5450 *pos++ = 0x00;
5451 *pos++ = 0x00;
5452
5453 /* addr1 = DA (station) */
5454 memcpy(pos, addr_sta, 6);
5455 pos += 6;
5456 /* addr2 = SA (own address) */
5457 memcpy(pos, addr_own, 6);
5458 pos += 6;
5459 /* addr3 = BSSID (own address) */
5460 memcpy(pos, addr_own, 6);
5461 pos += 6;
5462
5463 /* Seq# (to be filled by driver/mac80211) */
5464 *pos++ = 0x00;
5465 *pos++ = 0x00;
5466
5467 if (protected == INCORRECT_KEY) {
5468 /* CCMP parameters */
5469 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
5470 pos += 8;
5471 }
5472
5473 if (protected == INCORRECT_KEY) {
5474 switch (frame) {
5475 case DEAUTH:
5476 /* Reason code (encrypted) */
5477 memcpy(pos, "\xa7\x39", 2);
5478 pos += 2;
5479 break;
5480 case DISASSOC:
5481 /* Reason code (encrypted) */
5482 memcpy(pos, "\xa7\x39", 2);
5483 pos += 2;
5484 break;
5485 case SAQUERY:
5486 /* Category|Action|TransID (encrypted) */
5487 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
5488 pos += 4;
5489 break;
5490 default:
5491 return -1;
5492 }
5493
5494 /* CCMP MIC */
5495 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
5496 pos += 8;
5497 } else {
5498 switch (frame) {
5499 case DEAUTH:
5500 /* reason code = 8 */
5501 *pos++ = 0x08;
5502 *pos++ = 0x00;
5503 break;
5504 case DISASSOC:
5505 /* reason code = 8 */
5506 *pos++ = 0x08;
5507 *pos++ = 0x00;
5508 break;
5509 case SAQUERY:
5510 /* Category - SA Query */
5511 *pos++ = 0x08;
5512 /* SA query Action - Request */
5513 *pos++ = 0x00;
5514 /* Transaction ID */
5515 *pos++ = 0x12;
5516 *pos++ = 0x34;
5517 break;
5518 }
5519 }
5520
5521 s = open_monitor("sigmadut");
5522 if (s < 0) {
5523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
5524 "monitor socket");
5525 return 0;
5526 }
5527
5528 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
5529 if (res < 0) {
5530 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5531 "inject frame");
5532 return 0;
5533 }
5534 if (res < pos - buf) {
5535 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
5536 "frame sent");
5537 return 0;
5538 }
5539
5540 close(s);
5541
5542 return 1;
5543#else /* __linux__ */
5544 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
5545 "yet supported");
5546 return 0;
5547#endif /* __linux__ */
5548}
5549
5550
5551int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
5552 struct sigma_cmd *cmd)
5553{
5554 const char *val, *dest;
5555 char buf[100];
5556
5557 val = get_param(cmd, "FrameName");
5558 if (val == NULL)
5559 return -1;
5560
5561 if (strcasecmp(val, "QoSMapConfigure") == 0) {
5562 dest = get_param(cmd, "Dest");
5563 if (!dest)
5564 return -1;
5565
5566 val = get_param(cmd, "QoS_MAP_SET");
5567 if (val) {
5568 dut->ap_qos_map_set = atoi(val);
5569 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
5570 dut->ap_qos_map_set);
5571 }
5572
5573 if (dut->ap_qos_map_set == 1)
5574 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
5575 else if (dut->ap_qos_map_set == 2)
5576 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
5577
5578 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
5579 if (run_hostapd_cli(dut, buf) != 0)
5580 return -1;
5581 }
5582
5583 return 1;
5584}
5585
5586
5587static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
5588 struct sigma_cmd *cmd)
5589{
5590 const char *val;
5591 char *ifname;
5592 char buf[100];
5593 int chwidth, nss;
5594
5595 val = get_param(cmd, "FrameName");
5596 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
5597 send_resp(dut, conn, SIGMA_ERROR,
5598 "errorCode,Unsupported FrameName");
5599 return 0;
5600 }
5601
5602 /*
5603 * Sequence of commands for Opmode notification on
5604 * Peregrine based products
5605 */
5606 ifname = get_main_ifname();
5607
5608 /* Disable STBC */
5609 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
5610 if (system(buf) != 0) {
5611 sigma_dut_print(dut, DUT_MSG_ERROR,
5612 "iwpriv tx_stbc 0 failed!");
5613 }
5614
5615 /* Check whether optional arg channel width was passed */
5616 val = get_param(cmd, "Channel_width");
5617 if (val) {
5618 switch (atoi(val)) {
5619 case 20:
5620 chwidth = 0;
5621 break;
5622 case 40:
5623 chwidth = 1;
5624 break;
5625 case 80:
5626 chwidth = 2;
5627 break;
5628 case 160:
5629 chwidth = 3;
5630 break;
5631 default:
5632 chwidth = 2;
5633 break;
5634 }
5635 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5636 ifname, chwidth);
5637 if (system(buf) != 0) {
5638 sigma_dut_print(dut, DUT_MSG_ERROR,
5639 "iwpriv chwidth failed!");
5640 }
5641 }
5642
5643 /* Check whether optional arg NSS was passed */
5644 val = get_param(cmd, "NSS");
5645 if (val) {
5646 /* Convert nss to chainmask */
5647 switch (atoi(val)) {
5648 case 1:
5649 nss = 1;
5650 break;
5651 case 2:
5652 nss = 3;
5653 break;
5654 case 3:
5655 nss = 7;
5656 break;
5657 default:
5658 /* We do not support NSS > 3 */
5659 nss = 3;
5660 break;
5661 }
5662 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
5663 ifname, nss);
5664 if (system(buf) != 0) {
5665 sigma_dut_print(dut, DUT_MSG_ERROR,
5666 "iwpriv rxchainmask failed!");
5667 }
5668 }
5669
5670 /* Send the opmode notification */
5671 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
5672 if (system(buf) != 0) {
5673 sigma_dut_print(dut, DUT_MSG_ERROR,
5674 "iwpriv opmode_notify failed!");
5675 }
5676
5677 return 1;
5678}
5679
5680
5681static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
5682 struct sigma_cmd *cmd)
5683{
5684 switch (get_driver_type()) {
5685 case DRIVER_ATHEROS:
5686 return ath_ap_send_frame_vht(dut, conn, cmd);
5687 break;
5688 case DRIVER_OPENWRT:
5689 switch (get_openwrt_driver_type()) {
5690 case OPENWRT_DRIVER_ATHEROS:
5691 return ath_ap_send_frame_vht(dut, conn, cmd);
5692 default:
5693 send_resp(dut, conn, SIGMA_ERROR,
5694 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
5695 return 0;
5696 }
5697 default:
5698 send_resp(dut, conn, SIGMA_ERROR,
5699 "errorCode,Unsupported ap_send_frame with the current driver");
5700 return 0;
5701 }
5702}
5703
5704
5705int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
5706 struct sigma_cmd *cmd)
5707{
5708 /* const char *name = get_param(cmd, "NAME"); */
5709 /* const char *ifname = get_param(cmd, "INTERFACE"); */
5710 const char *val;
5711 enum send_frame_type frame;
5712 enum send_frame_protection protected;
5713 char buf[100];
5714
5715 val = get_param(cmd, "Program");
5716 if (val) {
5717 if (strcasecmp(val, "HS2") == 0 ||
5718 strcasecmp(val, "HS2-R2") == 0)
5719 return ap_send_frame_hs2(dut, conn, cmd);
5720 if (strcasecmp(val, "VHT") == 0)
5721 return ap_send_frame_vht(dut, conn, cmd);
5722 }
5723
5724 val = get_param(cmd, "PMFFrameType");
5725 if (val == NULL)
5726 val = get_param(cmd, "FrameName");
5727 if (val == NULL)
5728 val = get_param(cmd, "Type");
5729 if (val == NULL)
5730 return -1;
5731 if (strcasecmp(val, "disassoc") == 0)
5732 frame = DISASSOC;
5733 else if (strcasecmp(val, "deauth") == 0)
5734 frame = DEAUTH;
5735 else if (strcasecmp(val, "saquery") == 0)
5736 frame = SAQUERY;
5737 else {
5738 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
5739 "PMFFrameType");
5740 return 0;
5741 }
5742
5743 val = get_param(cmd, "PMFProtected");
5744 if (val == NULL)
5745 val = get_param(cmd, "Protected");
5746 if (val == NULL)
5747 return -1;
5748 if (strcasecmp(val, "Correct-key") == 0 ||
5749 strcasecmp(val, "CorrectKey") == 0)
5750 protected = CORRECT_KEY;
5751 else if (strcasecmp(val, "IncorrectKey") == 0)
5752 protected = INCORRECT_KEY;
5753 else if (strcasecmp(val, "Unprotected") == 0)
5754 protected = UNPROTECTED;
5755 else {
5756 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
5757 "PMFProtected");
5758 return 0;
5759 }
5760
5761 val = get_param(cmd, "stationID");
5762 if (val == NULL)
5763 return -1;
5764
5765 if (protected == INCORRECT_KEY ||
5766 (protected == UNPROTECTED && frame == SAQUERY))
5767 return ap_inject_frame(dut, conn, frame, protected, val);
5768
5769 switch (frame) {
5770 case DISASSOC:
5771 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
5772 val, protected == CORRECT_KEY);
5773 break;
5774 case DEAUTH:
5775 snprintf(buf, sizeof(buf), "deauth %s test=%d",
5776 val, protected == CORRECT_KEY);
5777 break;
5778 case SAQUERY:
5779 snprintf(buf, sizeof(buf), "sa_query %s", val);
5780 break;
5781 }
5782
5783 if (run_hostapd_cli(dut, buf) != 0)
5784 return -2;
5785
5786 return 1;
5787}
5788
5789
5790static int cmd_ap_get_mac_address(struct sigma_dut *dut,
5791 struct sigma_conn *conn,
5792 struct sigma_cmd *cmd)
5793{
5794#if defined( __linux__)
5795 /* const char *name = get_param(cmd, "NAME"); */
5796 /* const char *ifname = get_param(cmd, "INTERFACE"); */
5797 char resp[50];
5798 unsigned char addr[6];
5799 char *ifname;
5800 struct ifreq ifr;
5801 int s;
5802 enum driver_type drv;
5803
5804 drv = get_driver_type();
5805
5806 if (drv == DRIVER_ATHEROS) {
5807 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
5808 dut->ap_mode == AP_11ac) &&
5809 if_nametoindex("ath1") > 0)
5810 ifname = "ath1";
5811 else
5812 ifname = "ath0";
5813 } else if (drv == DRIVER_OPENWRT) {
5814 if (sigma_radio_ifname[0] &&
5815 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
5816 ifname = "ath2";
5817 else if (sigma_radio_ifname[0] &&
5818 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
5819 ifname = "ath1";
5820 else
5821 ifname = "ath0";
5822 } else {
5823 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
5824 dut->ap_mode == AP_11ac) &&
5825 if_nametoindex("wlan1") > 0)
5826 ifname = "wlan1";
5827 else
5828 ifname = "wlan0";
5829 }
5830
5831 s = socket(AF_INET, SOCK_DGRAM, 0);
5832 if (s < 0)
5833 return -1;
5834 memset(&ifr, 0, sizeof(ifr));
5835 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
5836 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
5837 perror("ioctl");
5838 close(s);
5839 return -1;
5840 }
5841 close(s);
5842 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
5843
5844 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
5845 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
5846 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5847 return 0;
5848#elif defined( __QNXNTO__)
5849 char resp[50];
5850 unsigned char addr[6];
5851
5852 if (!sigma_main_ifname) {
5853 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
5854 return 0;
5855 }
5856
5857 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
5858 send_resp(dut, conn, SIGMA_ERROR,
5859 "errorCode,Failed to get address");
5860 return 0;
5861 }
5862 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
5863 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
5864 send_resp(dut, conn, SIGMA_COMPLETE, resp);
5865 return 0;
5866#else /* __linux__ */
5867 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
5868 "yet supported");
5869 return 0;
5870#endif /* __linux__ */
5871}
5872
5873
5874static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
5875 struct sigma_cmd *cmd)
5876{
5877 /*
5878 * Ignore the command since the parameters are already handled through
5879 * ap_set_security.
5880 */
5881
5882 return 1;
5883}
5884
5885
5886static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
5887 struct sigma_cmd *cmd)
5888{
5889 /* const char *name = get_param(cmd, "NAME"); */
5890 /* const char *ifname = get_param(cmd, "INTERFACE"); */
5891 const char *val, *dest;
5892 char *pos, buf[100];
5893 int i, wlan_tag = 1;
5894
5895 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
5896 "following parameters");
5897 for (i = 0; i < cmd->count; i++) {
5898 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
5899 (cmd->values[i] ? cmd->values[i] : "NULL"));
5900 }
5901
5902 val = get_param(cmd, "ICMPv4_ECHO");
5903 if (val && atoi(val)) {
5904 snprintf(buf, sizeof(buf), "ebtables -F");
5905 if (system(buf) != 0) {
5906 sigma_dut_print(dut, DUT_MSG_ERROR,
5907 "Failed to set ebtables rules, RULE-12");
5908 }
5909 return 1;
5910 }
5911
5912 val = get_param(cmd, "WLAN_TAG");
5913 if (val) {
5914 wlan_tag = atoi(val);
5915 if (wlan_tag != 1 && wlan_tag != 2) {
5916 send_resp(dut, conn, SIGMA_INVALID,
5917 "errorCode,Invalid WLAN_TAG");
5918 return 0;
5919 }
5920 }
5921
5922 if (wlan_tag == 2) {
5923 val = get_param(cmd, "PROXY_ARP");
5924 if (val)
5925 dut->ap2_proxy_arp = atoi(val);
5926 return 1;
5927 }
5928
5929 dest = get_param(cmd, "STA_MAC");
5930 if (dest) {
5931 /* This is a special/ugly way of using this command.
5932 * If "Dest" MAC is included, assume that this command
5933 * is being issued after ap_config_commit for dynamically
5934 * setting the QoS Map Set.
5935 */
5936 val = get_param(cmd, "QoS_MAP_SET");
5937 if (val) {
5938 dut->ap_qos_map_set = atoi(val);
5939 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
5940 dut->ap_qos_map_set);
5941 }
5942
5943 if (dut->ap_qos_map_set == 1)
5944 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
5945 else if (dut->ap_qos_map_set == 2)
5946 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
5947
5948 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
5949 if (run_hostapd_cli(dut, buf) != 0)
5950 return -1;
5951 }
5952
5953 val = get_param(cmd, "DGAF_DISABLE");
5954 if (val)
5955 dut->ap_dgaf_disable = atoi(val);
5956
5957 dut->ap_interworking = 1;
5958
5959 val = get_param(cmd, "INTERWORKING");
5960 if (val == NULL)
5961 val = get_param(cmd, "INTERNETWORKING");
5962 if (val != NULL && atoi(val) == 0) {
5963 dut->ap_interworking = 0;
5964 dut->ap_hs2 = 0;
5965 return 1;
5966 }
5967
5968 val = get_param(cmd, "ACCS_NET_TYPE");
5969 if (val) {
5970 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
5971 strcasecmp(val, "Chargable_Public_Network") == 0 ||
5972 strcasecmp(val, "Chargable Public Network") == 0)
5973 dut->ap_access_net_type = 2;
5974 else
5975 dut->ap_access_net_type = atoi(val);
5976 }
5977
5978 val = get_param(cmd, "INTERNET");
5979 if (val)
5980 dut->ap_internet = atoi(val);
5981
5982 val = get_param(cmd, "VENUE_GRP");
5983 if (val) {
5984 if (strcasecmp(val, "Business") == 0)
5985 dut->ap_venue_group = 2;
5986 else
5987 dut->ap_venue_group = atoi(val);
5988 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
5989 dut->ap_venue_name);
5990 }
5991
5992 val = get_param(cmd, "VENUE_TYPE");
5993 if (val) {
5994 if (strcasecmp(val, "R&D") == 0)
5995 dut->ap_venue_type = 8;
5996 else
5997 dut->ap_venue_type = atoi(val);
5998 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
5999 dut->ap_venue_type);
6000 }
6001
6002 val = get_param(cmd, "HESSID");
6003 if (val) {
6004 if (strlen(val) >= sizeof(dut->ap_hessid)) {
6005 send_resp(dut, conn, SIGMA_ERROR,
6006 "errorCode,Invalid HESSID");
6007 return 0;
6008 }
6009 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
6010 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
6011 dut->ap_hessid);
6012 }
6013
6014 val = get_param(cmd, "ROAMING_CONS");
6015 if (val) {
6016 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
6017 send_resp(dut, conn, SIGMA_ERROR,
6018 "errorCode,Invalid ROAMING_CONS");
6019 return 0;
6020 }
6021 if (strcasecmp(val, "Disabled") == 0) {
6022 dut->ap_roaming_cons[0] = '\0';
6023 } else {
6024 snprintf(dut->ap_roaming_cons,
6025 sizeof(dut->ap_roaming_cons), "%s", val);
6026 }
6027 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
6028 dut->ap_roaming_cons);
6029 }
6030
6031 val = get_param(cmd, "ANQP");
6032 if (val)
6033 dut->ap_anqpserver_on = atoi(val);
6034
6035 val = get_param(cmd, "NAI_REALM_LIST");
6036 if (val) {
6037 dut->ap_nai_realm_list = atoi(val);
6038 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
6039 dut->ap_nai_realm_list);
6040 }
6041
6042 val = get_param(cmd, "3GPP_INFO");
6043 if (val) {
6044 /* What kind of encoding format is used?! */
6045 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
6046 "not yet supported (contents not fully defined)");
6047 return 0;
6048 }
6049
6050 val = get_param(cmd, "DOMAIN_LIST");
6051 if (val) {
6052 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
6053 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
6054 "DOMAIN_LIST");
6055 return 0;
6056 }
6057 snprintf(dut->ap_domain_name_list,
6058 sizeof(dut->ap_domain_name_list), "%s", val);
6059 pos = dut->ap_domain_name_list;
6060 while (*pos) {
6061 if (*pos == ';')
6062 *pos = ',';
6063 pos++;
6064 }
6065 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
6066 dut->ap_domain_name_list);
6067 }
6068
6069 val = get_param(cmd, "OPER_NAME");
6070 if (val) {
6071 dut->ap_oper_name = atoi(val);
6072 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
6073 dut->ap_oper_name);
6074 }
6075
6076 val = get_param(cmd, "VENUE_NAME");
6077 if (val) {
6078 dut->ap_venue_name = atoi(val);
6079 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
6080 dut->ap_venue_name);
6081 }
6082
6083 val = get_param(cmd, "GAS_CB_DELAY");
6084 if (val) {
6085 dut->ap_gas_cb_delay = atoi(val);
6086 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
6087 dut->ap_gas_cb_delay);
6088 }
6089
6090 val = get_param(cmd, "MIH");
6091 if (val && atoi(val) > 0) {
6092 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
6093 "supported");
6094 return 0;
6095 }
6096
6097 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
6098 if (val) {
6099 dut->ap_l2tif = atoi(val);
6100 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
6101 dut->ap_l2tif);
6102 }
6103
6104 val = get_param(cmd, "BCST_UNCST");
6105 if (val) {
6106 send_resp(dut, conn, SIGMA_ERROR,
6107 "errorCode,BCST_UNCST not yet supported");
6108 return 0;
6109 }
6110
6111 val = get_param(cmd, "PLMN_MCC");
6112 if (val) {
6113 char mcc[100], *start, *end;
6114 int i = 0;
6115 if (strlen(val) >= sizeof(mcc)) {
6116 send_resp(dut, conn, SIGMA_ERROR,
6117 "errorCode,PLMN_MCC too long");
6118 return 0;
6119 }
6120 strncpy(mcc, val, sizeof(mcc));
6121 start = mcc;
6122 while ((end = strchr(start, ';'))) {
6123 /* process all except the last */
6124 *end = '\0';
6125 if (strlen(start) != 3) {
6126 send_resp(dut, conn, SIGMA_ERROR,
6127 "errorCode,Invalid PLMN_MCC");
6128 return 0;
6129 }
6130 snprintf(dut->ap_plmn_mcc[i],
6131 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
6132 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
6133 dut->ap_plmn_mcc[i]);
6134 i++;
6135 start = end + 1;
6136 *end = ';';
6137 }
6138 if (strlen(start) != 3) {
6139 send_resp(dut, conn, SIGMA_ERROR,
6140 "errorCode,Invalid PLMN_MCC");
6141 return 0;
6142 }
6143 /* process last or only one */
6144 snprintf(dut->ap_plmn_mcc[i],
6145 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
6146 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
6147 dut->ap_plmn_mcc[i]);
6148 }
6149
6150 val = get_param(cmd, "PLMN_MNC");
6151 if (val) {
6152 char mnc[100], *start, *end;
6153 int i = 0;
6154 if (strlen(val) >= sizeof(mnc)) {
6155 send_resp(dut, conn, SIGMA_ERROR,
6156 "errorCode,PLMN_MNC too long");
6157 return 0;
6158 }
6159 strncpy(mnc, val, sizeof(mnc));
6160 start = mnc;
6161 while ((end = strchr(start, ';'))) {
6162 *end = '\0';
6163 if (strlen(start) != 2 && strlen(start) != 3) {
6164 send_resp(dut, conn, SIGMA_ERROR,
6165 "errorCode,Invalid PLMN_MNC");
6166 return 0;
6167 }
6168 snprintf(dut->ap_plmn_mnc[i],
6169 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
6170 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
6171 dut->ap_plmn_mnc[i]);
6172 i++;
6173 start = end + 1;
6174 *end = ';';
6175 }
6176 if (strlen(start) != 2 && strlen(start) != 3) {
6177 send_resp(dut, conn, SIGMA_ERROR,
6178 "errorCode,Invalid PLMN_MNC");
6179 return 0;
6180 }
6181 snprintf(dut->ap_plmn_mnc[i],
6182 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
6183 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
6184 dut->ap_plmn_mnc[i]);
6185 }
6186
6187 val = get_param(cmd, "PROXY_ARP");
6188 if (val) {
6189 dut->ap_proxy_arp = atoi(val);
6190 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
6191 dut->ap_proxy_arp);
6192 }
6193
6194 val = get_param(cmd, "WAN_METRICS");
6195 if (val) {
6196 dut->ap_wan_metrics = atoi(val);
6197 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
6198 dut->ap_wan_metrics);
6199 }
6200
6201 val = get_param(cmd, "CONN_CAP");
6202 if (val) {
6203 dut->ap_conn_capab = atoi(val);
6204 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
6205 dut->ap_conn_capab);
6206 }
6207
6208 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
6209 if (val) {
6210 dut->ap_ip_addr_type_avail = atoi(val);
6211 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
6212 dut->ap_ip_addr_type_avail);
6213 }
6214
6215 val = get_param(cmd, "NET_AUTH_TYPE");
6216 if (val) {
6217 dut->ap_net_auth_type = atoi(val);
6218 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
6219 dut->ap_net_auth_type);
6220 }
6221
6222 val = get_param(cmd, "OP_CLASS");
6223 if (val == NULL)
6224 val = get_param(cmd, "OPER_CLASS");
6225 if (val) {
6226 dut->ap_oper_class = atoi(val);
6227 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
6228 dut->ap_oper_class);
6229 }
6230
6231 val = get_param(cmd, "OSU_PROVIDER_LIST");
6232 if (val) {
6233 dut->ap_osu_provider_list = atoi(val);
6234 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
6235 dut->ap_osu_provider_list);
6236 }
6237
6238 val = get_param(cmd, "OSU_SERVER_URI");
6239 if (val) {
6240 i = 0;
6241 do {
6242 int len;
6243 const char *uri = val;
6244 val = strchr(val, ' ');
6245 len = val ? (val++ - uri) : (int) strlen(uri);
6246 if (len > 0 && len < 256) {
6247 memcpy(dut->ap_osu_server_uri[i], uri, len);
6248 dut->ap_osu_server_uri[i][len] = '\0';
6249 sigma_dut_print(dut, DUT_MSG_INFO,
6250 "ap_osu_server_uri[%d] %s", i,
6251 dut->ap_osu_server_uri[i]);
6252 }
6253 } while (val && ++i < 10);
6254 }
6255
6256 val = get_param(cmd, "OSU_METHOD");
6257 if (val) {
6258 i = 0;
6259 do {
6260 int len;
6261 const char *method = val;
6262 val = strchr(val, ' ');
6263 len = val ? (val++ - method) : (int) strlen(method);
6264 if (len > 0) {
6265 if (strncasecmp(method, "SOAP", len) == 0)
6266 dut->ap_osu_method[i] = 1;
6267 else if (strncasecmp(method, "OMADM", len) == 0)
6268 dut->ap_osu_method[i] = 0;
6269 else
6270 return -2;
6271 }
6272 } while (val && ++i < 10);
6273 }
6274
6275 val = get_param(cmd, "OSU_SSID");
6276 if (val) {
6277 if (strlen(val) > 0 && strlen(val) <= 32) {
6278 strncpy(dut->ap_osu_ssid, val,
6279 sizeof(dut->ap_osu_ssid));
6280 sigma_dut_print(dut, DUT_MSG_INFO,
6281 "ap_osu_ssid %s",
6282 dut->ap_osu_ssid);
6283 }
6284 }
6285
6286 val = get_param(cmd, "OSU_ICON_TAG");
6287 if (val)
6288 dut->ap_osu_icon_tag = atoi(val);
6289
6290 val = get_param(cmd, "QoS_MAP_SET");
6291 if (val) {
6292 dut->ap_qos_map_set = atoi(val);
6293 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
6294 dut->ap_qos_map_set);
6295 }
6296
6297 val = get_param(cmd, "BSS_LOAD");
6298 if (val) {
6299 dut->ap_bss_load = atoi(val);
6300 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
6301 dut->ap_bss_load);
6302 }
6303
6304 return 1;
6305}
6306
6307
6308void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
6309{
6310 char buf[100];
6311
6312 if (!file_exists("nfc-status"))
6313 return;
6314
6315 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
6316 run_system(dut, buf);
6317}
6318
6319
6320static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
6321 const char *info)
6322{
6323 int res;
6324
6325 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
6326 printf("%s\n\n", info);
6327
6328 nfc_status(dut, "START", info);
6329 res = run_system(dut, cmd);
6330 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
6331 if (res) {
6332 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
6333 cmd, res);
6334 return res;
6335 }
6336
6337 return 0;
6338}
6339
6340
6341static int ap_nfc_write_config_token(struct sigma_dut *dut,
6342 struct sigma_conn *conn,
6343 struct sigma_cmd *cmd)
6344{
6345 int res;
6346 char buf[300];
6347
6348 run_system(dut, "killall wps-ap-nfc.py");
6349 unlink("nfc-success");
6350 snprintf(buf, sizeof(buf),
6351 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
6352 dut->summary_log ? "--summary " : "",
6353 dut->summary_log ? dut->summary_log : "");
6354 res = run_nfc_command(dut, buf,
6355 "Touch NFC Tag to write WPS configuration token");
6356 if (res || !file_exists("nfc-success")) {
6357 send_resp(dut, conn, SIGMA_ERROR,
6358 "ErrorCode,Failed to write tag");
6359 return 0;
6360 }
6361
6362 return 1;
6363}
6364
6365
6366static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
6367 struct sigma_conn *conn,
6368 struct sigma_cmd *cmd)
6369{
6370 int res;
6371 char buf[300];
6372
6373 run_system(dut, "killall wps-ap-nfc.py");
6374
6375 unlink("nfc-success");
6376 snprintf(buf, sizeof(buf),
6377 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
6378 dut->summary_log ? "--summary " : "",
6379 dut->summary_log ? dut->summary_log : "");
6380 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
6381 if (res || !file_exists("nfc-success")) {
6382 send_resp(dut, conn, SIGMA_ERROR,
6383 "ErrorCode,Failed to read tag");
6384 return 0;
6385 }
6386
6387 return 1;
6388}
6389
6390
6391static int ap_nfc_write_password_token(struct sigma_dut *dut,
6392 struct sigma_conn *conn,
6393 struct sigma_cmd *cmd)
6394{
6395 int res;
6396 char buf[300];
6397
6398 run_system(dut, "killall wps-ap-nfc.py");
6399 unlink("nfc-success");
6400 snprintf(buf, sizeof(buf),
6401 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
6402 dut->summary_log ? "--summary " : "",
6403 dut->summary_log ? dut->summary_log : "");
6404 res = run_nfc_command(dut, buf,
6405 "Touch NFC Tag to write WPS password token");
6406 if (res || !file_exists("nfc-success")) {
6407 send_resp(dut, conn, SIGMA_ERROR,
6408 "ErrorCode,Failed to write tag");
6409 return 0;
6410 }
6411
6412 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
6413 send_resp(dut, conn, SIGMA_ERROR,
6414 "ErrorCode,Failed to enable NFC password token");
6415 return 0;
6416 }
6417
6418 return 1;
6419}
6420
6421
6422static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
6423 struct sigma_conn *conn,
6424 struct sigma_cmd *cmd)
6425{
6426 int res;
6427 char buf[300];
6428
6429 run_system(dut, "killall wps-ap-nfc.py");
6430 unlink("nfc-success");
6431 snprintf(buf, sizeof(buf),
6432 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
6433 dut->summary_log ? "--summary " : "",
6434 dut->summary_log ? dut->summary_log : "");
6435 res = run_nfc_command(dut, buf,
6436 "Touch NFC Device to respond to WPS connection handover");
6437 if (res) {
6438 send_resp(dut, conn, SIGMA_ERROR,
6439 "ErrorCode,Failed to enable NFC for connection "
6440 "handover");
6441 return 0;
6442 }
6443 if (!file_exists("nfc-success")) {
6444 send_resp(dut, conn, SIGMA_ERROR,
6445 "ErrorCode,Failed to complete NFC connection handover");
6446 return 0;
6447 }
6448
6449 return 1;
6450}
6451
6452
6453static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
6454 struct sigma_cmd *cmd)
6455{
6456 /* const char *name = get_param(cmd, "Name"); */
6457 /* const char *intf = get_param(cmd, "Interface"); */
6458 const char *oper = get_param(cmd, "Operation");
6459
6460 if (oper == NULL)
6461 return -1;
6462
6463 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
6464 return ap_nfc_write_config_token(dut, conn, cmd);
6465 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
6466 return ap_nfc_write_password_token(dut, conn, cmd);
6467 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
6468 return ap_nfc_wps_read_passwd(dut, conn, cmd);
6469 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
6470 return ap_nfc_wps_connection_handover(dut, conn, cmd);
6471
6472 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
6473 return 0;
6474}
6475
6476
6477static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
6478 struct sigma_cmd *cmd)
6479{
6480 char *pin = "12345670"; /* TODO: use random PIN */
6481 char resp[100];
6482
6483 snprintf(resp, sizeof(resp), "PIN,%s", pin);
6484 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6485
6486 return 0;
6487}
6488
6489
6490static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
6491 const char *val)
6492{
6493 char *token, *result;
6494 int nss = 0, chwidth = 0;
6495 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306496 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006497
6498 /*
6499 * The following commands should be invoked to generate
6500 * VHT op mode notification
6501 */
6502
6503 /* Extract the NSS info */
6504 token = strdup(val);
6505 if (!token)
6506 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306507 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006508 if (result) {
6509 int count = atoi(result);
6510
6511 /* We do not support NSS > 3 */
6512 if (count < 0 || count > 3) {
6513 free(token);
6514 return -1;
6515 }
6516
6517 /* Convert nss to chainmask */
6518 while (count--)
6519 nss = (nss << 1) | 1;
6520
6521 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6522 ifname, nss);
6523 if (system(buf) != 0) {
6524 sigma_dut_print(dut, DUT_MSG_ERROR,
6525 "iwpriv wifi1 rxchainmask failed!");
6526 }
6527 }
6528
6529 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306530 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006531 if (result) {
6532 switch (atoi(result)) {
6533 case 20:
6534 chwidth = 0;
6535 break;
6536 case 40:
6537 chwidth = 1;
6538 break;
6539 case 80:
6540 chwidth = 2;
6541 break;
6542 case 160:
6543 chwidth = 3;
6544 break;
6545 default:
6546 chwidth = 2;
6547 break;
6548 }
6549 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6550 ifname, chwidth);
6551 if (system(buf) != 0) {
6552 sigma_dut_print(dut, DUT_MSG_ERROR,
6553 "iwpriv chwidth failed!");
6554 }
6555 }
6556
6557 /* Send the opmode notification */
6558 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
6559 if (system(buf) != 0) {
6560 sigma_dut_print(dut, DUT_MSG_ERROR,
6561 "iwpriv opmode_notify failed!");
6562 }
6563 free(token);
6564
6565 return 0;
6566}
6567
6568
6569static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
6570 const char *val)
6571{
6572 /* String (nss_operating_mode; mcs_operating_mode) */
6573 int nss, mcs;
6574 char *token, *result;
6575 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306576 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006577
6578 token = strdup(val);
6579 if (!token)
6580 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306581 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006582 if (strcasecmp(result, "def") != 0) {
6583 nss = atoi(result);
6584
6585 if (nss == 4)
6586 ath_disable_txbf(dut, ifname);
6587
6588 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
6589 if (system(buf) != 0) {
6590 sigma_dut_print(dut, DUT_MSG_ERROR,
6591 "iwpriv nss failed");
6592 }
6593 } else {
6594 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
6595 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
6596 if (system(buf) != 0) {
6597 sigma_dut_print(dut, DUT_MSG_ERROR,
6598 "iwpriv nss failed");
6599 }
6600 }
6601 }
6602
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306603 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006604 if (strcasecmp(result, "def") == 0) {
6605 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
6606 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
6607 ifname);
6608 if (system(buf) != 0) {
6609 sigma_dut_print(dut, DUT_MSG_ERROR,
6610 "iwpriv vhtmcs failed");
6611 }
6612 } else {
6613 snprintf(buf, sizeof(buf),
6614 "iwpriv %s set11NRates 0", ifname);
6615 if (system(buf) != 0) {
6616 sigma_dut_print(dut, DUT_MSG_ERROR,
6617 "iwpriv set11NRates failed");
6618 }
6619 }
6620 } else {
6621 mcs = atoi(result);
6622 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
6623 if (system(buf) != 0) {
6624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "iwpriv vhtmcs failed");
6626 }
6627 }
6628
6629 free(token);
6630 return 0;
6631}
6632
6633
6634static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
6635 const char *val)
6636{
6637 char *token, *result;
6638 int channel = 36;
6639 int chwidth = 80;
6640 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306641 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642
6643 /* Extract the channel info */
6644 token = strdup(val);
6645 if (!token)
6646 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306647 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006648 if (result)
6649 channel = atoi(result);
6650
6651 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306652 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006653 if (result)
6654 chwidth = atoi(result);
6655
6656 /* Issue the channel switch command */
6657 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
6658 ifname, channel, chwidth);
6659 if (system(buf) != 0) {
6660 sigma_dut_print(dut, DUT_MSG_ERROR,
6661 "iwpriv doth_ch_chwidth failed!");
6662 }
6663
6664 free(token);
6665 return 0;
6666}
6667
6668
6669static int parse_hex(char c)
6670{
6671 if (c >= '0' && c <= '9')
6672 return c - '0';
6673 if (c >= 'a' && c <= 'f')
6674 return c - 'a' + 10;
6675 if (c >= 'A' && c <= 'F')
6676 return c - 'A' + 10;
6677 return -1;
6678}
6679
6680
6681static int hex_byte(const char *str)
6682{
6683 int res1, res2;
6684
6685 res1 = parse_hex(str[0]);
6686 if (res1 < 0)
6687 return -1;
6688 res2 = parse_hex(str[1]);
6689 if (res2 < 0)
6690 return -1;
6691 return (res1 << 4) | res2;
6692}
6693
6694
6695static int parse_mac_address(struct sigma_dut *dut, const char *arg,
6696 unsigned char *addr)
6697{
6698 int i;
6699 const char *pos = arg;
6700
6701 if (strlen(arg) != 17)
6702 goto fail;
6703
6704 for (i = 0; i < ETH_ALEN; i++) {
6705 int val;
6706
6707 val = hex_byte(pos);
6708 if (val < 0)
6709 goto fail;
6710 addr[i] = val;
6711 if (i + 1 < ETH_ALEN) {
6712 pos += 2;
6713 if (*pos != ':')
6714 goto fail;
6715 pos++;
6716 }
6717 }
6718
6719 return 0;
6720
6721fail:
6722 sigma_dut_print(dut, DUT_MSG_ERROR,
6723 "Invalid MAC address %s (expected format xx:xx:xx:xx:xx:xx)",
6724 arg);
6725 return -1;
6726}
6727
6728
6729static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
6730 const char *val)
6731{
6732 char buf[80];
6733 unsigned char mac_addr[6];
6734
6735 if (parse_mac_address(dut, val, mac_addr) < 0)
6736 return -1;
6737
6738 snprintf(buf, sizeof(buf),
6739 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
6740 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
6741 run_system(dut, buf);
6742
6743 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
6744 ifname, mac_addr[4], mac_addr[5]);
6745 run_system(dut, buf);
6746
6747 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
6748 run_system(dut, buf);
6749
6750 return 0;
6751}
6752
6753
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006754void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08006755{
6756 char buf[60];
6757
6758 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
6759 if (system(buf) != 0) {
6760 sigma_dut_print(dut, DUT_MSG_ERROR,
6761 "disabling novap reset failed");
6762 }
6763}
6764
6765
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006766static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
6767 struct sigma_cmd *cmd)
6768{
6769 const char *val;
6770 char *ifname;
6771
6772 ifname = get_main_ifname();
6773
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08006774 /* Disable vap reset between the commands */
6775 novap_reset(dut, ifname);
6776
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006777 val = get_param(cmd, "Opt_md_notif_ie");
6778 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
6779 return -1;
6780
6781 /* TODO: Optional arguments */
6782
6783 val = get_param(cmd, "nss_mcs_opt");
6784 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
6785 return -1;
6786
6787 val = get_param(cmd, "chnum_band");
6788 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
6789 return -1;
6790
6791 val = get_param(cmd, "RTS_FORCE");
6792 if (val)
6793 ath_config_rts_force(dut, ifname, val);
6794
6795 val = get_param(cmd, "DYN_BW_SGNL");
6796 if (val)
6797 ath_config_dyn_bw_sig(dut, ifname, val);
6798
6799 val = get_param(cmd, "CTS_WIDTH");
6800 if (val)
6801 ath_set_cts_width(dut, ifname, val);
6802
6803 val = get_param(cmd, "Ndpa_stainfo_mac");
6804 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
6805 return -1;
6806
6807 val = get_param(cmd, "txBandwidth");
6808 if (val && ath_set_width(dut, conn, ifname, val) < 0)
6809 return -1;
6810
6811 return 1;
6812}
6813
6814
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05306815static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
6816 const char *val)
6817{
6818 char *token, *result;
6819 int channel = 36;
6820 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306821 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05306822
6823 /* Extract the channel info */
6824 token = strdup(val);
6825 if (!token)
6826 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306827 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05306828 if (result)
6829 channel = atoi(result);
6830
6831 /* Issue the channel switch command */
6832 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
6833 ifname, channel);
6834 if (system(buf) != 0) {
6835 sigma_dut_print(dut, DUT_MSG_ERROR,
6836 "iwpriv setChanChange failed!");
6837 }
6838
6839 free(token);
6840 return 0;
6841}
6842
6843
6844static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
6845 struct sigma_cmd *cmd)
6846{
6847 const char *val;
6848 char *ifname;
6849
6850 ifname = get_main_ifname();
6851
6852 val = get_param(cmd, "chnum_band");
6853 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
6854 return -1;
6855
6856 return 1;
6857}
6858
6859
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006860static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
6861 struct sigma_cmd *cmd)
6862{
6863 /* const char *name = get_param(cmd, "NAME"); */
6864 /* const char *type = get_param(cmd, "Type"); */
6865
6866 switch (get_driver_type()) {
6867 case DRIVER_ATHEROS:
6868 return ath_ap_set_rfeature(dut, conn, cmd);
6869 case DRIVER_OPENWRT:
6870 switch (get_openwrt_driver_type()) {
6871 case OPENWRT_DRIVER_ATHEROS:
6872 return ath_ap_set_rfeature(dut, conn, cmd);
6873 default:
6874 send_resp(dut, conn, SIGMA_ERROR,
6875 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
6876 return 0;
6877 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +05306878 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05306879 case DRIVER_WCN:
6880 return wcn_ap_set_rfeature(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006881 default:
6882 send_resp(dut, conn, SIGMA_ERROR,
6883 "errorCode,Unsupported ap_set_rfeature with the current driver");
6884 return 0;
6885 }
6886}
6887
6888
6889static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
6890 struct sigma_cmd *cmd)
6891{
6892 /* const char *name = get_param(cmd, "NAME"); */
6893 return 1;
6894}
6895
6896
6897void ap_register_cmds(void)
6898{
6899 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
6900 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
6901 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
6902 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
6903 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
6904 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05306905 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006906 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
6907 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
6908 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
6909 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
6910 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
6911 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
6912 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
6913 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
6914 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
6915 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
6916 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
6917 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
6918 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
6919 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
6920 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
6921 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
6922 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
6923}