HAMMER 60I/Many: Mirroring
[dragonfly.git] / contrib / hostapd-0.5.8 / wpa.h
blob633b2c56ab171963f7fdbef6b8b9dd3614e7b5f3
1 /*
2 * hostapd - IEEE 802.11i-2004 / WPA Authenticator
3 * Copyright (c) 2004-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_H
16 #define WPA_H
18 #include "wpa_common.h"
20 #define WPA_PMK_LEN PMK_LEN
21 #define WPA_GMK_LEN 32
22 #define WPA_GTK_MAX_LEN 32
23 #define PMKID_LEN 16
25 #define WPA_CAPABILITY_PREAUTH BIT(0)
26 #define WPA_CAPABILITY_MGMT_FRAME_PROTECTION BIT(6)
27 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9)
29 struct wpa_eapol_key {
30 u8 type;
31 u16 key_info;
32 u16 key_length;
33 u8 replay_counter[WPA_REPLAY_COUNTER_LEN];
34 u8 key_nonce[WPA_NONCE_LEN];
35 u8 key_iv[16];
36 u8 key_rsc[WPA_KEY_RSC_LEN];
37 u8 key_id[8]; /* Reserved */
38 u8 key_mic[16];
39 u16 key_data_length;
40 /* followed by key_data_length bytes of key_data */
41 } __attribute__ ((packed));
43 #define WPA_KEY_INFO_TYPE_MASK (BIT(0) | BIT(1) | BIT(2))
44 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
45 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
46 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1 = Pairwise, 0 = Group key */
47 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
48 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
49 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
50 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
51 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
52 #define WPA_KEY_INFO_ACK BIT(7)
53 #define WPA_KEY_INFO_MIC BIT(8)
54 #define WPA_KEY_INFO_SECURE BIT(9)
55 #define WPA_KEY_INFO_ERROR BIT(10)
56 #define WPA_KEY_INFO_REQUEST BIT(11)
57 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12)
58 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
61 /* per STA state machine data */
63 struct wpa_ptk {
64 u8 mic_key[16]; /* EAPOL-Key MIC Key (MK) */
65 u8 encr_key[16]; /* EAPOL-Key Encryption Key (EK) */
66 u8 tk1[16]; /* Temporal Key 1 (TK1) */
67 union {
68 u8 tk2[16]; /* Temporal Key 2 (TK2) */
69 struct {
70 u8 tx_mic_key[8];
71 u8 rx_mic_key[8];
72 } auth;
73 } u;
74 } __attribute__ ((packed));
76 struct wpa_authenticator;
77 struct wpa_state_machine;
78 struct rsn_pmksa_cache_entry;
81 struct wpa_auth_config {
82 int wpa;
83 int wpa_key_mgmt;
84 int wpa_pairwise;
85 int wpa_group;
86 int wpa_group_rekey;
87 int wpa_strict_rekey;
88 int wpa_gmk_rekey;
89 int rsn_preauth;
90 int eapol_version;
91 int peerkey;
92 int wme_enabled;
93 #ifdef CONFIG_IEEE80211W
94 enum {
95 WPA_NO_IEEE80211W = 0,
96 WPA_IEEE80211W_OPTIONAL = 1,
97 WPA_IEEE80211W_REQUIRED = 2
98 } ieee80211w;
99 #endif /* CONFIG_IEEE80211W */
102 typedef enum {
103 LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
104 } logger_level;
106 typedef enum {
107 WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
108 WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
109 WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
110 } wpa_eapol_variable;
112 struct wpa_auth_callbacks {
113 void *ctx;
114 void (*logger)(void *ctx, const u8 *addr, logger_level level,
115 const char *txt);
116 void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
117 void (*mic_failure_report)(void *ctx, const u8 *addr);
118 void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
119 int value);
120 int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
121 const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *prev_psk);
122 int (*get_pmk)(void *ctx, const u8 *addr, u8 *pmk, size_t *len);
123 int (*set_key)(void *ctx, int vlan_id, const char *alg, const u8 *addr,
124 int idx, u8 *key, size_t key_len);
125 int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
126 int (*get_seqnum_igtk)(void *ctx, const u8 *addr, int idx, u8 *seq);
127 int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
128 size_t data_len, int encrypt);
129 int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
130 void *ctx), void *cb_ctx);
133 struct wpa_authenticator * wpa_init(const u8 *addr,
134 struct wpa_auth_config *conf,
135 struct wpa_auth_callbacks *cb);
136 void wpa_deinit(struct wpa_authenticator *wpa_auth);
137 int wpa_reconfig(struct wpa_authenticator *wpa_auth,
138 struct wpa_auth_config *conf);
140 enum {
141 WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
142 WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
143 WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER
146 int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
147 struct wpa_state_machine *sm,
148 const u8 *wpa_ie, size_t wpa_ie_len);
149 struct wpa_state_machine *
150 wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr);
151 void wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
152 struct wpa_state_machine *sm);
153 void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
154 void wpa_receive(struct wpa_authenticator *wpa_auth,
155 struct wpa_state_machine *sm,
156 u8 *data, size_t data_len);
157 typedef enum {
158 WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
159 WPA_REAUTH_EAPOL
160 } wpa_event;
161 void wpa_remove_ptk(struct wpa_state_machine *sm);
162 void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
163 void wpa_auth_sm_notify(struct wpa_state_machine *sm);
164 void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
165 int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
166 int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
167 void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
168 int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
169 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
170 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
171 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
172 struct rsn_pmksa_cache_entry *entry);
173 struct rsn_pmksa_cache_entry *
174 wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
175 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
176 const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
177 size_t *len);
178 int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
179 int session_timeout, struct eapol_state_machine *eapol);
180 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
181 const u8 *pmk, size_t len, const u8 *sta_addr,
182 int session_timeout,
183 struct eapol_state_machine *eapol);
184 int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
186 #endif /* WPA_H */