]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/wpa_supplicant/wpa_supplicant_i.h
This commit was generated by cvs2svn to compensate for changes in r155420,
[FreeBSD/FreeBSD.git] / contrib / wpa_supplicant / wpa_supplicant_i.h
1 #ifndef WPA_SUPPLICANT_I_H
2 #define WPA_SUPPLICANT_I_H
3
4 #include "driver.h"
5
6 #ifdef EAPOL_TEST
7 #include <netinet/in.h>
8
9 struct hostapd_radius_server {
10         struct in_addr addr;
11         int port;
12         u8 *shared_secret;
13         size_t shared_secret_len;
14 };
15 #endif /* EAPOL_TEST */
16
17 #define PMKID_LEN 16
18 struct rsn_pmksa_cache {
19         struct rsn_pmksa_cache *next;
20         u8 pmkid[PMKID_LEN];
21         u8 pmk[PMK_LEN];
22         size_t pmk_len;
23         time_t expiration;
24         int akmp; /* WPA_KEY_MGMT_* */
25         u8 aa[ETH_ALEN];
26 };
27
28 struct rsn_pmksa_candidate {
29         struct rsn_pmksa_candidate *next;
30         u8 bssid[ETH_ALEN];
31         int priority;
32 };
33
34
35 struct wpa_ptk {
36         u8 mic_key[16]; /* EAPOL-Key MIC Key (MK) */
37         u8 encr_key[16]; /* EAPOL-Key Encryption Key (EK) */
38         u8 tk1[16]; /* Temporal Key 1 (TK1) */
39         union {
40                 u8 tk2[16]; /* Temporal Key 2 (TK2) */
41                 struct {
42                         u8 tx_mic_key[8];
43                         u8 rx_mic_key[8];
44                 } auth;
45         } u;
46 } __attribute__ ((packed));
47
48
49 struct wpa_blacklist {
50         struct wpa_blacklist *next;
51         u8 bssid[ETH_ALEN];
52         int count;
53 };
54
55
56 struct wpa_supplicant {
57         struct wpa_supplicant *head;
58         struct wpa_supplicant *next;
59         struct l2_packet_data *l2;
60         unsigned char own_addr[ETH_ALEN];
61         char ifname[100];
62 #ifdef CONFIG_XSUPPLICANT_IFACE
63         int dot1x_s; /* socket for connection to Xsupplicant */
64         int ext_pmk_received; /* 1 = PMK was received from Xsupplicant */
65 #endif /* CONFIG_XSUPPLICANT_IFACE */
66
67         u8 pmk[PMK_LEN];
68         size_t pmk_len;
69         u8 snonce[WPA_NONCE_LEN];
70         u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
71         struct wpa_ptk ptk, tptk;
72         int ptk_set, tptk_set;
73         int renew_snonce;
74         char *confname;
75         struct wpa_config *conf;
76         u8 request_counter[WPA_REPLAY_COUNTER_LEN];
77         int countermeasures;
78         time_t last_michael_mic_error;
79         u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
80         int rx_replay_counter_set;
81         u8 bssid[ETH_ALEN];
82         int reassociate; /* reassociation requested */
83         struct wpa_ssid *current_ssid;
84         u8 *ap_wpa_ie, *ap_rsn_ie;
85         size_t ap_wpa_ie_len, ap_rsn_ie_len;
86         u8 *assoc_wpa_ie;
87         size_t assoc_wpa_ie_len;
88
89         /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
90         int proto;
91         int pairwise_cipher;
92         int group_cipher;
93         int key_mgmt;
94
95         void *drv_priv; /* private data used by driver_ops */
96
97         struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
98                                           * NULL = not yet initialized (start
99                                           * with broadcast SSID)
100                                           * BROADCAST_SSID_SCAN = broadcast
101                                           * SSID was used in the previous scan
102                                           */
103 #define BROADCAST_SSID_SCAN ((struct wpa_ssid *) 1)
104
105         struct wpa_scan_result *scan_results;
106         int num_scan_results;
107
108         struct wpa_driver_ops *driver;
109         int interface_removed; /* whether the network interface has been
110                                 * removed */
111         struct eapol_sm *eapol;
112
113         int ctrl_sock; /* UNIX domain socket for control interface or -1 if
114                         * not used */
115         struct wpa_ctrl_dst *ctrl_dst;
116
117         enum {
118                 WPA_DISCONNECTED, WPA_SCANNING, WPA_ASSOCIATING,
119                 WPA_ASSOCIATED, WPA_4WAY_HANDSHAKE, WPA_GROUP_HANDSHAKE,
120                 WPA_COMPLETED
121         } wpa_state;
122
123         struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
124         int pmksa_count; /* number of entries in PMKSA cache */
125         struct rsn_pmksa_cache *cur_pmksa; /* current PMKSA entry */
126         struct rsn_pmksa_candidate *pmksa_candidates;
127
128         struct l2_packet_data *l2_preauth;
129         u8 preauth_bssid[ETH_ALEN]; /* current RSN pre-auth peer or
130                                      * 00:00:00:00:00:00 if no pre-auth is
131                                      * in progress */
132         struct eapol_sm *preauth_eapol;
133
134         int eapol_received; /* number of EAPOL packets received after the
135                              * previous association event */
136
137         u8 *imsi;
138         size_t imsi_len;
139         struct scard_data *scard;
140
141         unsigned char last_eapol_src[ETH_ALEN];
142
143         int keys_cleared;
144
145         struct wpa_blacklist *blacklist;
146
147 #ifdef EAPOL_TEST
148         u8 radius_identifier;
149         struct radius_msg *last_recv_radius;
150         struct in_addr own_ip_addr;
151         struct radius_client_data *radius;
152
153         /* RADIUS Authentication and Accounting servers in priority order */
154         struct hostapd_radius_server *auth_servers, *auth_server;
155         int num_auth_servers;
156         struct hostapd_radius_server *acct_servers, *acct_server;
157         int num_acct_servers;
158
159         int radius_retry_primary_interval;
160         int radius_acct_interim_interval;
161
162         u8 *last_eap_radius; /* last received EAP Response from Authentication
163                               * Server */
164         size_t last_eap_radius_len;
165
166         u8 authenticator_pmk[PMK_LEN];
167         size_t authenticator_pmk_len;
168         int radius_access_accept_received;
169         int radius_access_reject_received;
170         int auth_timed_out;
171
172         u8 *eap_identity;
173         size_t eap_identity_len;
174 #endif /* EAPOL_TEST */
175 };
176
177
178 /* wpa_supplicant.c */
179 void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx);
180
181 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
182
183 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
184
185 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
186                                  int reason_code);
187 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
188                                    int reason_code);
189
190 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
191                                      int sec, int usec);
192
193 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s);
194
195 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
196
197 int wpa_supplicant_get_beacon_ie(struct wpa_supplicant *wpa_s);
198
199
200 /* wpa.c */
201 void wpa_supplicant_key_request(struct wpa_supplicant *wpa_s,
202                                 int error, int pairwise);
203
204 struct wpa_ie_data {
205         int proto;
206         int pairwise_cipher;
207         int group_cipher;
208         int key_mgmt;
209         int capabilities;
210         int num_pmkid;
211         u8 *pmkid;
212 };
213
214 int wpa_parse_wpa_ie(struct wpa_supplicant *wpa_s, u8 *wpa_ie,
215                      size_t wpa_ie_len, struct wpa_ie_data *data);
216
217 int wpa_gen_wpa_ie(struct wpa_supplicant *wpa_s, u8 *wpa_ie);
218
219 void wpa_supplicant_rx_eapol(void *ctx, unsigned char *src_addr,
220                              unsigned char *buf, size_t len);
221
222 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s);
223
224 void pmksa_cache_free(struct wpa_supplicant *wpa_s);
225 struct rsn_pmksa_cache * pmksa_cache_get(struct wpa_supplicant *wpa_s,
226                                          u8 *aa, u8 *pmkid);
227 int pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf, size_t len);
228 void pmksa_candidate_free(struct wpa_supplicant *wpa_s);
229
230 int wpa_get_mib(struct wpa_supplicant *wpa_s, char *buf, size_t buflen);
231
232 struct wpa_scan_result;
233 #ifdef IEEE8021X_EAPOL
234 int rsn_preauth_init(struct wpa_supplicant *wpa_s, u8 *dst);
235 void rsn_preauth_deinit(struct wpa_supplicant *wpa_s);
236 void rsn_preauth_scan_results(struct wpa_supplicant *wpa_s,
237                               struct wpa_scan_result *results, int count);
238 void pmksa_candidate_add(struct wpa_supplicant *wpa_s, const u8 *bssid,
239                          int prio);
240 #else /* IEEE8021X_EAPOL */
241 static inline int rsn_preauth_init(struct wpa_supplicant *wpa_s, u8 *dst)
242 {
243         return -1;
244 }
245
246 static inline void rsn_preauth_deinit(struct wpa_supplicant *wpa_s)
247 {
248 }
249 static inline void rsn_preauth_scan_results(struct wpa_supplicant *wpa_s,
250                                             struct wpa_scan_result *results,
251                                             int count)
252 {
253 }
254
255 static inline void pmksa_candidate_add(struct wpa_supplicant *wpa_s,
256                                        const u8 *bssid,
257                                        int prio)
258 {
259 }
260 #endif /* IEEE8021X_EAPOL */
261
262 void wpa_supplicant_notify_eapol_done(void *ctx);
263
264 /**
265  * wpa_eapol_send - send IEEE 802.1X EAPOL packet to the Authenticator
266  * @ctx: pointer to wpa_supplicant data
267  * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
268  * @buf: EAPOL payload (after IEEE 802.1X header)
269  * @len: EAPOL payload length
270  *
271  * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
272  * to the current Authenticator or in case of pre-authentication, to the peer
273  * of the authentication.
274  */
275 int wpa_eapol_send(void *ctx, int type, u8 *buf, size_t len);
276 int wpa_eapol_send_preauth(void *ctx, int type, u8 *buf, size_t len);
277
278
279 /* driver_ops */
280 static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
281                                   const char *ifname)
282 {
283         if (wpa_s->driver->init) {
284                 return wpa_s->driver->init(wpa_s, ifname);
285         }
286         return NULL;
287 }
288
289 static inline void wpa_drv_deinit(struct wpa_supplicant *wpa_s)
290 {
291         if (wpa_s->driver->deinit)
292                 wpa_s->driver->deinit(wpa_s->drv_priv);
293 }
294
295 static inline int wpa_drv_set_drop_unencrypted(struct wpa_supplicant *wpa_s,
296                                                int enabled)
297 {
298         if (wpa_s->driver->set_drop_unencrypted) {
299                 return wpa_s->driver->set_drop_unencrypted(wpa_s->drv_priv,
300                                                            enabled);
301         }
302         return -1;
303 }
304
305 static inline int wpa_drv_set_countermeasures(struct wpa_supplicant *wpa_s,
306                                               int enabled)
307 {
308         if (wpa_s->driver->set_countermeasures) {
309                 return wpa_s->driver->set_countermeasures(wpa_s->drv_priv,
310                                                           enabled);
311         }
312         return -1;
313 }
314
315 static inline int wpa_drv_set_auth_alg(struct wpa_supplicant *wpa_s,
316                                        int auth_alg)
317 {
318         if (wpa_s->driver->set_auth_alg) {
319                 return wpa_s->driver->set_auth_alg(wpa_s->drv_priv,
320                                                    auth_alg);
321         }
322         return -1;
323 }
324
325 static inline int wpa_drv_set_wpa(struct wpa_supplicant *wpa_s, int enabled)
326 {
327         if (wpa_s->driver->set_wpa) {
328                 return wpa_s->driver->set_wpa(wpa_s->drv_priv, enabled);
329         }
330         return 0;
331 }
332
333 static inline int wpa_drv_associate(struct wpa_supplicant *wpa_s,
334                                     struct wpa_driver_associate_params *params)
335 {
336         if (wpa_s->driver->associate) {
337                 return wpa_s->driver->associate(wpa_s->drv_priv, params);
338         }
339         return -1;
340 }
341
342 static inline int wpa_drv_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
343                                size_t ssid_len)
344 {
345         if (wpa_s->driver->scan) {
346                 return wpa_s->driver->scan(wpa_s->drv_priv, ssid, ssid_len);
347         }
348         return -1;
349 }
350
351 static inline int wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s,
352                                            struct wpa_scan_result *results,
353                                            size_t max_size)
354 {
355         if (wpa_s->driver->get_scan_results) {
356                 return wpa_s->driver->get_scan_results(wpa_s->drv_priv,
357                                                        results, max_size);
358         }
359         return -1;
360 }
361
362 static inline int wpa_drv_get_bssid(struct wpa_supplicant *wpa_s, u8 *bssid)
363 {
364         if (wpa_s->driver->get_bssid) {
365                 return wpa_s->driver->get_bssid(wpa_s->drv_priv, bssid);
366         }
367         return -1;
368 }
369
370 static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid)
371 {
372         if (wpa_s->driver->get_ssid) {
373                 return wpa_s->driver->get_ssid(wpa_s->drv_priv, ssid);
374         }
375         return -1;
376 }
377
378 static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, wpa_alg alg,
379                                    const u8 *addr, int key_idx, int set_tx,
380                                    const u8 *seq, size_t seq_len,
381                                    const u8 *key, size_t key_len)
382 {
383         if (wpa_s->driver->set_key) {
384                 return wpa_s->driver->set_key(wpa_s->drv_priv, alg, addr,
385                                               key_idx, set_tx, seq, seq_len,
386                                               key, key_len);
387         }
388         return -1;
389 }
390
391 static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,
392                                          const u8 *addr, int reason_code)
393 {
394         if (wpa_s->driver->deauthenticate) {
395                 return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,
396                                                      reason_code);
397         }
398         return -1;
399 }
400
401 static inline int wpa_drv_disassociate(struct wpa_supplicant *wpa_s,
402                                        const u8 *addr, int reason_code)
403 {
404         if (wpa_s->driver->disassociate) {
405                 return wpa_s->driver->disassociate(wpa_s->drv_priv, addr,
406                                                    reason_code);
407         }
408         return -1;
409 }
410
411 static inline int wpa_drv_add_pmkid(struct wpa_supplicant *wpa_s,
412                                     const u8 *bssid, const u8 *pmkid)
413 {
414         if (wpa_s->driver->add_pmkid) {
415                 return wpa_s->driver->add_pmkid(wpa_s->drv_priv, bssid, pmkid);
416         }
417         return -1;
418 }
419
420 static inline int wpa_drv_remove_pmkid(struct wpa_supplicant *wpa_s,
421                                        const u8 *bssid, const u8 *pmkid)
422 {
423         if (wpa_s->driver->remove_pmkid) {
424                 return wpa_s->driver->remove_pmkid(wpa_s->drv_priv, bssid,
425                                                    pmkid);
426         }
427         return -1;
428 }
429
430 static inline int wpa_drv_flush_pmkid(struct wpa_supplicant *wpa_s)
431 {
432         if (wpa_s->driver->flush_pmkid) {
433                 return wpa_s->driver->flush_pmkid(wpa_s->drv_priv);
434         }
435         return -1;
436 }
437
438 static inline int wpa_drv_get_capa(struct wpa_supplicant *wpa_s,
439                                    struct wpa_driver_capa *capa)
440 {
441         if (wpa_s->driver->get_capa) {
442                 return wpa_s->driver->get_capa(wpa_s->drv_priv, capa);
443         }
444         return -1;
445 }
446
447 static inline void wpa_drv_poll(struct wpa_supplicant *wpa_s)
448 {
449         if (wpa_s->driver->poll) {
450                 wpa_s->driver->poll(wpa_s->drv_priv);
451         }
452 }
453
454 static inline const char * wpa_drv_get_ifname(struct wpa_supplicant *wpa_s)
455 {
456         if (wpa_s->driver->get_ifname) {
457                 return wpa_s->driver->get_ifname(wpa_s->drv_priv);
458         }
459         return NULL;
460 }
461
462 static inline const u8 * wpa_drv_get_mac_addr(struct wpa_supplicant *wpa_s)
463 {
464         if (wpa_s->driver->get_mac_addr) {
465                 return wpa_s->driver->get_mac_addr(wpa_s->drv_priv);
466         }
467         return NULL;
468 }
469
470 #endif /* WPA_SUPPLICANT_I_H */