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