~ubuntu-branches/ubuntu/natty/wpasupplicant/natty

« back to all changes in this revision

Viewing changes to wpa_supplicant_i.h

  • Committer: Bazaar Package Importer
  • Author(s): Kyle McMartin
  • Date: 2005-02-15 00:51:28 UTC
  • Revision ID: james.westby@ubuntu.com-20050215005128-xr4m8owiunur2008
Tags: upstream-0.3.8
ImportĀ upstreamĀ versionĀ 0.3.8

Show diffs side-by-side

added added

removed removed

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