435c7731126176bc00b65d360fac01c4fc8fa250
[libeap.git] / hostapd / hostapd.h
1 /*
2  * hostapd / Initialization and configuration
3  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef HOSTAPD_H
16 #define HOSTAPD_H
17
18 #include "common/defs.h"
19
20 struct wpa_driver_ops;
21 struct wpa_ctrl_dst;
22 struct radius_server_data;
23 struct upnp_wps_device_sm;
24 struct hapd_interfaces;
25 struct hostapd_data;
26 struct sta_info;
27 struct hostap_sta_driver_data;
28
29 #ifdef CONFIG_FULL_DYNAMIC_VLAN
30 struct full_dynamic_vlan;
31 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
32
33 struct hostapd_probereq_cb {
34         void (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
35         void *ctx;
36 };
37
38 #define HOSTAPD_RATE_BASIC 0x00000001
39
40 struct hostapd_rate_data {
41         int rate; /* rate in 100 kbps */
42         int flags; /* HOSTAPD_RATE_ flags */
43 };
44
45
46 struct hostapd_driver_ops {
47         int (*set_ap_wps_ie)(struct hostapd_data *hapd,
48                              const struct wpabuf *beacon,
49                              const struct wpabuf *probe);
50         int (*send_mgmt_frame)(struct hostapd_data *hapd, const void *msg,
51                                size_t len);
52         int (*send_eapol)(struct hostapd_data *hapd, const u8 *addr,
53                           const u8 *data, size_t data_len, int encrypt);
54         int (*set_authorized)(struct hostapd_data *hapd, struct sta_info *sta,
55                               int authorized);
56         int (*set_key)(const char *ifname, struct hostapd_data *hapd,
57                        wpa_alg alg, const u8 *addr, int key_idx,
58                        int set_tx, const u8 *seq, size_t seq_len,
59                        const u8 *key, size_t key_len);
60         int (*read_sta_data)(struct hostapd_data *hapd,
61                              struct hostap_sta_driver_data *data,
62                              const u8 *addr);
63         int (*sta_clear_stats)(struct hostapd_data *hapd, const u8 *addr);
64         int (*set_sta_flags)(struct hostapd_data *hapd, struct sta_info *sta);
65         int (*set_drv_ieee8021x)(struct hostapd_data *hapd, const char *ifname,
66                                  int enabled);
67         int (*set_radius_acl_auth)(struct hostapd_data *hapd,
68                                    const u8 *mac, int accepted,
69                                    u32 session_timeout);
70         int (*set_radius_acl_expire)(struct hostapd_data *hapd,
71                                      const u8 *mac);
72         int (*set_bss_params)(struct hostapd_data *hapd, int use_protection);
73         int (*set_beacon)(const char *ifname, struct hostapd_data *hapd,
74                           const u8 *head, size_t head_len,
75                           const u8 *tail, size_t tail_len, int dtim_period,
76                           int beacon_int);
77         int (*vlan_if_add)(struct hostapd_data *hapd, const char *ifname);
78         int (*vlan_if_remove)(struct hostapd_data *hapd, const char *ifname);
79 };
80
81 /**
82  * struct hostapd_data - hostapd per-BSS data structure
83  */
84 struct hostapd_data {
85         struct hostapd_iface *iface;
86         struct hostapd_config *iconf;
87         struct hostapd_bss_config *conf;
88         int interface_added; /* virtual interface added for this BSS */
89
90         u8 own_addr[ETH_ALEN];
91
92         int num_sta; /* number of entries in sta_list */
93         struct sta_info *sta_list; /* STA info list head */
94 #define STA_HASH_SIZE 256
95 #define STA_HASH(sta) (sta[5])
96         struct sta_info *sta_hash[STA_HASH_SIZE];
97
98         /*
99          * Bitfield for indicating which AIDs are allocated. Only AID values
100          * 1-2007 are used and as such, the bit at index 0 corresponds to AID
101          * 1.
102          */
103 #define AID_WORDS ((2008 + 31) / 32)
104         u32 sta_aid[AID_WORDS];
105
106         const struct wpa_driver_ops *driver;
107         void *drv_priv;
108         struct hostapd_driver_ops drv;
109
110         void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
111                                  struct sta_info *sta, int reassoc);
112
113         void *msg_ctx; /* ctx for wpa_msg() calls */
114
115         struct radius_client_data *radius;
116         u32 acct_session_id_hi, acct_session_id_lo;
117
118         struct iapp_data *iapp;
119
120         struct hostapd_cached_radius_acl *acl_cache;
121         struct hostapd_acl_query_data *acl_queries;
122
123         struct wpa_authenticator *wpa_auth;
124         struct eapol_authenticator *eapol_auth;
125
126         struct rsn_preauth_interface *preauth_iface;
127         time_t michael_mic_failure;
128         int michael_mic_failures;
129         int tkip_countermeasures;
130
131         int ctrl_sock;
132         struct wpa_ctrl_dst *ctrl_dst;
133
134         void *ssl_ctx;
135         void *eap_sim_db_priv;
136         struct radius_server_data *radius_srv;
137
138         int parameter_set_count;
139
140 #ifdef CONFIG_FULL_DYNAMIC_VLAN
141         struct full_dynamic_vlan *full_dynamic_vlan;
142 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
143
144         struct l2_packet_data *l2;
145         struct wps_context *wps;
146
147 #ifdef CONFIG_WPS
148         struct wpabuf *wps_beacon_ie;
149         struct wpabuf *wps_probe_resp_ie;
150         unsigned int ap_pin_failures;
151         struct upnp_wps_device_sm *wps_upnp;
152 #endif /* CONFIG_WPS */
153
154         struct hostapd_probereq_cb *probereq_cb;
155         size_t num_probereq_cb;
156 };
157
158
159 /**
160  * struct hostapd_iface - hostapd per-interface data structure
161  */
162 struct hostapd_iface {
163         struct hapd_interfaces *interfaces;
164         void *owner;
165         struct hostapd_config * (*config_read_cb)(const char *config_fname);
166         char *config_fname;
167         struct hostapd_config *conf;
168
169         size_t num_bss;
170         struct hostapd_data **bss;
171
172         int num_ap; /* number of entries in ap_list */
173         struct ap_info *ap_list; /* AP info list head */
174         struct ap_info *ap_hash[STA_HASH_SIZE];
175         struct ap_info *ap_iter_list;
176
177         struct hostapd_hw_modes *hw_features;
178         int num_hw_features;
179         struct hostapd_hw_modes *current_mode;
180         /* Rates that are currently used (i.e., filtered copy of
181          * current_mode->channels */
182         int num_rates;
183         struct hostapd_rate_data *current_rates;
184
185         u16 hw_flags;
186
187         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
188          * in 802.11g BSS) */
189         int num_sta_non_erp;
190
191         /* Number of associated stations that do not support Short Slot Time */
192         int num_sta_no_short_slot_time;
193
194         /* Number of associated stations that do not support Short Preamble */
195         int num_sta_no_short_preamble;
196
197         int olbc; /* Overlapping Legacy BSS Condition */
198
199         /* Number of HT associated stations that do not support greenfield */
200         int num_sta_ht_no_gf;
201
202         /* Number of associated non-HT stations */
203         int num_sta_no_ht;
204
205         /* Number of HT associated stations 20 MHz */
206         int num_sta_ht_20mhz;
207
208         /* Overlapping BSS information */
209         int olbc_ht;
210
211         u16 ht_op_mode;
212         void (*scan_cb)(struct hostapd_iface *iface);
213 };
214
215 int hostapd_reload_config(struct hostapd_iface *iface);
216 struct hostapd_data *
217 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
218                        struct hostapd_config *conf,
219                        struct hostapd_bss_config *bss);
220 int hostapd_setup_interface(struct hostapd_iface *iface);
221 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
222 void hostapd_interface_deinit(struct hostapd_iface *iface);
223 int handle_reload_iface(struct hostapd_iface *iface, void *ctx);
224 int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx);
225
226 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
227                                int (*cb)(struct hostapd_iface *iface,
228                                          void *ctx), void *ctx);
229
230 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
231                                  void (*cb)(void *ctx, const u8 *sa,
232                                             const u8 *ie, size_t ie_len),
233                                  void *ctx);
234
235 int eap_server_register_methods(void);
236 void hostapd_set_driver_ops(struct hostapd_driver_ops *ops);
237 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
238                            int reassoc);
239
240 #endif /* HOSTAPD_H */