Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / contrib / wpa_supplicant-0.4.9 / wpa_supplicant_i.h
1 /*
2  * wpa_supplicant - Internal definitions
3  * Copyright (c) 2003-2006, Jouni Malinen <jkmaline@cc.hut.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 WPA_SUPPLICANT_I_H
16 #define WPA_SUPPLICANT_I_H
17
18 #include "driver.h"
19
20 struct wpa_blacklist {
21         struct wpa_blacklist *next;
22         u8 bssid[ETH_ALEN];
23         int count;
24 };
25
26
27 struct wpa_scan_result;
28 struct wpa_sm;
29 struct wpa_supplicant;
30
31 /**
32  * struct wpa_interface - Parameters for wpa_supplicant_add_iface()
33  */
34 struct wpa_interface {
35         /**
36          * confname - Configuration name (file or profile) name
37          *
38          * This can also be %NULL when a configuration file is not used. In
39          * that case, ctrl_interface must be set to allow the interface to be
40          * configured.
41          */
42         const char *confname;
43
44         /**
45          * ctrl_interface - Control interface parameter
46          *
47          * If a configuration file is not used, this variable can be used to
48          * set the ctrl_interface parameter that would have otherwise been read
49          * from the configuration file. If both confname and ctrl_interface are
50          * set, ctrl_interface is used to override the value from configuration
51          * file.
52          */
53         const char *ctrl_interface;
54
55         /**
56          * driver - Driver interface name, or %NULL to use the default driver
57          */
58         const char *driver;
59
60         /**
61          * driver_param - Driver interface parameters
62          *
63          * If a configuration file is not used, this variable can be used to
64          * set the driver_param parameters that would have otherwise been read
65          * from the configuration file. If both confname and driver_param are
66          * set, driver_param is used to override the value from configuration
67          * file.
68          */
69         const char *driver_param;
70
71         /**
72          * ifname - Interface name
73          */
74         const char *ifname;
75 };
76
77 /**
78  * struct wpa_params - Parameters for wpa_supplicant_init()
79  */
80 struct wpa_params {
81         /**
82          * daemonize - Run %wpa_supplicant in the background
83          */
84         int daemonize;
85
86         /**
87          * wait_for_interface - Wait for the network interface to appear
88          *
89          * If set, %wpa_supplicant will wait until all the configured network
90          * interfaces are available before starting processing. Please note
91          * that in many cases, a better alternative would be to start
92          * %wpa_supplicant without network interfaces and add the interfaces
93          * dynamically whenever they become available.
94          */
95         int wait_for_interface;
96
97         /**
98          * wait_for_monitor - Wait for a monitor program before starting
99          */
100         int wait_for_monitor;
101
102         /**
103          * pid_file - Path to a PID (process ID) file
104          *
105          * If this and daemonize are set, process ID of the background process
106          * will be written to the specified file.
107          */
108         char *pid_file;
109
110         /**
111          * wpa_debug_level - Debugging verbosity level (e.g., MSG_INFO)
112          */
113         int wpa_debug_level;
114
115         /**
116          * wpa_debug_show_keys - Whether keying material is included in debug
117          *
118          * This parameter can be used to allow keying material to be included
119          * in debug messages. This is a security risk and this option should
120          * not be enabled in normal configuration. If needed during
121          * development or while troubleshooting, this option can provide more
122          * details for figuring out what is happening.
123          */
124         int wpa_debug_show_keys;
125
126         /**
127          * wpa_debug_timestamp - Whether to include timestamp in debug messages
128          */
129         int wpa_debug_timestamp;
130
131         /**
132          * ctrl_interface - Global ctrl_iface path/parameter
133          */
134         char *ctrl_interface;
135 };
136
137 /**
138  * struct wpa_global - Internal, global data for all %wpa_supplicant interfaces
139  *
140  * This structure is initialized by calling wpa_supplicant_init() when starting
141  * %wpa_supplicant.
142  */
143 struct wpa_global {
144         struct wpa_supplicant *ifaces;
145         struct wpa_params params;
146         int ctrl_sock;
147 };
148
149 /**
150  * struct wpa_supplicant - Internal data for wpa_supplicant interface
151  *
152  * This structure contains the internal data for core wpa_supplicant code. This
153  * should be only used directly from the core code. However, a pointer to this
154  * data is used from other files as an arbitrary context pointer in calls to
155  * core functions.
156  */
157 struct wpa_supplicant {
158         struct wpa_global *global;
159         struct wpa_supplicant *next;
160         struct l2_packet_data *l2;
161         unsigned char own_addr[ETH_ALEN];
162         char ifname[100];
163
164         char *confname;
165         struct wpa_config *conf;
166         int countermeasures;
167         time_t last_michael_mic_error;
168         u8 bssid[ETH_ALEN];
169         int reassociate; /* reassociation requested */
170         int disconnected; /* all connections disabled; i.e., do no reassociate
171                            * before this has been cleared */
172         struct wpa_ssid *current_ssid;
173
174         /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
175         int pairwise_cipher;
176         int group_cipher;
177         int key_mgmt;
178
179         void *drv_priv; /* private data used by driver_ops */
180
181         struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
182                                           * NULL = not yet initialized (start
183                                           * with broadcast SSID)
184                                           * BROADCAST_SSID_SCAN = broadcast
185                                           * SSID was used in the previous scan
186                                           */
187 #define BROADCAST_SSID_SCAN ((struct wpa_ssid *) 1)
188
189         struct wpa_scan_result *scan_results;
190         int num_scan_results;
191
192         struct wpa_driver_ops *driver;
193         int interface_removed; /* whether the network interface has been
194                                 * removed */
195         struct wpa_sm *wpa;
196         struct eapol_sm *eapol;
197
198         int ctrl_sock; /* UNIX domain socket for control interface or -1 if
199                         * not used */
200         struct wpa_ctrl_dst *ctrl_dst;
201
202         wpa_states wpa_state;
203         int new_connection;
204         int reassociated_connection;
205
206         int eapol_received; /* number of EAPOL packets received after the
207                              * previous association event */
208
209         struct scard_data *scard;
210
211         unsigned char last_eapol_src[ETH_ALEN];
212
213         int keys_cleared;
214
215         struct wpa_blacklist *blacklist;
216
217         int scan_req; /* manual scan request; this forces a scan even if there
218                        * are no enabled networks in the configuration */
219 };
220
221
222 /* wpa_supplicant.c */
223 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
224
225 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
226
227 const char * wpa_supplicant_state_txt(int state);
228 int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s,
229                                int wait_for_interface);
230 struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
231                                          const u8 *bssid);
232 int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid);
233 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s);
234 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
235                               struct wpa_scan_result *bss,
236                               struct wpa_ssid *ssid,
237                               u8 *wpa_ie, size_t *wpa_ie_len);
238 void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
239                               struct wpa_scan_result *bss,
240                               struct wpa_ssid *ssid);
241 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
242                                        struct wpa_ssid *ssid);
243 void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s);
244 int wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s);
245 void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr);
246 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
247                                      int sec, int usec);
248 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state);
249 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s);
250 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s);
251 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
252                                    int reason_code);
253 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
254                                  int reason_code);
255 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
256
257 void wpa_show_license(void);
258
259 struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
260                                                  struct wpa_interface *iface);
261 int wpa_supplicant_remove_iface(struct wpa_global *global,
262                                 struct wpa_supplicant *wpa_s);
263 struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
264                                                  const char *ifname);
265 struct wpa_global * wpa_supplicant_init(struct wpa_params *params);
266 int wpa_supplicant_run(struct wpa_global *global);
267 void wpa_supplicant_deinit(struct wpa_global *global);
268
269 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
270                               struct wpa_ssid *ssid);
271
272
273 /* driver_ops */
274 static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
275                                   const char *ifname)
276 {
277         if (wpa_s->driver->init) {
278                 return wpa_s->driver->init(wpa_s, ifname);
279         }
280         return NULL;
281 }
282
283 static inline void wpa_drv_deinit(struct wpa_supplicant *wpa_s)
284 {
285         if (wpa_s->driver->deinit)
286                 wpa_s->driver->deinit(wpa_s->drv_priv);
287 }
288
289 static inline int wpa_drv_set_param(struct wpa_supplicant *wpa_s,
290                                     const char *param)
291 {
292         if (wpa_s->driver->set_param)
293                 return wpa_s->driver->set_param(wpa_s->drv_priv, param);
294         return 0;
295 }
296
297 static inline int wpa_drv_set_drop_unencrypted(struct wpa_supplicant *wpa_s,
298                                                int enabled)
299 {
300         if (wpa_s->driver->set_drop_unencrypted) {
301                 return wpa_s->driver->set_drop_unencrypted(wpa_s->drv_priv,
302                                                            enabled);
303         }
304         return -1;
305 }
306
307 static inline int wpa_drv_set_countermeasures(struct wpa_supplicant *wpa_s,
308                                               int enabled)
309 {
310         if (wpa_s->driver->set_countermeasures) {
311                 return wpa_s->driver->set_countermeasures(wpa_s->drv_priv,
312                                                           enabled);
313         }
314         return -1;
315 }
316
317 static inline int wpa_drv_set_auth_alg(struct wpa_supplicant *wpa_s,
318                                        int auth_alg)
319 {
320         if (wpa_s->driver->set_auth_alg) {
321                 return wpa_s->driver->set_auth_alg(wpa_s->drv_priv,
322                                                    auth_alg);
323         }
324         return -1;
325 }
326
327 static inline int wpa_drv_set_wpa(struct wpa_supplicant *wpa_s, int enabled)
328 {
329         if (wpa_s->driver->set_wpa) {
330                 return wpa_s->driver->set_wpa(wpa_s->drv_priv, enabled);
331         }
332         return 0;
333 }
334
335 static inline int wpa_drv_associate(struct wpa_supplicant *wpa_s,
336                                     struct wpa_driver_associate_params *params)
337 {
338         if (wpa_s->driver->associate) {
339                 return wpa_s->driver->associate(wpa_s->drv_priv, params);
340         }
341         return -1;
342 }
343
344 static inline int wpa_drv_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
345                                size_t ssid_len)
346 {
347         if (wpa_s->driver->scan) {
348                 return wpa_s->driver->scan(wpa_s->drv_priv, ssid, ssid_len);
349         }
350         return -1;
351 }
352
353 static inline int wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s,
354                                            struct wpa_scan_result *results,
355                                            size_t max_size)
356 {
357         if (wpa_s->driver->get_scan_results) {
358                 return wpa_s->driver->get_scan_results(wpa_s->drv_priv,
359                                                        results, max_size);
360         }
361         return -1;
362 }
363
364 static inline int wpa_drv_get_bssid(struct wpa_supplicant *wpa_s, u8 *bssid)
365 {
366         if (wpa_s->driver->get_bssid) {
367                 return wpa_s->driver->get_bssid(wpa_s->drv_priv, bssid);
368         }
369         return -1;
370 }
371
372 static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
373 {
374         if (wpa_s->driver->get_ssid) {
375                 return wpa_s->driver->get_ssid(wpa_s->drv_priv, ssid);
376         }
377         return -1;
378 }
379
380 static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, wpa_alg alg,
381                                    const u8 *addr, int key_idx, int set_tx,
382                                    const u8 *seq, size_t seq_len,
383                                    const u8 *key, size_t key_len)
384 {
385         if (wpa_s->driver->set_key) {
386                 wpa_s->keys_cleared = 0;
387                 return wpa_s->driver->set_key(wpa_s->drv_priv, alg, addr,
388                                               key_idx, set_tx, seq, seq_len,
389                                               key, key_len);
390         }
391         return -1;
392 }
393
394 static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,
395                                          const u8 *addr, int reason_code)
396 {
397         if (wpa_s->driver->deauthenticate) {
398                 return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,
399                                                      reason_code);
400         }
401         return -1;
402 }
403
404 static inline int wpa_drv_disassociate(struct wpa_supplicant *wpa_s,
405                                        const u8 *addr, int reason_code)
406 {
407         if (wpa_s->driver->disassociate) {
408                 return wpa_s->driver->disassociate(wpa_s->drv_priv, addr,
409                                                    reason_code);
410         }
411         return -1;
412 }
413
414 static inline int wpa_drv_add_pmkid(struct wpa_supplicant *wpa_s,
415                                     const u8 *bssid, const u8 *pmkid)
416 {
417         if (wpa_s->driver->add_pmkid) {
418                 return wpa_s->driver->add_pmkid(wpa_s->drv_priv, bssid, pmkid);
419         }
420         return -1;
421 }
422
423 static inline int wpa_drv_remove_pmkid(struct wpa_supplicant *wpa_s,
424                                        const u8 *bssid, const u8 *pmkid)
425 {
426         if (wpa_s->driver->remove_pmkid) {
427                 return wpa_s->driver->remove_pmkid(wpa_s->drv_priv, bssid,
428                                                    pmkid);
429         }
430         return -1;
431 }
432
433 static inline int wpa_drv_flush_pmkid(struct wpa_supplicant *wpa_s)
434 {
435         if (wpa_s->driver->flush_pmkid) {
436                 return wpa_s->driver->flush_pmkid(wpa_s->drv_priv);
437         }
438         return -1;
439 }
440
441 static inline int wpa_drv_get_capa(struct wpa_supplicant *wpa_s,
442                                    struct wpa_driver_capa *capa)
443 {
444         if (wpa_s->driver->get_capa) {
445                 return wpa_s->driver->get_capa(wpa_s->drv_priv, capa);
446         }
447         return -1;
448 }
449
450 static inline void wpa_drv_poll(struct wpa_supplicant *wpa_s)
451 {
452         if (wpa_s->driver->poll) {
453                 wpa_s->driver->poll(wpa_s->drv_priv);
454         }
455 }
456
457 static inline const char * wpa_drv_get_ifname(struct wpa_supplicant *wpa_s)
458 {
459         if (wpa_s->driver->get_ifname) {
460                 return wpa_s->driver->get_ifname(wpa_s->drv_priv);
461         }
462         return NULL;
463 }
464
465 static inline const u8 * wpa_drv_get_mac_addr(struct wpa_supplicant *wpa_s)
466 {
467         if (wpa_s->driver->get_mac_addr) {
468                 return wpa_s->driver->get_mac_addr(wpa_s->drv_priv);
469         }
470         return NULL;
471 }
472
473 static inline int wpa_drv_send_eapol(struct wpa_supplicant *wpa_s,
474                                      const u8 *dst, u16 proto,
475                                      const u8 *data, size_t data_len)
476 {
477         if (wpa_s->driver->send_eapol)
478                 return wpa_s->driver->send_eapol(wpa_s->drv_priv, dst, proto,
479                                                  data, data_len);
480         return -1;
481 }
482
483 #endif /* WPA_SUPPLICANT_I_H */