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 "common/wpa_common.h"
14 
15 #define MAX_STA_COUNT 4
16 #define MAX_VLAN_ID 4094
17 
18 typedef u8 macaddr[ETH_ALEN];
19 
20 struct mac_acl_entry {
21 	macaddr addr;
22 	int vlan_id;
23 };
24 
25 struct hostapd_radius_servers;
26 struct ft_remote_r0kh;
27 struct ft_remote_r1kh;
28 
29 #define HOSTAPD_MAX_SSID_LEN 32
30 
31 #define NUM_WEP_KEYS 4
32 struct hostapd_wep_keys {
33 	u8 idx;
34 	u8 *key[NUM_WEP_KEYS];
35 	size_t len[NUM_WEP_KEYS];
36 	int keys_set;
37 	size_t default_len; /* key length used for dynamic key generation */
38 };
39 
40 typedef enum hostap_security_policy {
41 	SECURITY_PLAINTEXT = 0,
42 	SECURITY_STATIC_WEP = 1,
43 	SECURITY_IEEE_802_1X = 2,
44 	SECURITY_WPA_PSK = 3,
45 	SECURITY_WPA = 4
46 } secpolicy;
47 
48 struct hostapd_ssid {
49 	u8 ssid[HOSTAPD_MAX_SSID_LEN];
50 	size_t ssid_len;
51 	unsigned int ssid_set:1;
52 	unsigned int utf8_ssid:1;
53 
54 	struct hostapd_wpa_psk *wpa_psk;
55 	char *wpa_passphrase;
56 
57 	struct hostapd_wep_keys wep;
58 
59 #if 0
60 #define DYNAMIC_VLAN_DISABLED 0
61 #define DYNAMIC_VLAN_OPTIONAL 1
62 #define DYNAMIC_VLAN_REQUIRED 2
63 	int dynamic_vlan;
64 #define DYNAMIC_VLAN_NAMING_WITHOUT_DEVICE 0
65 #define DYNAMIC_VLAN_NAMING_WITH_DEVICE 1
66 #define DYNAMIC_VLAN_NAMING_END 2
67 	int vlan_naming;
68 #ifdef CONFIG_FULL_DYNAMIC_VLAN
69 	char *vlan_tagged_interface;
70 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
71 	struct hostapd_wep_keys **dyn_vlan_keys;
72 	size_t max_dyn_vlan_keys;
73 #endif
74 };
75 
76 #if 0
77 #define VLAN_ID_WILDCARD -1
78 
79 struct hostapd_vlan {
80 	struct hostapd_vlan *next;
81 	int vlan_id; /* VLAN ID or -1 (VLAN_ID_WILDCARD) for wildcard entry */
82 	char ifname[IFNAMSIZ + 1];
83 	int dynamic_vlan;
84 #ifdef CONFIG_FULL_DYNAMIC_VLAN
85 
86 #define DVLAN_CLEAN_BR 	0x1
87 #define DVLAN_CLEAN_VLAN	0x2
88 #define DVLAN_CLEAN_VLAN_PORT	0x4
89 #define DVLAN_CLEAN_WLAN_PORT	0x8
90 	int clean;
91 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
92 };
93 #endif
94 
95 #define PMK_LEN 32
96 struct hostapd_sta_wpa_psk_short {
97 	struct hostapd_sta_wpa_psk_short *next;
98 	u8 psk[PMK_LEN];
99 };
100 
101 struct hostapd_wpa_psk {
102 	struct hostapd_wpa_psk *next;
103 	int group;
104 	u8 psk[PMK_LEN];
105 	u8 addr[ETH_ALEN];
106 };
107 
108 #if 0
109 struct hostapd_eap_user {
110 	struct hostapd_eap_user *next;
111 	u8 *identity;
112 	size_t identity_len;
113 	struct {
114 		int vendor;
115 		u32 method;
116 	} methods[EAP_MAX_METHODS];
117 	u8 *password;
118 	size_t password_len;
119 	int phase2;
120 	int force_version;
121 	unsigned int wildcard_prefix:1;
122 	unsigned int password_hash:1; /* whether password is hashed with
123 				       * nt_password_hash() */
124 	int ttls_auth; /* EAP_TTLS_AUTH_* bitfield */
125 };
126 
127 struct hostapd_radius_attr {
128 	u8 type;
129 	struct wpabuf *val;
130 	struct hostapd_radius_attr *next;
131 };
132 
133 
134 #define NUM_TX_QUEUES 4
135 
136 struct hostapd_tx_queue_params {
137 	int aifs;
138 	int cwmin;
139 	int cwmax;
140 	int burst; /* maximum burst time in 0.1 ms, i.e., 10 = 1 ms */
141 };
142 
143 
144 #define MAX_ROAMING_CONSORTIUM_LEN 15
145 
146 struct hostapd_roaming_consortium {
147 	u8 len;
148 	u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
149 };
150 
151 struct hostapd_lang_string {
152 	u8 lang[3];
153 	u8 name_len;
154 	u8 name[252];
155 };
156 
157 #define MAX_NAI_REALMS 10
158 #define MAX_NAI_REALMLEN 255
159 #define MAX_NAI_EAP_METHODS 5
160 #define MAX_NAI_AUTH_TYPES 4
161 struct hostapd_nai_realm_data {
162 	u8 encoding;
163 	char realm_buf[MAX_NAI_REALMLEN + 1];
164 	char *realm[MAX_NAI_REALMS];
165 	u8 eap_method_count;
166 	struct hostapd_nai_realm_eap {
167 		u8 eap_method;
168 		u8 num_auths;
169 		u8 auth_id[MAX_NAI_AUTH_TYPES];
170 		u8 auth_val[MAX_NAI_AUTH_TYPES];
171 	} eap_method[MAX_NAI_EAP_METHODS];
172 };
173 #endif
174 
175 /**
176  * struct hostapd_bss_config - Per-BSS configuration
177  */
178 struct hostapd_bss_config {
179 	int max_num_sta; /* maximum number of STAs in station table */
180 
181 	int dtim_period;
182 
183 	int ieee802_1x; /* use IEEE 802.1X */
184 	int eapol_version;
185 	struct hostapd_ssid ssid;
186 
187 	int wep_rekeying_period;
188 	int broadcast_key_idx_min, broadcast_key_idx_max;
189 
190 	enum {
191 		ACCEPT_UNLESS_DENIED = 0,
192 		DENY_UNLESS_ACCEPTED = 1,
193 		USE_EXTERNAL_RADIUS_AUTH = 2
194 	} macaddr_acl;
195 
196 	int auth_algs; /* bitfield of allowed IEEE 802.11 authentication
197 			* algorithms, WPA_AUTH_ALG_{OPEN,SHARED,LEAP} */
198 
199 	int wpa; /* bitfield of WPA_PROTO_WPA, WPA_PROTO_RSN */
200 	int wpa_key_mgmt;
201 #ifdef CONFIG_IEEE80211W
202 	enum mfp_options ieee80211w;
203 	/* dot11AssociationSAQueryMaximumTimeout (in TUs) */
204 	unsigned int assoc_sa_query_max_timeout;
205 	/* dot11AssociationSAQueryRetryTimeout (in TUs) */
206 	int assoc_sa_query_retry_timeout;
207 #endif /* CONFIG_IEEE80211W */
208 	enum {
209 		PSK_RADIUS_IGNORED = 0,
210 		PSK_RADIUS_ACCEPTED = 1,
211 		PSK_RADIUS_REQUIRED = 2
212 	} wpa_psk_radius;
213 	int wpa_pairwise;
214 	int wpa_group;
215 	int wpa_group_rekey;
216 	int wpa_strict_rekey;
217 	int wpa_gmk_rekey;
218 	int wpa_ptk_rekey;
219 	int rsn_pairwise;
220 	int rsn_preauth;
221 	char *rsn_preauth_interfaces;
222 	int peerkey;
223 
224 #ifdef CONFIG_IEEE80211R
225 	/* IEEE 802.11r - Fast BSS Transition */
226 	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
227 	u8 r1_key_holder[FT_R1KH_ID_LEN];
228 	u32 r0_key_lifetime;
229 	u32 reassociation_deadline;
230 	struct ft_remote_r0kh *r0kh_list;
231 	struct ft_remote_r1kh *r1kh_list;
232 	int pmk_r1_push;
233 	int ft_over_ds;
234 #endif /* CONFIG_IEEE80211R */
235 
236 	int ap_max_inactivity;
237 	int ignore_broadcast_ssid;
238 
239 	int wmm_enabled;
240 	int wmm_uapsd;
241 
242 	macaddr bssid;
243 
244 	/*
245 	 * Maximum listen interval that STAs can use when associating with this
246 	 * BSS. If a STA tries to use larger value, the association will be
247 	 * denied with status code 51.
248 	 */
249 	u16 max_listen_interval;
250 
251 #ifdef CONFIG_WPS
252 	int ap_setup_locked;
253 	u8 uuid[16];
254 	char *wps_pin_requests;
255 	char *device_name;
256 	char *manufacturer;
257 	char *model_name;
258 	char *model_number;
259 	char *serial_number;
260 	u8 device_type[WPS_DEV_TYPE_LEN];
261 	char *config_methods;
262 	u8 os_version[4];
263 	char *ap_pin;
264 	int skip_cred_build;
265 	u8 *extra_cred;
266 	size_t extra_cred_len;
267 	int wps_cred_processing;
268 	u8 *ap_settings;
269 	size_t ap_settings_len;
270 	char *upnp_iface;
271 	char *friendly_name;
272 	char *manufacturer_url;
273 	char *model_description;
274 	char *model_url;
275 	char *upc;
276 	struct wpabuf *wps_vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
277 	int wps_nfc_dev_pw_id;
278 	struct wpabuf *wps_nfc_dh_pubkey;
279 	struct wpabuf *wps_nfc_dh_privkey;
280 	struct wpabuf *wps_nfc_dev_pw;
281 #endif /* CONFIG_WPS */
282 
283 #ifdef CONFIG_HS20
284 	int hs20;
285 	int disable_dgaf;
286 	unsigned int hs20_oper_friendly_name_count;
287 	struct hostapd_lang_string *hs20_oper_friendly_name;
288 	u8 *hs20_wan_metrics;
289 	u8 *hs20_connection_capability;
290 	size_t hs20_connection_capability_len;
291 	u8 *hs20_operating_class;
292 	u8 hs20_operating_class_len;
293 #endif /* CONFIG_HS20 */
294 
295 #ifdef CONFIG_RADIUS_TEST
296 	char *dump_msk_file;
297 #endif /* CONFIG_RADIUS_TEST */
298 
299 };
300 
301 
302 /**
303  * struct hostapd_config - Per-radio interface configuration
304  */
305 struct hostapd_config {
306 	struct hostapd_bss_config *bss, *last_bss;
307 	size_t num_bss;
308 
309 	u16 beacon_int;
310 	int rts_threshold;
311 	int fragm_threshold;
312 	u8 send_probe_response;
313 	u8 channel;
314 	enum hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */
315 	enum {
316 		LONG_PREAMBLE = 0,
317 		SHORT_PREAMBLE = 1
318 	} preamble;
319 
320 	int *supported_rates;
321 	int *basic_rates;
322 
323 	const struct wpa_driver_ops *driver;
324 
325 	int ap_table_max_size;
326 	int ap_table_expiration_time;
327 
328 	char country[3]; /* first two octets: country code as described in
329 			  * ISO/IEC 3166-1. Third octet:
330 			  * ' ' (ascii 32): all environments
331 			  * 'O': Outdoor environemnt only
332 			  * 'I': Indoor environment only
333 			  */
334 
335 	int ieee80211d;
336 
337 	/*
338 	 * WMM AC parameters, in same order as 802.1D, i.e.
339 	 * 0 = BE (best effort)
340 	 * 1 = BK (background)
341 	 * 2 = VI (video)
342 	 * 3 = VO (voice)
343 	 */
344 
345 	int ht_op_mode_fixed;
346 	u16 ht_capab;
347 	int ieee80211n;
348 	int secondary_channel;
349 	int require_ht;
350 	u32 vht_capab;
351 	int ieee80211ac;
352 	int require_vht;
353 	u8 vht_oper_chwidth;
354 	u8 vht_oper_centr_freq_seg0_idx;
355 	u8 vht_oper_centr_freq_seg1_idx;
356 };
357 
358 
359 int hostapd_mac_comp(const void *a, const void *b);
360 int hostapd_mac_comp_empty(const void *a);
361 struct hostapd_config * hostapd_config_defaults(void);
362 void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
363 void hostapd_config_free(struct hostapd_config *conf);
364 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
365 			  const u8 *addr, int *vlan_id);
366 int hostapd_rate_found(int *list, int rate);
367 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a,
368 			struct hostapd_wep_keys *b);
369 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
370 			   const u8 *addr, const u8 *prev_psk);
371 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf);
372 bool wpa_ap_join(void** sm, uint8_t *bssid, uint8_t *wpa_ie, uint8_t wpa_ie_len);
373 bool wpa_ap_remove(void* sm);
374 
375 #endif /* HOSTAPD_CONFIG_H */
376