2 * hostapd / Configuration file
3 * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
17 #ifndef CONFIG_NATIVE_WINDOWS
19 #endif /* CONFIG_NATIVE_WINDOWS */
24 #include "eap_server/eap.h"
25 #include "radius/radius_client.h"
26 #include "wpa_common.h"
31 #define MAX_STA_COUNT 2007
33 extern struct wpa_driver_ops
*hostapd_drivers
[];
36 static int hostapd_config_read_vlan_file(struct hostapd_bss_config
*bss
,
40 char buf
[128], *pos
, *pos2
;
41 int line
= 0, vlan_id
;
42 struct hostapd_vlan
*vlan
;
44 f
= fopen(fname
, "r");
46 printf("VLAN file '%s' not readable.\n", fname
);
50 while (fgets(buf
, sizeof(buf
), f
)) {
56 while (*pos
!= '\0') {
67 vlan_id
= VLAN_ID_WILDCARD
;
70 vlan_id
= strtol(buf
, &pos
, 10);
71 if (buf
== pos
|| vlan_id
< 1 ||
72 vlan_id
> MAX_VLAN_ID
) {
73 printf("Invalid VLAN ID at line %d in '%s'\n",
80 while (*pos
== ' ' || *pos
== '\t')
83 while (*pos2
!= ' ' && *pos2
!= '\t' && *pos2
!= '\0')
86 if (*pos
== '\0' || os_strlen(pos
) > IFNAMSIZ
) {
87 printf("Invalid VLAN ifname at line %d in '%s'\n",
93 vlan
= os_malloc(sizeof(*vlan
));
95 printf("Out of memory while reading VLAN interfaces "
96 "from '%s'\n", fname
);
101 os_memset(vlan
, 0, sizeof(*vlan
));
102 vlan
->vlan_id
= vlan_id
;
103 os_strlcpy(vlan
->ifname
, pos
, sizeof(vlan
->ifname
));
105 bss
->vlan_tail
->next
= vlan
;
108 bss
->vlan_tail
= vlan
;
117 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
119 struct hostapd_vlan
*vlan
, *prev
;
133 /* convert floats with one decimal place to value*10 int, i.e.,
134 * "1.5" will return 15 */
135 static int hostapd_config_read_int10(const char *value
)
141 pos
= os_strchr(value
, '.');
145 if (*pos
>= '0' && *pos
<= '9')
153 static void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
155 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
156 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
157 bss
->logger_syslog
= (unsigned int) -1;
158 bss
->logger_stdout
= (unsigned int) -1;
160 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
162 bss
->wep_rekeying_period
= 300;
163 /* use key0 in individual key and key1 in broadcast key */
164 bss
->broadcast_key_idx_min
= 1;
165 bss
->broadcast_key_idx_max
= 2;
166 bss
->eap_reauth_period
= 3600;
168 bss
->wpa_group_rekey
= 600;
169 bss
->wpa_gmk_rekey
= 86400;
170 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
171 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
172 bss
->wpa_group
= WPA_CIPHER_TKIP
;
173 bss
->rsn_pairwise
= 0;
175 bss
->max_num_sta
= MAX_STA_COUNT
;
177 bss
->dtim_period
= 2;
179 bss
->radius_server_auth_port
= 1812;
180 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
181 bss
->eapol_version
= EAPOL_VERSION
;
183 bss
->max_listen_interval
= 65535;
185 #ifdef CONFIG_IEEE80211W
186 bss
->assoc_ping_timeout
= 1000;
187 bss
->assoc_ping_attempts
= 3;
188 #endif /* CONFIG_IEEE80211W */
192 static struct hostapd_config
* hostapd_config_defaults(void)
194 struct hostapd_config
*conf
;
195 struct hostapd_bss_config
*bss
;
197 const int aCWmin
= 15, aCWmax
= 1024;
198 const struct hostapd_wme_ac_params ac_bk
=
199 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
200 const struct hostapd_wme_ac_params ac_be
=
201 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
202 const struct hostapd_wme_ac_params ac_vi
= /* video traffic */
203 { aCWmin
>> 1, aCWmin
, 2, 3000 / 32, 1 };
204 const struct hostapd_wme_ac_params ac_vo
= /* voice traffic */
205 { aCWmin
>> 2, aCWmin
>> 1, 2, 1500 / 32, 1 };
207 conf
= os_zalloc(sizeof(*conf
));
208 bss
= os_zalloc(sizeof(*bss
));
209 if (conf
== NULL
|| bss
== NULL
) {
210 printf("Failed to allocate memory for configuration data.\n");
216 /* set default driver based on configuration */
217 conf
->driver
= hostapd_drivers
[0];
218 if (conf
->driver
== NULL
) {
219 printf("No driver wrappers registered!\n");
225 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
226 if (bss
->radius
== NULL
) {
232 hostapd_config_defaults_bss(bss
);
237 conf
->beacon_int
= 100;
238 conf
->rts_threshold
= -1; /* use driver default: 2347 */
239 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
240 conf
->send_probe_response
= 1;
241 conf
->bridge_packets
= INTERNAL_BRIDGE_DO_NOT_CONTROL
;
243 os_memcpy(conf
->country
, "US ", 3);
245 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
246 conf
->tx_queue
[i
].aifs
= -1; /* use hw default */
248 conf
->wme_ac_params
[0] = ac_be
;
249 conf
->wme_ac_params
[1] = ac_bk
;
250 conf
->wme_ac_params
[2] = ac_vi
;
251 conf
->wme_ac_params
[3] = ac_vo
;
253 #ifdef CONFIG_IEEE80211N
254 SET_2BIT_LE16(&conf
->ht_capab
,
255 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET
,
256 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS
);
258 conf
->ht_capab
|= HT_CAP_INFO_GREEN_FIELD
;
259 #endif /* CONFIG_IEEE80211N */
265 int hostapd_mac_comp(const void *a
, const void *b
)
267 return os_memcmp(a
, b
, sizeof(macaddr
));
271 int hostapd_mac_comp_empty(const void *a
)
273 macaddr empty
= { 0 };
274 return os_memcmp(a
, empty
, sizeof(macaddr
));
278 static int hostapd_acl_comp(const void *a
, const void *b
)
280 const struct mac_acl_entry
*aa
= a
;
281 const struct mac_acl_entry
*bb
= b
;
282 return os_memcmp(aa
->addr
, bb
->addr
, sizeof(macaddr
));
286 static int hostapd_config_read_maclist(const char *fname
,
287 struct mac_acl_entry
**acl
, int *num
)
293 struct mac_acl_entry
*newacl
;
299 f
= fopen(fname
, "r");
301 printf("MAC list file '%s' not found.\n", fname
);
305 while (fgets(buf
, sizeof(buf
), f
)) {
311 while (*pos
!= '\0') {
321 if (hwaddr_aton(buf
, addr
)) {
322 printf("Invalid MAC address '%s' at line %d in '%s'\n",
330 while (*pos
!= '\0' && *pos
!= ' ' && *pos
!= '\t')
332 while (*pos
== ' ' || *pos
== '\t')
337 newacl
= os_realloc(*acl
, (*num
+ 1) * sizeof(**acl
));
338 if (newacl
== NULL
) {
339 printf("MAC list reallocation failed\n");
345 os_memcpy((*acl
)[*num
].addr
, addr
, ETH_ALEN
);
346 (*acl
)[*num
].vlan_id
= vlan_id
;
352 qsort(*acl
, *num
, sizeof(**acl
), hostapd_acl_comp
);
358 static int hostapd_config_read_wpa_psk(const char *fname
,
359 struct hostapd_ssid
*ssid
)
363 int line
= 0, ret
= 0, len
, ok
;
365 struct hostapd_wpa_psk
*psk
;
370 f
= fopen(fname
, "r");
372 printf("WPA PSK file '%s' not found.\n", fname
);
376 while (fgets(buf
, sizeof(buf
), f
)) {
382 while (*pos
!= '\0') {
392 if (hwaddr_aton(buf
, addr
)) {
393 printf("Invalid MAC address '%s' on line %d in '%s'\n",
399 psk
= os_zalloc(sizeof(*psk
));
401 printf("WPA PSK allocation failed\n");
405 if (is_zero_ether_addr(addr
))
408 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
412 printf("No PSK on line %d in '%s'\n", line
, fname
);
420 len
= os_strlen(pos
);
421 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
423 else if (len
>= 8 && len
< 64) {
424 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
425 4096, psk
->psk
, PMK_LEN
);
429 printf("Invalid PSK '%s' on line %d in '%s'\n",
436 psk
->next
= ssid
->wpa_psk
;
446 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
448 struct hostapd_ssid
*ssid
= &conf
->ssid
;
450 if (ssid
->wpa_passphrase
!= NULL
) {
451 if (ssid
->wpa_psk
!= NULL
) {
452 printf("Warning: both WPA PSK and passphrase set. "
453 "Using passphrase.\n");
454 os_free(ssid
->wpa_psk
);
456 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
457 if (ssid
->wpa_psk
== NULL
) {
458 printf("Unable to alloc space for PSK\n");
461 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
462 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
463 wpa_hexdump_ascii(MSG_DEBUG
, "PSK (ASCII passphrase)",
464 (u8
*) ssid
->wpa_passphrase
,
465 os_strlen(ssid
->wpa_passphrase
));
466 pbkdf2_sha1(ssid
->wpa_passphrase
,
467 ssid
->ssid
, ssid
->ssid_len
,
468 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
469 wpa_hexdump(MSG_DEBUG
, "PSK (from passphrase)",
470 ssid
->wpa_psk
->psk
, PMK_LEN
);
471 ssid
->wpa_psk
->group
= 1;
473 os_memset(ssid
->wpa_passphrase
, 0,
474 os_strlen(ssid
->wpa_passphrase
));
475 os_free(ssid
->wpa_passphrase
);
476 ssid
->wpa_passphrase
= NULL
;
479 if (ssid
->wpa_psk_file
) {
480 if (hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
,
490 static int hostapd_config_read_eap_user(const char *fname
,
491 struct hostapd_bss_config
*conf
)
494 char buf
[512], *pos
, *start
, *pos2
;
495 int line
= 0, ret
= 0, num_methods
;
496 struct hostapd_eap_user
*user
, *tail
= NULL
;
501 f
= fopen(fname
, "r");
503 printf("EAP user file '%s' not found.\n", fname
);
507 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
508 while (fgets(buf
, sizeof(buf
), f
)) {
514 while (*pos
!= '\0') {
526 if (buf
[0] != '"' && buf
[0] != '*') {
527 printf("Invalid EAP identity (no \" in start) on "
528 "line %d in '%s'\n", line
, fname
);
532 user
= os_zalloc(sizeof(*user
));
534 printf("EAP user allocation failed\n");
537 user
->force_version
= -1;
544 while (*pos
!= '"' && *pos
!= '\0')
547 printf("Invalid EAP identity (no \" in end) on"
548 " line %d in '%s'\n", line
, fname
);
552 user
->identity
= os_malloc(pos
- start
);
553 if (user
->identity
== NULL
) {
554 printf("Failed to allocate memory for EAP "
558 os_memcpy(user
->identity
, start
, pos
- start
);
559 user
->identity_len
= pos
- start
;
561 if (pos
[0] == '"' && pos
[1] == '*') {
562 user
->wildcard_prefix
= 1;
567 while (*pos
== ' ' || *pos
== '\t')
571 printf("No EAP method on line %d in '%s'\n",
577 while (*pos
!= ' ' && *pos
!= '\t' && *pos
!= '\0')
587 char *pos3
= os_strchr(start
, ',');
591 user
->methods
[num_methods
].method
=
594 &user
->methods
[num_methods
].vendor
);
595 if (user
->methods
[num_methods
].vendor
==
597 user
->methods
[num_methods
].method
== EAP_TYPE_NONE
)
599 if (os_strcmp(start
, "TTLS-PAP") == 0) {
600 user
->ttls_auth
|= EAP_TTLS_AUTH_PAP
;
603 if (os_strcmp(start
, "TTLS-CHAP") == 0) {
604 user
->ttls_auth
|= EAP_TTLS_AUTH_CHAP
;
607 if (os_strcmp(start
, "TTLS-MSCHAP") == 0) {
609 EAP_TTLS_AUTH_MSCHAP
;
612 if (os_strcmp(start
, "TTLS-MSCHAPV2") == 0) {
614 EAP_TTLS_AUTH_MSCHAPV2
;
617 printf("Unsupported EAP type '%s' on line %d "
618 "in '%s'\n", start
, line
, fname
);
623 if (num_methods
>= EAP_USER_MAX_METHODS
)
630 if (num_methods
== 0 && user
->ttls_auth
== 0) {
631 printf("No EAP types configured on line %d in '%s'\n",
639 while (*pos
== ' ' || *pos
== '\t')
644 if (os_strncmp(pos
, "[ver=0]", 7) == 0) {
645 user
->force_version
= 0;
649 if (os_strncmp(pos
, "[ver=1]", 7) == 0) {
650 user
->force_version
= 1;
654 if (os_strncmp(pos
, "[2]", 3) == 0) {
662 while (*pos
!= '"' && *pos
!= '\0')
665 printf("Invalid EAP password (no \" in end) "
666 "on line %d in '%s'\n", line
, fname
);
670 user
->password
= os_malloc(pos
- start
);
671 if (user
->password
== NULL
) {
672 printf("Failed to allocate memory for EAP "
676 os_memcpy(user
->password
, start
, pos
- start
);
677 user
->password_len
= pos
- start
;
680 } else if (os_strncmp(pos
, "hash:", 5) == 0) {
683 while (*pos2
!= '\0' && *pos2
!= ' ' &&
684 *pos2
!= '\t' && *pos2
!= '#')
686 if (pos2
- pos
!= 32) {
687 printf("Invalid password hash on line %d in "
688 "'%s'\n", line
, fname
);
691 user
->password
= os_malloc(16);
692 if (user
->password
== NULL
) {
693 printf("Failed to allocate memory for EAP "
697 if (hexstr2bin(pos
, user
->password
, 16) < 0) {
698 printf("Invalid hash password on line %d in "
699 "'%s'\n", line
, fname
);
702 user
->password_len
= 16;
703 user
->password_hash
= 1;
707 while (*pos2
!= '\0' && *pos2
!= ' ' &&
708 *pos2
!= '\t' && *pos2
!= '#')
710 if ((pos2
- pos
) & 1) {
711 printf("Invalid hex password on line %d in "
712 "'%s'\n", line
, fname
);
715 user
->password
= os_malloc((pos2
- pos
) / 2);
716 if (user
->password
== NULL
) {
717 printf("Failed to allocate memory for EAP "
721 if (hexstr2bin(pos
, user
->password
,
722 (pos2
- pos
) / 2) < 0) {
723 printf("Invalid hex password on line %d in "
724 "'%s'\n", line
, fname
);
727 user
->password_len
= (pos2
- pos
) / 2;
731 while (*pos
== ' ' || *pos
== '\t')
733 if (os_strncmp(pos
, "[2]", 3) == 0) {
739 tail
= conf
->eap_user
= user
;
748 os_free(user
->password
);
749 os_free(user
->identity
);
760 #endif /* EAP_SERVER */
764 hostapd_config_read_radius_addr(struct hostapd_radius_server
**server
,
765 int *num_server
, const char *val
, int def_port
,
766 struct hostapd_radius_server
**curr_serv
)
768 struct hostapd_radius_server
*nserv
;
770 static int server_index
= 1;
772 nserv
= os_realloc(*server
, (*num_server
+ 1) * sizeof(*nserv
));
777 nserv
= &nserv
[*num_server
];
779 (*curr_serv
) = nserv
;
781 os_memset(nserv
, 0, sizeof(*nserv
));
782 nserv
->port
= def_port
;
783 ret
= hostapd_parse_ip_addr(val
, &nserv
->addr
);
784 nserv
->index
= server_index
++;
790 static int hostapd_config_parse_key_mgmt(int line
, const char *value
)
793 char *start
, *end
, *buf
;
795 buf
= os_strdup(value
);
800 while (start
!= '\0') {
801 while (*start
== ' ' || *start
== '\t')
806 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
810 if (os_strcmp(start
, "WPA-PSK") == 0)
811 val
|= WPA_KEY_MGMT_PSK
;
812 else if (os_strcmp(start
, "WPA-EAP") == 0)
813 val
|= WPA_KEY_MGMT_IEEE8021X
;
814 #ifdef CONFIG_IEEE80211R
815 else if (os_strcmp(start
, "FT-PSK") == 0)
816 val
|= WPA_KEY_MGMT_FT_PSK
;
817 else if (os_strcmp(start
, "FT-EAP") == 0)
818 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
819 #endif /* CONFIG_IEEE80211R */
821 printf("Line %d: invalid key_mgmt '%s'\n",
834 printf("Line %d: no key_mgmt values configured.\n", line
);
842 static int hostapd_config_parse_cipher(int line
, const char *value
)
845 char *start
, *end
, *buf
;
847 buf
= os_strdup(value
);
852 while (start
!= '\0') {
853 while (*start
== ' ' || *start
== '\t')
858 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
862 if (os_strcmp(start
, "CCMP") == 0)
863 val
|= WPA_CIPHER_CCMP
;
864 else if (os_strcmp(start
, "TKIP") == 0)
865 val
|= WPA_CIPHER_TKIP
;
866 else if (os_strcmp(start
, "WEP104") == 0)
867 val
|= WPA_CIPHER_WEP104
;
868 else if (os_strcmp(start
, "WEP40") == 0)
869 val
|= WPA_CIPHER_WEP40
;
870 else if (os_strcmp(start
, "NONE") == 0)
871 val
|= WPA_CIPHER_NONE
;
873 printf("Line %d: invalid cipher '%s'.", line
, start
);
885 printf("Line %d: no cipher values configured.", line
);
892 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
893 struct hostapd_config
*conf
)
895 if (bss
->ieee802_1x
&& !bss
->eap_server
&&
896 !bss
->radius
->auth_servers
) {
897 printf("Invalid IEEE 802.1X configuration (no EAP "
898 "authenticator configured).\n");
902 if (bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
903 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
904 bss
->ssid
.wpa_psk_file
== NULL
) {
905 printf("WPA-PSK enabled, but PSK or passphrase is not "
910 if (hostapd_mac_comp_empty(bss
->bssid
) != 0) {
913 for (i
= 0; i
< conf
->num_bss
; i
++) {
914 if ((&conf
->bss
[i
] != bss
) &&
915 (hostapd_mac_comp(conf
->bss
[i
].bssid
,
917 printf("Duplicate BSSID " MACSTR
918 " on interface '%s' and '%s'.\n",
920 conf
->bss
[i
].iface
, bss
->iface
);
926 #ifdef CONFIG_IEEE80211R
927 if ((bss
->wpa_key_mgmt
&
928 (WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
)) &&
929 (bss
->nas_identifier
== NULL
||
930 os_strlen(bss
->nas_identifier
) < 1 ||
931 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
932 printf("FT (IEEE 802.11r) requires nas_identifier to be "
933 "configured as a 1..48 octet string\n");
936 #endif /* CONFIG_IEEE80211R */
942 static int hostapd_config_check(struct hostapd_config
*conf
)
946 for (i
= 0; i
< conf
->num_bss
; i
++) {
947 if (hostapd_config_check_bss(&conf
->bss
[i
], conf
))
955 static int hostapd_config_read_wep(struct hostapd_wep_keys
*wep
, int keyidx
,
958 size_t len
= os_strlen(val
);
960 if (keyidx
< 0 || keyidx
> 3 || wep
->key
[keyidx
] != NULL
)
964 if (len
< 2 || val
[len
- 1] != '"')
967 wep
->key
[keyidx
] = os_malloc(len
);
968 if (wep
->key
[keyidx
] == NULL
)
970 os_memcpy(wep
->key
[keyidx
], val
+ 1, len
);
971 wep
->len
[keyidx
] = len
;
976 wep
->key
[keyidx
] = os_malloc(len
);
977 if (wep
->key
[keyidx
] == NULL
)
979 wep
->len
[keyidx
] = len
;
980 if (hexstr2bin(val
, wep
->key
[keyidx
], len
) < 0)
990 static int hostapd_parse_rates(int **rate_list
, char *val
)
1001 while (*pos
!= '\0') {
1007 list
= os_malloc(sizeof(int) * (count
+ 2));
1012 while (*pos
!= '\0') {
1013 end
= os_strchr(pos
, ' ');
1017 list
[count
++] = atoi(pos
);
1029 static int hostapd_config_bss(struct hostapd_config
*conf
, const char *ifname
)
1031 struct hostapd_bss_config
*bss
;
1033 if (*ifname
== '\0')
1036 bss
= os_realloc(conf
->bss
, (conf
->num_bss
+ 1) *
1037 sizeof(struct hostapd_bss_config
));
1039 printf("Failed to allocate memory for multi-BSS entry\n");
1044 bss
= &(conf
->bss
[conf
->num_bss
]);
1045 os_memset(bss
, 0, sizeof(*bss
));
1046 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
1047 if (bss
->radius
== NULL
) {
1048 printf("Failed to allocate memory for multi-BSS RADIUS "
1054 conf
->last_bss
= bss
;
1056 hostapd_config_defaults_bss(bss
);
1057 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1058 os_memcpy(bss
->ssid
.vlan
, bss
->iface
, IFNAMSIZ
+ 1);
1064 static int valid_cw(int cw
)
1066 return (cw
== 1 || cw
== 3 || cw
== 7 || cw
== 15 || cw
== 31 ||
1067 cw
== 63 || cw
== 127 || cw
== 255 || cw
== 511 || cw
== 1023);
1072 IEEE80211_TX_QUEUE_DATA0
= 0, /* used for EDCA AC_VO data */
1073 IEEE80211_TX_QUEUE_DATA1
= 1, /* used for EDCA AC_VI data */
1074 IEEE80211_TX_QUEUE_DATA2
= 2, /* used for EDCA AC_BE data */
1075 IEEE80211_TX_QUEUE_DATA3
= 3, /* used for EDCA AC_BK data */
1076 IEEE80211_TX_QUEUE_DATA4
= 4,
1077 IEEE80211_TX_QUEUE_AFTER_BEACON
= 6,
1078 IEEE80211_TX_QUEUE_BEACON
= 7
1081 static int hostapd_config_tx_queue(struct hostapd_config
*conf
, char *name
,
1086 struct hostapd_tx_queue_params
*queue
;
1088 /* skip 'tx_queue_' prefix */
1090 if (os_strncmp(pos
, "data", 4) == 0 &&
1091 pos
[4] >= '0' && pos
[4] <= '9' && pos
[5] == '_') {
1094 } else if (os_strncmp(pos
, "after_beacon_", 13) == 0) {
1095 num
= IEEE80211_TX_QUEUE_AFTER_BEACON
;
1097 } else if (os_strncmp(pos
, "beacon_", 7) == 0) {
1098 num
= IEEE80211_TX_QUEUE_BEACON
;
1101 printf("Unknown tx_queue name '%s'\n", pos
);
1105 queue
= &conf
->tx_queue
[num
];
1107 if (os_strcmp(pos
, "aifs") == 0) {
1108 queue
->aifs
= atoi(val
);
1109 if (queue
->aifs
< 0 || queue
->aifs
> 255) {
1110 printf("Invalid AIFS value %d\n", queue
->aifs
);
1113 } else if (os_strcmp(pos
, "cwmin") == 0) {
1114 queue
->cwmin
= atoi(val
);
1115 if (!valid_cw(queue
->cwmin
)) {
1116 printf("Invalid cwMin value %d\n", queue
->cwmin
);
1119 } else if (os_strcmp(pos
, "cwmax") == 0) {
1120 queue
->cwmax
= atoi(val
);
1121 if (!valid_cw(queue
->cwmax
)) {
1122 printf("Invalid cwMax value %d\n", queue
->cwmax
);
1125 } else if (os_strcmp(pos
, "burst") == 0) {
1126 queue
->burst
= hostapd_config_read_int10(val
);
1128 printf("Unknown tx_queue field '%s'\n", pos
);
1132 queue
->configured
= 1;
1138 static int hostapd_config_wme_ac(struct hostapd_config
*conf
, char *name
,
1143 struct hostapd_wme_ac_params
*ac
;
1145 /* skip 'wme_ac_' prefix */
1147 if (os_strncmp(pos
, "be_", 3) == 0) {
1150 } else if (os_strncmp(pos
, "bk_", 3) == 0) {
1153 } else if (os_strncmp(pos
, "vi_", 3) == 0) {
1156 } else if (os_strncmp(pos
, "vo_", 3) == 0) {
1160 printf("Unknown wme name '%s'\n", pos
);
1164 ac
= &conf
->wme_ac_params
[num
];
1166 if (os_strcmp(pos
, "aifs") == 0) {
1168 if (v
< 1 || v
> 255) {
1169 printf("Invalid AIFS value %d\n", v
);
1173 } else if (os_strcmp(pos
, "cwmin") == 0) {
1175 if (v
< 0 || v
> 12) {
1176 printf("Invalid cwMin value %d\n", v
);
1180 } else if (os_strcmp(pos
, "cwmax") == 0) {
1182 if (v
< 0 || v
> 12) {
1183 printf("Invalid cwMax value %d\n", v
);
1187 } else if (os_strcmp(pos
, "txop_limit") == 0) {
1189 if (v
< 0 || v
> 0xffff) {
1190 printf("Invalid txop value %d\n", v
);
1194 } else if (os_strcmp(pos
, "acm") == 0) {
1196 if (v
< 0 || v
> 1) {
1197 printf("Invalid acm value %d\n", v
);
1200 ac
->admission_control_mandatory
= v
;
1202 printf("Unknown wme_ac_ field '%s'\n", pos
);
1210 #ifdef CONFIG_IEEE80211R
1211 static int add_r0kh(struct hostapd_bss_config
*bss
, char *value
)
1213 struct ft_remote_r0kh
*r0kh
;
1216 r0kh
= os_zalloc(sizeof(*r0kh
));
1220 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1222 next
= os_strchr(pos
, ' ');
1225 if (next
== NULL
|| hwaddr_aton(pos
, r0kh
->addr
)) {
1226 printf("Invalid R0KH MAC address: '%s'\n", pos
);
1232 next
= os_strchr(pos
, ' ');
1235 if (next
== NULL
|| next
- pos
> FT_R0KH_ID_MAX_LEN
) {
1236 printf("Invalid R0KH-ID: '%s'\n", pos
);
1240 r0kh
->id_len
= next
- pos
- 1;
1241 os_memcpy(r0kh
->id
, pos
, r0kh
->id_len
);
1244 if (hexstr2bin(pos
, r0kh
->key
, sizeof(r0kh
->key
))) {
1245 printf("Invalid R0KH key: '%s'\n", pos
);
1250 r0kh
->next
= bss
->r0kh_list
;
1251 bss
->r0kh_list
= r0kh
;
1257 static int add_r1kh(struct hostapd_bss_config
*bss
, char *value
)
1259 struct ft_remote_r1kh
*r1kh
;
1262 r1kh
= os_zalloc(sizeof(*r1kh
));
1266 /* 02:01:02:03:04:05 02:01:02:03:04:05
1267 * 000102030405060708090a0b0c0d0e0f */
1269 next
= os_strchr(pos
, ' ');
1272 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->addr
)) {
1273 printf("Invalid R1KH MAC address: '%s'\n", pos
);
1279 next
= os_strchr(pos
, ' ');
1282 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->id
)) {
1283 printf("Invalid R1KH-ID: '%s'\n", pos
);
1289 if (hexstr2bin(pos
, r1kh
->key
, sizeof(r1kh
->key
))) {
1290 printf("Invalid R1KH key: '%s'\n", pos
);
1295 r1kh
->next
= bss
->r1kh_list
;
1296 bss
->r1kh_list
= r1kh
;
1300 #endif /* CONFIG_IEEE80211R */
1303 struct hostapd_config
* hostapd_config_read(const char *fname
)
1305 struct hostapd_config
*conf
;
1306 struct hostapd_bss_config
*bss
;
1308 char buf
[256], *pos
;
1314 f
= fopen(fname
, "r");
1316 printf("Could not open configuration file '%s' for reading.\n",
1321 conf
= hostapd_config_defaults();
1326 bss
= conf
->last_bss
= conf
->bss
;
1328 while (fgets(buf
, sizeof(buf
), f
)) {
1329 bss
= conf
->last_bss
;
1335 while (*pos
!= '\0') {
1345 pos
= os_strchr(buf
, '=');
1347 printf("Line %d: invalid line '%s'\n", line
, buf
);
1354 if (os_strcmp(buf
, "interface") == 0) {
1355 os_strlcpy(conf
->bss
[0].iface
, pos
,
1356 sizeof(conf
->bss
[0].iface
));
1357 } else if (os_strcmp(buf
, "bridge") == 0) {
1358 os_strlcpy(bss
->bridge
, pos
, sizeof(bss
->bridge
));
1359 } else if (os_strcmp(buf
, "driver") == 0) {
1361 /* clear to get error below if setting is invalid */
1362 conf
->driver
= NULL
;
1363 for (i
= 0; hostapd_drivers
[i
]; i
++) {
1364 if (os_strcmp(pos
, hostapd_drivers
[i
]->name
) ==
1366 conf
->driver
= hostapd_drivers
[i
];
1370 if (conf
->driver
== NULL
) {
1371 printf("Line %d: invalid/unknown driver "
1372 "'%s'\n", line
, pos
);
1375 } else if (os_strcmp(buf
, "debug") == 0) {
1376 wpa_printf(MSG_DEBUG
, "Line %d: DEPRECATED: 'debug' "
1377 "configuration variable is not used "
1379 } else if (os_strcmp(buf
, "logger_syslog_level") == 0) {
1380 bss
->logger_syslog_level
= atoi(pos
);
1381 } else if (os_strcmp(buf
, "logger_stdout_level") == 0) {
1382 bss
->logger_stdout_level
= atoi(pos
);
1383 } else if (os_strcmp(buf
, "logger_syslog") == 0) {
1384 bss
->logger_syslog
= atoi(pos
);
1385 } else if (os_strcmp(buf
, "logger_stdout") == 0) {
1386 bss
->logger_stdout
= atoi(pos
);
1387 } else if (os_strcmp(buf
, "dump_file") == 0) {
1388 bss
->dump_log_name
= os_strdup(pos
);
1389 } else if (os_strcmp(buf
, "ssid") == 0) {
1390 bss
->ssid
.ssid_len
= os_strlen(pos
);
1391 if (bss
->ssid
.ssid_len
> HOSTAPD_MAX_SSID_LEN
||
1392 bss
->ssid
.ssid_len
< 1) {
1393 printf("Line %d: invalid SSID '%s'\n", line
,
1397 os_memcpy(bss
->ssid
.ssid
, pos
,
1398 bss
->ssid
.ssid_len
);
1399 bss
->ssid
.ssid
[bss
->ssid
.ssid_len
] = '\0';
1400 bss
->ssid
.ssid_set
= 1;
1402 } else if (os_strcmp(buf
, "macaddr_acl") == 0) {
1403 bss
->macaddr_acl
= atoi(pos
);
1404 if (bss
->macaddr_acl
!= ACCEPT_UNLESS_DENIED
&&
1405 bss
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
&&
1406 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1407 printf("Line %d: unknown macaddr_acl %d\n",
1408 line
, bss
->macaddr_acl
);
1410 } else if (os_strcmp(buf
, "accept_mac_file") == 0) {
1411 if (hostapd_config_read_maclist(pos
, &bss
->accept_mac
,
1412 &bss
->num_accept_mac
))
1414 printf("Line %d: Failed to read "
1415 "accept_mac_file '%s'\n",
1419 } else if (os_strcmp(buf
, "deny_mac_file") == 0) {
1420 if (hostapd_config_read_maclist(pos
, &bss
->deny_mac
,
1421 &bss
->num_deny_mac
))
1423 printf("Line %d: Failed to read "
1424 "deny_mac_file '%s'\n",
1428 } else if (os_strcmp(buf
, "ap_max_inactivity") == 0) {
1429 bss
->ap_max_inactivity
= atoi(pos
);
1430 } else if (os_strcmp(buf
, "country_code") == 0) {
1431 os_memcpy(conf
->country
, pos
, 2);
1432 /* FIX: make this configurable */
1433 conf
->country
[2] = ' ';
1434 } else if (os_strcmp(buf
, "ieee80211d") == 0) {
1435 conf
->ieee80211d
= atoi(pos
);
1436 } else if (os_strcmp(buf
, "ieee80211h") == 0) {
1437 conf
->ieee80211h
= atoi(pos
);
1438 } else if (os_strcmp(buf
, "assoc_ap_addr") == 0) {
1439 if (hwaddr_aton(pos
, bss
->assoc_ap_addr
)) {
1440 printf("Line %d: invalid MAC address '%s'\n",
1445 } else if (os_strcmp(buf
, "ieee8021x") == 0) {
1446 bss
->ieee802_1x
= atoi(pos
);
1447 } else if (os_strcmp(buf
, "eapol_version") == 0) {
1448 bss
->eapol_version
= atoi(pos
);
1449 if (bss
->eapol_version
< 1 ||
1450 bss
->eapol_version
> 2) {
1451 printf("Line %d: invalid EAPOL "
1452 "version (%d): '%s'.\n",
1453 line
, bss
->eapol_version
, pos
);
1456 wpa_printf(MSG_DEBUG
, "eapol_version=%d",
1457 bss
->eapol_version
);
1459 } else if (os_strcmp(buf
, "eap_authenticator") == 0) {
1460 bss
->eap_server
= atoi(pos
);
1461 printf("Line %d: obsolete eap_authenticator used; "
1462 "this has been renamed to eap_server\n", line
);
1463 } else if (os_strcmp(buf
, "eap_server") == 0) {
1464 bss
->eap_server
= atoi(pos
);
1465 } else if (os_strcmp(buf
, "eap_user_file") == 0) {
1466 if (hostapd_config_read_eap_user(pos
, bss
))
1468 } else if (os_strcmp(buf
, "ca_cert") == 0) {
1469 os_free(bss
->ca_cert
);
1470 bss
->ca_cert
= os_strdup(pos
);
1471 } else if (os_strcmp(buf
, "server_cert") == 0) {
1472 os_free(bss
->server_cert
);
1473 bss
->server_cert
= os_strdup(pos
);
1474 } else if (os_strcmp(buf
, "private_key") == 0) {
1475 os_free(bss
->private_key
);
1476 bss
->private_key
= os_strdup(pos
);
1477 } else if (os_strcmp(buf
, "private_key_passwd") == 0) {
1478 os_free(bss
->private_key_passwd
);
1479 bss
->private_key_passwd
= os_strdup(pos
);
1480 } else if (os_strcmp(buf
, "check_crl") == 0) {
1481 bss
->check_crl
= atoi(pos
);
1482 } else if (os_strcmp(buf
, "dh_file") == 0) {
1483 os_free(bss
->dh_file
);
1484 bss
->dh_file
= os_strdup(pos
);
1486 } else if (os_strcmp(buf
, "pac_opaque_encr_key") == 0) {
1487 os_free(bss
->pac_opaque_encr_key
);
1488 bss
->pac_opaque_encr_key
= os_malloc(16);
1489 if (bss
->pac_opaque_encr_key
== NULL
) {
1490 printf("Line %d: No memory for "
1491 "pac_opque_encr_key\n", line
);
1493 } else if (hexstr2bin(pos
, bss
->pac_opaque_encr_key
,
1495 printf("Line %d: Invalid pac_opque_encr_key\n",
1499 } else if (os_strcmp(buf
, "eap_fast_a_id") == 0) {
1500 os_free(bss
->eap_fast_a_id
);
1501 bss
->eap_fast_a_id
= os_strdup(pos
);
1502 #endif /* EAP_FAST */
1504 } else if (os_strcmp(buf
, "eap_sim_db") == 0) {
1505 os_free(bss
->eap_sim_db
);
1506 bss
->eap_sim_db
= os_strdup(pos
);
1507 } else if (os_strcmp(buf
, "eap_sim_aka_result_ind") == 0) {
1508 bss
->eap_sim_aka_result_ind
= atoi(pos
);
1509 #endif /* EAP_SIM */
1511 } else if (os_strcmp(buf
, "tnc") == 0) {
1512 bss
->tnc
= atoi(pos
);
1513 #endif /* EAP_TNC */
1514 #endif /* EAP_SERVER */
1515 } else if (os_strcmp(buf
, "eap_message") == 0) {
1517 bss
->eap_req_id_text
= os_strdup(pos
);
1518 if (bss
->eap_req_id_text
== NULL
) {
1519 printf("Line %d: Failed to allocate memory "
1520 "for eap_req_id_text\n", line
);
1524 bss
->eap_req_id_text_len
=
1525 os_strlen(bss
->eap_req_id_text
);
1526 term
= os_strstr(bss
->eap_req_id_text
, "\\0");
1529 os_memmove(term
, term
+ 1,
1530 bss
->eap_req_id_text_len
-
1531 (term
- bss
->eap_req_id_text
) - 1);
1532 bss
->eap_req_id_text_len
--;
1534 } else if (os_strcmp(buf
, "wep_key_len_broadcast") == 0) {
1535 bss
->default_wep_key_len
= atoi(pos
);
1536 if (bss
->default_wep_key_len
> 13) {
1537 printf("Line %d: invalid WEP key len %lu "
1538 "(= %lu bits)\n", line
,
1540 bss
->default_wep_key_len
,
1542 bss
->default_wep_key_len
* 8);
1545 } else if (os_strcmp(buf
, "wep_key_len_unicast") == 0) {
1546 bss
->individual_wep_key_len
= atoi(pos
);
1547 if (bss
->individual_wep_key_len
< 0 ||
1548 bss
->individual_wep_key_len
> 13) {
1549 printf("Line %d: invalid WEP key len %d "
1550 "(= %d bits)\n", line
,
1551 bss
->individual_wep_key_len
,
1552 bss
->individual_wep_key_len
* 8);
1555 } else if (os_strcmp(buf
, "wep_rekey_period") == 0) {
1556 bss
->wep_rekeying_period
= atoi(pos
);
1557 if (bss
->wep_rekeying_period
< 0) {
1558 printf("Line %d: invalid period %d\n",
1559 line
, bss
->wep_rekeying_period
);
1562 } else if (os_strcmp(buf
, "eap_reauth_period") == 0) {
1563 bss
->eap_reauth_period
= atoi(pos
);
1564 if (bss
->eap_reauth_period
< 0) {
1565 printf("Line %d: invalid period %d\n",
1566 line
, bss
->eap_reauth_period
);
1569 } else if (os_strcmp(buf
, "eapol_key_index_workaround") == 0) {
1570 bss
->eapol_key_index_workaround
= atoi(pos
);
1572 } else if (os_strcmp(buf
, "iapp_interface") == 0) {
1573 bss
->ieee802_11f
= 1;
1574 os_strlcpy(bss
->iapp_iface
, pos
,
1575 sizeof(bss
->iapp_iface
));
1576 #endif /* CONFIG_IAPP */
1577 } else if (os_strcmp(buf
, "own_ip_addr") == 0) {
1578 if (hostapd_parse_ip_addr(pos
, &bss
->own_ip_addr
)) {
1579 printf("Line %d: invalid IP address '%s'\n",
1583 } else if (os_strcmp(buf
, "nas_identifier") == 0) {
1584 bss
->nas_identifier
= os_strdup(pos
);
1585 } else if (os_strcmp(buf
, "auth_server_addr") == 0) {
1586 if (hostapd_config_read_radius_addr(
1587 &bss
->radius
->auth_servers
,
1588 &bss
->radius
->num_auth_servers
, pos
, 1812,
1589 &bss
->radius
->auth_server
)) {
1590 printf("Line %d: invalid IP address '%s'\n",
1594 } else if (bss
->radius
->auth_server
&&
1595 os_strcmp(buf
, "auth_server_port") == 0) {
1596 bss
->radius
->auth_server
->port
= atoi(pos
);
1597 } else if (bss
->radius
->auth_server
&&
1598 os_strcmp(buf
, "auth_server_shared_secret") == 0) {
1599 int len
= os_strlen(pos
);
1601 /* RFC 2865, Ch. 3 */
1602 printf("Line %d: empty shared secret is not "
1603 "allowed.\n", line
);
1606 bss
->radius
->auth_server
->shared_secret
=
1607 (u8
*) os_strdup(pos
);
1608 bss
->radius
->auth_server
->shared_secret_len
= len
;
1609 } else if (os_strcmp(buf
, "acct_server_addr") == 0) {
1610 if (hostapd_config_read_radius_addr(
1611 &bss
->radius
->acct_servers
,
1612 &bss
->radius
->num_acct_servers
, pos
, 1813,
1613 &bss
->radius
->acct_server
)) {
1614 printf("Line %d: invalid IP address '%s'\n",
1618 } else if (bss
->radius
->acct_server
&&
1619 os_strcmp(buf
, "acct_server_port") == 0) {
1620 bss
->radius
->acct_server
->port
= atoi(pos
);
1621 } else if (bss
->radius
->acct_server
&&
1622 os_strcmp(buf
, "acct_server_shared_secret") == 0) {
1623 int len
= os_strlen(pos
);
1625 /* RFC 2865, Ch. 3 */
1626 printf("Line %d: empty shared secret is not "
1627 "allowed.\n", line
);
1630 bss
->radius
->acct_server
->shared_secret
=
1631 (u8
*) os_strdup(pos
);
1632 bss
->radius
->acct_server
->shared_secret_len
= len
;
1633 } else if (os_strcmp(buf
, "radius_retry_primary_interval") ==
1635 bss
->radius
->retry_primary_interval
= atoi(pos
);
1636 } else if (os_strcmp(buf
, "radius_acct_interim_interval") == 0)
1638 bss
->radius
->acct_interim_interval
= atoi(pos
);
1639 } else if (os_strcmp(buf
, "auth_algs") == 0) {
1640 bss
->auth_algs
= atoi(pos
);
1641 if (bss
->auth_algs
== 0) {
1642 printf("Line %d: no authentication algorithms "
1647 } else if (os_strcmp(buf
, "max_num_sta") == 0) {
1648 bss
->max_num_sta
= atoi(pos
);
1649 if (bss
->max_num_sta
< 0 ||
1650 bss
->max_num_sta
> MAX_STA_COUNT
) {
1651 printf("Line %d: Invalid max_num_sta=%d; "
1652 "allowed range 0..%d\n", line
,
1653 bss
->max_num_sta
, MAX_STA_COUNT
);
1656 } else if (os_strcmp(buf
, "wpa") == 0) {
1657 bss
->wpa
= atoi(pos
);
1658 } else if (os_strcmp(buf
, "wpa_group_rekey") == 0) {
1659 bss
->wpa_group_rekey
= atoi(pos
);
1660 } else if (os_strcmp(buf
, "wpa_strict_rekey") == 0) {
1661 bss
->wpa_strict_rekey
= atoi(pos
);
1662 } else if (os_strcmp(buf
, "wpa_gmk_rekey") == 0) {
1663 bss
->wpa_gmk_rekey
= atoi(pos
);
1664 } else if (os_strcmp(buf
, "wpa_passphrase") == 0) {
1665 int len
= os_strlen(pos
);
1666 if (len
< 8 || len
> 63) {
1667 printf("Line %d: invalid WPA passphrase length"
1668 " %d (expected 8..63)\n", line
, len
);
1671 os_free(bss
->ssid
.wpa_passphrase
);
1672 bss
->ssid
.wpa_passphrase
= os_strdup(pos
);
1674 } else if (os_strcmp(buf
, "wpa_psk") == 0) {
1675 os_free(bss
->ssid
.wpa_psk
);
1677 os_zalloc(sizeof(struct hostapd_wpa_psk
));
1678 if (bss
->ssid
.wpa_psk
== NULL
)
1680 else if (hexstr2bin(pos
, bss
->ssid
.wpa_psk
->psk
,
1682 pos
[PMK_LEN
* 2] != '\0') {
1683 printf("Line %d: Invalid PSK '%s'.\n", line
,
1687 bss
->ssid
.wpa_psk
->group
= 1;
1689 } else if (os_strcmp(buf
, "wpa_psk_file") == 0) {
1690 os_free(bss
->ssid
.wpa_psk_file
);
1691 bss
->ssid
.wpa_psk_file
= os_strdup(pos
);
1692 if (!bss
->ssid
.wpa_psk_file
) {
1693 printf("Line %d: allocation failed\n", line
);
1696 } else if (os_strcmp(buf
, "wpa_key_mgmt") == 0) {
1698 hostapd_config_parse_key_mgmt(line
, pos
);
1699 if (bss
->wpa_key_mgmt
== -1)
1701 } else if (os_strcmp(buf
, "wpa_pairwise") == 0) {
1703 hostapd_config_parse_cipher(line
, pos
);
1704 if (bss
->wpa_pairwise
== -1 ||
1705 bss
->wpa_pairwise
== 0)
1707 else if (bss
->wpa_pairwise
&
1708 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1709 WPA_CIPHER_WEP104
)) {
1710 printf("Line %d: unsupported pairwise "
1711 "cipher suite '%s'\n",
1712 bss
->wpa_pairwise
, pos
);
1715 } else if (os_strcmp(buf
, "rsn_pairwise") == 0) {
1717 hostapd_config_parse_cipher(line
, pos
);
1718 if (bss
->rsn_pairwise
== -1 ||
1719 bss
->rsn_pairwise
== 0)
1721 else if (bss
->rsn_pairwise
&
1722 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1723 WPA_CIPHER_WEP104
)) {
1724 printf("Line %d: unsupported pairwise "
1725 "cipher suite '%s'\n",
1726 bss
->rsn_pairwise
, pos
);
1729 #ifdef CONFIG_RSN_PREAUTH
1730 } else if (os_strcmp(buf
, "rsn_preauth") == 0) {
1731 bss
->rsn_preauth
= atoi(pos
);
1732 } else if (os_strcmp(buf
, "rsn_preauth_interfaces") == 0) {
1733 bss
->rsn_preauth_interfaces
= os_strdup(pos
);
1734 #endif /* CONFIG_RSN_PREAUTH */
1735 #ifdef CONFIG_PEERKEY
1736 } else if (os_strcmp(buf
, "peerkey") == 0) {
1737 bss
->peerkey
= atoi(pos
);
1738 #endif /* CONFIG_PEERKEY */
1739 #ifdef CONFIG_IEEE80211R
1740 } else if (os_strcmp(buf
, "mobility_domain") == 0) {
1741 if (os_strlen(pos
) != 2 * MOBILITY_DOMAIN_ID_LEN
||
1742 hexstr2bin(pos
, bss
->mobility_domain
,
1743 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1744 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1745 "mobility_domain '%s'", line
, pos
);
1749 } else if (os_strcmp(buf
, "r1_key_holder") == 0) {
1750 if (os_strlen(pos
) != 2 * FT_R1KH_ID_LEN
||
1751 hexstr2bin(pos
, bss
->r1_key_holder
,
1752 FT_R1KH_ID_LEN
) != 0) {
1753 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1754 "r1_key_holder '%s'", line
, pos
);
1758 } else if (os_strcmp(buf
, "r0_key_lifetime") == 0) {
1759 bss
->r0_key_lifetime
= atoi(pos
);
1760 } else if (os_strcmp(buf
, "reassociation_deadline") == 0) {
1761 bss
->reassociation_deadline
= atoi(pos
);
1762 } else if (os_strcmp(buf
, "r0kh") == 0) {
1763 if (add_r0kh(bss
, pos
) < 0) {
1764 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1765 "r0kh '%s'", line
, pos
);
1769 } else if (os_strcmp(buf
, "r1kh") == 0) {
1770 if (add_r1kh(bss
, pos
) < 0) {
1771 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1772 "r1kh '%s'", line
, pos
);
1776 } else if (os_strcmp(buf
, "pmk_r1_push") == 0) {
1777 bss
->pmk_r1_push
= atoi(pos
);
1778 #endif /* CONFIG_IEEE80211R */
1779 } else if (os_strcmp(buf
, "ctrl_interface") == 0) {
1780 os_free(bss
->ctrl_interface
);
1781 bss
->ctrl_interface
= os_strdup(pos
);
1782 } else if (os_strcmp(buf
, "ctrl_interface_group") == 0) {
1783 #ifndef CONFIG_NATIVE_WINDOWS
1786 const char *group
= pos
;
1788 grp
= getgrnam(group
);
1790 bss
->ctrl_interface_gid
= grp
->gr_gid
;
1791 bss
->ctrl_interface_gid_set
= 1;
1792 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d"
1793 " (from group name '%s')",
1794 bss
->ctrl_interface_gid
, group
);
1798 /* Group name not found - try to parse this as gid */
1799 bss
->ctrl_interface_gid
= strtol(group
, &endp
, 10);
1800 if (*group
== '\0' || *endp
!= '\0') {
1801 wpa_printf(MSG_DEBUG
, "Line %d: Invalid group "
1802 "'%s'", line
, group
);
1806 bss
->ctrl_interface_gid_set
= 1;
1807 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d",
1808 bss
->ctrl_interface_gid
);
1809 #endif /* CONFIG_NATIVE_WINDOWS */
1810 #ifdef RADIUS_SERVER
1811 } else if (os_strcmp(buf
, "radius_server_clients") == 0) {
1812 os_free(bss
->radius_server_clients
);
1813 bss
->radius_server_clients
= os_strdup(pos
);
1814 } else if (os_strcmp(buf
, "radius_server_auth_port") == 0) {
1815 bss
->radius_server_auth_port
= atoi(pos
);
1816 } else if (os_strcmp(buf
, "radius_server_ipv6") == 0) {
1817 bss
->radius_server_ipv6
= atoi(pos
);
1818 #endif /* RADIUS_SERVER */
1819 } else if (os_strcmp(buf
, "test_socket") == 0) {
1820 os_free(bss
->test_socket
);
1821 bss
->test_socket
= os_strdup(pos
);
1822 } else if (os_strcmp(buf
, "use_pae_group_addr") == 0) {
1823 bss
->use_pae_group_addr
= atoi(pos
);
1824 } else if (os_strcmp(buf
, "hw_mode") == 0) {
1825 if (os_strcmp(pos
, "a") == 0)
1826 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211A
;
1827 else if (os_strcmp(pos
, "b") == 0)
1828 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211B
;
1829 else if (os_strcmp(pos
, "g") == 0)
1830 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
1832 printf("Line %d: unknown hw_mode '%s'\n",
1836 } else if (os_strcmp(buf
, "channel") == 0) {
1837 conf
->channel
= atoi(pos
);
1838 } else if (os_strcmp(buf
, "beacon_int") == 0) {
1839 int val
= atoi(pos
);
1840 /* MIB defines range as 1..65535, but very small values
1841 * cause problems with the current implementation.
1842 * Since it is unlikely that this small numbers are
1843 * useful in real life scenarios, do not allow beacon
1844 * period to be set below 15 TU. */
1845 if (val
< 15 || val
> 65535) {
1846 printf("Line %d: invalid beacon_int %d "
1847 "(expected 15..65535)\n",
1851 conf
->beacon_int
= val
;
1852 } else if (os_strcmp(buf
, "dtim_period") == 0) {
1853 bss
->dtim_period
= atoi(pos
);
1854 if (bss
->dtim_period
< 1 || bss
->dtim_period
> 255) {
1855 printf("Line %d: invalid dtim_period %d\n",
1856 line
, bss
->dtim_period
);
1859 } else if (os_strcmp(buf
, "rts_threshold") == 0) {
1860 conf
->rts_threshold
= atoi(pos
);
1861 if (conf
->rts_threshold
< 0 ||
1862 conf
->rts_threshold
> 2347) {
1863 printf("Line %d: invalid rts_threshold %d\n",
1864 line
, conf
->rts_threshold
);
1867 } else if (os_strcmp(buf
, "fragm_threshold") == 0) {
1868 conf
->fragm_threshold
= atoi(pos
);
1869 if (conf
->fragm_threshold
< 256 ||
1870 conf
->fragm_threshold
> 2346) {
1871 printf("Line %d: invalid fragm_threshold %d\n",
1872 line
, conf
->fragm_threshold
);
1875 } else if (os_strcmp(buf
, "send_probe_response") == 0) {
1876 int val
= atoi(pos
);
1877 if (val
!= 0 && val
!= 1) {
1878 printf("Line %d: invalid send_probe_response "
1879 "%d (expected 0 or 1)\n", line
, val
);
1881 conf
->send_probe_response
= val
;
1882 } else if (os_strcmp(buf
, "supported_rates") == 0) {
1883 if (hostapd_parse_rates(&conf
->supported_rates
, pos
)) {
1884 printf("Line %d: invalid rate list\n", line
);
1887 } else if (os_strcmp(buf
, "basic_rates") == 0) {
1888 if (hostapd_parse_rates(&conf
->basic_rates
, pos
)) {
1889 printf("Line %d: invalid rate list\n", line
);
1892 } else if (os_strcmp(buf
, "preamble") == 0) {
1894 conf
->preamble
= SHORT_PREAMBLE
;
1896 conf
->preamble
= LONG_PREAMBLE
;
1897 } else if (os_strcmp(buf
, "ignore_broadcast_ssid") == 0) {
1898 bss
->ignore_broadcast_ssid
= atoi(pos
);
1899 } else if (os_strcmp(buf
, "bridge_packets") == 0) {
1900 conf
->bridge_packets
= atoi(pos
);
1901 } else if (os_strcmp(buf
, "wep_default_key") == 0) {
1902 bss
->ssid
.wep
.idx
= atoi(pos
);
1903 if (bss
->ssid
.wep
.idx
> 3) {
1904 printf("Invalid wep_default_key index %d\n",
1908 } else if (os_strcmp(buf
, "wep_key0") == 0 ||
1909 os_strcmp(buf
, "wep_key1") == 0 ||
1910 os_strcmp(buf
, "wep_key2") == 0 ||
1911 os_strcmp(buf
, "wep_key3") == 0) {
1912 if (hostapd_config_read_wep(&bss
->ssid
.wep
,
1913 buf
[7] - '0', pos
)) {
1914 printf("Line %d: invalid WEP key '%s'\n",
1918 } else if (os_strcmp(buf
, "dynamic_vlan") == 0) {
1919 bss
->ssid
.dynamic_vlan
= atoi(pos
);
1920 } else if (os_strcmp(buf
, "vlan_file") == 0) {
1921 if (hostapd_config_read_vlan_file(bss
, pos
)) {
1922 printf("Line %d: failed to read VLAN file "
1923 "'%s'\n", line
, pos
);
1926 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1927 } else if (os_strcmp(buf
, "vlan_tagged_interface") == 0) {
1928 bss
->ssid
.vlan_tagged_interface
= os_strdup(pos
);
1929 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1930 } else if (os_strcmp(buf
, "passive_scan_interval") == 0) {
1931 conf
->passive_scan_interval
= atoi(pos
);
1932 } else if (os_strcmp(buf
, "passive_scan_listen") == 0) {
1933 conf
->passive_scan_listen
= atoi(pos
);
1934 } else if (os_strcmp(buf
, "passive_scan_mode") == 0) {
1935 conf
->passive_scan_mode
= atoi(pos
);
1936 } else if (os_strcmp(buf
, "ap_table_max_size") == 0) {
1937 conf
->ap_table_max_size
= atoi(pos
);
1938 } else if (os_strcmp(buf
, "ap_table_expiration_time") == 0) {
1939 conf
->ap_table_expiration_time
= atoi(pos
);
1940 } else if (os_strncmp(buf
, "tx_queue_", 9) == 0) {
1941 if (hostapd_config_tx_queue(conf
, buf
, pos
)) {
1942 printf("Line %d: invalid TX queue item\n",
1946 } else if (os_strcmp(buf
, "wme_enabled") == 0) {
1947 bss
->wme_enabled
= atoi(pos
);
1948 } else if (os_strncmp(buf
, "wme_ac_", 7) == 0) {
1949 if (hostapd_config_wme_ac(conf
, buf
, pos
)) {
1950 printf("Line %d: invalid wme ac item\n",
1954 } else if (os_strcmp(buf
, "bss") == 0) {
1955 if (hostapd_config_bss(conf
, pos
)) {
1956 printf("Line %d: invalid bss item\n", line
);
1959 } else if (os_strcmp(buf
, "bssid") == 0) {
1960 if (bss
== conf
->bss
&&
1961 (!conf
->driver
|| !conf
->driver
->init_bssid
)) {
1962 printf("Line %d: bssid item not allowed "
1963 "for the default interface and this "
1966 } else if (hwaddr_aton(pos
, bss
->bssid
)) {
1967 printf("Line %d: invalid bssid item\n", line
);
1970 #ifdef CONFIG_IEEE80211W
1971 } else if (os_strcmp(buf
, "ieee80211w") == 0) {
1972 bss
->ieee80211w
= atoi(pos
);
1973 } else if (os_strcmp(buf
, "assoc_ping_timeout") == 0) {
1974 bss
->assoc_ping_timeout
= atoi(pos
);
1975 if (bss
->assoc_ping_timeout
== 0) {
1976 printf("Line %d: invalid assoc_ping_timeout\n",
1980 } else if (os_strcmp(buf
, "assoc_ping_attempts") == 0) {
1981 bss
->assoc_ping_timeout
= atoi(pos
);
1982 if (bss
->assoc_ping_timeout
== 0) {
1983 printf("Line %d: invalid assoc_ping_attempts "
1984 "(valid range: 1..255)\n",
1988 #endif /* CONFIG_IEEE80211W */
1989 #ifdef CONFIG_IEEE80211N
1990 } else if (os_strcmp(buf
, "ieee80211n") == 0) {
1991 conf
->ieee80211n
= atoi(pos
);
1992 #endif /* CONFIG_IEEE80211N */
1993 } else if (os_strcmp(buf
, "max_listen_interval") == 0) {
1994 bss
->max_listen_interval
= atoi(pos
);
1995 } else if (os_strcmp(buf
, "okc") == 0) {
1996 bss
->okc
= atoi(pos
);
1998 printf("Line %d: unknown configuration item '%s'\n",
2006 if (bss
->individual_wep_key_len
== 0) {
2007 /* individual keys are not use; can use key idx0 for broadcast
2009 bss
->broadcast_key_idx_min
= 0;
2012 /* Select group cipher based on the enabled pairwise cipher suites */
2015 pairwise
|= bss
->wpa_pairwise
;
2017 if (bss
->rsn_pairwise
== 0)
2018 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
2019 pairwise
|= bss
->rsn_pairwise
;
2021 if (pairwise
& WPA_CIPHER_TKIP
)
2022 bss
->wpa_group
= WPA_CIPHER_TKIP
;
2024 bss
->wpa_group
= WPA_CIPHER_CCMP
;
2026 for (i
= 0; i
< conf
->num_bss
; i
++) {
2027 bss
= &conf
->bss
[i
];
2029 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
2030 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
2032 if (bss
->wpa
&& bss
->ieee802_1x
) {
2033 bss
->ssid
.security_policy
= SECURITY_WPA
;
2034 } else if (bss
->wpa
) {
2035 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
2036 } else if (bss
->ieee802_1x
) {
2037 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
2038 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
2039 } else if (bss
->ssid
.wep
.keys_set
)
2040 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
2042 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
2045 if (hostapd_config_check(conf
))
2049 printf("%d errors found in configuration file '%s'\n",
2051 hostapd_config_free(conf
);
2059 int hostapd_wep_key_cmp(struct hostapd_wep_keys
*a
, struct hostapd_wep_keys
*b
)
2063 if (a
->idx
!= b
->idx
|| a
->default_len
!= b
->default_len
)
2065 for (i
= 0; i
< NUM_WEP_KEYS
; i
++)
2066 if (a
->len
[i
] != b
->len
[i
] ||
2067 os_memcmp(a
->key
[i
], b
->key
[i
], a
->len
[i
]) != 0)
2073 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
2078 for (i
= 0; i
< num_servers
; i
++) {
2079 os_free(servers
[i
].shared_secret
);
2085 static void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
2087 os_free(user
->identity
);
2088 os_free(user
->password
);
2093 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
2096 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
2097 os_free(keys
->key
[i
]);
2098 keys
->key
[i
] = NULL
;
2103 static void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
2105 struct hostapd_wpa_psk
*psk
, *prev
;
2106 struct hostapd_eap_user
*user
, *prev_user
;
2111 psk
= conf
->ssid
.wpa_psk
;
2118 os_free(conf
->ssid
.wpa_passphrase
);
2119 os_free(conf
->ssid
.wpa_psk_file
);
2120 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2121 os_free(conf
->ssid
.vlan_tagged_interface
);
2122 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2124 user
= conf
->eap_user
;
2128 hostapd_config_free_eap_user(prev_user
);
2131 os_free(conf
->dump_log_name
);
2132 os_free(conf
->eap_req_id_text
);
2133 os_free(conf
->accept_mac
);
2134 os_free(conf
->deny_mac
);
2135 os_free(conf
->nas_identifier
);
2136 hostapd_config_free_radius(conf
->radius
->auth_servers
,
2137 conf
->radius
->num_auth_servers
);
2138 hostapd_config_free_radius(conf
->radius
->acct_servers
,
2139 conf
->radius
->num_acct_servers
);
2140 os_free(conf
->rsn_preauth_interfaces
);
2141 os_free(conf
->ctrl_interface
);
2142 os_free(conf
->ca_cert
);
2143 os_free(conf
->server_cert
);
2144 os_free(conf
->private_key
);
2145 os_free(conf
->private_key_passwd
);
2146 os_free(conf
->dh_file
);
2147 os_free(conf
->pac_opaque_encr_key
);
2148 os_free(conf
->eap_fast_a_id
);
2149 os_free(conf
->eap_sim_db
);
2150 os_free(conf
->radius_server_clients
);
2151 os_free(conf
->test_socket
);
2152 os_free(conf
->radius
);
2153 hostapd_config_free_vlan(conf
);
2154 if (conf
->ssid
.dyn_vlan_keys
) {
2155 struct hostapd_ssid
*ssid
= &conf
->ssid
;
2157 for (i
= 0; i
<= ssid
->max_dyn_vlan_keys
; i
++) {
2158 if (ssid
->dyn_vlan_keys
[i
] == NULL
)
2160 hostapd_config_free_wep(ssid
->dyn_vlan_keys
[i
]);
2161 os_free(ssid
->dyn_vlan_keys
[i
]);
2163 os_free(ssid
->dyn_vlan_keys
);
2164 ssid
->dyn_vlan_keys
= NULL
;
2167 #ifdef CONFIG_IEEE80211R
2169 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
2170 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
2172 r0kh
= conf
->r0kh_list
;
2173 conf
->r0kh_list
= NULL
;
2180 r1kh
= conf
->r1kh_list
;
2181 conf
->r1kh_list
= NULL
;
2188 #endif /* CONFIG_IEEE80211R */
2192 void hostapd_config_free(struct hostapd_config
*conf
)
2199 for (i
= 0; i
< conf
->num_bss
; i
++)
2200 hostapd_config_free_bss(&conf
->bss
[i
]);
2207 /* Perform a binary search for given MAC address from a pre-sorted list.
2208 * Returns 1 if address is in the list or 0 if not. */
2209 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
2210 const u8
*addr
, int *vlan_id
)
2212 int start
, end
, middle
, res
;
2215 end
= num_entries
- 1;
2217 while (start
<= end
) {
2218 middle
= (start
+ end
) / 2;
2219 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
2222 *vlan_id
= list
[middle
].vlan_id
;
2235 int hostapd_rate_found(int *list
, int rate
)
2242 for (i
= 0; list
[i
] >= 0; i
++)
2243 if (list
[i
] == rate
)
2250 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
2252 struct hostapd_vlan
*v
= vlan
;
2254 if (v
->vlan_id
== vlan_id
|| v
->vlan_id
== VLAN_ID_WILDCARD
)
2262 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
2263 const u8
*addr
, const u8
*prev_psk
)
2265 struct hostapd_wpa_psk
*psk
;
2266 int next_ok
= prev_psk
== NULL
;
2268 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
2270 (psk
->group
|| os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0))
2273 if (psk
->psk
== prev_psk
)
2281 const struct hostapd_eap_user
*
2282 hostapd_get_eap_user(const struct hostapd_bss_config
*conf
, const u8
*identity
,
2283 size_t identity_len
, int phase2
)
2285 struct hostapd_eap_user
*user
= conf
->eap_user
;
2288 if (!phase2
&& user
->identity
== NULL
) {
2289 /* Wildcard match */
2293 if (user
->phase2
== !!phase2
&& user
->wildcard_prefix
&&
2294 identity_len
>= user
->identity_len
&&
2295 os_memcmp(user
->identity
, identity
, user
->identity_len
) ==
2297 /* Wildcard prefix match */
2301 if (user
->phase2
== !!phase2
&&
2302 user
->identity_len
== identity_len
&&
2303 os_memcmp(user
->identity
, identity
, identity_len
) == 0)