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