Home | History | Annotate | Download | only in ap
      1 /*
      2  * hostapd / Initialization and configuration
      3  * Copyright (c) 2002-2009, Jouni Malinen <j (at) 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 
     14 struct wpa_driver_ops;
     15 struct wpa_ctrl_dst;
     16 struct radius_server_data;
     17 struct upnp_wps_device_sm;
     18 struct hostapd_data;
     19 struct sta_info;
     20 struct hostap_sta_driver_data;
     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 	struct hostapd_iface **iface;
     43 };
     44 
     45 
     46 struct hostapd_probereq_cb {
     47 	int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid,
     48 		  const u8 *ie, size_t ie_len, int ssi_signal);
     49 	void *ctx;
     50 };
     51 
     52 #define HOSTAPD_RATE_BASIC 0x00000001
     53 
     54 struct hostapd_rate_data {
     55 	int rate; /* rate in 100 kbps */
     56 	int flags; /* HOSTAPD_RATE_ flags */
     57 };
     58 
     59 struct hostapd_frame_info {
     60 	u32 channel;
     61 	u32 datarate;
     62 	int ssi_signal; /* dBm */
     63 };
     64 
     65 
     66 /**
     67  * struct hostapd_data - hostapd per-BSS data structure
     68  */
     69 struct hostapd_data {
     70 	struct hostapd_iface *iface;
     71 	struct hostapd_config *iconf;
     72 	struct hostapd_bss_config *conf;
     73 	int interface_added; /* virtual interface added for this BSS */
     74 
     75 	u8 own_addr[ETH_ALEN];
     76 
     77 	int num_sta; /* number of entries in sta_list */
     78 	struct sta_info *sta_list; /* STA info list head */
     79 #define STA_HASH_SIZE 256
     80 #define STA_HASH(sta) (sta[5])
     81 	struct sta_info *sta_hash[STA_HASH_SIZE];
     82 
     83 	/*
     84 	 * Bitfield for indicating which AIDs are allocated. Only AID values
     85 	 * 1-2007 are used and as such, the bit at index 0 corresponds to AID
     86 	 * 1.
     87 	 */
     88 #define AID_WORDS ((2008 + 31) / 32)
     89 	u32 sta_aid[AID_WORDS];
     90 
     91 	const struct wpa_driver_ops *driver;
     92 	void *drv_priv;
     93 
     94 	void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
     95 				 struct sta_info *sta, int reassoc);
     96 
     97 	void *msg_ctx; /* ctx for wpa_msg() calls */
     98 	void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */
     99 
    100 	struct radius_client_data *radius;
    101 	u32 acct_session_id_hi, acct_session_id_lo;
    102 	struct radius_das_data *radius_das;
    103 
    104 	struct iapp_data *iapp;
    105 
    106 	struct hostapd_cached_radius_acl *acl_cache;
    107 	struct hostapd_acl_query_data *acl_queries;
    108 
    109 	struct wpa_authenticator *wpa_auth;
    110 	struct eapol_authenticator *eapol_auth;
    111 
    112 	struct rsn_preauth_interface *preauth_iface;
    113 	time_t michael_mic_failure;
    114 	int michael_mic_failures;
    115 	int tkip_countermeasures;
    116 
    117 	int ctrl_sock;
    118 	struct wpa_ctrl_dst *ctrl_dst;
    119 
    120 	void *ssl_ctx;
    121 	void *eap_sim_db_priv;
    122 	struct radius_server_data *radius_srv;
    123 
    124 	int parameter_set_count;
    125 
    126 	/* Time Advertisement */
    127 	u8 time_update_counter;
    128 	struct wpabuf *time_adv;
    129 
    130 #ifdef CONFIG_FULL_DYNAMIC_VLAN
    131 	struct full_dynamic_vlan *full_dynamic_vlan;
    132 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
    133 
    134 	struct l2_packet_data *l2;
    135 	struct wps_context *wps;
    136 
    137 	int beacon_set_done;
    138 	struct wpabuf *wps_beacon_ie;
    139 	struct wpabuf *wps_probe_resp_ie;
    140 #ifdef CONFIG_WPS
    141 	unsigned int ap_pin_failures;
    142 	unsigned int ap_pin_failures_consecutive;
    143 	struct upnp_wps_device_sm *wps_upnp;
    144 	unsigned int ap_pin_lockout_time;
    145 #endif /* CONFIG_WPS */
    146 
    147 	struct hostapd_probereq_cb *probereq_cb;
    148 	size_t num_probereq_cb;
    149 
    150 	void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
    151 				 int freq);
    152 	void *public_action_cb_ctx;
    153 
    154 	int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
    155 				int freq);
    156 	void *vendor_action_cb_ctx;
    157 
    158 	void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
    159 				   const u8 *uuid_e);
    160 	void *wps_reg_success_cb_ctx;
    161 
    162 	void (*wps_event_cb)(void *ctx, enum wps_event event,
    163 			     union wps_event_data *data);
    164 	void *wps_event_cb_ctx;
    165 
    166 	void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr,
    167 				  int authorized, const u8 *p2p_dev_addr);
    168 	void *sta_authorized_cb_ctx;
    169 
    170 	void (*setup_complete_cb)(void *ctx);
    171 	void *setup_complete_cb_ctx;
    172 
    173 #ifdef CONFIG_P2P
    174 	struct p2p_data *p2p;
    175 	struct p2p_group *p2p_group;
    176 	struct wpabuf *p2p_beacon_ie;
    177 	struct wpabuf *p2p_probe_resp_ie;
    178 
    179 	/* Number of non-P2P association stations */
    180 	int num_sta_no_p2p;
    181 
    182 	/* Periodic NoA (used only when no non-P2P clients in the group) */
    183 	int noa_enabled;
    184 	int noa_start;
    185 	int noa_duration;
    186 #endif /* CONFIG_P2P */
    187 #ifdef CONFIG_INTERWORKING
    188 	size_t gas_frag_limit;
    189 #endif /* CONFIG_INTERWORKING */
    190 };
    191 
    192 
    193 /**
    194  * struct hostapd_iface - hostapd per-interface data structure
    195  */
    196 struct hostapd_iface {
    197 	struct hapd_interfaces *interfaces;
    198 	void *owner;
    199 	char *config_fname;
    200 	struct hostapd_config *conf;
    201 
    202 	size_t num_bss;
    203 	struct hostapd_data **bss;
    204 
    205 	int num_ap; /* number of entries in ap_list */
    206 	struct ap_info *ap_list; /* AP info list head */
    207 	struct ap_info *ap_hash[STA_HASH_SIZE];
    208 	struct ap_info *ap_iter_list;
    209 
    210 	unsigned int drv_flags;
    211 
    212 	/*
    213 	 * A bitmap of supported protocols for probe response offload. See
    214 	 * struct wpa_driver_capa in driver.h
    215 	 */
    216 	unsigned int probe_resp_offloads;
    217 
    218 	struct hostapd_hw_modes *hw_features;
    219 	int num_hw_features;
    220 	struct hostapd_hw_modes *current_mode;
    221 	/* Rates that are currently used (i.e., filtered copy of
    222 	 * current_mode->channels */
    223 	int num_rates;
    224 	struct hostapd_rate_data *current_rates;
    225 	int *basic_rates;
    226 	int freq;
    227 
    228 	u16 hw_flags;
    229 
    230 	/* Number of associated Non-ERP stations (i.e., stations using 802.11b
    231 	 * in 802.11g BSS) */
    232 	int num_sta_non_erp;
    233 
    234 	/* Number of associated stations that do not support Short Slot Time */
    235 	int num_sta_no_short_slot_time;
    236 
    237 	/* Number of associated stations that do not support Short Preamble */
    238 	int num_sta_no_short_preamble;
    239 
    240 	int olbc; /* Overlapping Legacy BSS Condition */
    241 
    242 	/* Number of HT associated stations that do not support greenfield */
    243 	int num_sta_ht_no_gf;
    244 
    245 	/* Number of associated non-HT stations */
    246 	int num_sta_no_ht;
    247 
    248 	/* Number of HT associated stations 20 MHz */
    249 	int num_sta_ht_20mhz;
    250 
    251 	/* Overlapping BSS information */
    252 	int olbc_ht;
    253 
    254 	u16 ht_op_mode;
    255 	void (*scan_cb)(struct hostapd_iface *iface);
    256 };
    257 
    258 /* hostapd.c */
    259 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
    260 			       int (*cb)(struct hostapd_iface *iface,
    261 					 void *ctx), void *ctx);
    262 int hostapd_reload_config(struct hostapd_iface *iface);
    263 struct hostapd_data *
    264 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
    265 		       struct hostapd_config *conf,
    266 		       struct hostapd_bss_config *bss);
    267 int hostapd_setup_interface(struct hostapd_iface *iface);
    268 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
    269 void hostapd_interface_deinit(struct hostapd_iface *iface);
    270 void hostapd_interface_free(struct hostapd_iface *iface);
    271 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
    272 			   int reassoc);
    273 void hostapd_interface_deinit_free(struct hostapd_iface *iface);
    274 int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
    275 int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
    276 int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
    277 int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
    278 int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
    279 
    280 /* utils.c */
    281 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
    282 				 int (*cb)(void *ctx, const u8 *sa,
    283 					   const u8 *da, const u8 *bssid,
    284 					   const u8 *ie, size_t ie_len,
    285 					   int ssi_signal),
    286 				 void *ctx);
    287 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
    288 
    289 /* drv_callbacks.c (TODO: move to somewhere else?) */
    290 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
    291 			const u8 *ie, size_t ielen, int reassoc);
    292 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
    293 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
    294 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
    295 			 const u8 *bssid, const u8 *ie, size_t ie_len,
    296 			 int ssi_signal);
    297 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
    298 			     int offset);
    299 
    300 #endif /* HOSTAPD_H */
    301