AP: Add support for BSS load element (STA Count, Channel Utilization)
[mech_eap.git] / src / ap / hostapd.h
1 /*
2  * hostapd / Initialization and configuration
3  * Copyright (c) 2002-2013, 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_H
10 #define HOSTAPD_H
11
12 #include "common/defs.h"
13 #include "ap_config.h"
14 #include "drivers/driver.h"
15
16 struct wpa_ctrl_dst;
17 struct radius_server_data;
18 struct upnp_wps_device_sm;
19 struct hostapd_data;
20 struct sta_info;
21 struct ieee80211_ht_capabilities;
22 struct full_dynamic_vlan;
23 enum wps_event;
24 union wps_event_data;
25
26 struct hostapd_iface;
27
28 struct hapd_interfaces {
29         int (*reload_config)(struct hostapd_iface *iface);
30         struct hostapd_config * (*config_read_cb)(const char *config_fname);
31         int (*ctrl_iface_init)(struct hostapd_data *hapd);
32         void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
33         int (*for_each_interface)(struct hapd_interfaces *interfaces,
34                                   int (*cb)(struct hostapd_iface *iface,
35                                             void *ctx), void *ctx);
36         int (*driver_init)(struct hostapd_iface *iface);
37
38         size_t count;
39         int global_ctrl_sock;
40         char *global_iface_path;
41         char *global_iface_name;
42 #ifndef CONFIG_NATIVE_WINDOWS
43         gid_t ctrl_iface_group;
44 #endif /* CONFIG_NATIVE_WINDOWS */
45         struct hostapd_iface **iface;
46
47         size_t terminate_on_error;
48 };
49
50 enum hostapd_chan_status {
51         HOSTAPD_CHAN_VALID = 0, /* channel is ready */
52         HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */
53         HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */
54 };
55
56 struct hostapd_probereq_cb {
57         int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid,
58                   const u8 *ie, size_t ie_len, int ssi_signal);
59         void *ctx;
60 };
61
62 #define HOSTAPD_RATE_BASIC 0x00000001
63
64 struct hostapd_rate_data {
65         int rate; /* rate in 100 kbps */
66         int flags; /* HOSTAPD_RATE_ flags */
67 };
68
69 struct hostapd_frame_info {
70         u32 channel;
71         u32 datarate;
72         int ssi_signal; /* dBm */
73 };
74
75 enum wps_status {
76         WPS_STATUS_SUCCESS = 1,
77         WPS_STATUS_FAILURE
78 };
79
80 enum pbc_status {
81         WPS_PBC_STATUS_DISABLE,
82         WPS_PBC_STATUS_ACTIVE,
83         WPS_PBC_STATUS_TIMEOUT,
84         WPS_PBC_STATUS_OVERLAP
85 };
86
87 struct wps_stat {
88         enum wps_status status;
89         enum wps_error_indication failure_reason;
90         enum pbc_status pbc_status;
91         u8 peer_addr[ETH_ALEN];
92 };
93
94
95 /**
96  * struct hostapd_data - hostapd per-BSS data structure
97  */
98 struct hostapd_data {
99         struct hostapd_iface *iface;
100         struct hostapd_config *iconf;
101         struct hostapd_bss_config *conf;
102         int interface_added; /* virtual interface added for this BSS */
103         unsigned int started:1;
104
105         u8 own_addr[ETH_ALEN];
106
107         int num_sta; /* number of entries in sta_list */
108         struct sta_info *sta_list; /* STA info list head */
109 #define STA_HASH_SIZE 256
110 #define STA_HASH(sta) (sta[5])
111         struct sta_info *sta_hash[STA_HASH_SIZE];
112
113         /*
114          * Bitfield for indicating which AIDs are allocated. Only AID values
115          * 1-2007 are used and as such, the bit at index 0 corresponds to AID
116          * 1.
117          */
118 #define AID_WORDS ((2008 + 31) / 32)
119         u32 sta_aid[AID_WORDS];
120
121         const struct wpa_driver_ops *driver;
122         void *drv_priv;
123
124         void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
125                                  struct sta_info *sta, int reassoc);
126
127         void *msg_ctx; /* ctx for wpa_msg() calls */
128         void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */
129
130         struct radius_client_data *radius;
131         u32 acct_session_id_hi, acct_session_id_lo;
132         struct radius_das_data *radius_das;
133
134         struct iapp_data *iapp;
135
136         struct hostapd_cached_radius_acl *acl_cache;
137         struct hostapd_acl_query_data *acl_queries;
138
139         struct wpa_authenticator *wpa_auth;
140         struct eapol_authenticator *eapol_auth;
141
142         struct rsn_preauth_interface *preauth_iface;
143         struct os_reltime michael_mic_failure;
144         int michael_mic_failures;
145         int tkip_countermeasures;
146
147         int ctrl_sock;
148         struct wpa_ctrl_dst *ctrl_dst;
149
150         void *ssl_ctx;
151         void *eap_sim_db_priv;
152         struct radius_server_data *radius_srv;
153
154         int parameter_set_count;
155
156         /* Time Advertisement */
157         u8 time_update_counter;
158         struct wpabuf *time_adv;
159
160 #ifdef CONFIG_FULL_DYNAMIC_VLAN
161         struct full_dynamic_vlan *full_dynamic_vlan;
162 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
163
164         struct l2_packet_data *l2;
165         struct wps_context *wps;
166
167         int beacon_set_done;
168         struct wpabuf *wps_beacon_ie;
169         struct wpabuf *wps_probe_resp_ie;
170 #ifdef CONFIG_WPS
171         unsigned int ap_pin_failures;
172         unsigned int ap_pin_failures_consecutive;
173         struct upnp_wps_device_sm *wps_upnp;
174         unsigned int ap_pin_lockout_time;
175
176         struct wps_stat wps_stats;
177 #endif /* CONFIG_WPS */
178
179         struct hostapd_probereq_cb *probereq_cb;
180         size_t num_probereq_cb;
181
182         void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
183                                  int freq);
184         void *public_action_cb_ctx;
185         void (*public_action_cb2)(void *ctx, const u8 *buf, size_t len,
186                                   int freq);
187         void *public_action_cb2_ctx;
188
189         int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
190                                 int freq);
191         void *vendor_action_cb_ctx;
192
193         void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
194                                    const u8 *uuid_e);
195         void *wps_reg_success_cb_ctx;
196
197         void (*wps_event_cb)(void *ctx, enum wps_event event,
198                              union wps_event_data *data);
199         void *wps_event_cb_ctx;
200
201         void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr,
202                                   int authorized, const u8 *p2p_dev_addr);
203         void *sta_authorized_cb_ctx;
204
205         void (*setup_complete_cb)(void *ctx);
206         void *setup_complete_cb_ctx;
207
208         void (*new_psk_cb)(void *ctx, const u8 *mac_addr,
209                            const u8 *p2p_dev_addr, const u8 *psk,
210                            size_t psk_len);
211         void *new_psk_cb_ctx;
212
213         /* channel switch parameters */
214         struct hostapd_freq_params cs_freq_params;
215         u8 cs_count;
216         int cs_block_tx;
217         unsigned int cs_c_off_beacon;
218         unsigned int cs_c_off_proberesp;
219         int csa_in_progress;
220
221         /* BSS Load */
222         unsigned int bss_load_update_timeout;
223
224 #ifdef CONFIG_P2P
225         struct p2p_data *p2p;
226         struct p2p_group *p2p_group;
227         struct wpabuf *p2p_beacon_ie;
228         struct wpabuf *p2p_probe_resp_ie;
229
230         /* Number of non-P2P association stations */
231         int num_sta_no_p2p;
232
233         /* Periodic NoA (used only when no non-P2P clients in the group) */
234         int noa_enabled;
235         int noa_start;
236         int noa_duration;
237 #endif /* CONFIG_P2P */
238 #ifdef CONFIG_INTERWORKING
239         size_t gas_frag_limit;
240 #endif /* CONFIG_INTERWORKING */
241
242 #ifdef CONFIG_SQLITE
243         struct hostapd_eap_user tmp_eap_user;
244 #endif /* CONFIG_SQLITE */
245
246 #ifdef CONFIG_SAE
247         /** Key used for generating SAE anti-clogging tokens */
248         u8 sae_token_key[8];
249         struct os_reltime last_sae_token_key_update;
250 #endif /* CONFIG_SAE */
251
252 #ifdef CONFIG_TESTING_OPTIONS
253         unsigned int ext_mgmt_frame_handling:1;
254         unsigned int ext_eapol_frame_io:1;
255
256         struct l2_packet_data *l2_test;
257 #endif /* CONFIG_TESTING_OPTIONS */
258 };
259
260
261 /**
262  * struct hostapd_iface - hostapd per-interface data structure
263  */
264 struct hostapd_iface {
265         struct hapd_interfaces *interfaces;
266         void *owner;
267         char *config_fname;
268         struct hostapd_config *conf;
269         char phy[16]; /* Name of the PHY (radio) */
270
271         enum hostapd_iface_state {
272                 HAPD_IFACE_UNINITIALIZED,
273                 HAPD_IFACE_DISABLED,
274                 HAPD_IFACE_COUNTRY_UPDATE,
275                 HAPD_IFACE_ACS,
276                 HAPD_IFACE_HT_SCAN,
277                 HAPD_IFACE_DFS,
278                 HAPD_IFACE_ENABLED
279         } state;
280
281         size_t num_bss;
282         struct hostapd_data **bss;
283
284         unsigned int wait_channel_update:1;
285         unsigned int cac_started:1;
286
287         /*
288          * When set, indicates that the driver will handle the AP
289          * teardown: delete global keys, station keys, and stations.
290          */
291         unsigned int driver_ap_teardown:1;
292
293         int num_ap; /* number of entries in ap_list */
294         struct ap_info *ap_list; /* AP info list head */
295         struct ap_info *ap_hash[STA_HASH_SIZE];
296
297         unsigned int drv_flags;
298
299         /*
300          * A bitmap of supported protocols for probe response offload. See
301          * struct wpa_driver_capa in driver.h
302          */
303         unsigned int probe_resp_offloads;
304
305         /* extended capabilities supported by the driver */
306         const u8 *extended_capa, *extended_capa_mask;
307         unsigned int extended_capa_len;
308
309         unsigned int drv_max_acl_mac_addrs;
310
311         struct hostapd_hw_modes *hw_features;
312         int num_hw_features;
313         struct hostapd_hw_modes *current_mode;
314         /* Rates that are currently used (i.e., filtered copy of
315          * current_mode->channels */
316         int num_rates;
317         struct hostapd_rate_data *current_rates;
318         int *basic_rates;
319         int freq;
320
321         u16 hw_flags;
322
323         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
324          * in 802.11g BSS) */
325         int num_sta_non_erp;
326
327         /* Number of associated stations that do not support Short Slot Time */
328         int num_sta_no_short_slot_time;
329
330         /* Number of associated stations that do not support Short Preamble */
331         int num_sta_no_short_preamble;
332
333         int olbc; /* Overlapping Legacy BSS Condition */
334
335         /* Number of HT associated stations that do not support greenfield */
336         int num_sta_ht_no_gf;
337
338         /* Number of associated non-HT stations */
339         int num_sta_no_ht;
340
341         /* Number of HT associated stations 20 MHz */
342         int num_sta_ht_20mhz;
343
344         /* Number of HT40 intolerant stations */
345         int num_sta_ht40_intolerant;
346
347         /* Overlapping BSS information */
348         int olbc_ht;
349
350         u16 ht_op_mode;
351
352         /* surveying helpers */
353
354         /* number of channels surveyed */
355         unsigned int chans_surveyed;
356
357         /* lowest observed noise floor in dBm */
358         s8 lowest_nf;
359
360         /* channel utilization calculation */
361         u64 last_channel_time;
362         u64 last_channel_time_busy;
363         u8 channel_utilization;
364
365         unsigned int dfs_cac_ms;
366         struct os_reltime dfs_cac_start;
367
368         /* Latched with the actual secondary channel information and will be
369          * used while juggling between HT20 and HT40 modes. */
370         int secondary_ch;
371
372 #ifdef CONFIG_ACS
373         unsigned int acs_num_completed_scans;
374 #endif /* CONFIG_ACS */
375
376         void (*scan_cb)(struct hostapd_iface *iface);
377         int num_ht40_scan_tries;
378 };
379
380 /* hostapd.c */
381 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
382                                int (*cb)(struct hostapd_iface *iface,
383                                          void *ctx), void *ctx);
384 int hostapd_reload_config(struct hostapd_iface *iface);
385 struct hostapd_data *
386 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
387                        struct hostapd_config *conf,
388                        struct hostapd_bss_config *bss);
389 int hostapd_setup_interface(struct hostapd_iface *iface);
390 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
391 void hostapd_interface_deinit(struct hostapd_iface *iface);
392 void hostapd_interface_free(struct hostapd_iface *iface);
393 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
394                                     const char *config_file);
395 struct hostapd_iface *
396 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
397                            const char *config_fname, int debug);
398 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
399                            int reassoc);
400 void hostapd_interface_deinit_free(struct hostapd_iface *iface);
401 int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
402 int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
403 int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
404 int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
405 int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
406 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator);
407 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
408 const char * hostapd_state_text(enum hostapd_iface_state s);
409 int hostapd_switch_channel(struct hostapd_data *hapd,
410                            struct csa_settings *settings);
411 void
412 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
413                                 const struct hostapd_freq_params *freq_params);
414 void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
415
416 /* utils.c */
417 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
418                                  int (*cb)(void *ctx, const u8 *sa,
419                                            const u8 *da, const u8 *bssid,
420                                            const u8 *ie, size_t ie_len,
421                                            int ssi_signal),
422                                  void *ctx);
423 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
424
425 /* drv_callbacks.c (TODO: move to somewhere else?) */
426 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
427                         const u8 *ie, size_t ielen, int reassoc);
428 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
429 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
430 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
431                                          const u8 *addr, int reason_code);
432 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
433                          const u8 *bssid, const u8 *ie, size_t ie_len,
434                          int ssi_signal);
435 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
436                              int offset, int width, int cf1, int cf2);
437
438 const struct hostapd_eap_user *
439 hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
440                      size_t identity_len, int phase2);
441
442 #endif /* HOSTAPD_H */