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 const struct wpa_driver_ops
* const 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
;
182 bss
->max_listen_interval
= 65535;
186 static struct hostapd_config
* hostapd_config_defaults(void)
188 struct hostapd_config
*conf
;
189 struct hostapd_bss_config
*bss
;
191 const int aCWmin
= 15, aCWmax
= 1024;
192 const struct hostapd_wme_ac_params ac_bk
=
193 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
194 const struct hostapd_wme_ac_params ac_be
=
195 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
196 const struct hostapd_wme_ac_params ac_vi
= /* video traffic */
197 { aCWmin
>> 1, aCWmin
, 2, 3000 / 32, 1 };
198 const struct hostapd_wme_ac_params ac_vo
= /* voice traffic */
199 { aCWmin
>> 2, aCWmin
>> 1, 2, 1500 / 32, 1 };
201 conf
= os_zalloc(sizeof(*conf
));
202 bss
= os_zalloc(sizeof(*bss
));
203 if (conf
== NULL
|| bss
== NULL
) {
204 printf("Failed to allocate memory for configuration data.\n");
210 /* set default driver based on configuration */
211 conf
->driver
= hostapd_drivers
[0];
212 if (conf
->driver
== NULL
) {
213 printf("No driver wrappers registered!\n");
219 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
220 if (bss
->radius
== NULL
) {
226 hostapd_config_defaults_bss(bss
);
231 conf
->beacon_int
= 100;
232 conf
->rts_threshold
= -1; /* use driver default: 2347 */
233 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
234 conf
->send_probe_response
= 1;
235 conf
->bridge_packets
= INTERNAL_BRIDGE_DO_NOT_CONTROL
;
237 os_memcpy(conf
->country
, "US ", 3);
239 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
240 conf
->tx_queue
[i
].aifs
= -1; /* use hw default */
242 conf
->wme_ac_params
[0] = ac_be
;
243 conf
->wme_ac_params
[1] = ac_bk
;
244 conf
->wme_ac_params
[2] = ac_vi
;
245 conf
->wme_ac_params
[3] = ac_vo
;
251 int hostapd_mac_comp(const void *a
, const void *b
)
253 return os_memcmp(a
, b
, sizeof(macaddr
));
257 int hostapd_mac_comp_empty(const void *a
)
259 macaddr empty
= { 0 };
260 return os_memcmp(a
, empty
, sizeof(macaddr
));
264 static int hostapd_config_read_maclist(const char *fname
, macaddr
**acl
,
276 f
= fopen(fname
, "r");
278 printf("MAC list file '%s' not found.\n", fname
);
282 while (fgets(buf
, sizeof(buf
), f
)) {
288 while (*pos
!= '\0') {
298 if (hwaddr_aton(buf
, addr
)) {
299 printf("Invalid MAC address '%s' at line %d in '%s'\n",
305 newacl
= os_realloc(*acl
, (*num
+ 1) * ETH_ALEN
);
306 if (newacl
== NULL
) {
307 printf("MAC list reallocation failed\n");
313 os_memcpy((*acl
)[*num
], addr
, ETH_ALEN
);
319 qsort(*acl
, *num
, sizeof(macaddr
), hostapd_mac_comp
);
325 static int hostapd_config_read_wpa_psk(const char *fname
,
326 struct hostapd_ssid
*ssid
)
330 int line
= 0, ret
= 0, len
, ok
;
332 struct hostapd_wpa_psk
*psk
;
337 f
= fopen(fname
, "r");
339 printf("WPA PSK file '%s' not found.\n", fname
);
343 while (fgets(buf
, sizeof(buf
), f
)) {
349 while (*pos
!= '\0') {
359 if (hwaddr_aton(buf
, addr
)) {
360 printf("Invalid MAC address '%s' on line %d in '%s'\n",
366 psk
= os_zalloc(sizeof(*psk
));
368 printf("WPA PSK allocation failed\n");
372 if (is_zero_ether_addr(addr
))
375 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
379 printf("No PSK on line %d in '%s'\n", line
, fname
);
387 len
= os_strlen(pos
);
388 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
390 else if (len
>= 8 && len
< 64) {
391 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
392 4096, psk
->psk
, PMK_LEN
);
396 printf("Invalid PSK '%s' on line %d in '%s'\n",
403 psk
->next
= ssid
->wpa_psk
;
413 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
415 struct hostapd_ssid
*ssid
= &conf
->ssid
;
417 if (ssid
->wpa_passphrase
!= NULL
) {
418 if (ssid
->wpa_psk
!= NULL
) {
419 printf("Warning: both WPA PSK and passphrase set. "
420 "Using passphrase.\n");
421 os_free(ssid
->wpa_psk
);
423 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
424 if (ssid
->wpa_psk
== NULL
) {
425 printf("Unable to alloc space for PSK\n");
428 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
429 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
430 wpa_hexdump_ascii(MSG_DEBUG
, "PSK (ASCII passphrase)",
431 (u8
*) ssid
->wpa_passphrase
,
432 os_strlen(ssid
->wpa_passphrase
));
433 pbkdf2_sha1(ssid
->wpa_passphrase
,
434 ssid
->ssid
, ssid
->ssid_len
,
435 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
436 wpa_hexdump(MSG_DEBUG
, "PSK (from passphrase)",
437 ssid
->wpa_psk
->psk
, PMK_LEN
);
438 ssid
->wpa_psk
->group
= 1;
440 os_memset(ssid
->wpa_passphrase
, 0,
441 os_strlen(ssid
->wpa_passphrase
));
442 os_free(ssid
->wpa_passphrase
);
443 ssid
->wpa_passphrase
= NULL
;
446 if (ssid
->wpa_psk_file
) {
447 if (hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
,
457 static int hostapd_config_read_eap_user(const char *fname
,
458 struct hostapd_bss_config
*conf
)
461 char buf
[512], *pos
, *start
, *pos2
;
462 int line
= 0, ret
= 0, num_methods
;
463 struct hostapd_eap_user
*user
, *tail
= NULL
;
468 f
= fopen(fname
, "r");
470 printf("EAP user file '%s' not found.\n", fname
);
474 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
475 while (fgets(buf
, sizeof(buf
), f
)) {
481 while (*pos
!= '\0') {
493 if (buf
[0] != '"' && buf
[0] != '*') {
494 printf("Invalid EAP identity (no \" in start) on "
495 "line %d in '%s'\n", line
, fname
);
499 user
= os_zalloc(sizeof(*user
));
501 printf("EAP user allocation failed\n");
504 user
->force_version
= -1;
511 while (*pos
!= '"' && *pos
!= '\0')
514 printf("Invalid EAP identity (no \" in end) on"
515 " line %d in '%s'\n", line
, fname
);
519 user
->identity
= os_malloc(pos
- start
);
520 if (user
->identity
== NULL
) {
521 printf("Failed to allocate memory for EAP "
525 os_memcpy(user
->identity
, start
, pos
- start
);
526 user
->identity_len
= pos
- start
;
528 if (pos
[0] == '"' && pos
[1] == '*') {
529 user
->wildcard_prefix
= 1;
534 while (*pos
== ' ' || *pos
== '\t')
538 printf("No EAP method on line %d in '%s'\n",
544 while (*pos
!= ' ' && *pos
!= '\t' && *pos
!= '\0')
554 char *pos3
= os_strchr(start
, ',');
558 user
->methods
[num_methods
].method
=
561 &user
->methods
[num_methods
].vendor
);
562 if (user
->methods
[num_methods
].vendor
==
564 user
->methods
[num_methods
].method
== EAP_TYPE_NONE
)
566 if (os_strcmp(start
, "TTLS-PAP") == 0) {
567 user
->ttls_auth
|= EAP_TTLS_AUTH_PAP
;
570 if (os_strcmp(start
, "TTLS-CHAP") == 0) {
571 user
->ttls_auth
|= EAP_TTLS_AUTH_CHAP
;
574 if (os_strcmp(start
, "TTLS-MSCHAP") == 0) {
576 EAP_TTLS_AUTH_MSCHAP
;
579 if (os_strcmp(start
, "TTLS-MSCHAPV2") == 0) {
581 EAP_TTLS_AUTH_MSCHAPV2
;
584 printf("Unsupported EAP type '%s' on line %d "
585 "in '%s'\n", start
, line
, fname
);
590 if (num_methods
>= EAP_USER_MAX_METHODS
)
597 if (num_methods
== 0 && user
->ttls_auth
== 0) {
598 printf("No EAP types configured on line %d in '%s'\n",
606 while (*pos
== ' ' || *pos
== '\t')
611 if (os_strncmp(pos
, "[ver=0]", 7) == 0) {
612 user
->force_version
= 0;
616 if (os_strncmp(pos
, "[ver=1]", 7) == 0) {
617 user
->force_version
= 1;
621 if (os_strncmp(pos
, "[2]", 3) == 0) {
629 while (*pos
!= '"' && *pos
!= '\0')
632 printf("Invalid EAP password (no \" in end) "
633 "on line %d in '%s'\n", line
, fname
);
637 user
->password
= os_malloc(pos
- start
);
638 if (user
->password
== NULL
) {
639 printf("Failed to allocate memory for EAP "
643 os_memcpy(user
->password
, start
, pos
- start
);
644 user
->password_len
= pos
- start
;
647 } else if (os_strncmp(pos
, "hash:", 5) == 0) {
650 while (*pos2
!= '\0' && *pos2
!= ' ' &&
651 *pos2
!= '\t' && *pos2
!= '#')
653 if (pos2
- pos
!= 32) {
654 printf("Invalid password hash on line %d in "
655 "'%s'\n", line
, fname
);
658 user
->password
= os_malloc(16);
659 if (user
->password
== NULL
) {
660 printf("Failed to allocate memory for EAP "
664 if (hexstr2bin(pos
, user
->password
, 16) < 0) {
665 printf("Invalid hash password on line %d in "
666 "'%s'\n", line
, fname
);
669 user
->password_len
= 16;
670 user
->password_hash
= 1;
674 while (*pos2
!= '\0' && *pos2
!= ' ' &&
675 *pos2
!= '\t' && *pos2
!= '#')
677 if ((pos2
- pos
) & 1) {
678 printf("Invalid hex password on line %d in "
679 "'%s'\n", line
, fname
);
682 user
->password
= os_malloc((pos2
- pos
) / 2);
683 if (user
->password
== NULL
) {
684 printf("Failed to allocate memory for EAP "
688 if (hexstr2bin(pos
, user
->password
,
689 (pos2
- pos
) / 2) < 0) {
690 printf("Invalid hex password on line %d in "
691 "'%s'\n", line
, fname
);
694 user
->password_len
= (pos2
- pos
) / 2;
698 while (*pos
== ' ' || *pos
== '\t')
700 if (os_strncmp(pos
, "[2]", 3) == 0) {
706 tail
= conf
->eap_user
= user
;
715 os_free(user
->password
);
716 os_free(user
->identity
);
727 #endif /* EAP_SERVER */
731 hostapd_config_read_radius_addr(struct hostapd_radius_server
**server
,
732 int *num_server
, const char *val
, int def_port
,
733 struct hostapd_radius_server
**curr_serv
)
735 struct hostapd_radius_server
*nserv
;
737 static int server_index
= 1;
739 nserv
= os_realloc(*server
, (*num_server
+ 1) * sizeof(*nserv
));
744 nserv
= &nserv
[*num_server
];
746 (*curr_serv
) = nserv
;
748 os_memset(nserv
, 0, sizeof(*nserv
));
749 nserv
->port
= def_port
;
750 ret
= hostapd_parse_ip_addr(val
, &nserv
->addr
);
751 nserv
->index
= server_index
++;
757 static int hostapd_config_parse_key_mgmt(int line
, const char *value
)
760 char *start
, *end
, *buf
;
762 buf
= os_strdup(value
);
767 while (start
!= '\0') {
768 while (*start
== ' ' || *start
== '\t')
773 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
777 if (os_strcmp(start
, "WPA-PSK") == 0)
778 val
|= WPA_KEY_MGMT_PSK
;
779 else if (os_strcmp(start
, "WPA-EAP") == 0)
780 val
|= WPA_KEY_MGMT_IEEE8021X
;
781 #ifdef CONFIG_IEEE80211R
782 else if (os_strcmp(start
, "FT-PSK") == 0)
783 val
|= WPA_KEY_MGMT_FT_PSK
;
784 else if (os_strcmp(start
, "FT-EAP") == 0)
785 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
786 #endif /* CONFIG_IEEE80211R */
788 printf("Line %d: invalid key_mgmt '%s'\n",
801 printf("Line %d: no key_mgmt values configured.\n", line
);
809 static int hostapd_config_parse_cipher(int line
, const char *value
)
812 char *start
, *end
, *buf
;
814 buf
= os_strdup(value
);
819 while (start
!= '\0') {
820 while (*start
== ' ' || *start
== '\t')
825 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
829 if (os_strcmp(start
, "CCMP") == 0)
830 val
|= WPA_CIPHER_CCMP
;
831 else if (os_strcmp(start
, "TKIP") == 0)
832 val
|= WPA_CIPHER_TKIP
;
833 else if (os_strcmp(start
, "WEP104") == 0)
834 val
|= WPA_CIPHER_WEP104
;
835 else if (os_strcmp(start
, "WEP40") == 0)
836 val
|= WPA_CIPHER_WEP40
;
837 else if (os_strcmp(start
, "NONE") == 0)
838 val
|= WPA_CIPHER_NONE
;
840 printf("Line %d: invalid cipher '%s'.", line
, start
);
852 printf("Line %d: no cipher values configured.", line
);
859 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
860 struct hostapd_config
*conf
)
862 if (bss
->ieee802_1x
&& !bss
->eap_server
&&
863 !bss
->radius
->auth_servers
) {
864 printf("Invalid IEEE 802.1X configuration (no EAP "
865 "authenticator configured).\n");
869 if (bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
870 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
871 bss
->ssid
.wpa_psk_file
== NULL
) {
872 printf("WPA-PSK enabled, but PSK or passphrase is not "
877 if (hostapd_mac_comp_empty(bss
->bssid
) != 0) {
880 for (i
= 0; i
< conf
->num_bss
; i
++) {
881 if ((&conf
->bss
[i
] != bss
) &&
882 (hostapd_mac_comp(conf
->bss
[i
].bssid
,
884 printf("Duplicate BSSID " MACSTR
885 " on interface '%s' and '%s'.\n",
887 conf
->bss
[i
].iface
, bss
->iface
);
893 #ifdef CONFIG_IEEE80211R
894 if ((bss
->wpa_key_mgmt
&
895 (WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
)) &&
896 (bss
->nas_identifier
== NULL
||
897 os_strlen(bss
->nas_identifier
) < 1 ||
898 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
899 printf("FT (IEEE 802.11r) requires nas_identifier to be "
900 "configured as a 1..48 octet string\n");
903 #endif /* CONFIG_IEEE80211R */
909 static int hostapd_config_check(struct hostapd_config
*conf
)
913 for (i
= 0; i
< conf
->num_bss
; i
++) {
914 if (hostapd_config_check_bss(&conf
->bss
[i
], conf
))
922 static int hostapd_config_read_wep(struct hostapd_wep_keys
*wep
, int keyidx
,
925 size_t len
= os_strlen(val
);
927 if (keyidx
< 0 || keyidx
> 3 || wep
->key
[keyidx
] != NULL
)
931 if (len
< 2 || val
[len
- 1] != '"')
934 wep
->key
[keyidx
] = os_malloc(len
);
935 if (wep
->key
[keyidx
] == NULL
)
937 os_memcpy(wep
->key
[keyidx
], val
+ 1, len
);
938 wep
->len
[keyidx
] = len
;
943 wep
->key
[keyidx
] = os_malloc(len
);
944 if (wep
->key
[keyidx
] == NULL
)
946 wep
->len
[keyidx
] = len
;
947 if (hexstr2bin(val
, wep
->key
[keyidx
], len
) < 0)
957 static int hostapd_parse_rates(int **rate_list
, char *val
)
968 while (*pos
!= '\0') {
974 list
= os_malloc(sizeof(int) * (count
+ 2));
979 while (*pos
!= '\0') {
980 end
= os_strchr(pos
, ' ');
984 list
[count
++] = atoi(pos
);
996 static int hostapd_config_bss(struct hostapd_config
*conf
, const char *ifname
)
998 struct hostapd_bss_config
*bss
;
1000 if (*ifname
== '\0')
1003 bss
= os_realloc(conf
->bss
, (conf
->num_bss
+ 1) *
1004 sizeof(struct hostapd_bss_config
));
1006 printf("Failed to allocate memory for multi-BSS entry\n");
1011 bss
= &(conf
->bss
[conf
->num_bss
]);
1012 os_memset(bss
, 0, sizeof(*bss
));
1013 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
1014 if (bss
->radius
== NULL
) {
1015 printf("Failed to allocate memory for multi-BSS RADIUS "
1021 conf
->last_bss
= bss
;
1023 hostapd_config_defaults_bss(bss
);
1024 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1025 os_memcpy(bss
->ssid
.vlan
, bss
->iface
, IFNAMSIZ
+ 1);
1031 static int valid_cw(int cw
)
1033 return (cw
== 1 || cw
== 3 || cw
== 7 || cw
== 15 || cw
== 31 ||
1034 cw
== 63 || cw
== 127 || cw
== 255 || cw
== 511 || cw
== 1023);
1039 IEEE80211_TX_QUEUE_DATA0
= 0, /* used for EDCA AC_VO data */
1040 IEEE80211_TX_QUEUE_DATA1
= 1, /* used for EDCA AC_VI data */
1041 IEEE80211_TX_QUEUE_DATA2
= 2, /* used for EDCA AC_BE data */
1042 IEEE80211_TX_QUEUE_DATA3
= 3, /* used for EDCA AC_BK data */
1043 IEEE80211_TX_QUEUE_DATA4
= 4,
1044 IEEE80211_TX_QUEUE_AFTER_BEACON
= 6,
1045 IEEE80211_TX_QUEUE_BEACON
= 7
1048 static int hostapd_config_tx_queue(struct hostapd_config
*conf
, char *name
,
1053 struct hostapd_tx_queue_params
*queue
;
1055 /* skip 'tx_queue_' prefix */
1057 if (os_strncmp(pos
, "data", 4) == 0 &&
1058 pos
[4] >= '0' && pos
[4] <= '9' && pos
[5] == '_') {
1061 } else if (os_strncmp(pos
, "after_beacon_", 13) == 0) {
1062 num
= IEEE80211_TX_QUEUE_AFTER_BEACON
;
1064 } else if (os_strncmp(pos
, "beacon_", 7) == 0) {
1065 num
= IEEE80211_TX_QUEUE_BEACON
;
1068 printf("Unknown tx_queue name '%s'\n", pos
);
1072 queue
= &conf
->tx_queue
[num
];
1074 if (os_strcmp(pos
, "aifs") == 0) {
1075 queue
->aifs
= atoi(val
);
1076 if (queue
->aifs
< 0 || queue
->aifs
> 255) {
1077 printf("Invalid AIFS value %d\n", queue
->aifs
);
1080 } else if (os_strcmp(pos
, "cwmin") == 0) {
1081 queue
->cwmin
= atoi(val
);
1082 if (!valid_cw(queue
->cwmin
)) {
1083 printf("Invalid cwMin value %d\n", queue
->cwmin
);
1086 } else if (os_strcmp(pos
, "cwmax") == 0) {
1087 queue
->cwmax
= atoi(val
);
1088 if (!valid_cw(queue
->cwmax
)) {
1089 printf("Invalid cwMax value %d\n", queue
->cwmax
);
1092 } else if (os_strcmp(pos
, "burst") == 0) {
1093 queue
->burst
= hostapd_config_read_int10(val
);
1095 printf("Unknown tx_queue field '%s'\n", pos
);
1099 queue
->configured
= 1;
1105 static int hostapd_config_wme_ac(struct hostapd_config
*conf
, char *name
,
1110 struct hostapd_wme_ac_params
*ac
;
1112 /* skip 'wme_ac_' prefix */
1114 if (os_strncmp(pos
, "be_", 3) == 0) {
1117 } else if (os_strncmp(pos
, "bk_", 3) == 0) {
1120 } else if (os_strncmp(pos
, "vi_", 3) == 0) {
1123 } else if (os_strncmp(pos
, "vo_", 3) == 0) {
1127 printf("Unknown wme name '%s'\n", pos
);
1131 ac
= &conf
->wme_ac_params
[num
];
1133 if (os_strcmp(pos
, "aifs") == 0) {
1135 if (v
< 1 || v
> 255) {
1136 printf("Invalid AIFS value %d\n", v
);
1140 } else if (os_strcmp(pos
, "cwmin") == 0) {
1142 if (v
< 0 || v
> 12) {
1143 printf("Invalid cwMin value %d\n", v
);
1147 } else if (os_strcmp(pos
, "cwmax") == 0) {
1149 if (v
< 0 || v
> 12) {
1150 printf("Invalid cwMax value %d\n", v
);
1154 } else if (os_strcmp(pos
, "txop_limit") == 0) {
1156 if (v
< 0 || v
> 0xffff) {
1157 printf("Invalid txop value %d\n", v
);
1161 } else if (os_strcmp(pos
, "acm") == 0) {
1163 if (v
< 0 || v
> 1) {
1164 printf("Invalid acm value %d\n", v
);
1167 ac
->admission_control_mandatory
= v
;
1169 printf("Unknown wme_ac_ field '%s'\n", pos
);
1177 #ifdef CONFIG_IEEE80211R
1178 static int add_r0kh(struct hostapd_bss_config
*bss
, char *value
)
1180 struct ft_remote_r0kh
*r0kh
;
1183 r0kh
= os_zalloc(sizeof(*r0kh
));
1187 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1189 next
= os_strchr(pos
, ' ');
1192 if (next
== NULL
|| hwaddr_aton(pos
, r0kh
->addr
)) {
1193 printf("Invalid R0KH MAC address: '%s'\n", pos
);
1199 next
= os_strchr(pos
, ' ');
1202 if (next
== NULL
|| next
- pos
> FT_R0KH_ID_MAX_LEN
) {
1203 printf("Invalid R0KH-ID: '%s'\n", pos
);
1207 r0kh
->id_len
= next
- pos
- 1;
1208 os_memcpy(r0kh
->id
, pos
, r0kh
->id_len
);
1211 if (hexstr2bin(pos
, r0kh
->key
, sizeof(r0kh
->key
))) {
1212 printf("Invalid R0KH key: '%s'\n", pos
);
1217 r0kh
->next
= bss
->r0kh_list
;
1218 bss
->r0kh_list
= r0kh
;
1224 static int add_r1kh(struct hostapd_bss_config
*bss
, char *value
)
1226 struct ft_remote_r1kh
*r1kh
;
1229 r1kh
= os_zalloc(sizeof(*r1kh
));
1233 /* 02:01:02:03:04:05 02:01:02:03:04:05
1234 * 000102030405060708090a0b0c0d0e0f */
1236 next
= os_strchr(pos
, ' ');
1239 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->addr
)) {
1240 printf("Invalid R1KH MAC address: '%s'\n", pos
);
1246 next
= os_strchr(pos
, ' ');
1249 if (next
== NULL
|| hwaddr_aton(pos
, r1kh
->id
)) {
1250 printf("Invalid R1KH-ID: '%s'\n", pos
);
1256 if (hexstr2bin(pos
, r1kh
->key
, sizeof(r1kh
->key
))) {
1257 printf("Invalid R1KH key: '%s'\n", pos
);
1262 r1kh
->next
= bss
->r1kh_list
;
1263 bss
->r1kh_list
= r1kh
;
1267 #endif /* CONFIG_IEEE80211R */
1270 struct hostapd_config
* hostapd_config_read(const char *fname
)
1272 struct hostapd_config
*conf
;
1273 struct hostapd_bss_config
*bss
;
1275 char buf
[256], *pos
;
1281 f
= fopen(fname
, "r");
1283 printf("Could not open configuration file '%s' for reading.\n",
1288 conf
= hostapd_config_defaults();
1293 bss
= conf
->last_bss
= conf
->bss
;
1295 while (fgets(buf
, sizeof(buf
), f
)) {
1296 bss
= conf
->last_bss
;
1302 while (*pos
!= '\0') {
1312 pos
= os_strchr(buf
, '=');
1314 printf("Line %d: invalid line '%s'\n", line
, buf
);
1321 if (os_strcmp(buf
, "interface") == 0) {
1322 os_strlcpy(conf
->bss
[0].iface
, pos
,
1323 sizeof(conf
->bss
[0].iface
));
1324 } else if (os_strcmp(buf
, "bridge") == 0) {
1325 os_strlcpy(bss
->bridge
, pos
, sizeof(bss
->bridge
));
1326 } else if (os_strcmp(buf
, "driver") == 0) {
1328 /* clear to get error below if setting is invalid */
1329 conf
->driver
= NULL
;
1330 for (i
= 0; hostapd_drivers
[i
]; i
++) {
1331 if (os_strcmp(pos
, hostapd_drivers
[i
]->name
) ==
1333 conf
->driver
= hostapd_drivers
[i
];
1337 if (conf
->driver
== NULL
) {
1338 printf("Line %d: invalid/unknown driver "
1339 "'%s'\n", line
, pos
);
1342 } else if (os_strcmp(buf
, "debug") == 0) {
1343 wpa_printf(MSG_DEBUG
, "Line %d: DEPRECATED: 'debug' "
1344 "configuration variable is not used "
1346 } else if (os_strcmp(buf
, "logger_syslog_level") == 0) {
1347 bss
->logger_syslog_level
= atoi(pos
);
1348 } else if (os_strcmp(buf
, "logger_stdout_level") == 0) {
1349 bss
->logger_stdout_level
= atoi(pos
);
1350 } else if (os_strcmp(buf
, "logger_syslog") == 0) {
1351 bss
->logger_syslog
= atoi(pos
);
1352 } else if (os_strcmp(buf
, "logger_stdout") == 0) {
1353 bss
->logger_stdout
= atoi(pos
);
1354 } else if (os_strcmp(buf
, "dump_file") == 0) {
1355 bss
->dump_log_name
= os_strdup(pos
);
1356 } else if (os_strcmp(buf
, "ssid") == 0) {
1357 bss
->ssid
.ssid_len
= os_strlen(pos
);
1358 if (bss
->ssid
.ssid_len
> HOSTAPD_MAX_SSID_LEN
||
1359 bss
->ssid
.ssid_len
< 1) {
1360 printf("Line %d: invalid SSID '%s'\n", line
,
1364 os_memcpy(bss
->ssid
.ssid
, pos
,
1365 bss
->ssid
.ssid_len
);
1366 bss
->ssid
.ssid
[bss
->ssid
.ssid_len
] = '\0';
1367 bss
->ssid
.ssid_set
= 1;
1369 } else if (os_strcmp(buf
, "macaddr_acl") == 0) {
1370 bss
->macaddr_acl
= atoi(pos
);
1371 if (bss
->macaddr_acl
!= ACCEPT_UNLESS_DENIED
&&
1372 bss
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
&&
1373 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1374 printf("Line %d: unknown macaddr_acl %d\n",
1375 line
, bss
->macaddr_acl
);
1377 } else if (os_strcmp(buf
, "accept_mac_file") == 0) {
1378 if (hostapd_config_read_maclist(pos
, &bss
->accept_mac
,
1379 &bss
->num_accept_mac
))
1381 printf("Line %d: Failed to read "
1382 "accept_mac_file '%s'\n",
1386 } else if (os_strcmp(buf
, "deny_mac_file") == 0) {
1387 if (hostapd_config_read_maclist(pos
, &bss
->deny_mac
,
1388 &bss
->num_deny_mac
))
1390 printf("Line %d: Failed to read "
1391 "deny_mac_file '%s'\n",
1395 } else if (os_strcmp(buf
, "ap_max_inactivity") == 0) {
1396 bss
->ap_max_inactivity
= atoi(pos
);
1397 } else if (os_strcmp(buf
, "country_code") == 0) {
1398 os_memcpy(conf
->country
, pos
, 2);
1399 /* FIX: make this configurable */
1400 conf
->country
[2] = ' ';
1401 } else if (os_strcmp(buf
, "ieee80211d") == 0) {
1402 conf
->ieee80211d
= atoi(pos
);
1403 } else if (os_strcmp(buf
, "ieee80211h") == 0) {
1404 conf
->ieee80211h
= atoi(pos
);
1405 } else if (os_strcmp(buf
, "assoc_ap_addr") == 0) {
1406 if (hwaddr_aton(pos
, bss
->assoc_ap_addr
)) {
1407 printf("Line %d: invalid MAC address '%s'\n",
1412 } else if (os_strcmp(buf
, "ieee8021x") == 0) {
1413 bss
->ieee802_1x
= atoi(pos
);
1414 } else if (os_strcmp(buf
, "eapol_version") == 0) {
1415 bss
->eapol_version
= atoi(pos
);
1416 if (bss
->eapol_version
< 1 ||
1417 bss
->eapol_version
> 2) {
1418 printf("Line %d: invalid EAPOL "
1419 "version (%d): '%s'.\n",
1420 line
, bss
->eapol_version
, pos
);
1423 wpa_printf(MSG_DEBUG
, "eapol_version=%d",
1424 bss
->eapol_version
);
1426 } else if (os_strcmp(buf
, "eap_authenticator") == 0) {
1427 bss
->eap_server
= atoi(pos
);
1428 printf("Line %d: obsolete eap_authenticator used; "
1429 "this has been renamed to eap_server\n", line
);
1430 } else if (os_strcmp(buf
, "eap_server") == 0) {
1431 bss
->eap_server
= atoi(pos
);
1432 } else if (os_strcmp(buf
, "eap_user_file") == 0) {
1433 if (hostapd_config_read_eap_user(pos
, bss
))
1435 } else if (os_strcmp(buf
, "ca_cert") == 0) {
1436 os_free(bss
->ca_cert
);
1437 bss
->ca_cert
= os_strdup(pos
);
1438 } else if (os_strcmp(buf
, "server_cert") == 0) {
1439 os_free(bss
->server_cert
);
1440 bss
->server_cert
= os_strdup(pos
);
1441 } else if (os_strcmp(buf
, "private_key") == 0) {
1442 os_free(bss
->private_key
);
1443 bss
->private_key
= os_strdup(pos
);
1444 } else if (os_strcmp(buf
, "private_key_passwd") == 0) {
1445 os_free(bss
->private_key_passwd
);
1446 bss
->private_key_passwd
= os_strdup(pos
);
1447 } else if (os_strcmp(buf
, "check_crl") == 0) {
1448 bss
->check_crl
= atoi(pos
);
1449 } else if (os_strcmp(buf
, "dh_file") == 0) {
1450 os_free(bss
->dh_file
);
1451 bss
->dh_file
= os_strdup(pos
);
1453 } else if (os_strcmp(buf
, "pac_opaque_encr_key") == 0) {
1454 os_free(bss
->pac_opaque_encr_key
);
1455 bss
->pac_opaque_encr_key
= os_malloc(16);
1456 if (bss
->pac_opaque_encr_key
== NULL
) {
1457 printf("Line %d: No memory for "
1458 "pac_opque_encr_key\n", line
);
1460 } else if (hexstr2bin(pos
, bss
->pac_opaque_encr_key
,
1462 printf("Line %d: Invalid pac_opque_encr_key\n",
1466 } else if (os_strcmp(buf
, "eap_fast_a_id") == 0) {
1467 os_free(bss
->eap_fast_a_id
);
1468 bss
->eap_fast_a_id
= os_strdup(pos
);
1469 #endif /* EAP_FAST */
1471 } else if (os_strcmp(buf
, "eap_sim_db") == 0) {
1472 os_free(bss
->eap_sim_db
);
1473 bss
->eap_sim_db
= os_strdup(pos
);
1474 } else if (os_strcmp(buf
, "eap_sim_aka_result_ind") == 0) {
1475 bss
->eap_sim_aka_result_ind
= atoi(pos
);
1476 #endif /* EAP_SIM */
1478 } else if (os_strcmp(buf
, "tnc") == 0) {
1479 bss
->tnc
= atoi(pos
);
1480 #endif /* EAP_TNC */
1481 #endif /* EAP_SERVER */
1482 } else if (os_strcmp(buf
, "eap_message") == 0) {
1484 bss
->eap_req_id_text
= os_strdup(pos
);
1485 if (bss
->eap_req_id_text
== NULL
) {
1486 printf("Line %d: Failed to allocate memory "
1487 "for eap_req_id_text\n", line
);
1491 bss
->eap_req_id_text_len
=
1492 os_strlen(bss
->eap_req_id_text
);
1493 term
= os_strstr(bss
->eap_req_id_text
, "\\0");
1496 os_memmove(term
, term
+ 1,
1497 bss
->eap_req_id_text_len
-
1498 (term
- bss
->eap_req_id_text
) - 1);
1499 bss
->eap_req_id_text_len
--;
1501 } else if (os_strcmp(buf
, "wep_key_len_broadcast") == 0) {
1502 bss
->default_wep_key_len
= atoi(pos
);
1503 if (bss
->default_wep_key_len
> 13) {
1504 printf("Line %d: invalid WEP key len %lu "
1505 "(= %lu bits)\n", line
,
1507 bss
->default_wep_key_len
,
1509 bss
->default_wep_key_len
* 8);
1512 } else if (os_strcmp(buf
, "wep_key_len_unicast") == 0) {
1513 bss
->individual_wep_key_len
= atoi(pos
);
1514 if (bss
->individual_wep_key_len
< 0 ||
1515 bss
->individual_wep_key_len
> 13) {
1516 printf("Line %d: invalid WEP key len %d "
1517 "(= %d bits)\n", line
,
1518 bss
->individual_wep_key_len
,
1519 bss
->individual_wep_key_len
* 8);
1522 } else if (os_strcmp(buf
, "wep_rekey_period") == 0) {
1523 bss
->wep_rekeying_period
= atoi(pos
);
1524 if (bss
->wep_rekeying_period
< 0) {
1525 printf("Line %d: invalid period %d\n",
1526 line
, bss
->wep_rekeying_period
);
1529 } else if (os_strcmp(buf
, "eap_reauth_period") == 0) {
1530 bss
->eap_reauth_period
= atoi(pos
);
1531 if (bss
->eap_reauth_period
< 0) {
1532 printf("Line %d: invalid period %d\n",
1533 line
, bss
->eap_reauth_period
);
1536 } else if (os_strcmp(buf
, "eapol_key_index_workaround") == 0) {
1537 bss
->eapol_key_index_workaround
= atoi(pos
);
1539 } else if (os_strcmp(buf
, "iapp_interface") == 0) {
1540 bss
->ieee802_11f
= 1;
1541 os_strlcpy(bss
->iapp_iface
, pos
,
1542 sizeof(bss
->iapp_iface
));
1543 #endif /* CONFIG_IAPP */
1544 } else if (os_strcmp(buf
, "own_ip_addr") == 0) {
1545 if (hostapd_parse_ip_addr(pos
, &bss
->own_ip_addr
)) {
1546 printf("Line %d: invalid IP address '%s'\n",
1550 } else if (os_strcmp(buf
, "nas_identifier") == 0) {
1551 bss
->nas_identifier
= os_strdup(pos
);
1552 } else if (os_strcmp(buf
, "auth_server_addr") == 0) {
1553 if (hostapd_config_read_radius_addr(
1554 &bss
->radius
->auth_servers
,
1555 &bss
->radius
->num_auth_servers
, pos
, 1812,
1556 &bss
->radius
->auth_server
)) {
1557 printf("Line %d: invalid IP address '%s'\n",
1561 } else if (bss
->radius
->auth_server
&&
1562 os_strcmp(buf
, "auth_server_port") == 0) {
1563 bss
->radius
->auth_server
->port
= atoi(pos
);
1564 } else if (bss
->radius
->auth_server
&&
1565 os_strcmp(buf
, "auth_server_shared_secret") == 0) {
1566 int len
= os_strlen(pos
);
1568 /* RFC 2865, Ch. 3 */
1569 printf("Line %d: empty shared secret is not "
1570 "allowed.\n", line
);
1573 bss
->radius
->auth_server
->shared_secret
=
1574 (u8
*) os_strdup(pos
);
1575 bss
->radius
->auth_server
->shared_secret_len
= len
;
1576 } else if (os_strcmp(buf
, "acct_server_addr") == 0) {
1577 if (hostapd_config_read_radius_addr(
1578 &bss
->radius
->acct_servers
,
1579 &bss
->radius
->num_acct_servers
, pos
, 1813,
1580 &bss
->radius
->acct_server
)) {
1581 printf("Line %d: invalid IP address '%s'\n",
1585 } else if (bss
->radius
->acct_server
&&
1586 os_strcmp(buf
, "acct_server_port") == 0) {
1587 bss
->radius
->acct_server
->port
= atoi(pos
);
1588 } else if (bss
->radius
->acct_server
&&
1589 os_strcmp(buf
, "acct_server_shared_secret") == 0) {
1590 int len
= os_strlen(pos
);
1592 /* RFC 2865, Ch. 3 */
1593 printf("Line %d: empty shared secret is not "
1594 "allowed.\n", line
);
1597 bss
->radius
->acct_server
->shared_secret
=
1598 (u8
*) os_strdup(pos
);
1599 bss
->radius
->acct_server
->shared_secret_len
= len
;
1600 } else if (os_strcmp(buf
, "radius_retry_primary_interval") ==
1602 bss
->radius
->retry_primary_interval
= atoi(pos
);
1603 } else if (os_strcmp(buf
, "radius_acct_interim_interval") == 0)
1605 bss
->radius
->acct_interim_interval
= atoi(pos
);
1606 } else if (os_strcmp(buf
, "auth_algs") == 0) {
1607 bss
->auth_algs
= atoi(pos
);
1608 if (bss
->auth_algs
== 0) {
1609 printf("Line %d: no authentication algorithms "
1614 } else if (os_strcmp(buf
, "max_num_sta") == 0) {
1615 bss
->max_num_sta
= atoi(pos
);
1616 if (bss
->max_num_sta
< 0 ||
1617 bss
->max_num_sta
> MAX_STA_COUNT
) {
1618 printf("Line %d: Invalid max_num_sta=%d; "
1619 "allowed range 0..%d\n", line
,
1620 bss
->max_num_sta
, MAX_STA_COUNT
);
1623 } else if (os_strcmp(buf
, "wpa") == 0) {
1624 bss
->wpa
= atoi(pos
);
1625 } else if (os_strcmp(buf
, "wpa_group_rekey") == 0) {
1626 bss
->wpa_group_rekey
= atoi(pos
);
1627 } else if (os_strcmp(buf
, "wpa_strict_rekey") == 0) {
1628 bss
->wpa_strict_rekey
= atoi(pos
);
1629 } else if (os_strcmp(buf
, "wpa_gmk_rekey") == 0) {
1630 bss
->wpa_gmk_rekey
= atoi(pos
);
1631 } else if (os_strcmp(buf
, "wpa_passphrase") == 0) {
1632 int len
= os_strlen(pos
);
1633 if (len
< 8 || len
> 63) {
1634 printf("Line %d: invalid WPA passphrase length"
1635 " %d (expected 8..63)\n", line
, len
);
1638 os_free(bss
->ssid
.wpa_passphrase
);
1639 bss
->ssid
.wpa_passphrase
= os_strdup(pos
);
1641 } else if (os_strcmp(buf
, "wpa_psk") == 0) {
1642 os_free(bss
->ssid
.wpa_psk
);
1644 os_zalloc(sizeof(struct hostapd_wpa_psk
));
1645 if (bss
->ssid
.wpa_psk
== NULL
)
1647 else if (hexstr2bin(pos
, bss
->ssid
.wpa_psk
->psk
,
1649 pos
[PMK_LEN
* 2] != '\0') {
1650 printf("Line %d: Invalid PSK '%s'.\n", line
,
1654 bss
->ssid
.wpa_psk
->group
= 1;
1656 } else if (os_strcmp(buf
, "wpa_psk_file") == 0) {
1657 os_free(bss
->ssid
.wpa_psk_file
);
1658 bss
->ssid
.wpa_psk_file
= os_strdup(pos
);
1659 if (!bss
->ssid
.wpa_psk_file
) {
1660 printf("Line %d: allocation failed\n", line
);
1663 } else if (os_strcmp(buf
, "wpa_key_mgmt") == 0) {
1665 hostapd_config_parse_key_mgmt(line
, pos
);
1666 if (bss
->wpa_key_mgmt
== -1)
1668 } else if (os_strcmp(buf
, "wpa_pairwise") == 0) {
1670 hostapd_config_parse_cipher(line
, pos
);
1671 if (bss
->wpa_pairwise
== -1 ||
1672 bss
->wpa_pairwise
== 0)
1674 else if (bss
->wpa_pairwise
&
1675 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1676 WPA_CIPHER_WEP104
)) {
1677 printf("Line %d: unsupported pairwise "
1678 "cipher suite '%s'\n",
1679 bss
->wpa_pairwise
, pos
);
1682 } else if (os_strcmp(buf
, "rsn_pairwise") == 0) {
1684 hostapd_config_parse_cipher(line
, pos
);
1685 if (bss
->rsn_pairwise
== -1 ||
1686 bss
->rsn_pairwise
== 0)
1688 else if (bss
->rsn_pairwise
&
1689 (WPA_CIPHER_NONE
| WPA_CIPHER_WEP40
|
1690 WPA_CIPHER_WEP104
)) {
1691 printf("Line %d: unsupported pairwise "
1692 "cipher suite '%s'\n",
1693 bss
->rsn_pairwise
, pos
);
1696 #ifdef CONFIG_RSN_PREAUTH
1697 } else if (os_strcmp(buf
, "rsn_preauth") == 0) {
1698 bss
->rsn_preauth
= atoi(pos
);
1699 } else if (os_strcmp(buf
, "rsn_preauth_interfaces") == 0) {
1700 bss
->rsn_preauth_interfaces
= os_strdup(pos
);
1701 #endif /* CONFIG_RSN_PREAUTH */
1702 #ifdef CONFIG_PEERKEY
1703 } else if (os_strcmp(buf
, "peerkey") == 0) {
1704 bss
->peerkey
= atoi(pos
);
1705 #endif /* CONFIG_PEERKEY */
1706 #ifdef CONFIG_IEEE80211R
1707 } else if (os_strcmp(buf
, "mobility_domain") == 0) {
1708 if (os_strlen(pos
) != 2 * MOBILITY_DOMAIN_ID_LEN
||
1709 hexstr2bin(pos
, bss
->mobility_domain
,
1710 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1711 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1712 "mobility_domain '%s'", line
, pos
);
1716 } else if (os_strcmp(buf
, "r1_key_holder") == 0) {
1717 if (os_strlen(pos
) != 2 * FT_R1KH_ID_LEN
||
1718 hexstr2bin(pos
, bss
->r1_key_holder
,
1719 FT_R1KH_ID_LEN
) != 0) {
1720 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1721 "r1_key_holder '%s'", line
, pos
);
1725 } else if (os_strcmp(buf
, "r0_key_lifetime") == 0) {
1726 bss
->r0_key_lifetime
= atoi(pos
);
1727 } else if (os_strcmp(buf
, "reassociation_deadline") == 0) {
1728 bss
->reassociation_deadline
= atoi(pos
);
1729 } else if (os_strcmp(buf
, "r0kh") == 0) {
1730 if (add_r0kh(bss
, pos
) < 0) {
1731 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1732 "r0kh '%s'", line
, pos
);
1736 } else if (os_strcmp(buf
, "r1kh") == 0) {
1737 if (add_r1kh(bss
, pos
) < 0) {
1738 wpa_printf(MSG_DEBUG
, "Line %d: Invalid "
1739 "r1kh '%s'", line
, pos
);
1743 } else if (os_strcmp(buf
, "pmk_r1_push") == 0) {
1744 bss
->pmk_r1_push
= atoi(pos
);
1745 #endif /* CONFIG_IEEE80211R */
1746 } else if (os_strcmp(buf
, "ctrl_interface") == 0) {
1747 os_free(bss
->ctrl_interface
);
1748 bss
->ctrl_interface
= os_strdup(pos
);
1749 } else if (os_strcmp(buf
, "ctrl_interface_group") == 0) {
1750 #ifndef CONFIG_NATIVE_WINDOWS
1753 const char *group
= pos
;
1755 grp
= getgrnam(group
);
1757 bss
->ctrl_interface_gid
= grp
->gr_gid
;
1758 bss
->ctrl_interface_gid_set
= 1;
1759 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d"
1760 " (from group name '%s')",
1761 bss
->ctrl_interface_gid
, group
);
1765 /* Group name not found - try to parse this as gid */
1766 bss
->ctrl_interface_gid
= strtol(group
, &endp
, 10);
1767 if (*group
== '\0' || *endp
!= '\0') {
1768 wpa_printf(MSG_DEBUG
, "Line %d: Invalid group "
1769 "'%s'", line
, group
);
1773 bss
->ctrl_interface_gid_set
= 1;
1774 wpa_printf(MSG_DEBUG
, "ctrl_interface_group=%d",
1775 bss
->ctrl_interface_gid
);
1776 #endif /* CONFIG_NATIVE_WINDOWS */
1777 #ifdef RADIUS_SERVER
1778 } else if (os_strcmp(buf
, "radius_server_clients") == 0) {
1779 os_free(bss
->radius_server_clients
);
1780 bss
->radius_server_clients
= os_strdup(pos
);
1781 } else if (os_strcmp(buf
, "radius_server_auth_port") == 0) {
1782 bss
->radius_server_auth_port
= atoi(pos
);
1783 } else if (os_strcmp(buf
, "radius_server_ipv6") == 0) {
1784 bss
->radius_server_ipv6
= atoi(pos
);
1785 #endif /* RADIUS_SERVER */
1786 } else if (os_strcmp(buf
, "test_socket") == 0) {
1787 os_free(bss
->test_socket
);
1788 bss
->test_socket
= os_strdup(pos
);
1789 } else if (os_strcmp(buf
, "use_pae_group_addr") == 0) {
1790 bss
->use_pae_group_addr
= atoi(pos
);
1791 } else if (os_strcmp(buf
, "hw_mode") == 0) {
1792 if (os_strcmp(pos
, "a") == 0)
1793 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211A
;
1794 else if (os_strcmp(pos
, "b") == 0)
1795 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211B
;
1796 else if (os_strcmp(pos
, "g") == 0)
1797 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
1799 printf("Line %d: unknown hw_mode '%s'\n",
1803 } else if (os_strcmp(buf
, "channel") == 0) {
1804 conf
->channel
= atoi(pos
);
1805 } else if (os_strcmp(buf
, "beacon_int") == 0) {
1806 int val
= atoi(pos
);
1807 /* MIB defines range as 1..65535, but very small values
1808 * cause problems with the current implementation.
1809 * Since it is unlikely that this small numbers are
1810 * useful in real life scenarios, do not allow beacon
1811 * period to be set below 15 TU. */
1812 if (val
< 15 || val
> 65535) {
1813 printf("Line %d: invalid beacon_int %d "
1814 "(expected 15..65535)\n",
1818 conf
->beacon_int
= val
;
1819 } else if (os_strcmp(buf
, "dtim_period") == 0) {
1820 bss
->dtim_period
= atoi(pos
);
1821 if (bss
->dtim_period
< 1 || bss
->dtim_period
> 255) {
1822 printf("Line %d: invalid dtim_period %d\n",
1823 line
, bss
->dtim_period
);
1826 } else if (os_strcmp(buf
, "rts_threshold") == 0) {
1827 conf
->rts_threshold
= atoi(pos
);
1828 if (conf
->rts_threshold
< 0 ||
1829 conf
->rts_threshold
> 2347) {
1830 printf("Line %d: invalid rts_threshold %d\n",
1831 line
, conf
->rts_threshold
);
1834 } else if (os_strcmp(buf
, "fragm_threshold") == 0) {
1835 conf
->fragm_threshold
= atoi(pos
);
1836 if (conf
->fragm_threshold
< 256 ||
1837 conf
->fragm_threshold
> 2346) {
1838 printf("Line %d: invalid fragm_threshold %d\n",
1839 line
, conf
->fragm_threshold
);
1842 } else if (os_strcmp(buf
, "send_probe_response") == 0) {
1843 int val
= atoi(pos
);
1844 if (val
!= 0 && val
!= 1) {
1845 printf("Line %d: invalid send_probe_response "
1846 "%d (expected 0 or 1)\n", line
, val
);
1848 conf
->send_probe_response
= val
;
1849 } else if (os_strcmp(buf
, "supported_rates") == 0) {
1850 if (hostapd_parse_rates(&conf
->supported_rates
, pos
)) {
1851 printf("Line %d: invalid rate list\n", line
);
1854 } else if (os_strcmp(buf
, "basic_rates") == 0) {
1855 if (hostapd_parse_rates(&conf
->basic_rates
, pos
)) {
1856 printf("Line %d: invalid rate list\n", line
);
1859 } else if (os_strcmp(buf
, "ignore_broadcast_ssid") == 0) {
1860 bss
->ignore_broadcast_ssid
= atoi(pos
);
1861 } else if (os_strcmp(buf
, "bridge_packets") == 0) {
1862 conf
->bridge_packets
= atoi(pos
);
1863 } else if (os_strcmp(buf
, "wep_default_key") == 0) {
1864 bss
->ssid
.wep
.idx
= atoi(pos
);
1865 if (bss
->ssid
.wep
.idx
> 3) {
1866 printf("Invalid wep_default_key index %d\n",
1870 } else if (os_strcmp(buf
, "wep_key0") == 0 ||
1871 os_strcmp(buf
, "wep_key1") == 0 ||
1872 os_strcmp(buf
, "wep_key2") == 0 ||
1873 os_strcmp(buf
, "wep_key3") == 0) {
1874 if (hostapd_config_read_wep(&bss
->ssid
.wep
,
1875 buf
[7] - '0', pos
)) {
1876 printf("Line %d: invalid WEP key '%s'\n",
1880 } else if (os_strcmp(buf
, "dynamic_vlan") == 0) {
1881 bss
->ssid
.dynamic_vlan
= atoi(pos
);
1882 } else if (os_strcmp(buf
, "vlan_file") == 0) {
1883 if (hostapd_config_read_vlan_file(bss
, pos
)) {
1884 printf("Line %d: failed to read VLAN file "
1885 "'%s'\n", line
, pos
);
1888 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1889 } else if (os_strcmp(buf
, "vlan_tagged_interface") == 0) {
1890 bss
->ssid
.vlan_tagged_interface
= os_strdup(pos
);
1891 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1892 } else if (os_strcmp(buf
, "passive_scan_interval") == 0) {
1893 conf
->passive_scan_interval
= atoi(pos
);
1894 } else if (os_strcmp(buf
, "passive_scan_listen") == 0) {
1895 conf
->passive_scan_listen
= atoi(pos
);
1896 } else if (os_strcmp(buf
, "passive_scan_mode") == 0) {
1897 conf
->passive_scan_mode
= atoi(pos
);
1898 } else if (os_strcmp(buf
, "ap_table_max_size") == 0) {
1899 conf
->ap_table_max_size
= atoi(pos
);
1900 } else if (os_strcmp(buf
, "ap_table_expiration_time") == 0) {
1901 conf
->ap_table_expiration_time
= atoi(pos
);
1902 } else if (os_strncmp(buf
, "tx_queue_", 9) == 0) {
1903 if (hostapd_config_tx_queue(conf
, buf
, pos
)) {
1904 printf("Line %d: invalid TX queue item\n",
1908 } else if (os_strcmp(buf
, "wme_enabled") == 0) {
1909 bss
->wme_enabled
= atoi(pos
);
1910 } else if (os_strncmp(buf
, "wme_ac_", 7) == 0) {
1911 if (hostapd_config_wme_ac(conf
, buf
, pos
)) {
1912 printf("Line %d: invalid wme ac item\n",
1916 } else if (os_strcmp(buf
, "bss") == 0) {
1917 if (hostapd_config_bss(conf
, pos
)) {
1918 printf("Line %d: invalid bss item\n", line
);
1921 } else if (os_strcmp(buf
, "bssid") == 0) {
1922 if (bss
== conf
->bss
&&
1923 (!conf
->driver
|| !conf
->driver
->init_bssid
)) {
1924 printf("Line %d: bssid item not allowed "
1925 "for the default interface and this "
1928 } else if (hwaddr_aton(pos
, bss
->bssid
)) {
1929 printf("Line %d: invalid bssid item\n", line
);
1932 #ifdef CONFIG_IEEE80211W
1933 } else if (os_strcmp(buf
, "ieee80211w") == 0) {
1934 bss
->ieee80211w
= atoi(pos
);
1935 #endif /* CONFIG_IEEE80211W */
1936 } else if (os_strcmp(buf
, "max_listen_interval") == 0) {
1937 bss
->max_listen_interval
= atoi(pos
);
1938 } else if (os_strcmp(buf
, "okc") == 0) {
1939 bss
->okc
= atoi(pos
);
1941 printf("Line %d: unknown configuration item '%s'\n",
1949 if (bss
->individual_wep_key_len
== 0) {
1950 /* individual keys are not use; can use key idx0 for broadcast
1952 bss
->broadcast_key_idx_min
= 0;
1955 /* Select group cipher based on the enabled pairwise cipher suites */
1958 pairwise
|= bss
->wpa_pairwise
;
1960 if (bss
->rsn_pairwise
== 0)
1961 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1962 pairwise
|= bss
->rsn_pairwise
;
1964 if (pairwise
& WPA_CIPHER_TKIP
)
1965 bss
->wpa_group
= WPA_CIPHER_TKIP
;
1967 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1969 for (i
= 0; i
< conf
->num_bss
; i
++) {
1970 bss
= &conf
->bss
[i
];
1972 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1973 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1975 if (bss
->wpa
&& bss
->ieee802_1x
) {
1976 bss
->ssid
.security_policy
= SECURITY_WPA
;
1977 } else if (bss
->wpa
) {
1978 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1979 } else if (bss
->ieee802_1x
) {
1980 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1981 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1982 } else if (bss
->ssid
.wep
.keys_set
)
1983 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1985 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1988 if (hostapd_config_check(conf
))
1992 printf("%d errors found in configuration file '%s'\n",
1994 hostapd_config_free(conf
);
2002 int hostapd_wep_key_cmp(struct hostapd_wep_keys
*a
, struct hostapd_wep_keys
*b
)
2006 if (a
->idx
!= b
->idx
|| a
->default_len
!= b
->default_len
)
2008 for (i
= 0; i
< NUM_WEP_KEYS
; i
++)
2009 if (a
->len
[i
] != b
->len
[i
] ||
2010 os_memcmp(a
->key
[i
], b
->key
[i
], a
->len
[i
]) != 0)
2016 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
2021 for (i
= 0; i
< num_servers
; i
++) {
2022 os_free(servers
[i
].shared_secret
);
2028 static void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
2030 os_free(user
->identity
);
2031 os_free(user
->password
);
2036 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
2039 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
2040 os_free(keys
->key
[i
]);
2041 keys
->key
[i
] = NULL
;
2046 static void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
2048 struct hostapd_wpa_psk
*psk
, *prev
;
2049 struct hostapd_eap_user
*user
, *prev_user
;
2054 psk
= conf
->ssid
.wpa_psk
;
2061 os_free(conf
->ssid
.wpa_passphrase
);
2062 os_free(conf
->ssid
.wpa_psk_file
);
2063 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2064 os_free(conf
->ssid
.vlan_tagged_interface
);
2065 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2067 user
= conf
->eap_user
;
2071 hostapd_config_free_eap_user(prev_user
);
2074 os_free(conf
->dump_log_name
);
2075 os_free(conf
->eap_req_id_text
);
2076 os_free(conf
->accept_mac
);
2077 os_free(conf
->deny_mac
);
2078 os_free(conf
->nas_identifier
);
2079 hostapd_config_free_radius(conf
->radius
->auth_servers
,
2080 conf
->radius
->num_auth_servers
);
2081 hostapd_config_free_radius(conf
->radius
->acct_servers
,
2082 conf
->radius
->num_acct_servers
);
2083 os_free(conf
->rsn_preauth_interfaces
);
2084 os_free(conf
->ctrl_interface
);
2085 os_free(conf
->ca_cert
);
2086 os_free(conf
->server_cert
);
2087 os_free(conf
->private_key
);
2088 os_free(conf
->private_key_passwd
);
2089 os_free(conf
->dh_file
);
2090 os_free(conf
->pac_opaque_encr_key
);
2091 os_free(conf
->eap_fast_a_id
);
2092 os_free(conf
->eap_sim_db
);
2093 os_free(conf
->radius_server_clients
);
2094 os_free(conf
->test_socket
);
2095 os_free(conf
->radius
);
2096 hostapd_config_free_vlan(conf
);
2097 if (conf
->ssid
.dyn_vlan_keys
) {
2098 struct hostapd_ssid
*ssid
= &conf
->ssid
;
2100 for (i
= 0; i
<= ssid
->max_dyn_vlan_keys
; i
++) {
2101 if (ssid
->dyn_vlan_keys
[i
] == NULL
)
2103 hostapd_config_free_wep(ssid
->dyn_vlan_keys
[i
]);
2104 os_free(ssid
->dyn_vlan_keys
[i
]);
2106 os_free(ssid
->dyn_vlan_keys
);
2107 ssid
->dyn_vlan_keys
= NULL
;
2110 #ifdef CONFIG_IEEE80211R
2112 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
2113 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
2115 r0kh
= conf
->r0kh_list
;
2116 conf
->r0kh_list
= NULL
;
2123 r1kh
= conf
->r1kh_list
;
2124 conf
->r1kh_list
= NULL
;
2131 #endif /* CONFIG_IEEE80211R */
2135 void hostapd_config_free(struct hostapd_config
*conf
)
2142 for (i
= 0; i
< conf
->num_bss
; i
++)
2143 hostapd_config_free_bss(&conf
->bss
[i
]);
2150 /* Perform a binary search for given MAC address from a pre-sorted list.
2151 * Returns 1 if address is in the list or 0 if not. */
2152 int hostapd_maclist_found(macaddr
*list
, int num_entries
, const u8
*addr
)
2154 int start
, end
, middle
, res
;
2157 end
= num_entries
- 1;
2159 while (start
<= end
) {
2160 middle
= (start
+ end
) / 2;
2161 res
= os_memcmp(list
[middle
], addr
, ETH_ALEN
);
2174 int hostapd_rate_found(int *list
, int rate
)
2181 for (i
= 0; list
[i
] >= 0; i
++)
2182 if (list
[i
] == rate
)
2189 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
2191 struct hostapd_vlan
*v
= vlan
;
2193 if (v
->vlan_id
== vlan_id
|| v
->vlan_id
== VLAN_ID_WILDCARD
)
2201 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
2202 const u8
*addr
, const u8
*prev_psk
)
2204 struct hostapd_wpa_psk
*psk
;
2205 int next_ok
= prev_psk
== NULL
;
2207 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
2209 (psk
->group
|| os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0))
2212 if (psk
->psk
== prev_psk
)
2220 const struct hostapd_eap_user
*
2221 hostapd_get_eap_user(const struct hostapd_bss_config
*conf
, const u8
*identity
,
2222 size_t identity_len
, int phase2
)
2224 struct hostapd_eap_user
*user
= conf
->eap_user
;
2227 if (!phase2
&& user
->identity
== NULL
) {
2228 /* Wildcard match */
2232 if (user
->phase2
== !!phase2
&& user
->wildcard_prefix
&&
2233 identity_len
>= user
->identity_len
&&
2234 os_memcmp(user
->identity
, identity
, user
->identity_len
) ==
2236 /* Wildcard prefix match */
2240 if (user
->phase2
== !!phase2
&&
2241 user
->identity_len
== identity_len
&&
2242 os_memcmp(user
->identity
, identity
, identity_len
) == 0)