VLAN: Avoid access to non-existing interfaces
[mech_eap.git] / src / ap / ap_config.h
1 /*
2  * hostapd / Configuration definitions and helpers functions
3  * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #ifndef HOSTAPD_CONFIG_H
10 #define HOSTAPD_CONFIG_H
11
12 #include "common/defs.h"
13 #include "ip_addr.h"
14 #include "common/wpa_common.h"
15 #include "common/ieee802_11_common.h"
16 #include "wps/wps.h"
17
18 #define MAX_STA_COUNT 2007
19 #define MAX_VLAN_ID 4094
20
21 typedef u8 macaddr[ETH_ALEN];
22
23 struct mac_acl_entry {
24         macaddr addr;
25         int vlan_id;
26 };
27
28 struct hostapd_radius_servers;
29 struct ft_remote_r0kh;
30 struct ft_remote_r1kh;
31
32 #define HOSTAPD_MAX_SSID_LEN 32
33
34 #define NUM_WEP_KEYS 4
35 struct hostapd_wep_keys {
36         u8 idx;
37         u8 *key[NUM_WEP_KEYS];
38         size_t len[NUM_WEP_KEYS];
39         int keys_set;
40         size_t default_len; /* key length used for dynamic key generation */
41 };
42
43 typedef enum hostap_security_policy {
44         SECURITY_PLAINTEXT = 0,
45         SECURITY_STATIC_WEP = 1,
46         SECURITY_IEEE_802_1X = 2,
47         SECURITY_WPA_PSK = 3,
48         SECURITY_WPA = 4
49 } secpolicy;
50
51 struct hostapd_ssid {
52         u8 ssid[HOSTAPD_MAX_SSID_LEN];
53         size_t ssid_len;
54         unsigned int ssid_set:1;
55         unsigned int utf8_ssid:1;
56
57         char vlan[IFNAMSIZ + 1];
58         secpolicy security_policy;
59
60         struct hostapd_wpa_psk *wpa_psk;
61         char *wpa_passphrase;
62         char *wpa_psk_file;
63
64         struct hostapd_wep_keys wep;
65
66 #define DYNAMIC_VLAN_DISABLED 0
67 #define DYNAMIC_VLAN_OPTIONAL 1
68 #define DYNAMIC_VLAN_REQUIRED 2
69         int dynamic_vlan;
70 #define DYNAMIC_VLAN_NAMING_WITHOUT_DEVICE 0
71 #define DYNAMIC_VLAN_NAMING_WITH_DEVICE 1
72 #define DYNAMIC_VLAN_NAMING_END 2
73         int vlan_naming;
74 #ifdef CONFIG_FULL_DYNAMIC_VLAN
75         char *vlan_tagged_interface;
76 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
77         struct hostapd_wep_keys **dyn_vlan_keys;
78         size_t max_dyn_vlan_keys;
79 };
80
81
82 #define VLAN_ID_WILDCARD -1
83
84 struct hostapd_vlan {
85         struct hostapd_vlan *next;
86         int vlan_id; /* VLAN ID or -1 (VLAN_ID_WILDCARD) for wildcard entry */
87         char ifname[IFNAMSIZ + 1];
88         int dynamic_vlan;
89 #ifdef CONFIG_FULL_DYNAMIC_VLAN
90
91 #define DVLAN_CLEAN_BR  0x1
92 #define DVLAN_CLEAN_VLAN        0x2
93 #define DVLAN_CLEAN_VLAN_PORT   0x4
94 #define DVLAN_CLEAN_WLAN_PORT   0x8
95         int clean;
96 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
97 };
98
99 #define PMK_LEN 32
100 struct hostapd_sta_wpa_psk_short {
101         struct hostapd_sta_wpa_psk_short *next;
102         u8 psk[PMK_LEN];
103 };
104
105 struct hostapd_wpa_psk {
106         struct hostapd_wpa_psk *next;
107         int group;
108         u8 psk[PMK_LEN];
109         u8 addr[ETH_ALEN];
110 };
111
112 struct hostapd_eap_user {
113         struct hostapd_eap_user *next;
114         u8 *identity;
115         size_t identity_len;
116         struct {
117                 int vendor;
118                 u32 method;
119         } methods[EAP_MAX_METHODS];
120         u8 *password;
121         size_t password_len;
122         int phase2;
123         int force_version;
124         unsigned int wildcard_prefix:1;
125         unsigned int password_hash:1; /* whether password is hashed with
126                                        * nt_password_hash() */
127         int ttls_auth; /* EAP_TTLS_AUTH_* bitfield */
128 };
129
130 struct hostapd_radius_attr {
131         u8 type;
132         struct wpabuf *val;
133         struct hostapd_radius_attr *next;
134 };
135
136
137 #define NUM_TX_QUEUES 4
138
139 struct hostapd_tx_queue_params {
140         int aifs;
141         int cwmin;
142         int cwmax;
143         int burst; /* maximum burst time in 0.1 ms, i.e., 10 = 1 ms */
144 };
145
146
147 #define MAX_ROAMING_CONSORTIUM_LEN 15
148
149 struct hostapd_roaming_consortium {
150         u8 len;
151         u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
152 };
153
154 struct hostapd_lang_string {
155         u8 lang[3];
156         u8 name_len;
157         u8 name[252];
158 };
159
160 #define MAX_NAI_REALMS 10
161 #define MAX_NAI_REALMLEN 255
162 #define MAX_NAI_EAP_METHODS 5
163 #define MAX_NAI_AUTH_TYPES 4
164 struct hostapd_nai_realm_data {
165         u8 encoding;
166         char realm_buf[MAX_NAI_REALMLEN + 1];
167         char *realm[MAX_NAI_REALMS];
168         u8 eap_method_count;
169         struct hostapd_nai_realm_eap {
170                 u8 eap_method;
171                 u8 num_auths;
172                 u8 auth_id[MAX_NAI_AUTH_TYPES];
173                 u8 auth_val[MAX_NAI_AUTH_TYPES];
174         } eap_method[MAX_NAI_EAP_METHODS];
175 };
176
177 /**
178  * struct hostapd_bss_config - Per-BSS configuration
179  */
180 struct hostapd_bss_config {
181         char iface[IFNAMSIZ + 1];
182         char bridge[IFNAMSIZ + 1];
183         char vlan_bridge[IFNAMSIZ + 1];
184         char wds_bridge[IFNAMSIZ + 1];
185
186         enum hostapd_logger_level logger_syslog_level, logger_stdout_level;
187
188         unsigned int logger_syslog; /* module bitfield */
189         unsigned int logger_stdout; /* module bitfield */
190
191         char *dump_log_name; /* file name for state dump (SIGUSR1) */
192
193         int max_num_sta; /* maximum number of STAs in station table */
194
195         int dtim_period;
196
197         int ieee802_1x; /* use IEEE 802.1X */
198         int eapol_version;
199         int eap_server; /* Use internal EAP server instead of external
200                          * RADIUS server */
201         struct hostapd_eap_user *eap_user;
202         char *eap_user_sqlite;
203         char *eap_sim_db;
204         struct hostapd_ip_addr own_ip_addr;
205         char *nas_identifier;
206         struct hostapd_radius_servers *radius;
207         int acct_interim_interval;
208         int radius_request_cui;
209         struct hostapd_radius_attr *radius_auth_req_attr;
210         struct hostapd_radius_attr *radius_acct_req_attr;
211         int radius_das_port;
212         unsigned int radius_das_time_window;
213         int radius_das_require_event_timestamp;
214         struct hostapd_ip_addr radius_das_client_addr;
215         u8 *radius_das_shared_secret;
216         size_t radius_das_shared_secret_len;
217
218         struct hostapd_ssid ssid;
219
220         char *eap_req_id_text; /* optional displayable message sent with
221                                 * EAP Request-Identity */
222         size_t eap_req_id_text_len;
223         int eapol_key_index_workaround;
224
225         size_t default_wep_key_len;
226         int individual_wep_key_len;
227         int wep_rekeying_period;
228         int broadcast_key_idx_min, broadcast_key_idx_max;
229         int eap_reauth_period;
230
231         int ieee802_11f; /* use IEEE 802.11f (IAPP) */
232         char iapp_iface[IFNAMSIZ + 1]; /* interface used with IAPP broadcast
233                                         * frames */
234
235         enum {
236                 ACCEPT_UNLESS_DENIED = 0,
237                 DENY_UNLESS_ACCEPTED = 1,
238                 USE_EXTERNAL_RADIUS_AUTH = 2
239         } macaddr_acl;
240         struct mac_acl_entry *accept_mac;
241         int num_accept_mac;
242         struct mac_acl_entry *deny_mac;
243         int num_deny_mac;
244         int wds_sta;
245         int isolate;
246
247         int auth_algs; /* bitfield of allowed IEEE 802.11 authentication
248                         * algorithms, WPA_AUTH_ALG_{OPEN,SHARED,LEAP} */
249
250         int wpa; /* bitfield of WPA_PROTO_WPA, WPA_PROTO_RSN */
251         int wpa_key_mgmt;
252 #ifdef CONFIG_IEEE80211W
253         enum mfp_options ieee80211w;
254         /* dot11AssociationSAQueryMaximumTimeout (in TUs) */
255         unsigned int assoc_sa_query_max_timeout;
256         /* dot11AssociationSAQueryRetryTimeout (in TUs) */
257         int assoc_sa_query_retry_timeout;
258 #endif /* CONFIG_IEEE80211W */
259         enum {
260                 PSK_RADIUS_IGNORED = 0,
261                 PSK_RADIUS_ACCEPTED = 1,
262                 PSK_RADIUS_REQUIRED = 2
263         } wpa_psk_radius;
264         int wpa_pairwise;
265         int wpa_group;
266         int wpa_group_rekey;
267         int wpa_strict_rekey;
268         int wpa_gmk_rekey;
269         int wpa_ptk_rekey;
270         int rsn_pairwise;
271         int rsn_preauth;
272         char *rsn_preauth_interfaces;
273         int peerkey;
274
275 #ifdef CONFIG_IEEE80211R
276         /* IEEE 802.11r - Fast BSS Transition */
277         u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
278         u8 r1_key_holder[FT_R1KH_ID_LEN];
279         u32 r0_key_lifetime;
280         u32 reassociation_deadline;
281         struct ft_remote_r0kh *r0kh_list;
282         struct ft_remote_r1kh *r1kh_list;
283         int pmk_r1_push;
284         int ft_over_ds;
285 #endif /* CONFIG_IEEE80211R */
286
287         char *ctrl_interface; /* directory for UNIX domain sockets */
288 #ifndef CONFIG_NATIVE_WINDOWS
289         gid_t ctrl_interface_gid;
290 #endif /* CONFIG_NATIVE_WINDOWS */
291         int ctrl_interface_gid_set;
292
293         char *ca_cert;
294         char *server_cert;
295         char *private_key;
296         char *private_key_passwd;
297         int check_crl;
298         char *dh_file;
299         u8 *pac_opaque_encr_key;
300         u8 *eap_fast_a_id;
301         size_t eap_fast_a_id_len;
302         char *eap_fast_a_id_info;
303         int eap_fast_prov;
304         int pac_key_lifetime;
305         int pac_key_refresh_time;
306         int eap_sim_aka_result_ind;
307         int tnc;
308         int fragment_size;
309         u16 pwd_group;
310
311         char *radius_server_clients;
312         int radius_server_auth_port;
313         int radius_server_ipv6;
314
315         char *test_socket; /* UNIX domain socket path for driver_test */
316
317         int use_pae_group_addr; /* Whether to send EAPOL frames to PAE group
318                                  * address instead of individual address
319                                  * (for driver_wired.c).
320                                  */
321
322         int ap_max_inactivity;
323         int ignore_broadcast_ssid;
324
325         int wmm_enabled;
326         int wmm_uapsd;
327
328         struct hostapd_vlan *vlan, *vlan_tail;
329
330         macaddr bssid;
331
332         /*
333          * Maximum listen interval that STAs can use when associating with this
334          * BSS. If a STA tries to use larger value, the association will be
335          * denied with status code 51.
336          */
337         u16 max_listen_interval;
338
339         int disable_pmksa_caching;
340         int okc; /* Opportunistic Key Caching */
341
342         int wps_state;
343 #ifdef CONFIG_WPS
344         int wps_independent;
345         int ap_setup_locked;
346         u8 uuid[16];
347         char *wps_pin_requests;
348         char *device_name;
349         char *manufacturer;
350         char *model_name;
351         char *model_number;
352         char *serial_number;
353         u8 device_type[WPS_DEV_TYPE_LEN];
354         char *config_methods;
355         u8 os_version[4];
356         char *ap_pin;
357         int skip_cred_build;
358         u8 *extra_cred;
359         size_t extra_cred_len;
360         int wps_cred_processing;
361         u8 *ap_settings;
362         size_t ap_settings_len;
363         char *upnp_iface;
364         char *friendly_name;
365         char *manufacturer_url;
366         char *model_description;
367         char *model_url;
368         char *upc;
369         struct wpabuf *wps_vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
370         int wps_nfc_pw_from_config;
371         int wps_nfc_dev_pw_id;
372         struct wpabuf *wps_nfc_dh_pubkey;
373         struct wpabuf *wps_nfc_dh_privkey;
374         struct wpabuf *wps_nfc_dev_pw;
375 #endif /* CONFIG_WPS */
376         int pbc_in_m1;
377
378 #define P2P_ENABLED BIT(0)
379 #define P2P_GROUP_OWNER BIT(1)
380 #define P2P_GROUP_FORMATION BIT(2)
381 #define P2P_MANAGE BIT(3)
382 #define P2P_ALLOW_CROSS_CONNECTION BIT(4)
383         int p2p;
384
385         int disassoc_low_ack;
386         int skip_inactivity_poll;
387
388 #define TDLS_PROHIBIT BIT(0)
389 #define TDLS_PROHIBIT_CHAN_SWITCH BIT(1)
390         int tdls;
391         int disable_11n;
392         int disable_11ac;
393
394         /* IEEE 802.11v */
395         int time_advertisement;
396         char *time_zone;
397         int wnm_sleep_mode;
398         int bss_transition;
399
400         /* IEEE 802.11u - Interworking */
401         int interworking;
402         int access_network_type;
403         int internet;
404         int asra;
405         int esr;
406         int uesa;
407         int venue_info_set;
408         u8 venue_group;
409         u8 venue_type;
410         u8 hessid[ETH_ALEN];
411
412         /* IEEE 802.11u - Roaming Consortium list */
413         unsigned int roaming_consortium_count;
414         struct hostapd_roaming_consortium *roaming_consortium;
415
416         /* IEEE 802.11u - Venue Name duples */
417         unsigned int venue_name_count;
418         struct hostapd_lang_string *venue_name;
419
420         /* IEEE 802.11u - Network Authentication Type */
421         u8 *network_auth_type;
422         size_t network_auth_type_len;
423
424         /* IEEE 802.11u - IP Address Type Availability */
425         u8 ipaddr_type_availability;
426         u8 ipaddr_type_configured;
427
428         /* IEEE 802.11u - 3GPP Cellular Network */
429         u8 *anqp_3gpp_cell_net;
430         size_t anqp_3gpp_cell_net_len;
431
432         /* IEEE 802.11u - Domain Name */
433         u8 *domain_name;
434         size_t domain_name_len;
435
436         unsigned int nai_realm_count;
437         struct hostapd_nai_realm_data *nai_realm_data;
438
439         u16 gas_comeback_delay;
440         int gas_frag_limit;
441
442 #ifdef CONFIG_HS20
443         int hs20;
444         int disable_dgaf;
445         unsigned int hs20_oper_friendly_name_count;
446         struct hostapd_lang_string *hs20_oper_friendly_name;
447         u8 *hs20_wan_metrics;
448         u8 *hs20_connection_capability;
449         size_t hs20_connection_capability_len;
450         u8 *hs20_operating_class;
451         u8 hs20_operating_class_len;
452 #endif /* CONFIG_HS20 */
453
454         u8 wps_rf_bands; /* RF bands for WPS (WPS_RF_*) */
455
456 #ifdef CONFIG_RADIUS_TEST
457         char *dump_msk_file;
458 #endif /* CONFIG_RADIUS_TEST */
459
460         struct wpabuf *vendor_elements;
461
462         unsigned int sae_anti_clogging_threshold;
463         int *sae_groups;
464 };
465
466
467 /**
468  * struct hostapd_config - Per-radio interface configuration
469  */
470 struct hostapd_config {
471         struct hostapd_bss_config *bss, *last_bss;
472         size_t num_bss;
473
474         u16 beacon_int;
475         int rts_threshold;
476         int fragm_threshold;
477         u8 send_probe_response;
478         u8 channel;
479         enum hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */
480         enum {
481                 LONG_PREAMBLE = 0,
482                 SHORT_PREAMBLE = 1
483         } preamble;
484
485         int *supported_rates;
486         int *basic_rates;
487
488         const struct wpa_driver_ops *driver;
489
490         int ap_table_max_size;
491         int ap_table_expiration_time;
492
493         char country[3]; /* first two octets: country code as described in
494                           * ISO/IEC 3166-1. Third octet:
495                           * ' ' (ascii 32): all environments
496                           * 'O': Outdoor environemnt only
497                           * 'I': Indoor environment only
498                           */
499
500         int ieee80211d;
501
502         int ieee80211h; /* DFS */
503
504         struct hostapd_tx_queue_params tx_queue[NUM_TX_QUEUES];
505
506         /*
507          * WMM AC parameters, in same order as 802.1D, i.e.
508          * 0 = BE (best effort)
509          * 1 = BK (background)
510          * 2 = VI (video)
511          * 3 = VO (voice)
512          */
513         struct hostapd_wmm_ac_params wmm_ac_params[4];
514
515         int ht_op_mode_fixed;
516         u16 ht_capab;
517         int ieee80211n;
518         int secondary_channel;
519         int require_ht;
520         u32 vht_capab;
521         int ieee80211ac;
522         int require_vht;
523         u8 vht_oper_chwidth;
524         u8 vht_oper_centr_freq_seg0_idx;
525         u8 vht_oper_centr_freq_seg1_idx;
526
527 #ifdef CONFIG_TESTING_OPTIONS
528         double ignore_probe_probability;
529         double ignore_auth_probability;
530         double ignore_assoc_probability;
531         double ignore_reassoc_probability;
532         double corrupt_gtk_rekey_mic_probability;
533 #endif /* CONFIG_TESTING_OPTIONS */
534 };
535
536
537 int hostapd_mac_comp(const void *a, const void *b);
538 int hostapd_mac_comp_empty(const void *a);
539 struct hostapd_config * hostapd_config_defaults(void);
540 void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
541 void hostapd_config_free(struct hostapd_config *conf);
542 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
543                           const u8 *addr, int *vlan_id);
544 int hostapd_rate_found(int *list, int rate);
545 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a,
546                         struct hostapd_wep_keys *b);
547 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
548                            const u8 *addr, const u8 *prev_psk);
549 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf);
550 int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id);
551 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
552                                         int vlan_id);
553 struct hostapd_radius_attr *
554 hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type);
555
556 #endif /* HOSTAPD_CONFIG_H */