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