MFC: An off-by-one malloc size was corrupting the installer's memory,
[dragonfly.git] / contrib / wpa_supplicant-0.5.8 / wpa_supplicant_i.h
blobbb80f898f8737402fe2e7f9203b15b072e9f8bf1
1 /*
2 * wpa_supplicant - Internal definitions
3 * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #ifndef WPA_SUPPLICANT_I_H
16 #define WPA_SUPPLICANT_I_H
18 #include "driver.h"
20 struct wpa_blacklist {
21 struct wpa_blacklist *next;
22 u8 bssid[ETH_ALEN];
23 int count;
27 struct wpa_scan_result;
28 struct wpa_sm;
29 struct wpa_supplicant;
32 * Forward declarations of private structures used within the ctrl_iface
33 * backends. Other parts of wpa_supplicant do not have access to data stored in
34 * these structures.
36 struct ctrl_iface_priv;
37 struct ctrl_iface_global_priv;
38 struct ctrl_iface_dbus_priv;
40 /**
41 * struct wpa_interface - Parameters for wpa_supplicant_add_iface()
43 struct wpa_interface {
44 /**
45 * confname - Configuration name (file or profile) name
47 * This can also be %NULL when a configuration file is not used. In
48 * that case, ctrl_interface must be set to allow the interface to be
49 * configured.
51 const char *confname;
53 /**
54 * ctrl_interface - Control interface parameter
56 * If a configuration file is not used, this variable can be used to
57 * set the ctrl_interface parameter that would have otherwise been read
58 * from the configuration file. If both confname and ctrl_interface are
59 * set, ctrl_interface is used to override the value from configuration
60 * file.
62 const char *ctrl_interface;
64 /**
65 * driver - Driver interface name, or %NULL to use the default driver
67 const char *driver;
69 /**
70 * driver_param - Driver interface parameters
72 * If a configuration file is not used, this variable can be used to
73 * set the driver_param parameters that would have otherwise been read
74 * from the configuration file. If both confname and driver_param are
75 * set, driver_param is used to override the value from configuration
76 * file.
78 const char *driver_param;
80 /**
81 * ifname - Interface name
83 const char *ifname;
85 /**
86 * bridge_ifname - Optional bridge interface name
88 * If the driver interface (ifname) is included in a Linux bridge
89 * device, the bridge interface may need to be used for receiving EAPOL
90 * frames. This can be enabled by setting this variable to enable
91 * receiving of EAPOL frames from an additional interface.
93 const char *bridge_ifname;
96 /**
97 * struct wpa_params - Parameters for wpa_supplicant_init()
99 struct wpa_params {
101 * daemonize - Run %wpa_supplicant in the background
103 int daemonize;
106 * wait_for_interface - Wait for the network interface to appear
108 * If set, %wpa_supplicant will wait until all the configured network
109 * interfaces are available before starting processing. Please note
110 * that in many cases, a better alternative would be to start
111 * %wpa_supplicant without network interfaces and add the interfaces
112 * dynamically whenever they become available.
114 int wait_for_interface;
117 * wait_for_monitor - Wait for a monitor program before starting
119 int wait_for_monitor;
122 * pid_file - Path to a PID (process ID) file
124 * If this and daemonize are set, process ID of the background process
125 * will be written to the specified file.
127 char *pid_file;
130 * wpa_debug_level - Debugging verbosity level (e.g., MSG_INFO)
132 int wpa_debug_level;
135 * wpa_debug_show_keys - Whether keying material is included in debug
137 * This parameter can be used to allow keying material to be included
138 * in debug messages. This is a security risk and this option should
139 * not be enabled in normal configuration. If needed during
140 * development or while troubleshooting, this option can provide more
141 * details for figuring out what is happening.
143 int wpa_debug_show_keys;
146 * wpa_debug_timestamp - Whether to include timestamp in debug messages
148 int wpa_debug_timestamp;
151 * ctrl_interface - Global ctrl_iface path/parameter
153 char *ctrl_interface;
156 * dbus_ctrl_interface - Enable the DBus control interface
158 int dbus_ctrl_interface;
161 * wpa_debug_use_file - Write debug to a file (instead of stdout)
163 int wpa_debug_use_file;
167 * struct wpa_global - Internal, global data for all %wpa_supplicant interfaces
169 * This structure is initialized by calling wpa_supplicant_init() when starting
170 * %wpa_supplicant.
172 struct wpa_global {
173 struct wpa_supplicant *ifaces;
174 struct wpa_params params;
175 struct ctrl_iface_global_priv *ctrl_iface;
176 struct ctrl_iface_dbus_priv *dbus_ctrl_iface;
180 struct wpa_client_mlme {
181 #ifdef CONFIG_CLIENT_MLME
182 enum {
183 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
184 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
185 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
186 } state;
187 u8 prev_bssid[ETH_ALEN];
188 u8 ssid[32];
189 size_t ssid_len;
190 u16 aid;
191 u16 ap_capab, capab;
192 u8 *extra_ie; /* to be added to the end of AssocReq */
193 size_t extra_ie_len;
194 wpa_key_mgmt key_mgmt;
196 /* The last AssocReq/Resp IEs */
197 u8 *assocreq_ies, *assocresp_ies;
198 size_t assocreq_ies_len, assocresp_ies_len;
200 int auth_tries, assoc_tries;
202 unsigned int ssid_set:1;
203 unsigned int bssid_set:1;
204 unsigned int prev_bssid_set:1;
205 unsigned int authenticated:1;
206 unsigned int associated:1;
207 unsigned int probereq_poll:1;
208 unsigned int use_protection:1;
209 unsigned int create_ibss:1;
210 unsigned int mixed_cell:1;
211 unsigned int wmm_enabled:1;
213 struct os_time last_probe;
215 #define IEEE80211_AUTH_ALG_OPEN BIT(0)
216 #define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
217 #define IEEE80211_AUTH_ALG_LEAP BIT(2)
218 unsigned int auth_algs; /* bitfield of allowed auth algs */
219 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
220 int auth_transaction;
222 struct os_time ibss_join_req;
223 u8 *probe_resp; /* ProbeResp template for IBSS */
224 size_t probe_resp_len;
225 u32 supp_rates_bits;
227 int wmm_last_param_set;
229 int sta_scanning;
230 int scan_hw_mode_idx;
231 int scan_channel_idx;
232 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
233 struct os_time last_scan_completed;
234 int scan_oper_channel;
235 int scan_oper_freq;
236 int scan_oper_phymode;
237 u8 scan_ssid[32];
238 size_t scan_ssid_len;
239 int scan_skip_11b;
241 struct ieee80211_sta_bss *sta_bss_list;
242 #define STA_HASH_SIZE 256
243 #define STA_HASH(sta) (sta[5])
244 struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
246 int cts_protect_erp_frames;
248 int phymode; /* current mode; WPA_MODE_IEEE80211A, .. */
249 struct wpa_hw_modes *modes;
250 size_t num_modes;
251 unsigned int hw_modes; /* bitfield of allowed hardware modes;
252 * (1 << MODE_*) */
253 int num_curr_rates;
254 struct wpa_rate_data *curr_rates;
255 int freq; /* The current frequency in MHz */
256 int channel; /* The current IEEE 802.11 channel number */
257 #else /* CONFIG_CLIENT_MLME */
258 int dummy; /* to keep MSVC happy */
259 #endif /* CONFIG_CLIENT_MLME */
263 * struct wpa_supplicant - Internal data for wpa_supplicant interface
265 * This structure contains the internal data for core wpa_supplicant code. This
266 * should be only used directly from the core code. However, a pointer to this
267 * data is used from other files as an arbitrary context pointer in calls to
268 * core functions.
270 struct wpa_supplicant {
271 struct wpa_global *global;
272 struct wpa_supplicant *next;
273 struct l2_packet_data *l2;
274 struct l2_packet_data *l2_br;
275 unsigned char own_addr[ETH_ALEN];
276 char ifname[100];
277 #ifdef CONFIG_CTRL_IFACE_DBUS
278 char *dbus_path;
279 #endif /* CONFIG_CTRL_IFACE_DBUS */
280 char bridge_ifname[16];
282 char *confname;
283 struct wpa_config *conf;
284 int countermeasures;
285 os_time_t last_michael_mic_error;
286 u8 bssid[ETH_ALEN];
287 u8 pending_bssid[ETH_ALEN]; /* If wpa_state == WPA_ASSOCIATING, this
288 * field contains the targer BSSID. */
289 int reassociate; /* reassociation requested */
290 int disconnected; /* all connections disabled; i.e., do no reassociate
291 * before this has been cleared */
292 struct wpa_ssid *current_ssid;
294 /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
295 int pairwise_cipher;
296 int group_cipher;
297 int key_mgmt;
298 int mgmt_group_cipher;
300 void *drv_priv; /* private data used by driver_ops */
302 struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
303 * NULL = not yet initialized (start
304 * with broadcast SSID)
305 * BROADCAST_SSID_SCAN = broadcast
306 * SSID was used in the previous scan
308 #define BROADCAST_SSID_SCAN ((struct wpa_ssid *) 1)
310 struct wpa_scan_result *scan_results;
311 int num_scan_results;
313 struct wpa_driver_ops *driver;
314 int interface_removed; /* whether the network interface has been
315 * removed */
316 struct wpa_sm *wpa;
317 struct eapol_sm *eapol;
319 struct ctrl_iface_priv *ctrl_iface;
321 wpa_states wpa_state;
322 int new_connection;
323 int reassociated_connection;
325 int eapol_received; /* number of EAPOL packets received after the
326 * previous association event */
328 struct scard_data *scard;
330 unsigned char last_eapol_src[ETH_ALEN];
332 int keys_cleared;
334 struct wpa_blacklist *blacklist;
336 int scan_req; /* manual scan request; this forces a scan even if there
337 * are no enabled networks in the configuration */
338 int scan_res_tried; /* whether ap_scan=1 mode has tried to fetch scan
339 * results without a new scan request; this is used
340 * to speed up the first association if the driver
341 * has already available scan results. */
343 struct wpa_client_mlme mlme;
344 int use_client_mlme;
348 /* wpa_supplicant.c */
349 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
351 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
353 const char * wpa_supplicant_state_txt(int state);
354 int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s,
355 int wait_for_interface);
356 struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
357 const u8 *bssid);
358 int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid);
359 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s);
360 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
361 struct wpa_scan_result *bss,
362 struct wpa_ssid *ssid,
363 u8 *wpa_ie, size_t *wpa_ie_len);
364 void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
365 struct wpa_scan_result *bss,
366 struct wpa_ssid *ssid);
367 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
368 struct wpa_ssid *ssid);
369 void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s);
370 int wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s);
371 void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr);
372 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
373 int sec, int usec);
374 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state);
375 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s);
376 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s);
377 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
378 int reason_code);
379 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
380 int reason_code);
381 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
383 void wpa_show_license(void);
385 struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
386 struct wpa_interface *iface);
387 int wpa_supplicant_remove_iface(struct wpa_global *global,
388 struct wpa_supplicant *wpa_s);
389 struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
390 const char *ifname);
391 struct wpa_global * wpa_supplicant_init(struct wpa_params *params);
392 int wpa_supplicant_run(struct wpa_global *global);
393 void wpa_supplicant_deinit(struct wpa_global *global);
395 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
396 struct wpa_ssid *ssid);
398 /* events.c */
399 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s);
401 /* driver_ops */
402 static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
403 const char *ifname)
405 if (wpa_s->driver->init) {
406 return wpa_s->driver->init(wpa_s, ifname);
408 return NULL;
411 static inline void wpa_drv_deinit(struct wpa_supplicant *wpa_s)
413 if (wpa_s->driver->deinit)
414 wpa_s->driver->deinit(wpa_s->drv_priv);
417 static inline int wpa_drv_set_param(struct wpa_supplicant *wpa_s,
418 const char *param)
420 if (wpa_s->driver->set_param)
421 return wpa_s->driver->set_param(wpa_s->drv_priv, param);
422 return 0;
425 static inline int wpa_drv_set_drop_unencrypted(struct wpa_supplicant *wpa_s,
426 int enabled)
428 if (wpa_s->driver->set_drop_unencrypted) {
429 return wpa_s->driver->set_drop_unencrypted(wpa_s->drv_priv,
430 enabled);
432 return -1;
435 static inline int wpa_drv_set_countermeasures(struct wpa_supplicant *wpa_s,
436 int enabled)
438 if (wpa_s->driver->set_countermeasures) {
439 return wpa_s->driver->set_countermeasures(wpa_s->drv_priv,
440 enabled);
442 return -1;
445 static inline int wpa_drv_set_auth_alg(struct wpa_supplicant *wpa_s,
446 int auth_alg)
448 if (wpa_s->driver->set_auth_alg) {
449 return wpa_s->driver->set_auth_alg(wpa_s->drv_priv,
450 auth_alg);
452 return -1;
455 static inline int wpa_drv_set_wpa(struct wpa_supplicant *wpa_s, int enabled)
457 if (wpa_s->driver->set_wpa) {
458 return wpa_s->driver->set_wpa(wpa_s->drv_priv, enabled);
460 return 0;
463 static inline int wpa_drv_associate(struct wpa_supplicant *wpa_s,
464 struct wpa_driver_associate_params *params)
466 if (wpa_s->driver->associate) {
467 return wpa_s->driver->associate(wpa_s->drv_priv, params);
469 return -1;
472 static inline int wpa_drv_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
473 size_t ssid_len)
475 if (wpa_s->driver->scan) {
476 return wpa_s->driver->scan(wpa_s->drv_priv, ssid, ssid_len);
478 return -1;
481 static inline int wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s,
482 struct wpa_scan_result *results,
483 size_t max_size)
485 if (wpa_s->driver->get_scan_results) {
486 return wpa_s->driver->get_scan_results(wpa_s->drv_priv,
487 results, max_size);
489 return -1;
492 static inline int wpa_drv_get_bssid(struct wpa_supplicant *wpa_s, u8 *bssid)
494 if (wpa_s->driver->get_bssid) {
495 return wpa_s->driver->get_bssid(wpa_s->drv_priv, bssid);
497 return -1;
500 static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
502 if (wpa_s->driver->get_ssid) {
503 return wpa_s->driver->get_ssid(wpa_s->drv_priv, ssid);
505 return -1;
508 static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, wpa_alg alg,
509 const u8 *addr, int key_idx, int set_tx,
510 const u8 *seq, size_t seq_len,
511 const u8 *key, size_t key_len)
513 if (wpa_s->driver->set_key) {
514 wpa_s->keys_cleared = 0;
515 return wpa_s->driver->set_key(wpa_s->drv_priv, alg, addr,
516 key_idx, set_tx, seq, seq_len,
517 key, key_len);
519 return -1;
522 static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,
523 const u8 *addr, int reason_code)
525 if (wpa_s->driver->deauthenticate) {
526 return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,
527 reason_code);
529 return -1;
532 static inline int wpa_drv_disassociate(struct wpa_supplicant *wpa_s,
533 const u8 *addr, int reason_code)
535 if (wpa_s->driver->disassociate) {
536 return wpa_s->driver->disassociate(wpa_s->drv_priv, addr,
537 reason_code);
539 return -1;
542 static inline int wpa_drv_add_pmkid(struct wpa_supplicant *wpa_s,
543 const u8 *bssid, const u8 *pmkid)
545 if (wpa_s->driver->add_pmkid) {
546 return wpa_s->driver->add_pmkid(wpa_s->drv_priv, bssid, pmkid);
548 return -1;
551 static inline int wpa_drv_remove_pmkid(struct wpa_supplicant *wpa_s,
552 const u8 *bssid, const u8 *pmkid)
554 if (wpa_s->driver->remove_pmkid) {
555 return wpa_s->driver->remove_pmkid(wpa_s->drv_priv, bssid,
556 pmkid);
558 return -1;
561 static inline int wpa_drv_flush_pmkid(struct wpa_supplicant *wpa_s)
563 if (wpa_s->driver->flush_pmkid) {
564 return wpa_s->driver->flush_pmkid(wpa_s->drv_priv);
566 return -1;
569 static inline int wpa_drv_get_capa(struct wpa_supplicant *wpa_s,
570 struct wpa_driver_capa *capa)
572 if (wpa_s->driver->get_capa) {
573 return wpa_s->driver->get_capa(wpa_s->drv_priv, capa);
575 return -1;
578 static inline void wpa_drv_poll(struct wpa_supplicant *wpa_s)
580 if (wpa_s->driver->poll) {
581 wpa_s->driver->poll(wpa_s->drv_priv);
585 static inline const char * wpa_drv_get_ifname(struct wpa_supplicant *wpa_s)
587 if (wpa_s->driver->get_ifname) {
588 return wpa_s->driver->get_ifname(wpa_s->drv_priv);
590 return NULL;
593 static inline const u8 * wpa_drv_get_mac_addr(struct wpa_supplicant *wpa_s)
595 if (wpa_s->driver->get_mac_addr) {
596 return wpa_s->driver->get_mac_addr(wpa_s->drv_priv);
598 return NULL;
601 static inline int wpa_drv_send_eapol(struct wpa_supplicant *wpa_s,
602 const u8 *dst, u16 proto,
603 const u8 *data, size_t data_len)
605 if (wpa_s->driver->send_eapol)
606 return wpa_s->driver->send_eapol(wpa_s->drv_priv, dst, proto,
607 data, data_len);
608 return -1;
611 static inline int wpa_drv_set_operstate(struct wpa_supplicant *wpa_s,
612 int state)
614 if (wpa_s->driver->set_operstate)
615 return wpa_s->driver->set_operstate(wpa_s->drv_priv, state);
616 return 0;
619 static inline int wpa_drv_mlme_setprotection(struct wpa_supplicant *wpa_s,
620 const u8 *addr, int protect_type,
621 int key_type)
623 if (wpa_s->driver->mlme_setprotection)
624 return wpa_s->driver->mlme_setprotection(wpa_s->drv_priv, addr,
625 protect_type,
626 key_type);
627 return 0;
630 static inline struct wpa_hw_modes *
631 wpa_drv_get_hw_feature_data(struct wpa_supplicant *wpa_s, u16 *num_modes,
632 u16 *flags)
634 if (wpa_s->driver->get_hw_feature_data)
635 return wpa_s->driver->get_hw_feature_data(wpa_s->drv_priv,
636 num_modes, flags);
637 return NULL;
640 static inline int wpa_drv_set_channel(struct wpa_supplicant *wpa_s,
641 wpa_hw_mode phymode, int chan,
642 int freq)
644 if (wpa_s->driver->set_channel)
645 return wpa_s->driver->set_channel(wpa_s->drv_priv, phymode,
646 chan, freq);
647 return -1;
650 static inline int wpa_drv_set_ssid(struct wpa_supplicant *wpa_s,
651 const u8 *ssid, size_t ssid_len)
653 if (wpa_s->driver->set_ssid) {
654 return wpa_s->driver->set_ssid(wpa_s->drv_priv, ssid,
655 ssid_len);
657 return -1;
660 static inline int wpa_drv_set_bssid(struct wpa_supplicant *wpa_s,
661 const u8 *bssid)
663 if (wpa_s->driver->set_bssid) {
664 return wpa_s->driver->set_bssid(wpa_s->drv_priv, bssid);
666 return -1;
669 static inline int wpa_drv_send_mlme(struct wpa_supplicant *wpa_s,
670 const u8 *data, size_t data_len)
672 if (wpa_s->driver->send_mlme)
673 return wpa_s->driver->send_mlme(wpa_s->drv_priv,
674 data, data_len);
675 return -1;
678 static inline int wpa_drv_mlme_add_sta(struct wpa_supplicant *wpa_s,
679 const u8 *addr, const u8 *supp_rates,
680 size_t supp_rates_len)
682 if (wpa_s->driver->mlme_add_sta)
683 return wpa_s->driver->mlme_add_sta(wpa_s->drv_priv, addr,
684 supp_rates, supp_rates_len);
685 return -1;
688 static inline int wpa_drv_mlme_remove_sta(struct wpa_supplicant *wpa_s,
689 const u8 *addr)
691 if (wpa_s->driver->mlme_remove_sta)
692 return wpa_s->driver->mlme_remove_sta(wpa_s->drv_priv, addr);
693 return -1;
696 #endif /* WPA_SUPPLICANT_I_H */