]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/hostapd/wpa.h
This commit was generated by cvs2svn to compensate for changes in r154180,
[FreeBSD/FreeBSD.git] / contrib / hostapd / wpa.h
1 #ifndef WPA_H
2 #define WPA_H
3
4 #define WPA_NONCE_LEN 32
5 #define WPA_PMK_LEN PMK_LEN
6 #define WPA_REPLAY_COUNTER_LEN 8
7 #define WPA_GMK_LEN 32
8 #define WPA_GTK_MAX_LEN 32
9 #define WPA_KEY_RSC_LEN 8
10 #define PMKID_LEN 16
11
12 struct rsn_pmksa_cache {
13         struct rsn_pmksa_cache *next, *hnext;
14         u8 pmkid[PMKID_LEN];
15         u8 pmk[PMK_LEN];
16         time_t expiration;
17         int akmp; /* WPA_KEY_MGMT_* */
18         u8 spa[ETH_ALEN];
19 };
20
21 struct rsn_preauth_interface {
22         struct rsn_preauth_interface *next;
23         struct hostapd_data *hapd;
24         struct l2_packet_data *l2;
25         char *ifname;
26         int ifindex;
27 };
28
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));
42
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
59
60 /* per STA state machine data */
61
62 struct wpa_ptk {
63         u8 mic_key[16]; /* EAPOL-Key MIC Key (MK) */
64         u8 encr_key[16]; /* EAPOL-Key Encryption Key (EK) */
65         u8 tk1[16]; /* Temporal Key 1 (TK1) */
66         union {
67                 u8 tk2[16]; /* Temporal Key 2 (TK2) */
68                 struct {
69                         u8 tx_mic_key[8];
70                         u8 rx_mic_key[8];
71                 } auth;
72         } u;
73 } __attribute__ ((packed));
74
75 struct wpa_state_machine {
76         struct hostapd_data *hapd;
77         struct sta_info *sta;
78
79         enum {
80                 WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
81                 WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
82                 WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
83                 WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
84                 WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
85         } wpa_ptk_state;
86
87         enum {
88                 WPA_PTK_GROUP_IDLE = 0,
89                 WPA_PTK_GROUP_REKEYNEGOTIATING,
90                 WPA_PTK_GROUP_REKEYESTABLISHED,
91                 WPA_PTK_GROUP_KEYERROR
92         } wpa_ptk_group_state;
93
94         Boolean Init;
95         Boolean DeauthenticationRequest;
96         Boolean AuthenticationRequest;
97         Boolean ReAuthenticationRequest;
98         Boolean Disconnect;
99         int TimeoutCtr;
100         int GTimeoutCtr;
101         Boolean TimeoutEvt;
102         Boolean EAPOLKeyReceived;
103         Boolean EAPOLKeyPairwise;
104         Boolean EAPOLKeyRequest;
105         Boolean MICVerified;
106         Boolean GUpdateStationKeys;
107         u8 ANonce[WPA_NONCE_LEN];
108         u8 SNonce[WPA_NONCE_LEN];
109         u8 PMK[WPA_PMK_LEN];
110         struct wpa_ptk PTK;
111         Boolean PTK_valid;
112         Boolean pairwise_set;
113         int keycount;
114         Boolean Pair;
115         u8 key_replay_counter[WPA_REPLAY_COUNTER_LEN];
116         Boolean key_replay_counter_valid;
117         Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i/D8 */
118         Boolean PTKRequest; /* not in IEEE 802.11i state machine */
119         Boolean has_GTK;
120
121         u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
122         size_t last_rx_eapol_key_len;
123
124         Boolean changed;
125 };
126
127 /* per authenticator data */
128 struct wpa_authenticator {
129         Boolean GInit;
130         int GNoStations;
131         int GKeyDoneStations;
132         Boolean GTKReKey;
133         int GTK_len;
134         int GN, GM;
135         Boolean GTKAuthenticator;
136         u8 Counter[WPA_NONCE_LEN];
137
138         enum {
139                 WPA_GROUP_GTK_INIT = 0,
140                 WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE
141         } wpa_group_state;
142
143         u8 GMK[WPA_GMK_LEN];
144         u8 GTK[2][WPA_GTK_MAX_LEN];
145         u8 GNonce[WPA_NONCE_LEN];
146         Boolean changed;
147
148         unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
149         u8 dot11RSNAAuthenticationSuiteSelected[4];
150         u8 dot11RSNAPairwiseCipherSelected[4];
151         u8 dot11RSNAGroupCipherSelected[4];
152         u8 dot11RSNAPMKIDUsed[PMKID_LEN];
153         u8 dot11RSNAAuthenticationSuiteRequested[4]; /* FIX: update */
154         u8 dot11RSNAPairwiseCipherRequested[4]; /* FIX: update */
155         u8 dot11RSNAGroupCipherRequested[4]; /* FIX: update */
156         unsigned int dot11RSNATKIPCounterMeasuresInvoked;
157         unsigned int dot11RSNA4WayHandshakeFailures;
158 };
159
160
161 int wpa_init(struct hostapd_data *hapd);
162 void wpa_deinit(struct hostapd_data *hapd);
163
164 enum {
165         WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
166         WPA_INVALID_AKMP
167 };
168         
169 int wpa_validate_wpa_ie(struct hostapd_data *hapd, struct sta_info *sta,
170                         u8 *wpa_ie, size_t wpa_ie_len, int version);
171 void wpa_new_station(struct hostapd_data *hapd, struct sta_info *sta);
172 void wpa_free_station(struct sta_info *sta);
173 void wpa_receive(struct hostapd_data *hapd, struct sta_info *sta,
174                  u8 *data, size_t data_len);
175 typedef enum {
176         WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
177         WPA_REAUTH_EAPOL
178 } wpa_event;
179 void wpa_sm_event(struct hostapd_data *hapd, struct sta_info *sta,
180                   wpa_event event);
181 void wpa_sm_notify(struct hostapd_data *hapd, struct sta_info *sta);
182 void pmksa_cache_add(struct hostapd_data *hapd, struct sta_info *sta, u8 *pmk,
183                      int session_timeout);
184 void rsn_preauth_finished(struct hostapd_data *hapd, struct sta_info *sta,
185                           int success);
186 void rsn_preauth_send(struct hostapd_data *hapd, struct sta_info *sta,
187                       u8 *buf, size_t len);
188 void wpa_gtk_rekey(struct hostapd_data *hapd);
189 int wpa_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen);
190 int wpa_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
191                     char *buf, size_t buflen);
192
193 #endif /* WPA_H */