wpa_auth.h revision 252726
11556Srgrimes/* 2139969Simp * hostapd - IEEE 802.11i-2004 / WPA Authenticator 3139969Simp * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi> 41556Srgrimes * 51556Srgrimes * This software may be distributed under the terms of the BSD license. 61556Srgrimes * See README for more details. 71556Srgrimes */ 81556Srgrimes 91556Srgrimes#ifndef WPA_AUTH_H 101556Srgrimes#define WPA_AUTH_H 111556Srgrimes 121556Srgrimes#include "common/defs.h" 131556Srgrimes#include "common/eapol_common.h" 141556Srgrimes#include "common/wpa_common.h" 151556Srgrimes 161556Srgrimes#ifdef _MSC_VER 171556Srgrimes#pragma pack(push, 1) 181556Srgrimes#endif /* _MSC_VER */ 191556Srgrimes 201556Srgrimes/* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition 211556Srgrimes */ 221556Srgrimesstruct ft_rrb_frame { 231556Srgrimes u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */ 241556Srgrimes u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */ 251556Srgrimes le16 action_length; /* little endian length of action_frame */ 261556Srgrimes u8 ap_address[ETH_ALEN]; 271556Srgrimes /* 281556Srgrimes * Followed by action_length bytes of FT Action frame (from Category 291556Srgrimes * field to the end of Action Frame body. 301556Srgrimes */ 311556Srgrimes} STRUCT_PACKED; 321556Srgrimes 331556Srgrimes#define RSN_REMOTE_FRAME_TYPE_FT_RRB 1 3417987Speter 3550471Speter#define FT_PACKET_REQUEST 0 361556Srgrimes#define FT_PACKET_RESPONSE 1 3769029Skris/* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */ 381556Srgrimes#define FT_PACKET_R0KH_R1KH_PULL 200 39120023Sschweikh#define FT_PACKET_R0KH_R1KH_RESP 201 401556Srgrimes#define FT_PACKET_R0KH_R1KH_PUSH 202 411556Srgrimes 4217987Speter#define FT_R0KH_R1KH_PULL_DATA_LEN 44 4317987Speter#define FT_R0KH_R1KH_RESP_DATA_LEN 76 4417987Speter#define FT_R0KH_R1KH_PUSH_DATA_LEN 88 4517987Speter 467502Sphkstruct ft_r0kh_r1kh_pull_frame { 4717987Speter u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */ 4817987Speter u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */ 491556Srgrimes le16 data_length; /* little endian length of data (44) */ 501556Srgrimes u8 ap_address[ETH_ALEN]; 511556Srgrimes 521556Srgrimes u8 nonce[16]; 531556Srgrimes u8 pmk_r0_name[WPA_PMK_NAME_LEN]; 5490832Simp u8 r1kh_id[FT_R1KH_ID_LEN]; 551556Srgrimes u8 s1kh_id[ETH_ALEN]; 561556Srgrimes u8 pad[4]; /* 8-octet boundary for AES key wrap */ 571556Srgrimes u8 key_wrap_extra[8]; 581556Srgrimes} STRUCT_PACKED; 5917987Speter 60105389Stjrstruct ft_r0kh_r1kh_resp_frame { 61149015Sstefanf u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */ 621556Srgrimes u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */ 63149015Sstefanf le16 data_length; /* little endian length of data (76) */ 641556Srgrimes u8 ap_address[ETH_ALEN]; 651556Srgrimes 661556Srgrimes u8 nonce[16]; /* copied from pull */ 671556Srgrimes u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */ 681556Srgrimes u8 s1kh_id[ETH_ALEN]; /* copied from pull */ 69157413Sstefanf u8 pmk_r1[PMK_LEN]; 70157413Sstefanf u8 pmk_r1_name[WPA_PMK_NAME_LEN]; 71157413Sstefanf le16 pairwise; 72157413Sstefanf u8 pad[2]; /* 8-octet boundary for AES key wrap */ 73157413Sstefanf u8 key_wrap_extra[8]; 74157413Sstefanf} STRUCT_PACKED; 751556Srgrimes 76157413Sstefanfstruct ft_r0kh_r1kh_push_frame { 771556Srgrimes u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */ 781556Srgrimes u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */ 7917987Speter le16 data_length; /* little endian length of data (88) */ 801556Srgrimes u8 ap_address[ETH_ALEN]; 811556Srgrimes 821556Srgrimes /* Encrypted with AES key-wrap */ 831556Srgrimes u8 timestamp[4]; /* current time in seconds since unix epoch, little 841556Srgrimes * endian */ 851556Srgrimes u8 r1kh_id[FT_R1KH_ID_LEN]; 861556Srgrimes u8 s1kh_id[ETH_ALEN]; 871556Srgrimes u8 pmk_r0_name[WPA_PMK_NAME_LEN]; 881556Srgrimes u8 pmk_r1[PMK_LEN]; 891556Srgrimes u8 pmk_r1_name[WPA_PMK_NAME_LEN]; 901556Srgrimes le16 pairwise; 911556Srgrimes u8 pad[6]; /* 8-octet boundary for AES key wrap */ 921556Srgrimes u8 key_wrap_extra[8]; 93157413Sstefanf} STRUCT_PACKED; 941556Srgrimes 951556Srgrimes#ifdef _MSC_VER 96149015Sstefanf#pragma pack(pop) 971556Srgrimes#endif /* _MSC_VER */ 981556Srgrimes 99 100/* per STA state machine data */ 101 102struct wpa_authenticator; 103struct wpa_state_machine; 104struct rsn_pmksa_cache_entry; 105struct eapol_state_machine; 106 107 108struct ft_remote_r0kh { 109 struct ft_remote_r0kh *next; 110 u8 addr[ETH_ALEN]; 111 u8 id[FT_R0KH_ID_MAX_LEN]; 112 size_t id_len; 113 u8 key[16]; 114}; 115 116 117struct ft_remote_r1kh { 118 struct ft_remote_r1kh *next; 119 u8 addr[ETH_ALEN]; 120 u8 id[FT_R1KH_ID_LEN]; 121 u8 key[16]; 122}; 123 124 125struct wpa_auth_config { 126 int wpa; 127 int wpa_key_mgmt; 128 int wpa_pairwise; 129 int wpa_group; 130 int wpa_group_rekey; 131 int wpa_strict_rekey; 132 int wpa_gmk_rekey; 133 int wpa_ptk_rekey; 134 int rsn_pairwise; 135 int rsn_preauth; 136 int eapol_version; 137 int peerkey; 138 int wmm_enabled; 139 int wmm_uapsd; 140 int disable_pmksa_caching; 141 int okc; 142 int tx_status; 143#ifdef CONFIG_IEEE80211W 144 enum mfp_options ieee80211w; 145#endif /* CONFIG_IEEE80211W */ 146#ifdef CONFIG_IEEE80211R 147#define SSID_LEN 32 148 u8 ssid[SSID_LEN]; 149 size_t ssid_len; 150 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN]; 151 u8 r0_key_holder[FT_R0KH_ID_MAX_LEN]; 152 size_t r0_key_holder_len; 153 u8 r1_key_holder[FT_R1KH_ID_LEN]; 154 u32 r0_key_lifetime; 155 u32 reassociation_deadline; 156 struct ft_remote_r0kh *r0kh_list; 157 struct ft_remote_r1kh *r1kh_list; 158 int pmk_r1_push; 159 int ft_over_ds; 160#endif /* CONFIG_IEEE80211R */ 161 int disable_gtk; 162 int ap_mlme; 163}; 164 165typedef enum { 166 LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING 167} logger_level; 168 169typedef enum { 170 WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized, 171 WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable, 172 WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx 173} wpa_eapol_variable; 174 175struct wpa_auth_callbacks { 176 void *ctx; 177 void (*logger)(void *ctx, const u8 *addr, logger_level level, 178 const char *txt); 179 void (*disconnect)(void *ctx, const u8 *addr, u16 reason); 180 int (*mic_failure_report)(void *ctx, const u8 *addr); 181 void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var, 182 int value); 183 int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var); 184 const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *prev_psk); 185 int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len); 186 int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg, 187 const u8 *addr, int idx, u8 *key, size_t key_len); 188 int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq); 189 int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data, 190 size_t data_len, int encrypt); 191 int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm, 192 void *ctx), void *cb_ctx); 193 int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a, 194 void *ctx), void *cb_ctx); 195 int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data, 196 size_t data_len); 197#ifdef CONFIG_IEEE80211R 198 struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr); 199 int (*send_ft_action)(void *ctx, const u8 *dst, 200 const u8 *data, size_t data_len); 201 int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie, 202 size_t tspec_ielen); 203#endif /* CONFIG_IEEE80211R */ 204}; 205 206struct wpa_authenticator * wpa_init(const u8 *addr, 207 struct wpa_auth_config *conf, 208 struct wpa_auth_callbacks *cb); 209int wpa_init_keys(struct wpa_authenticator *wpa_auth); 210void wpa_deinit(struct wpa_authenticator *wpa_auth); 211int wpa_reconfig(struct wpa_authenticator *wpa_auth, 212 struct wpa_auth_config *conf); 213 214enum { 215 WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE, 216 WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL, 217 WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER, 218 WPA_INVALID_MDIE, WPA_INVALID_PROTO 219}; 220 221int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth, 222 struct wpa_state_machine *sm, 223 const u8 *wpa_ie, size_t wpa_ie_len, 224 const u8 *mdie, size_t mdie_len); 225int wpa_auth_uses_mfp(struct wpa_state_machine *sm); 226struct wpa_state_machine * 227wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr); 228int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth, 229 struct wpa_state_machine *sm); 230void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm); 231void wpa_auth_sta_deinit(struct wpa_state_machine *sm); 232void wpa_receive(struct wpa_authenticator *wpa_auth, 233 struct wpa_state_machine *sm, 234 u8 *data, size_t data_len); 235typedef enum { 236 WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH, 237 WPA_REAUTH_EAPOL, WPA_ASSOC_FT 238} wpa_event; 239void wpa_remove_ptk(struct wpa_state_machine *sm); 240int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event); 241void wpa_auth_sm_notify(struct wpa_state_machine *sm); 242void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth); 243int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen); 244int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen); 245void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth); 246int wpa_auth_pairwise_set(struct wpa_state_machine *sm); 247int wpa_auth_get_pairwise(struct wpa_state_machine *sm); 248int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm); 249int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm); 250int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm, 251 struct rsn_pmksa_cache_entry *entry); 252struct rsn_pmksa_cache_entry * 253wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm); 254void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm); 255const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth, 256 size_t *len); 257int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk, 258 int session_timeout, struct eapol_state_machine *eapol); 259int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth, 260 const u8 *pmk, size_t len, const u8 *sta_addr, 261 int session_timeout, 262 struct eapol_state_machine *eapol); 263int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id); 264void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth, 265 struct wpa_state_machine *sm, int ack); 266 267#ifdef CONFIG_IEEE80211R 268u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos, 269 size_t max_len, int auth_alg, 270 const u8 *req_ies, size_t req_ies_len); 271void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid, 272 u16 auth_transaction, const u8 *ies, size_t ies_len, 273 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid, 274 u16 auth_transaction, u16 resp, 275 const u8 *ies, size_t ies_len), 276 void *ctx); 277u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies, 278 size_t ies_len); 279int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len); 280int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr, 281 const u8 *data, size_t data_len); 282void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr); 283#endif /* CONFIG_IEEE80211R */ 284 285void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm); 286void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag); 287int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos); 288int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos); 289 290int wpa_auth_uses_sae(struct wpa_state_machine *sm); 291 292#endif /* WPA_AUTH_H */ 293