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
12 * See README and COPYING for more details.
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
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
{
33 u8 replay_counter
[WPA_REPLAY_COUNTER_LEN
];
34 u8 key_nonce
[WPA_NONCE_LEN
];
36 u8 key_rsc
[WPA_KEY_RSC_LEN
];
37 u8 key_id
[8]; /* Reserved */
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 */
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) */
68 u8 tk2
[16]; /* Temporal Key 2 (TK2) */
74 } __attribute__ ((packed
));
76 struct wpa_authenticator
;
77 struct wpa_state_machine
;
78 struct rsn_pmksa_cache_entry
;
81 struct wpa_auth_config
{
93 #ifdef CONFIG_IEEE80211W
95 WPA_NO_IEEE80211W
= 0,
96 WPA_IEEE80211W_OPTIONAL
= 1,
97 WPA_IEEE80211W_REQUIRED
= 2
99 #endif /* CONFIG_IEEE80211W */
103 LOGGER_DEBUG
, LOGGER_INFO
, LOGGER_WARNING
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
{
114 void (*logger
)(void *ctx
, const u8
*addr
, logger_level level
,
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
,
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
);
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
);
158 WPA_AUTH
, WPA_ASSOC
, WPA_DISASSOC
, WPA_DEAUTH
, WPA_REAUTH
,
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
,
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
,
183 struct eapol_state_machine
*eapol
);
184 int wpa_auth_sta_set_vlan(struct wpa_state_machine
*sm
, int vlan_id
);