021d2e8847cdc9998908cccaa766596dd648cf9e
[libeap.git] / src / ap / 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 struct ieee80211_ht_capabilities;
29 struct full_dynamic_vlan;
30
31 struct hostapd_probereq_cb {
32         int (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
33         void *ctx;
34 };
35
36 #define HOSTAPD_RATE_BASIC 0x00000001
37
38 struct hostapd_rate_data {
39         int rate; /* rate in 100 kbps */
40         int flags; /* HOSTAPD_RATE_ flags */
41 };
42
43 struct hostapd_frame_info {
44         u32 channel;
45         u32 datarate;
46         u32 ssi_signal;
47 };
48
49
50 struct hostapd_driver_ops {
51         int (*set_ap_wps_ie)(struct hostapd_data *hapd);
52         int (*send_mgmt_frame)(struct hostapd_data *hapd, const void *msg,
53                                size_t len);
54         int (*send_eapol)(struct hostapd_data *hapd, const u8 *addr,
55                           const u8 *data, size_t data_len, int encrypt);
56         int (*set_authorized)(struct hostapd_data *hapd, struct sta_info *sta,
57                               int authorized);
58         int (*set_key)(const char *ifname, struct hostapd_data *hapd,
59                        enum wpa_alg alg, const u8 *addr, int key_idx,
60                        int set_tx, const u8 *seq, size_t seq_len,
61                        const u8 *key, size_t key_len);
62         int (*read_sta_data)(struct hostapd_data *hapd,
63                              struct hostap_sta_driver_data *data,
64                              const u8 *addr);
65         int (*sta_clear_stats)(struct hostapd_data *hapd, const u8 *addr);
66         int (*set_sta_flags)(struct hostapd_data *hapd, struct sta_info *sta);
67         int (*set_drv_ieee8021x)(struct hostapd_data *hapd, const char *ifname,
68                                  int enabled);
69         int (*set_radius_acl_auth)(struct hostapd_data *hapd,
70                                    const u8 *mac, int accepted,
71                                    u32 session_timeout);
72         int (*set_radius_acl_expire)(struct hostapd_data *hapd,
73                                      const u8 *mac);
74         int (*set_bss_params)(struct hostapd_data *hapd, int use_protection);
75         int (*set_beacon)(struct hostapd_data *hapd,
76                           const u8 *head, size_t head_len,
77                           const u8 *tail, size_t tail_len, int dtim_period,
78                           int beacon_int);
79         int (*vlan_if_add)(struct hostapd_data *hapd, const char *ifname);
80         int (*vlan_if_remove)(struct hostapd_data *hapd, const char *ifname);
81         int (*set_wds_sta)(struct hostapd_data *hapd, const u8 *addr, int aid,
82                            int val);
83         int (*set_sta_vlan)(const char *ifname, struct hostapd_data *hapd,
84                             const u8 *addr, int vlan_id);
85         int (*get_inact_sec)(struct hostapd_data *hapd, const u8 *addr);
86         int (*sta_deauth)(struct hostapd_data *hapd, const u8 *addr,
87                           int reason);
88         int (*sta_disassoc)(struct hostapd_data *hapd, const u8 *addr,
89                             int reason);
90         int (*sta_add)(struct hostapd_data *hapd,
91                        const u8 *addr, u16 aid, u16 capability,
92                        const u8 *supp_rates, size_t supp_rates_len,
93                        u16 listen_interval,
94                        const struct ieee80211_ht_capabilities *ht_capab);
95         int (*sta_remove)(struct hostapd_data *hapd, const u8 *addr);
96         int (*set_countermeasures)(struct hostapd_data *hapd, int enabled);
97 };
98
99 /**
100  * struct hostapd_data - hostapd per-BSS data structure
101  */
102 struct hostapd_data {
103         struct hostapd_iface *iface;
104         struct hostapd_config *iconf;
105         struct hostapd_bss_config *conf;
106         int interface_added; /* virtual interface added for this BSS */
107
108         u8 own_addr[ETH_ALEN];
109
110         int num_sta; /* number of entries in sta_list */
111         struct sta_info *sta_list; /* STA info list head */
112 #define STA_HASH_SIZE 256
113 #define STA_HASH(sta) (sta[5])
114         struct sta_info *sta_hash[STA_HASH_SIZE];
115
116         /*
117          * Bitfield for indicating which AIDs are allocated. Only AID values
118          * 1-2007 are used and as such, the bit at index 0 corresponds to AID
119          * 1.
120          */
121 #define AID_WORDS ((2008 + 31) / 32)
122         u32 sta_aid[AID_WORDS];
123
124         const struct wpa_driver_ops *driver;
125         void *drv_priv;
126         struct hostapd_driver_ops drv;
127
128         void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
129                                  struct sta_info *sta, int reassoc);
130
131         void *msg_ctx; /* ctx for wpa_msg() calls */
132
133         struct radius_client_data *radius;
134         u32 acct_session_id_hi, acct_session_id_lo;
135
136         struct iapp_data *iapp;
137
138         struct hostapd_cached_radius_acl *acl_cache;
139         struct hostapd_acl_query_data *acl_queries;
140
141         struct wpa_authenticator *wpa_auth;
142         struct eapol_authenticator *eapol_auth;
143
144         struct rsn_preauth_interface *preauth_iface;
145         time_t michael_mic_failure;
146         int michael_mic_failures;
147         int tkip_countermeasures;
148
149         int ctrl_sock;
150         struct wpa_ctrl_dst *ctrl_dst;
151
152         void *ssl_ctx;
153         void *eap_sim_db_priv;
154         struct radius_server_data *radius_srv;
155
156         int parameter_set_count;
157
158 #ifdef CONFIG_FULL_DYNAMIC_VLAN
159         struct full_dynamic_vlan *full_dynamic_vlan;
160 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
161
162         struct l2_packet_data *l2;
163         struct wps_context *wps;
164
165         struct wpabuf *wps_beacon_ie;
166         struct wpabuf *wps_probe_resp_ie;
167 #ifdef CONFIG_WPS
168         unsigned int ap_pin_failures;
169         struct upnp_wps_device_sm *wps_upnp;
170         unsigned int ap_pin_lockout_time;
171 #endif /* CONFIG_WPS */
172
173         struct hostapd_probereq_cb *probereq_cb;
174         size_t num_probereq_cb;
175
176         void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
177                                  int freq);
178         void *public_action_cb_ctx;
179
180         int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
181                                 int freq);
182         void *vendor_action_cb_ctx;
183
184         void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
185                                    const u8 *uuid_e);
186         void *wps_reg_success_cb_ctx;
187
188 #ifdef CONFIG_P2P
189         struct p2p_data *p2p;
190         struct p2p_group *p2p_group;
191         struct wpabuf *p2p_beacon_ie;
192         struct wpabuf *p2p_probe_resp_ie;
193
194         /* Number of non-P2P association stations */
195         int num_sta_no_p2p;
196
197         /* Periodic NoA (used only when no non-P2P clients in the group) */
198         int noa_enabled;
199         int noa_start;
200         int noa_duration;
201 #endif /* CONFIG_P2P */
202 };
203
204
205 /**
206  * struct hostapd_iface - hostapd per-interface data structure
207  */
208 struct hostapd_iface {
209         struct hapd_interfaces *interfaces;
210         void *owner;
211         int (*reload_config)(struct hostapd_iface *iface);
212         struct hostapd_config * (*config_read_cb)(const char *config_fname);
213         char *config_fname;
214         struct hostapd_config *conf;
215
216         size_t num_bss;
217         struct hostapd_data **bss;
218
219         int num_ap; /* number of entries in ap_list */
220         struct ap_info *ap_list; /* AP info list head */
221         struct ap_info *ap_hash[STA_HASH_SIZE];
222         struct ap_info *ap_iter_list;
223
224         struct hostapd_hw_modes *hw_features;
225         int num_hw_features;
226         struct hostapd_hw_modes *current_mode;
227         /* Rates that are currently used (i.e., filtered copy of
228          * current_mode->channels */
229         int num_rates;
230         struct hostapd_rate_data *current_rates;
231         int freq;
232
233         u16 hw_flags;
234
235         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
236          * in 802.11g BSS) */
237         int num_sta_non_erp;
238
239         /* Number of associated stations that do not support Short Slot Time */
240         int num_sta_no_short_slot_time;
241
242         /* Number of associated stations that do not support Short Preamble */
243         int num_sta_no_short_preamble;
244
245         int olbc; /* Overlapping Legacy BSS Condition */
246
247         /* Number of HT associated stations that do not support greenfield */
248         int num_sta_ht_no_gf;
249
250         /* Number of associated non-HT stations */
251         int num_sta_no_ht;
252
253         /* Number of HT associated stations 20 MHz */
254         int num_sta_ht_20mhz;
255
256         /* Overlapping BSS information */
257         int olbc_ht;
258
259         u16 ht_op_mode;
260         void (*scan_cb)(struct hostapd_iface *iface);
261
262         int (*ctrl_iface_init)(struct hostapd_data *hapd);
263         void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
264
265         int (*for_each_interface)(struct hapd_interfaces *interfaces,
266                                   int (*cb)(struct hostapd_iface *iface,
267                                             void *ctx), void *ctx);
268 };
269
270 /* hostapd.c */
271 int hostapd_reload_config(struct hostapd_iface *iface);
272 struct hostapd_data *
273 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
274                        struct hostapd_config *conf,
275                        struct hostapd_bss_config *bss);
276 int hostapd_setup_interface(struct hostapd_iface *iface);
277 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
278 void hostapd_interface_deinit(struct hostapd_iface *iface);
279 void hostapd_interface_free(struct hostapd_iface *iface);
280 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
281                            int reassoc);
282
283 /* utils.c */
284 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
285                                  int (*cb)(void *ctx, const u8 *sa,
286                                            const u8 *ie, size_t ie_len),
287                                  void *ctx);
288 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
289
290 /* drv_callbacks.c (TODO: move to somewhere else?) */
291 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
292                         const u8 *ie, size_t ielen);
293 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
294
295 #endif /* HOSTAPD_H */