2 * hostapd / Configuration file
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #ifndef CONFIG_NATIVE_WINDOWS
18 #endif /* CONFIG_NATIVE_WINDOWS */
23 #include "eap_server/eap.h"
24 #include "radius/radius_client.h"
25 #include "wpa_common.h"
30 #define MAX_STA_COUNT 2007
32 extern struct wpa_driver_ops
*hostapd_drivers
[];
35 static int hostapd_config_read_vlan_file(struct hostapd_bss_config
*bss
,
39 char buf
[128], *pos
, *pos2
;
40 int line
= 0, vlan_id
;
41 struct hostapd_vlan
*vlan
;
43 f
= fopen(fname
, "r");
45 printf("VLAN file '%s' not readable.\n", fname
);
49 while (fgets(buf
, sizeof(buf
), f
)) {
55 while (*pos
!= '\0') {
66 vlan_id
= VLAN_ID_WILDCARD
;
69 vlan_id
= strtol(buf
, &pos
, 10);
70 if (buf
== pos
|| vlan_id
< 1 ||
71 vlan_id
> MAX_VLAN_ID
) {
72 printf("Invalid VLAN ID at line %d in '%s'\n",
79 while (*pos
== ' ' || *pos
== '\t')
82 while (*pos2
!= ' ' && *pos2
!= '\t' && *pos2
!= '\0')
85 if (*pos
== '\0' || os_strlen(pos
) > IFNAMSIZ
) {
86 printf("Invalid VLAN ifname at line %d in '%s'\n",
92 vlan
= os_malloc(sizeof(*vlan
));
94 printf("Out of memory while reading VLAN interfaces "
95 "from '%s'\n", fname
);
100 os_memset(vlan
, 0, sizeof(*vlan
));
101 vlan
->vlan_id
= vlan_id
;
102 os_strlcpy(vlan
->ifname
, pos
, sizeof(vlan
->ifname
));
104 bss
->vlan_tail
->next
= vlan
;
107 bss
->vlan_tail
= vlan
;
116 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
118 struct hostapd_vlan
*vlan
, *prev
;
132 /* convert floats with one decimal place to value*10 int, i.e.,
133 * "1.5" will return 15 */
134 static int hostapd_config_read_int10(const char *value
)
140 pos
= os_strchr(value
, '.');
144 if (*pos
>= '0' && *pos
<= '9')
152 static void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
154 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
155 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
156 bss
->logger_syslog
= (unsigned int) -1;
157 bss
->logger_stdout
= (unsigned int) -1;
159 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
161 bss
->wep_rekeying_period
= 300;
162 /* use key0 in individual key and key1 in broadcast key */
163 bss
->broadcast_key_idx_min
= 1;
164 bss
->broadcast_key_idx_max
= 2;
165 bss
->eap_reauth_period
= 3600;
167 bss
->wpa_group_rekey
= 600;
168 bss
->wpa_gmk_rekey
= 86400;
169 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
170 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
171 bss
->wpa_group
= WPA_CIPHER_TKIP
;
172 bss
->rsn_pairwise
= 0;
174 bss
->max_num_sta
= MAX_STA_COUNT
;
176 bss
->dtim_period
= 2;
178 bss
->radius_server_auth_port
= 1812;
179 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
180 bss
->eapol_version
= EAPOL_VERSION
;
184 static struct hostapd_config
* hostapd_config_defaults(void)
186 struct hostapd_config
*conf
;
187 struct hostapd_bss_config
*bss
;
189 const int aCWmin
= 15, aCWmax
= 1024;
190 const struct hostapd_wme_ac_params ac_bk
=
191 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
192 const struct hostapd_wme_ac_params ac_be
=
193 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
194 const struct hostapd_wme_ac_params ac_vi
= /* video traffic */
195 { aCWmin
>> 1, aCWmin
, 2, 3000 / 32, 1 };
196 const struct hostapd_wme_ac_params ac_vo
= /* voice traffic */
197 { aCWmin
>> 2, aCWmin
>> 1, 2, 1500 / 32, 1 };
199 conf
= os_zalloc(sizeof(*conf
));
200 bss
= os_zalloc(sizeof(*bss
));
201 if (conf
== NULL
|| bss
== NULL
) {
202 printf("Failed to allocate memory for configuration data.\n");
208 /* set default driver based on configuration */
209 conf
->driver
= hostapd_drivers
[0];
210 if (conf
->driver
== NULL
) {
211 printf("No driver wrappers registered!\n");
217 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
218 if (bss
->radius
== NULL
) {
224 hostapd_config_defaults_bss(bss
);
229 conf
->beacon_int
= 100;
230 conf
->rts_threshold
= -1; /* use driver default: 2347 */
231 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
232 conf
->send_probe_response
= 1;
233 conf
->bridge_packets
= INTERNAL_BRIDGE_DO_NOT_CONTROL
;
235 os_memcpy(conf
->country
, "US ", 3);
237 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
238 conf
->tx_queue
[i
].aifs
= -1; /* use hw default */
240 conf
->wme_ac_params
[0] = ac_be
;
241 conf
->wme_ac_params
[1] = ac_bk
;
242 conf
->wme_ac_params
[2] = ac_vi
;
243 conf
->wme_ac_params
[3] = ac_vo
;
249 int hostapd_mac_comp(const void *a
, const void *b
)
251 return os_memcmp(a
, b
, sizeof(macaddr
));
255 int hostapd_mac_comp_empty(const void *a
)
257 macaddr empty
= { 0 };
258 return os_memcmp(a
, empty
, sizeof(macaddr
));
262 static int hostapd_config_read_maclist(const char *fname
, macaddr
**acl
,
274 f
= fopen(fname
, "r");
276 printf("MAC list file '%s' not found.\n", fname
);
280 while (fgets(buf
, sizeof(buf
), f
)) {
286 while (*pos
!= '\0') {
296 if (hwaddr_aton(buf
, addr
)) {
297 printf("Invalid MAC address '%s' at line %d in '%s'\n",
303 newacl
= os_realloc(*acl
, (*num
+ 1) * ETH_ALEN
);
304 if (newacl
== NULL
) {
305 printf("MAC list reallocation failed\n");
311 os_memcpy((*acl
)[*num
], addr
, ETH_ALEN
);
317 qsort(*acl
, *num
, sizeof(macaddr
), hostapd_mac_comp
);
323 static int hostapd_config_read_wpa_psk(const char *fname
,
324 struct hostapd_ssid
*ssid
)
328 int line
= 0, ret
= 0, len
, ok
;
330 struct hostapd_wpa_psk
*psk
;
335 f
= fopen(fname
, "r");
337 printf("WPA PSK file '%s' not found.\n", fname
);
341 while (fgets(buf
, sizeof(buf
), f
)) {
347 while (*pos
!= '\0') {
357 if (hwaddr_aton(buf
, addr
)) {
358 printf("Invalid MAC address '%s' on line %d in '%s'\n",
364 psk
= os_zalloc(sizeof(*psk
));
366 printf("WPA PSK allocation failed\n");
370 if (os_memcmp(addr
, "\x00\x00\x00\x00\x00\x00", ETH_ALEN
) == 0)
373 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
377 printf("No PSK on line %d in '%s'\n", line
, fname
);
385 len
= os_strlen(pos
);
386 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
388 else if (len
>= 8 && len
< 64) {
389 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
390 4096, psk
->psk
, PMK_LEN
);
394 printf("Invalid PSK '%s' on line %d in '%s'\n",
401 psk
->next
= ssid
->wpa_psk
;
411 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
413 struct hostapd_ssid
*ssid
= &conf
->ssid
;
415 if (ssid
->wpa_passphrase
!= NULL
) {
416 if (ssid
->wpa_psk
!= NULL
) {
417 printf("Warning: both WPA PSK and passphrase set. "
418 "Using passphrase.\n");
419 os_free(ssid
->wpa_psk
);
421 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
422 if (ssid
->wpa_psk
== NULL
) {
423 printf("Unable to alloc space for PSK\n");
426 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
427 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
428 wpa_hexdump_ascii(MSG_DEBUG
, "PSK (ASCII passphrase)",
429 (u8
*) ssid
->wpa_passphrase
,
430 os_strlen(ssid
->wpa_passphrase
));
431 pbkdf2_sha1(ssid
->wpa_passphrase
,
432 ssid
->ssid
, ssid
->ssid_len
,
433 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
434 wpa_hexdump(MSG_DEBUG
, "PSK (from passphrase)",
435 ssid
->wpa_psk
->psk
, PMK_LEN
);
436 ssid
->wpa_psk
->group
= 1;
438 os_memset(ssid
->wpa_passphrase
, 0,
439 os_strlen(ssid
->wpa_passphrase
));
440 os_free(ssid
->wpa_passphrase
);
441 ssid
->wpa_passphrase
= NULL
;
444 if (ssid
->wpa_psk_file
) {
445 if (hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
,
455 static int hostapd_config_read_eap_user(const char *fname
,
456 struct hostapd_bss_config
*conf
)
459 char buf
[512], *pos
, *start
, *pos2
;
460 int line
= 0, ret
= 0, num_methods
;
461 struct hostapd_eap_user
*user
, *tail
= NULL
;
466 f
= fopen(fname
, "r");
468 printf("EAP user file '%s' not found.\n", fname
);
472 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
473 while (fgets(buf
, sizeof(buf
), f
)) {
479 while (*pos
!= '\0') {
491 if (buf
[0] != '"' && buf
[0] != '*') {
492 printf("Invalid EAP identity (no \" in start) on "
493 "line %d in '%s'\n", line
, fname
);
497 user
= os_zalloc(sizeof(*user
));
499 printf("EAP user allocation failed\n");
502 user
->force_version
= -1;
509 while (*pos
!= '"' && *pos
!= '\0')
512 printf("Invalid EAP identity (no \" in end) on"
513 " line %d in '%s'\n", line
, fname
);
517 user
->identity
= os_malloc(pos
- start
);
518 if (user
->identity
== NULL
) {
519 printf("Failed to allocate memory for EAP "
523 os_memcpy(user
->identity
, start
, pos
- start
);
524 user
->identity_len
= pos
- start
;
526 if (pos
[0] == '"' && pos
[1] == '*') {
527 user
->wildcard_prefix
= 1;
532 while (*pos
== ' ' || *pos
== '\t')
536 printf("No EAP method on line %d in '%s'\n",
542 while (*pos
!= ' ' && *pos
!= '\t' && *pos
!= '\0')
552 char *pos3
= os_strchr(start
, ',');
556 user
->methods
[num_methods
].method
=
559 &user
->methods
[num_methods
].vendor
);
560 if (user
->methods
[num_methods
].vendor
==
562 user
->methods
[num_methods
].method
== EAP_TYPE_NONE
)
564 if (os_strcmp(start
, "TTLS-PAP") == 0) {
565 user
->ttls_auth
|= EAP_TTLS_AUTH_PAP
;
568 if (os_strcmp(start
, "TTLS-CHAP") == 0) {
569 user
->ttls_auth
|= EAP_TTLS_AUTH_CHAP
;
572 if (os_strcmp(start
, "TTLS-MSCHAP") == 0) {
574 EAP_TTLS_AUTH_MSCHAP
;
577 if (os_strcmp(start
, "TTLS-MSCHAPV2") == 0) {
579 EAP_TTLS_AUTH_MSCHAPV2
;
582 printf("Unsupported EAP type '%s' on line %d "
583 "in '%s'\n", start
, line
, fname
);
588 if (num_methods
>= EAP_USER_MAX_METHODS
)
595 if (num_methods
== 0 && user
->ttls_auth
== 0) {
596 printf("No EAP types configured on line %d in '%s'\n",
604 while (*pos
== ' ' || *pos
== '\t')
609 if (os_strncmp(pos
, "[ver=0]", 7) == 0) {
610 user
->force_version
= 0;
614 if (os_strncmp(pos
, "[ver=1]", 7) == 0) {
615 user
->force_version
= 1;
619 if (os_strncmp(pos
, "[2]", 3) == 0) {
627 while (*pos
!= '"' && *pos
!= '\0')
630 printf("Invalid EAP password (no \" in end) "
631 "on line %d in '%s'\n", line
, fname
);
635 user
->password
= os_malloc(pos
- start
);
636 if (user
->password
== NULL
) {
637 printf("Failed to allocate memory for EAP "
641 os_memcpy(user
->password
, start
, pos
- start
);
642 user
->password_len
= pos
- start
;
645 } else if (os_strncmp(pos
, "hash:", 5) == 0) {
648 while (*pos2
!= '\0' && *pos2
!= ' ' &&
649 *pos2
!= '\t' && *pos2
!= '#')
651 if (pos2
- pos
!= 32) {
652 printf("Invalid password hash on line %d in "
653 "'%s'\n", line
, fname
);
656 user
->password
= os_malloc(16);
657 if (user
->password
== NULL
) {
658 printf("Failed to allocate memory for EAP "
662 if (hexstr2bin(pos
, user
->password
, 16) < 0) {
663 printf("Invalid hash password on line %d in "
664 "'%s'\n", line
, fname
);
667 user
->password_len
= 16;
668 user
->password_hash
= 1;
672 while (*pos2
!= '\0' && *pos2
!= ' ' &&
673 *pos2
!= '\t' && *pos2
!= '#')
675 if ((pos2
- pos
) & 1) {
676 printf("Invalid hex password on line %d in "
677 "'%s'\n", line
, fname
);
680 user
->password
= os_malloc((pos2
- pos
) / 2);
681 if (user
->password
== NULL
) {
682 printf("Failed to allocate memory for EAP "
686 if (hexstr2bin(pos
, user
->password
,
687 (pos2
- pos
) / 2) < 0) {
688 printf("Invalid hex password on line %d in "
689 "'%s'\n", line
, fname
);
692 user
->password_len
= (pos2
- pos
) / 2;
696 while (*pos
== ' ' || *pos
== '\t')
698 if (os_strncmp(pos
, "[2]", 3) == 0) {
704 tail
= conf
->eap_user
= user
;
713 os_free(user
->password
);
714 os_free(user
->identity
);
725 #endif /* EAP_SERVER */
729 hostapd_config_read_radius_addr(struct hostapd_radius_server
**server
,
730 int *num_server
, const char *val
, int def_port
,
731 struct hostapd_radius_server
**curr_serv
)
733 struct hostapd_radius_server
*nserv
;
735 static int server_index
= 1;
737 nserv
= os_realloc(*server
, (*num_server
+ 1) * sizeof(*nserv
));
742 nserv
= &nserv
[*num_server
];
744 (*curr_serv
) = nserv
;
746 os_memset(nserv
, 0, sizeof(*nserv
));
747 nserv
->port
= def_port
;
748 ret
= hostapd_parse_ip_addr(val
, &nserv
->addr
);
749 nserv
->index
= server_index
++;
755 static int hostapd_config_parse_key_mgmt(int line
, const char *value
)
758 char *start
, *end
, *buf
;
760 buf
= os_strdup(value
);
765 while (start
!= '\0') {
766 while (*start
== ' ' || *start
== '\t')
771 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
775 if (os_strcmp(start
, "WPA-PSK") == 0)
776 val
|= WPA_KEY_MGMT_PSK
;
777 else if (os_strcmp(start
, "WPA-EAP") == 0)
778 val
|= WPA_KEY_MGMT_IEEE8021X
;
779 #ifdef CONFIG_IEEE80211R
780 else if (os_strcmp(start
, "FT-PSK") == 0)
781 val
|= WPA_KEY_MGMT_FT_PSK
;
782 else if (os_strcmp(start
, "FT-EAP") == 0)
783 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
784 #endif /* CONFIG_IEEE80211R */
786 printf("Line %d: invalid key_mgmt '%s'\n",
799 printf("Line %d: no key_mgmt values configured.\n", line
);
807 static int hostapd_config_parse_cipher(int line
, const char *value
)
810 char *start
, *end
, *buf
;
812 buf
= os_strdup(value
);
817 while (start
!= '\0') {
818 while (*start
== ' ' || *start
== '\t')
823 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
827 if (os_strcmp(start
, "CCMP") == 0)
828 val
|= WPA_CIPHER_CCMP
;
829 else if (os_strcmp(start
, "TKIP") == 0)
830 val
|= WPA_CIPHER_TKIP
;
831 else if (os_strcmp(start
, "WEP104") == 0)
832 val
|= WPA_CIPHER_WEP104
;
833 else if (os_strcmp(start
, "WEP40") == 0)
834 val
|= WPA_CIPHER_WEP40
;
835 else if (os_strcmp(start
, "NONE") == 0)
836 val
|= WPA_CIPHER_NONE
;
838 printf("Line %d: invalid cipher '%s'.", line
, start
);
850 printf("Line %d: no cipher values configured.", line
);
857 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
858 struct hostapd_config
*conf
)
860 if (bss
->ieee802_1x
&& !bss
->eap_server
&&
861 !bss
->radius
->auth_servers
) {
862 printf("Invalid IEEE 802.1X configuration (no EAP "
863 "authenticator configured).\n");
867 if (bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
868 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
869 bss
->ssid
.wpa_psk_file
== NULL
) {
870 printf("WPA-PSK enabled, but PSK or passphrase is not "
875 if (hostapd_mac_comp_empty(bss
->bssid
) != 0) {
878 for (i
= 0; i
< conf
->num_bss
; i
++) {
879 if ((&conf
->bss
[i
] != bss
) &&
880 (hostapd_mac_comp(conf
->bss
[i
].bssid
,
882 printf("Duplicate BSSID " MACSTR
883 " on interface '%s' and '%s'.\n",
885 conf
->bss
[i
].iface
, bss
->iface
);
891 #ifdef CONFIG_IEEE80211R
892 if ((bss
->wpa_key_mgmt
&
893 (WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
)) &&
894 (bss
->nas_identifier
== NULL
||
895 os_strlen(bss
->nas_identifier
) < 1 ||
896 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
897 printf("FT (IEEE 802.11r) requires nas_identifier to be "
898 "configured as a 1..48 octet string\n");
901 #endif /* CONFIG_IEEE80211R */
907 static int hostapd_config_check(struct hostapd_config
*conf
)
911 for (i
= 0; i
< conf
->num_bss
; i
++) {
912 if (hostapd_config_check_bss(&conf
->bss
[i
], conf
))
920 static int hostapd_config_read_wep(struct hostapd_wep_keys
*wep
, int keyidx
,
923 size_t len
= os_strlen(val
);
925 if (keyidx
< 0 || keyidx
> 3 || wep
->key
[keyidx
] != NULL
)
929 if (len
< 2 || val
[len
- 1] != '"')
932 wep
->key
[keyidx
] = os_malloc(len
);
933 if (wep
->key
[keyidx
] == NULL
)
935 os_memcpy(wep
->key
[keyidx
], val
+ 1, len
);
936 wep
->len
[keyidx
] = len
;
941 wep
->key
[keyidx
] = os_malloc(len
);
942 if (wep
->key
[keyidx
] == NULL
)
944 wep
->len
[keyidx
] = len
;
945 if (hexstr2bin(val
, wep
->key
[keyidx
], len
) < 0)
955 static int hostapd_parse_rates(int **rate_list
, char *val
)
966 while (*pos
!= '\0') {
972 list
= os_malloc(sizeof(int) * (count
+ 2));
977 while (*pos
!= '\0') {
978 end
= os_strchr(pos
, ' ');
982 list
[count
++] = atoi(pos
);
994 static int hostapd_config_bss(struct hostapd_config
*conf
, const char *ifname
)
996 struct hostapd_bss_config
*bss
;
1001 bss
= os_realloc(conf
->bss
, (conf
->num_bss
+ 1) *
1002 sizeof(struct hostapd_bss_config
));
1004 printf("Failed to allocate memory for multi-BSS entry\n");
1009 bss
= &(conf
->bss
[conf
->num_bss
]);
1010 os_memset(bss
, 0, sizeof(*bss
));
1011 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
1012 if (bss
->radius
== NULL
) {
1013 printf("Failed to allocate memory for multi-BSS RADIUS "
1019 conf
->last_bss
= bss
;
1021 hostapd_config_defaults_bss(bss
);
1022 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1023 os_memcpy(bss
->ssid
.vlan
, bss
->iface
, IFNAMSIZ
+ 1);
1029 static int valid_cw(int cw
)
1031 return (cw
== 1 || cw
== 3 || cw
== 7 || cw
== 15 || cw
== 31 ||
1032 cw
== 63 || cw
== 127 || cw
== 255 || cw
== 511 || cw
== 1023);
1037 IEEE80211_TX_QUEUE_DATA0
= 0, /* used for EDCA AC_VO data */
1038 IEEE80211_TX_QUEUE_DATA1
= 1, /* used for EDCA AC_VI data */
1039 IEEE80211_TX_QUEUE_DATA2
= 2, /* used for EDCA AC_BE data */
1040 IEEE80211_TX_QUEUE_DATA3
= 3, /* used for EDCA AC_BK data */
1041 IEEE80211_TX_QUEUE_DATA4
= 4,
1042 IEEE80211_TX_QUEUE_AFTER_BEACON
= 6,
1043 IEEE80211_TX_QUEUE_BEACON
= 7
1046 static int hostapd_config_tx_queue(struct hostapd_config
*conf
, char *name
,
1051 struct hostapd_tx_queue_params
*queue
;
1053 /* skip 'tx_queue_' prefix */
1055 if (os_strncmp(pos
, "data", 4) == 0 &&
1056 pos
[4] >= '0' && pos
[4] <= '9' && pos
[5] == '_') {
1059 } else if (os_strncmp(pos
, "after_beacon_", 13) == 0) {
1060 num
= IEEE80211_TX_QUEUE_AFTER_BEACON
;
1062 } else if (os_strncmp(pos
, "beacon_", 7) == 0) {
1063 num
= IEEE80211_TX_QUEUE_BEACON
;
1066 printf("Unknown tx_queue name '%s'\n", pos
);
1070 queue
= &conf
->tx_queue
[num
];
1072 if (os_strcmp(pos
, "aifs") == 0) {
1073 queue
->aifs
= atoi(val
);
1074 if (queue
->aifs
< 0 || queue
->aifs
> 255) {
1075 printf("Invalid AIFS value %d\n", queue
->aifs
);
1078 } else if (os_strcmp(pos
, "cwmin") == 0) {
1079 queue
->cwmin
= atoi(val
);
1080 if (!valid_cw(queue
->cwmin
)) {
1081 printf("Invalid cwMin value %d\n", queue
->cwmin
);
1084 } else if (os_strcmp(pos
, "cwmax") == 0) {
1085 queue
->cwmax
= atoi(val
);
1086 if (!valid_cw(queue
->cwmax
)) {
1087 printf("Invalid cwMax value %d\n", queue
->cwmax
);
1090 } else if (os_strcmp(pos
, "burst") == 0) {
1091 queue
->burst
= hostapd_config_read_int10(val
);
1093 printf("Unknown tx_queue field '%s'\n", pos
);
1097 queue
->configured
= 1;
1103 static int hostapd_config_wme_ac(struct hostapd_config
*conf
, char *name
,
1108 struct hostapd_wme_ac_params
*ac
;
1110 /* skip 'wme_ac_' prefix */
1112 if (os_strncmp(pos
, "be_", 3) == 0) {
1115 } else if (os_strncmp(pos
, "bk_", 3) == 0) {
1118 } else if (os_strncmp(pos
, "vi_", 3) == 0) {
1121 } else if (os_strncmp(pos
, "vo_", 3) == 0) {
1125 printf("Unknown wme name '%s'\n", pos
);
1129 ac
= &conf
->wme_ac_params
[num
];
1131 if (os_strcmp(pos
, "aifs") == 0) {
1133 if (v
< 1 || v
> 255) {
1134 printf("Invalid AIFS value %d\n", v
);
1138 } else if (os_strcmp(pos
, "cwmin") == 0) {
1140 if (v
< 0 || v
> 12) {
1141 printf("Invalid cwMin value %d\n", v
);
1145 } else if (os_strcmp(pos
, "cwmax") == 0) {
1147 if (v
< 0 || v
> 12) {
1148 printf("Invalid cwMax value %d\n", v
);
1152 } else if (os_strcmp(pos
, "txop_limit") == 0) {
1154 if (v
< 0 || v
> 0xffff) {
1155 printf("Invalid txop value %d\n", v
);
1159 } else if (os_strcmp(pos
, "acm") == 0) {
1161 if (v
< 0 || v
> 1) {
1162 printf("Invalid acm value %d\n", v
);
1165 ac
->admission_control_mandatory
= v
;
1167 printf("Unknown wme_ac_ field '%s'\n", pos
);
1175 #ifdef CONFIG_IEEE80211R
1176 static int add_r0kh(struct hostapd_bss_config
*bss
, char *value
)
1178 struct ft_remote_r0kh
*r0kh
;
1181 r0kh
= os_zalloc(sizeof(*r0kh
));
1185 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1187 next
= os_strchr(pos
, ' ');
1190 if (next
== NULL
|| hwaddr_aton(pos
, r0kh
->addr
)) {
1191 printf("Invalid R0KH MAC address: '%s'\n", pos
);
1197 next
= os_strchr(pos
, ' ');
1200 if (next
== NULL
|| next
- pos
> FT_R0KH_ID_MAX_LEN
) {
1201 printf("Invalid R0KH-ID: '%s'\n", pos
);
1205 r0kh
->id_len
= next
- pos
- 1;
1206 os_memcpy(r0kh
->id
, pos
, r0kh
->id_len
);
1209 if (hexstr2bin(pos
, r0kh
->key
, sizeof(r0kh
->key
))) {
1210 printf("Invalid R0KH key: '%s'\n", pos
);
1215 r0kh
->next
= bss
->r0kh_list
;
1216 bss
->r0kh_list
= r0kh
;
1222 static int add_r1kh(struct hostapd_bss_config
*bss
, char *value
)
1224 struct ft_remote_r1kh
*r1kh
;
1227 r1kh
= os_zalloc(sizeof(*r1kh
));
1231 /* 02:01:02:03:04:05 02:01:02:03:04:05
1232 * 000102030405060708090a0b0c0d0e0f */
1234 next
= os_strchr(pos
, ' ');
1237 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->addr
)) {
1238 printf("Invalid R1KH MAC address: '%s'\n", pos
);
1244 next
= os_strchr(pos
, ' ');
1247 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->id
)) {
1248 printf("Invalid R1KH-ID: '%s'\n", pos
);
1254 if (hexstr2bin(pos
, r1kh
->key
, sizeof(r1kh
->key
))) {
1255 printf("Invalid R1KH key: '%s'\n", pos
);
1260 r1kh
->next
= bss
->r1kh_list
;
1261 bss
->r1kh_list
= r1kh
;
1265 #endif /* CONFIG_IEEE80211R */
1268 struct hostapd_config
* hostapd_config_read(const char *fname
)
1270 struct hostapd_config
*conf
;
1271 struct hostapd_bss_config
*bss
;
1273 char buf
[256], *pos
;
1279 f
= fopen(fname
, "r");
1281 printf("Could not open configuration file '%s' for reading.\n",
1286 conf
= hostapd_config_defaults();
1291 bss
= conf
->last_bss
= conf
->bss
;
1293 while (fgets(buf
, sizeof(buf
), f
)) {
1294 bss
= conf
->last_bss
;
1300 while (*pos
!= '\0') {
1310 pos
= os_strchr(buf
, '=');
1312 printf("Line %d: invalid line '%s'\n", line
, buf
);
1319 if (os_strcmp(buf
, "interface") == 0) {
1320 os_strlcpy(conf
->bss
[0].iface
, pos
,
1321 sizeof(conf
->bss
[0].iface
));
1322 } else if (os_strcmp(buf
, "bridge") == 0) {
1323 os_strlcpy(bss
->bridge
, pos
, sizeof(bss
->bridge
));
1324 } else if (os_strcmp(buf
, "driver") == 0) {
1326 /* clear to get error below if setting is invalid */
1327 conf
->driver
= NULL
;
1328 for (i
= 0; hostapd_drivers
[i
]; i
++) {
1329 if (os_strcmp(pos
, hostapd_drivers
[i
]->name
) ==
1331 conf
->driver
= hostapd_drivers
[i
];
1335 if (conf
->driver
== NULL
) {
1336 printf("Line %d: invalid/unknown driver "
1337 "'%s'\n", line
, pos
);
1340 } else if (os_strcmp(buf
, "debug") == 0) {
1341 wpa_printf(MSG_DEBUG
, "Line %d: DEPRECATED: 'debug' "
1342 "configuration variable is not used "
1344 } else if (os_strcmp(buf
, "logger_syslog_level") == 0) {
1345 bss
->logger_syslog_level
= atoi(pos
);
1346 } else if (os_strcmp(buf
, "logger_stdout_level") == 0) {
1347 bss
->logger_stdout_level
= atoi(pos
);
1348 } else if (os_strcmp(buf
, "logger_syslog") == 0) {
1349 bss
->logger_syslog
= atoi(pos
);
1350 } else if (os_strcmp(buf
, "logger_stdout") == 0) {
1351 bss
->logger_stdout
= atoi(pos
);
1352 } else if (os_strcmp(buf
, "dump_file") == 0) {
1353 bss
->dump_log_name
= os_strdup(pos
);
1354 } else if (os_strcmp(buf
, "ssid") == 0) {
1355 bss
->ssid
.ssid_len
= os_strlen(pos
);
1356 if (bss
->ssid
.ssid_len
> HOSTAPD_MAX_SSID_LEN
||
1357 bss
->ssid
.ssid_len
< 1) {
1358 printf("Line %d: invalid SSID '%s'\n", line
,
1362 os_memcpy(bss
->ssid
.ssid
, pos
,
1363 bss
->ssid
.ssid_len
);
1364 bss
->ssid
.ssid
[bss
->ssid
.ssid_len
] = '\0';
1365 bss
->ssid
.ssid_set
= 1;
1367 } else if (os_strcmp(buf
, "macaddr_acl") == 0) {
1368 bss
->macaddr_acl
= atoi(pos
);
1369 if (bss
->macaddr_acl
!= ACCEPT_UNLESS_DENIED
&&
1370 bss
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
&&
1371 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1372 printf("Line %d: unknown macaddr_acl %d\n",
1373 line
, bss
->macaddr_acl
);
1375 } else if (os_strcmp(buf
, "accept_mac_file") == 0) {
1376 if (hostapd_config_read_maclist(pos
, &bss
->accept_mac
,
1377 &bss
->num_accept_mac
))
1379 printf("Line %d: Failed to read "
1380 "accept_mac_file '%s'\n",
1384 } else if (os_strcmp(buf
, "deny_mac_file") == 0) {
1385 if (hostapd_config_read_maclist(pos
, &bss
->deny_mac
,
1386 &bss
->num_deny_mac
))
1388 printf("Line %d: Failed to read "
1389 "deny_mac_file '%s'\n",
1393 } else if (os_strcmp(buf
, "ap_max_inactivity") == 0) {
1394 bss
->ap_max_inactivity
= atoi(pos
);
1395 } else if (os_strcmp(buf
, "country_code") == 0) {
1396 os_memcpy(conf
->country
, pos
, 2);
1397 /* FIX: make this configurable */
1398 conf
->country
[2] = ' ';
1399 } else if (os_strcmp(buf
, "ieee80211d") == 0) {
1400 conf
->ieee80211d
= atoi(pos
);
1401 } else if (os_strcmp(buf
, "ieee80211h") == 0) {
1402 conf
->ieee80211h
= atoi(pos
);
1403 } else if (os_strcmp(buf
, "assoc_ap_addr") == 0) {
1404 if (hwaddr_aton(pos
, bss
->assoc_ap_addr
)) {
1405 printf("Line %d: invalid MAC address '%s'\n",
1410 } else if (os_strcmp(buf
, "ieee8021x") == 0) {
1411 bss
->ieee802_1x
= atoi(pos
);
1412 } else if (os_strcmp(buf
, "eapol_version") == 0) {
1413 bss
->eapol_version
= atoi(pos
);
1414 if (bss
->eapol_version
< 1 ||
1415 bss
->eapol_version
> 2) {
1416 printf("Line %d: invalid EAPOL "
1417 "version (%d): '%s'.\n",
1418 line
, bss
->eapol_version
, pos
);
1421 wpa_printf(MSG_DEBUG
, "eapol_version=%d",
1422 bss
->eapol_version
);
1424 } else if (os_strcmp(buf
, "eap_authenticator") == 0) {
1425 bss
->eap_server
= atoi(pos
);
1426 printf("Line %d: obsolete eap_authenticator used; "
1427 "this has been renamed to eap_server\n", line
);
1428 } else if (os_strcmp(buf
, "eap_server") == 0) {
1429 bss
->eap_server
= atoi(pos
);
1430 } else if (os_strcmp(buf
, "eap_user_file") == 0) {
1431 if (hostapd_config_read_eap_user(pos
, bss
))
1433 } else if (os_strcmp(buf
, "ca_cert") == 0) {
1434 os_free(bss
->ca_cert
);
1435 bss
->ca_cert
= os_strdup(pos
);
1436 } else if (os_strcmp(buf
, "server_cert") == 0) {
1437 os_free(bss
->server_cert
);
1438 bss
->server_cert
= os_strdup(pos
);
1439 } else if (os_strcmp(buf
, "private_key") == 0) {
1440 os_free(bss
->private_key
);
1441 bss
->private_key
= os_strdup(pos
);
1442 } else if (os_strcmp(buf
, "private_key_passwd") == 0) {
1443 os_free(bss
->private_key_passwd
);
1444 bss
->private_key_passwd
= os_strdup(pos
);
1445 } else if (os_strcmp(buf
, "check_crl") == 0) {
1446 bss
->check_crl
= atoi(pos
);
1447 } else if (os_strcmp(buf
, "dh_file") == 0) {
1448 os_free(bss
->dh_file
);
1449 bss
->dh_file
= os_strdup(pos
);
1451 } else if (os_strcmp(buf
, "pac_opaque_encr_key") == 0) {
1452 os_free(bss
->pac_opaque_encr_key
);
1453 bss
->pac_opaque_encr_key
= os_malloc(16);
1454 if (bss
->pac_opaque_encr_key
== NULL
) {
1455 printf("Line %d: No memory for "
1456 "pac_opque_encr_key\n", line
);
1458 } else if (hexstr2bin(pos
, bss
->pac_opaque_encr_key
,
1460 printf("Line %d: Invalid pac_opque_encr_key\n",
1464 } else if (os_strcmp(buf
, "eap_fast_a_id") == 0) {
1465 os_free(bss
->eap_fast_a_id
);
1466 bss
->eap_fast_a_id
= os_strdup(pos
);
1467 #endif /* EAP_FAST */
1469 } else if (os_strcmp(buf
, "eap_sim_db") == 0) {
1470 os_free(bss
->eap_sim_db
);
1471 bss
->eap_sim_db
= os_strdup(pos
);
1472 } else if (os_strcmp(buf
, "eap_sim_aka_result_ind") == 0) {
1473 bss
->eap_sim_aka_result_ind
= atoi(pos
);
1474 #endif /* EAP_SIM */
1475 #endif /* EAP_SERVER */
1476 } else if (os_strcmp(buf
, "eap_message") == 0) {
1478 bss
->eap_req_id_text
= os_strdup(pos
);
1479 if (bss
->eap_req_id_text
== NULL
) {
1480 printf("Line %d: Failed to allocate memory "
1481 "for eap_req_id_text\n", line
);
1485 bss
->eap_req_id_text_len
=
1486 os_strlen(bss
->eap_req_id_text
);
1487 term
= os_strstr(bss
->eap_req_id_text
, "\\0");
1490 os_memmove(term
, term
+ 1,
1491 bss
->eap_req_id_text_len
-
1492 (term
- bss
->eap_req_id_text
) - 1);
1493 bss
->eap_req_id_text_len
--;
1495 } else if (os_strcmp(buf
, "wep_key_len_broadcast") == 0) {
1496 bss
->default_wep_key_len
= atoi(pos
);
1497 if (bss
->default_wep_key_len
> 13) {
1498 printf("Line %d: invalid WEP key len %lu "
1499 "(= %lu bits)\n", line
,
1501 bss
->default_wep_key_len
,
1503 bss
->default_wep_key_len
* 8);
1506 } else if (os_strcmp(buf
, "wep_key_len_unicast") == 0) {
1507 bss
->individual_wep_key_len
= atoi(pos
);
1508 if (bss
->individual_wep_key_len
< 0 ||
1509 bss
->individual_wep_key_len
> 13) {
1510 printf("Line %d: invalid WEP key len %d "
1511 "(= %d bits)\n", line
,
1512 bss
->individual_wep_key_len
,
1513 bss
->individual_wep_key_len
* 8);
1516 } else if (os_strcmp(buf
, "wep_rekey_period") == 0) {
1517 bss
->wep_rekeying_period
= atoi(pos
);
1518 if (bss
->wep_rekeying_period
< 0) {
1519 printf("Line %d: invalid period %d\n",
1520 line
, bss
->wep_rekeying_period
);
1523 } else if (os_strcmp(buf
, "eap_reauth_period") == 0) {
1524 bss
->eap_reauth_period
= atoi(pos
);
1525 if (bss
->eap_reauth_period
< 0) {
1526 printf("Line %d: invalid period %d\n",
1527 line
, bss
->eap_reauth_period
);
1530 } else if (os_strcmp(buf
, "eapol_key_index_workaround") == 0) {
1531 bss
->eapol_key_index_workaround
= atoi(pos
);
1533 } else if (os_strcmp(buf
, "iapp_interface") == 0) {
1534 bss
->ieee802_11f
= 1;
1535 os_strlcpy(bss
->iapp_iface
, pos
,
1536 sizeof(bss
->iapp_iface
));
1537 #endif /* CONFIG_IAPP */
1538 } else if (os_strcmp(buf
, "own_ip_addr") == 0) {
1539 if (hostapd_parse_ip_addr(pos
, &bss
->own_ip_addr
)) {
1540 printf("Line %d: invalid IP address '%s'\n",
1544 } else if (os_strcmp(buf
, "nas_identifier") == 0) {
1545 bss
->nas_identifier
= os_strdup(pos
);
1546 } else if (os_strcmp(buf
, "auth_server_addr") == 0) {
1547 if (hostapd_config_read_radius_addr(
1548 &bss
->radius
->auth_servers
,
1549 &bss
->radius
->num_auth_servers
, pos
, 1812,
1550 &bss
->radius
->auth_server
)) {
1551 printf("Line %d: invalid IP address '%s'\n",
1555 } else if (bss
->radius
->auth_server
&&
1556 os_strcmp(buf
, "auth_server_port") == 0) {
1557 bss
->radius
->auth_server
->port
= atoi(pos
);
1558 } else if (bss
->radius
->auth_server
&&
1559 os_strcmp(buf
, "auth_server_shared_secret") == 0) {
1560 int len
= os_strlen(pos
);
1562 /* RFC 2865, Ch. 3 */
1563 printf("Line %d: empty shared secret is not "
1564 "allowed.\n", line
);
1567 bss
->radius
->auth_server
->shared_secret
=
1568 (u8
*) os_strdup(pos
);
1569 bss
->radius
->auth_server
->shared_secret_len
= len
;
1570 } else if (os_strcmp(buf
, "acct_server_addr") == 0) {
1571 if (hostapd_config_read_radius_addr(
1572 &bss
->radius
->acct_servers
,
1573 &bss
->radius
->num_acct_servers
, pos
, 1813,
1574 &bss
->radius
->acct_server
)) {
1575 printf("Line %d: invalid IP address '%s'\n",
1579 } else if (bss
->radius
->acct_server
&&
1580 os_strcmp(buf
, "acct_server_port") == 0) {
1581 bss
->radius
->acct_server
->port
= atoi(pos
);
1582 } else if (bss
->radius
->acct_server
&&
1583 os_strcmp(buf
, "acct_server_shared_secret") == 0) {
1584 int len
= os_strlen(pos
);
1586 /* RFC 2865, Ch. 3 */
1587 printf("Line %d: empty shared secret is not "
1588 "allowed.\n", line
);
1591 bss
->radius
->acct_server
->shared_secret
=
1592 (u8
*) os_strdup(pos
);
1593 bss
->radius
->acct_server
->shared_secret_len
= len
;
1594 } else if (os_strcmp(buf
, "radius_retry_primary_interval") ==
1596 bss
->radius
->retry_primary_interval
= atoi(pos
);
1597 } else if (os_strcmp(buf
, "radius_acct_interim_interval") == 0)
1599 bss
->radius
->acct_interim_interval
= atoi(pos
);
1600 } else if (os_strcmp(buf
, "auth_algs") == 0) {
1601 bss
->auth_algs
= atoi(pos
);
1602 if (bss
->auth_algs
== 0) {
1603 printf("Line %d: no authentication algorithms "
1608 } else if (os_strcmp(buf
, "max_num_sta") == 0) {
1609 bss
->max_num_sta
= atoi(pos
);
1610 if (bss
->max_num_sta
< 0 ||
1611 bss
->max_num_sta
> MAX_STA_COUNT
) {
1612 printf("Line %d: Invalid max_num_sta=%d; "
1613 "allowed range 0..%d\n", line
,
1614 bss
->max_num_sta
, MAX_STA_COUNT
);
1617 } else if (os_strcmp(buf
, "wpa") == 0) {
1618 bss
->wpa
= atoi(pos
);
1619 } else if (os_strcmp(buf
, "wpa_group_rekey") == 0) {
1620 bss
->wpa_group_rekey
= atoi(pos
);
1621 } else if (os_strcmp(buf
, "wpa_strict_rekey") == 0) {
1622 bss
->wpa_strict_rekey
= atoi(pos
);
1623 } else if (os_strcmp(buf
, "wpa_gmk_rekey") == 0) {
1624 bss
->wpa_gmk_rekey
= atoi(pos
);
1625 } else if (os_strcmp(buf
, "wpa_passphrase") == 0) {
1626 int len
= os_strlen(pos
);
1627 if (len
< 8 || len
> 63) {
1628 printf("Line %d: invalid WPA passphrase length"
1629 " %d (expected 8..63)\n", line
, len
);
1632 os_free(bss
->ssid
.wpa_passphrase
);
1633 bss
->ssid
.wpa_passphrase
= os_strdup(pos
);
1635 } else if (os_strcmp(buf
, "wpa_psk") == 0) {
1636 os_free(bss
->ssid
.wpa_psk
);
1638 os_zalloc(sizeof(struct hostapd_wpa_psk
));
1639 if (bss
->ssid
.wpa_psk
== NULL
)
1641 else if (hexstr2bin(pos
, bss
->ssid
.wpa_psk
->psk
,
1643 pos
[PMK_LEN
* 2] != '\0') {
1644 printf("Line %d: Invalid PSK '%s'.\n", line
,
1648 bss
->ssid
.wpa_psk
->group
= 1;
1650 } else if (os_strcmp(buf
, "wpa_psk_file") == 0) {
1651 os_free(bss
->ssid
.wpa_psk_file
);
1652 bss
->ssid
.wpa_psk_file
= os_strdup(pos
);
1653 if (!bss
->ssid
.wpa_psk_file
) {
1654 printf("Line %d: allocation failed\n", line
);
1657 } else if (os_strcmp(buf
, "wpa_key_mgmt") == 0) {
1659 hostapd_config_parse_key_mgmt(line
, pos
);
1660 if (bss
->wpa_key_mgmt
== -1)
1662 } else if (os_strcmp(buf
, "wpa_pairwise") == 0) {
1664 hostapd_config_parse_cipher(line
, pos
);
1665 if (bss
->wpa_pairwise
== -1 ||
1666 bss
->wpa_pairwise
== 0)
1668 else if (bss
->wpa_pairwise
&
1669 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1670 WPA_CIPHER_WEP104
)) {
1671 printf("Line %d: unsupported pairwise "
1672 "cipher suite '%s'\n",
1673 bss
->wpa_pairwise
, pos
);
1676 } else if (os_strcmp(buf
, "rsn_pairwise") == 0) {
1678 hostapd_config_parse_cipher(line
, pos
);
1679 if (bss
->rsn_pairwise
== -1 ||
1680 bss
->rsn_pairwise
== 0)
1682 else if (bss
->rsn_pairwise
&
1683 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1684 WPA_CIPHER_WEP104
)) {
1685 printf("Line %d: unsupported pairwise "
1686 "cipher suite '%s'\n",
1687 bss
->rsn_pairwise
, pos
);
1690 #ifdef CONFIG_RSN_PREAUTH
1691 } else if (os_strcmp(buf
, "rsn_preauth") == 0) {
1692 bss
->rsn_preauth
= atoi(pos
);
1693 } else if (os_strcmp(buf
, "rsn_preauth_interfaces") == 0) {
1694 bss
->rsn_preauth_interfaces
= os_strdup(pos
);
1695 #endif /* CONFIG_RSN_PREAUTH */
1696 #ifdef CONFIG_PEERKEY
1697 } else if (os_strcmp(buf
, "peerkey") == 0) {
1698 bss
->peerkey
= atoi(pos
);
1699 #endif /* CONFIG_PEERKEY */
1700 #ifdef CONFIG_IEEE80211R
1701 } else if (os_strcmp(buf
, "mobility_domain") == 0) {
1702 if (os_strlen(pos
) != 2 * MOBILITY_DOMAIN_ID_LEN
||
1703 hexstr2bin(pos
, bss
->mobility_domain
,
1704 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1705 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1706 "mobility_domain '%s'", line
, pos
);
1710 } else if (os_strcmp(buf
, "r1_key_holder") == 0) {
1711 if (os_strlen(pos
) != 2 * FT_R1KH_ID_LEN
||
1712 hexstr2bin(pos
, bss
->r1_key_holder
,
1713 FT_R1KH_ID_LEN
) != 0) {
1714 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1715 "r1_key_holder '%s'", line
, pos
);
1719 } else if (os_strcmp(buf
, "r0_key_lifetime") == 0) {
1720 bss
->r0_key_lifetime
= atoi(pos
);
1721 } else if (os_strcmp(buf
, "reassociation_deadline") == 0) {
1722 bss
->reassociation_deadline
= atoi(pos
);
1723 } else if (os_strcmp(buf
, "r0kh") == 0) {
1724 if (add_r0kh(bss
, pos
) < 0) {
1725 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1726 "r0kh '%s'", line
, pos
);
1730 } else if (os_strcmp(buf
, "r1kh") == 0) {
1731 if (add_r1kh(bss
, pos
) < 0) {
1732 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1733 "r1kh '%s'", line
, pos
);
1737 } else if (os_strcmp(buf
, "pmk_r1_push") == 0) {
1738 bss
->pmk_r1_push
= atoi(pos
);
1739 #endif /* CONFIG_IEEE80211R */
1740 } else if (os_strcmp(buf
, "ctrl_interface") == 0) {
1741 os_free(bss
->ctrl_interface
);
1742 bss
->ctrl_interface
= os_strdup(pos
);
1743 } else if (os_strcmp(buf
, "ctrl_interface_group") == 0) {
1744 #ifndef CONFIG_NATIVE_WINDOWS
1747 const char *group
= pos
;
1749 grp
= getgrnam(group
);
1751 bss
->ctrl_interface_gid
= grp
->gr_gid
;
1752 bss
->ctrl_interface_gid_set
= 1;
1753 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d"
1754 " (from group name '%s')",
1755 bss
->ctrl_interface_gid
, group
);
1759 /* Group name not found - try to parse this as gid */
1760 bss
->ctrl_interface_gid
= strtol(group
, &endp
, 10);
1761 if (*group
== '\0' || *endp
!= '\0') {
1762 wpa_printf(MSG_DEBUG
, "Line %d: Invalid group "
1763 "'%s'", line
, group
);
1767 bss
->ctrl_interface_gid_set
= 1;
1768 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d",
1769 bss
->ctrl_interface_gid
);
1770 #endif /* CONFIG_NATIVE_WINDOWS */
1771 #ifdef RADIUS_SERVER
1772 } else if (os_strcmp(buf
, "radius_server_clients") == 0) {
1773 os_free(bss
->radius_server_clients
);
1774 bss
->radius_server_clients
= os_strdup(pos
);
1775 } else if (os_strcmp(buf
, "radius_server_auth_port") == 0) {
1776 bss
->radius_server_auth_port
= atoi(pos
);
1777 } else if (os_strcmp(buf
, "radius_server_ipv6") == 0) {
1778 bss
->radius_server_ipv6
= atoi(pos
);
1779 #endif /* RADIUS_SERVER */
1780 } else if (os_strcmp(buf
, "test_socket") == 0) {
1781 os_free(bss
->test_socket
);
1782 bss
->test_socket
= os_strdup(pos
);
1783 } else if (os_strcmp(buf
, "use_pae_group_addr") == 0) {
1784 bss
->use_pae_group_addr
= atoi(pos
);
1785 } else if (os_strcmp(buf
, "hw_mode") == 0) {
1786 if (os_strcmp(pos
, "a") == 0)
1787 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211A
;
1788 else if (os_strcmp(pos
, "b") == 0)
1789 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211B
;
1790 else if (os_strcmp(pos
, "g") == 0)
1791 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
1793 printf("Line %d: unknown hw_mode '%s'\n",
1797 } else if (os_strcmp(buf
, "channel") == 0) {
1798 conf
->channel
= atoi(pos
);
1799 } else if (os_strcmp(buf
, "beacon_int") == 0) {
1800 int val
= atoi(pos
);
1801 /* MIB defines range as 1..65535, but very small values
1802 * cause problems with the current implementation.
1803 * Since it is unlikely that this small numbers are
1804 * useful in real life scenarios, do not allow beacon
1805 * period to be set below 15 TU. */
1806 if (val
< 15 || val
> 65535) {
1807 printf("Line %d: invalid beacon_int %d "
1808 "(expected 15..65535)\n",
1812 conf
->beacon_int
= val
;
1813 } else if (os_strcmp(buf
, "dtim_period") == 0) {
1814 bss
->dtim_period
= atoi(pos
);
1815 if (bss
->dtim_period
< 1 || bss
->dtim_period
> 255) {
1816 printf("Line %d: invalid dtim_period %d\n",
1817 line
, bss
->dtim_period
);
1820 } else if (os_strcmp(buf
, "rts_threshold") == 0) {
1821 conf
->rts_threshold
= atoi(pos
);
1822 if (conf
->rts_threshold
< 0 ||
1823 conf
->rts_threshold
> 2347) {
1824 printf("Line %d: invalid rts_threshold %d\n",
1825 line
, conf
->rts_threshold
);
1828 } else if (os_strcmp(buf
, "fragm_threshold") == 0) {
1829 conf
->fragm_threshold
= atoi(pos
);
1830 if (conf
->fragm_threshold
< 256 ||
1831 conf
->fragm_threshold
> 2346) {
1832 printf("Line %d: invalid fragm_threshold %d\n",
1833 line
, conf
->fragm_threshold
);
1836 } else if (os_strcmp(buf
, "send_probe_response") == 0) {
1837 int val
= atoi(pos
);
1838 if (val
!= 0 && val
!= 1) {
1839 printf("Line %d: invalid send_probe_response "
1840 "%d (expected 0 or 1)\n", line
, val
);
1842 conf
->send_probe_response
= val
;
1843 } else if (os_strcmp(buf
, "supported_rates") == 0) {
1844 if (hostapd_parse_rates(&conf
->supported_rates
, pos
)) {
1845 printf("Line %d: invalid rate list\n", line
);
1848 } else if (os_strcmp(buf
, "basic_rates") == 0) {
1849 if (hostapd_parse_rates(&conf
->basic_rates
, pos
)) {
1850 printf("Line %d: invalid rate list\n", line
);
1853 } else if (os_strcmp(buf
, "ignore_broadcast_ssid") == 0) {
1854 bss
->ignore_broadcast_ssid
= atoi(pos
);
1855 } else if (os_strcmp(buf
, "bridge_packets") == 0) {
1856 conf
->bridge_packets
= atoi(pos
);
1857 } else if (os_strcmp(buf
, "wep_default_key") == 0) {
1858 bss
->ssid
.wep
.idx
= atoi(pos
);
1859 if (bss
->ssid
.wep
.idx
> 3) {
1860 printf("Invalid wep_default_key index %d\n",
1864 } else if (os_strcmp(buf
, "wep_key0") == 0 ||
1865 os_strcmp(buf
, "wep_key1") == 0 ||
1866 os_strcmp(buf
, "wep_key2") == 0 ||
1867 os_strcmp(buf
, "wep_key3") == 0) {
1868 if (hostapd_config_read_wep(&bss
->ssid
.wep
,
1869 buf
[7] - '0', pos
)) {
1870 printf("Line %d: invalid WEP key '%s'\n",
1874 } else if (os_strcmp(buf
, "dynamic_vlan") == 0) {
1875 bss
->ssid
.dynamic_vlan
= atoi(pos
);
1876 } else if (os_strcmp(buf
, "vlan_file") == 0) {
1877 if (hostapd_config_read_vlan_file(bss
, pos
)) {
1878 printf("Line %d: failed to read VLAN file "
1879 "'%s'\n", line
, pos
);
1882 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1883 } else if (os_strcmp(buf
, "vlan_tagged_interface") == 0) {
1884 bss
->ssid
.vlan_tagged_interface
= os_strdup(pos
);
1885 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1886 } else if (os_strcmp(buf
, "passive_scan_interval") == 0) {
1887 conf
->passive_scan_interval
= atoi(pos
);
1888 } else if (os_strcmp(buf
, "passive_scan_listen") == 0) {
1889 conf
->passive_scan_listen
= atoi(pos
);
1890 } else if (os_strcmp(buf
, "passive_scan_mode") == 0) {
1891 conf
->passive_scan_mode
= atoi(pos
);
1892 } else if (os_strcmp(buf
, "ap_table_max_size") == 0) {
1893 conf
->ap_table_max_size
= atoi(pos
);
1894 } else if (os_strcmp(buf
, "ap_table_expiration_time") == 0) {
1895 conf
->ap_table_expiration_time
= atoi(pos
);
1896 } else if (os_strncmp(buf
, "tx_queue_", 9) == 0) {
1897 if (hostapd_config_tx_queue(conf
, buf
, pos
)) {
1898 printf("Line %d: invalid TX queue item\n",
1902 } else if (os_strcmp(buf
, "wme_enabled") == 0) {
1903 bss
->wme_enabled
= atoi(pos
);
1904 } else if (os_strncmp(buf
, "wme_ac_", 7) == 0) {
1905 if (hostapd_config_wme_ac(conf
, buf
, pos
)) {
1906 printf("Line %d: invalid wme ac item\n",
1910 } else if (os_strcmp(buf
, "bss") == 0) {
1911 if (hostapd_config_bss(conf
, pos
)) {
1912 printf("Line %d: invalid bss item\n", line
);
1915 } else if (os_strcmp(buf
, "bssid") == 0) {
1916 if (bss
== conf
->bss
&&
1917 (!conf
->driver
|| !conf
->driver
->init_bssid
)) {
1918 printf("Line %d: bssid item not allowed "
1919 "for the default interface and this "
1922 } else if (hwaddr_aton(pos
, bss
->bssid
)) {
1923 printf("Line %d: invalid bssid item\n", line
);
1926 #ifdef CONFIG_IEEE80211W
1927 } else if (os_strcmp(buf
, "ieee80211w") == 0) {
1928 bss
->ieee80211w
= atoi(pos
);
1929 #endif /* CONFIG_IEEE80211W */
1931 printf("Line %d: unknown configuration item '%s'\n",
1939 if (bss
->individual_wep_key_len
== 0) {
1940 /* individual keys are not use; can use key idx0 for broadcast
1942 bss
->broadcast_key_idx_min
= 0;
1945 /* Select group cipher based on the enabled pairwise cipher suites */
1948 pairwise
|= bss
->wpa_pairwise
;
1950 if (bss
->rsn_pairwise
== 0)
1951 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1952 pairwise
|= bss
->rsn_pairwise
;
1954 if (pairwise
& WPA_CIPHER_TKIP
)
1955 bss
->wpa_group
= WPA_CIPHER_TKIP
;
1957 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1959 for (i
= 0; i
< conf
->num_bss
; i
++) {
1960 bss
= &conf
->bss
[i
];
1962 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1963 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1965 if (bss
->wpa
&& bss
->ieee802_1x
) {
1966 bss
->ssid
.security_policy
= SECURITY_WPA
;
1967 } else if (bss
->wpa
) {
1968 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1969 } else if (bss
->ieee802_1x
) {
1970 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1971 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1972 } else if (bss
->ssid
.wep
.keys_set
)
1973 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1975 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1978 if (hostapd_config_check(conf
))
1982 printf("%d errors found in configuration file '%s'\n",
1984 hostapd_config_free(conf
);
1992 int hostapd_wep_key_cmp(struct hostapd_wep_keys
*a
, struct hostapd_wep_keys
*b
)
1996 if (a
->idx
!= b
->idx
|| a
->default_len
!= b
->default_len
)
1998 for (i
= 0; i
< NUM_WEP_KEYS
; i
++)
1999 if (a
->len
[i
] != b
->len
[i
] ||
2000 os_memcmp(a
->key
[i
], b
->key
[i
], a
->len
[i
]) != 0)
2006 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
2011 for (i
= 0; i
< num_servers
; i
++) {
2012 os_free(servers
[i
].shared_secret
);
2018 static void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
2020 os_free(user
->identity
);
2021 os_free(user
->password
);
2026 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
2029 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
2030 os_free(keys
->key
[i
]);
2031 keys
->key
[i
] = NULL
;
2036 static void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
2038 struct hostapd_wpa_psk
*psk
, *prev
;
2039 struct hostapd_eap_user
*user
, *prev_user
;
2044 psk
= conf
->ssid
.wpa_psk
;
2051 os_free(conf
->ssid
.wpa_passphrase
);
2052 os_free(conf
->ssid
.wpa_psk_file
);
2053 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2054 os_free(conf
->ssid
.vlan_tagged_interface
);
2055 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2057 user
= conf
->eap_user
;
2061 hostapd_config_free_eap_user(prev_user
);
2064 os_free(conf
->dump_log_name
);
2065 os_free(conf
->eap_req_id_text
);
2066 os_free(conf
->accept_mac
);
2067 os_free(conf
->deny_mac
);
2068 os_free(conf
->nas_identifier
);
2069 hostapd_config_free_radius(conf
->radius
->auth_servers
,
2070 conf
->radius
->num_auth_servers
);
2071 hostapd_config_free_radius(conf
->radius
->acct_servers
,
2072 conf
->radius
->num_acct_servers
);
2073 os_free(conf
->rsn_preauth_interfaces
);
2074 os_free(conf
->ctrl_interface
);
2075 os_free(conf
->ca_cert
);
2076 os_free(conf
->server_cert
);
2077 os_free(conf
->private_key
);
2078 os_free(conf
->private_key_passwd
);
2079 os_free(conf
->dh_file
);
2080 os_free(conf
->pac_opaque_encr_key
);
2081 os_free(conf
->eap_fast_a_id
);
2082 os_free(conf
->eap_sim_db
);
2083 os_free(conf
->radius_server_clients
);
2084 os_free(conf
->test_socket
);
2085 os_free(conf
->radius
);
2086 hostapd_config_free_vlan(conf
);
2087 if (conf
->ssid
.dyn_vlan_keys
) {
2088 struct hostapd_ssid
*ssid
= &conf
->ssid
;
2090 for (i
= 0; i
<= ssid
->max_dyn_vlan_keys
; i
++) {
2091 if (ssid
->dyn_vlan_keys
[i
] == NULL
)
2093 hostapd_config_free_wep(ssid
->dyn_vlan_keys
[i
]);
2094 os_free(ssid
->dyn_vlan_keys
[i
]);
2096 os_free(ssid
->dyn_vlan_keys
);
2097 ssid
->dyn_vlan_keys
= NULL
;
2100 #ifdef CONFIG_IEEE80211R
2102 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
2103 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
2105 r0kh
= conf
->r0kh_list
;
2106 conf
->r0kh_list
= NULL
;
2113 r1kh
= conf
->r1kh_list
;
2114 conf
->r1kh_list
= NULL
;
2121 #endif /* CONFIG_IEEE80211R */
2125 void hostapd_config_free(struct hostapd_config
*conf
)
2132 for (i
= 0; i
< conf
->num_bss
; i
++)
2133 hostapd_config_free_bss(&conf
->bss
[i
]);
2140 /* Perform a binary search for given MAC address from a pre-sorted list.
2141 * Returns 1 if address is in the list or 0 if not. */
2142 int hostapd_maclist_found(macaddr
*list
, int num_entries
, const u8
*addr
)
2144 int start
, end
, middle
, res
;
2147 end
= num_entries
- 1;
2149 while (start
<= end
) {
2150 middle
= (start
+ end
) / 2;
2151 res
= os_memcmp(list
[middle
], addr
, ETH_ALEN
);
2164 int hostapd_rate_found(int *list
, int rate
)
2171 for (i
= 0; list
[i
] >= 0; i
++)
2172 if (list
[i
] == rate
)
2179 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
2181 struct hostapd_vlan
*v
= vlan
;
2183 if (v
->vlan_id
== vlan_id
|| v
->vlan_id
== VLAN_ID_WILDCARD
)
2191 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
2192 const u8
*addr
, const u8
*prev_psk
)
2194 struct hostapd_wpa_psk
*psk
;
2195 int next_ok
= prev_psk
== NULL
;
2197 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
2199 (psk
->group
|| os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0))
2202 if (psk
->psk
== prev_psk
)
2210 const struct hostapd_eap_user
*
2211 hostapd_get_eap_user(const struct hostapd_bss_config
*conf
, const u8
*identity
,
2212 size_t identity_len
, int phase2
)
2214 struct hostapd_eap_user
*user
= conf
->eap_user
;
2217 if (!phase2
&& user
->identity
== NULL
) {
2218 /* Wildcard match */
2222 if (user
->phase2
== !!phase2
&& user
->wildcard_prefix
&&
2223 identity_len
>= user
->identity_len
&&
2224 os_memcmp(user
->identity
, identity
, user
->identity_len
) ==
2226 /* Wildcard prefix match */
2230 if (user
->phase2
== !!phase2
&&
2231 user
->identity_len
== identity_len
&&
2232 os_memcmp(user
->identity
, identity
, identity_len
) == 0)