wpa_common.h
Go to the documentation of this file.
00001 /*
00002  * WPA definitions shared between hostapd and wpa_supplicant
00003  * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #ifndef WPA_COMMON_H
00016 #define WPA_COMMON_H
00017 
00018 #define WPA_MAX_SSID_LEN 32
00019 
00020 /* IEEE 802.11i */
00021 #define PMKID_LEN 16
00022 #define PMK_LEN 32
00023 #define WPA_REPLAY_COUNTER_LEN 8
00024 #define WPA_NONCE_LEN 32
00025 #define WPA_KEY_RSC_LEN 8
00026 #define WPA_GMK_LEN 32
00027 #define WPA_GTK_MAX_LEN 32
00028 
00029 #define WPA_SELECTOR_LEN 4
00030 #define WPA_VERSION 1
00031 #define RSN_SELECTOR_LEN 4
00032 #define RSN_VERSION 1
00033 
00034 #define RSN_SELECTOR(a, b, c, d) \
00035         ((((u32) (a)) << 24) | (((u32) (b)) << 16) | (((u32) (c)) << 8) | \
00036          (u32) (d))
00037 
00038 #define WPA_AUTH_KEY_MGMT_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
00039 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
00040 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
00041 #define WPA_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
00042 #define WPA_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
00043 #define WPA_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
00044 #if 0
00045 #define WPA_CIPHER_SUITE_WRAP RSN_SELECTOR(0x00, 0x50, 0xf2, 3)
00046 #endif
00047 #define WPA_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x50, 0xf2, 4)
00048 #define WPA_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x50, 0xf2, 5)
00049 
00050 
00051 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
00052 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
00053 #ifdef CONFIG_IEEE80211R
00054 #define RSN_AUTH_KEY_MGMT_FT_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
00055 #define RSN_AUTH_KEY_MGMT_FT_PSK RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
00056 #endif /* CONFIG_IEEE80211R */
00057 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
00058 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
00059 
00060 #define RSN_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x0f, 0xac, 0)
00061 #define RSN_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
00062 #define RSN_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
00063 #if 0
00064 #define RSN_CIPHER_SUITE_WRAP RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
00065 #endif
00066 #define RSN_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
00067 #define RSN_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
00068 #ifdef CONFIG_IEEE80211W
00069 #define RSN_CIPHER_SUITE_AES_128_CMAC RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
00070 #endif /* CONFIG_IEEE80211W */
00071 
00072 /* EAPOL-Key Key Data Encapsulation
00073  * GroupKey and PeerKey require encryption, otherwise, encryption is optional.
00074  */
00075 #define RSN_KEY_DATA_GROUPKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
00076 #if 0
00077 #define RSN_KEY_DATA_STAKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
00078 #endif
00079 #define RSN_KEY_DATA_MAC_ADDR RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
00080 #define RSN_KEY_DATA_PMKID RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
00081 #ifdef CONFIG_PEERKEY
00082 #define RSN_KEY_DATA_SMK RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
00083 #define RSN_KEY_DATA_NONCE RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
00084 #define RSN_KEY_DATA_LIFETIME RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
00085 #define RSN_KEY_DATA_ERROR RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
00086 #endif /* CONFIG_PEERKEY */
00087 #ifdef CONFIG_IEEE80211W
00088 #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
00089 #endif /* CONFIG_IEEE80211W */
00090 
00091 #define WPA_OUI_TYPE RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
00092 
00093 #define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *) (a), (val))
00094 #define RSN_SELECTOR_GET(a) WPA_GET_BE32((const u8 *) (a))
00095 
00096 #define RSN_NUM_REPLAY_COUNTERS_1 0
00097 #define RSN_NUM_REPLAY_COUNTERS_2 1
00098 #define RSN_NUM_REPLAY_COUNTERS_4 2
00099 #define RSN_NUM_REPLAY_COUNTERS_16 3
00100 
00101 
00102 #ifdef _MSC_VER
00103 #pragma pack(push, 1)
00104 #endif /* _MSC_VER */
00105 
00106 #ifdef CONFIG_IEEE80211W
00107 #define WPA_IGTK_LEN 16
00108 #endif /* CONFIG_IEEE80211W */
00109 
00110 
00111 /* IEEE 802.11, 7.3.2.25.3 RSN Capabilities */
00112 #define WPA_CAPABILITY_PREAUTH BIT(0)
00113 #define WPA_CAPABILITY_NO_PAIRWISE BIT(1)
00114 /* B2-B3: PTKSA Replay Counter */
00115 /* B4-B5: GTKSA Replay Counter */
00116 #define WPA_CAPABILITY_MFPR BIT(6)
00117 #define WPA_CAPABILITY_MFPC BIT(7)
00118 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9)
00119 
00120 
00121 /* IEEE 802.11r */
00122 #define MOBILITY_DOMAIN_ID_LEN 2
00123 #define FT_R0KH_ID_MAX_LEN 48
00124 #define FT_R1KH_ID_LEN 6
00125 #define WPA_PMK_NAME_LEN 16
00126 
00127 
00128 /* IEEE 802.11, 8.5.2 EAPOL-Key frames */
00129 #define WPA_KEY_INFO_TYPE_MASK ((u16) (BIT(0) | BIT(1) | BIT(2)))
00130 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
00131 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
00132 #define WPA_KEY_INFO_TYPE_AES_128_CMAC 3
00133 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1 = Pairwise, 0 = Group key */
00134 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
00135 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
00136 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
00137 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
00138 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
00139 #define WPA_KEY_INFO_ACK BIT(7)
00140 #define WPA_KEY_INFO_MIC BIT(8)
00141 #define WPA_KEY_INFO_SECURE BIT(9)
00142 #define WPA_KEY_INFO_ERROR BIT(10)
00143 #define WPA_KEY_INFO_REQUEST BIT(11)
00144 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12) /* IEEE 802.11i/RSN only */
00145 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
00146 
00147 
00148 struct wpa_eapol_key {
00149         u8 type;
00150         /* Note: key_info, key_length, and key_data_length are unaligned */
00151         u8 key_info[2]; /* big endian */
00152         u8 key_length[2]; /* big endian */
00153         u8 replay_counter[WPA_REPLAY_COUNTER_LEN];
00154         u8 key_nonce[WPA_NONCE_LEN];
00155         u8 key_iv[16];
00156         u8 key_rsc[WPA_KEY_RSC_LEN];
00157         u8 key_id[8]; /* Reserved in IEEE 802.11i/RSN */
00158         u8 key_mic[16];
00159         u8 key_data_length[2]; /* big endian */
00160         /* followed by key_data_length bytes of key_data */
00161 } STRUCT_PACKED;
00162 
00167 struct wpa_ptk {
00168         u8 kck[16]; /* EAPOL-Key Key Confirmation Key (KCK) */
00169         u8 kek[16]; /* EAPOL-Key Key Encryption Key (KEK) */
00170         u8 tk1[16]; /* Temporal Key 1 (TK1) */
00171         union {
00172                 u8 tk2[16]; /* Temporal Key 2 (TK2) */
00173                 struct {
00174                         u8 tx_mic_key[8];
00175                         u8 rx_mic_key[8];
00176                 } auth;
00177         } u;
00178 } STRUCT_PACKED;
00179 
00180 
00181 /* WPA IE version 1
00182  * 00-50-f2:1 (OUI:OUI type)
00183  * 0x01 0x00 (version; little endian)
00184  * (all following fields are optional:)
00185  * Group Suite Selector (4 octets) (default: TKIP)
00186  * Pairwise Suite Count (2 octets, little endian) (default: 1)
00187  * Pairwise Suite List (4 * n octets) (default: TKIP)
00188  * Authenticated Key Management Suite Count (2 octets, little endian)
00189  *    (default: 1)
00190  * Authenticated Key Management Suite List (4 * n octets)
00191  *    (default: unspec 802.1X)
00192  * WPA Capabilities (2 octets, little endian) (default: 0)
00193  */
00194 
00195 struct wpa_ie_hdr {
00196         u8 elem_id;
00197         u8 len;
00198         u8 oui[4]; /* 24-bit OUI followed by 8-bit OUI type */
00199         u8 version[2]; /* little endian */
00200 } STRUCT_PACKED;
00201 
00202 
00203 /* 1/4: PMKID
00204  * 2/4: RSN IE
00205  * 3/4: one or two RSN IEs + GTK IE (encrypted)
00206  * 4/4: empty
00207  * 1/2: GTK IE (encrypted)
00208  * 2/2: empty
00209  */
00210 
00211 /* RSN IE version 1
00212  * 0x01 0x00 (version; little endian)
00213  * (all following fields are optional:)
00214  * Group Suite Selector (4 octets) (default: CCMP)
00215  * Pairwise Suite Count (2 octets, little endian) (default: 1)
00216  * Pairwise Suite List (4 * n octets) (default: CCMP)
00217  * Authenticated Key Management Suite Count (2 octets, little endian)
00218  *    (default: 1)
00219  * Authenticated Key Management Suite List (4 * n octets)
00220  *    (default: unspec 802.1X)
00221  * RSN Capabilities (2 octets, little endian) (default: 0)
00222  * PMKID Count (2 octets) (default: 0)
00223  * PMKID List (16 * n octets)
00224  * Management Group Cipher Suite (4 octets) (default: AES-128-CMAC)
00225  */
00226 
00227 struct rsn_ie_hdr {
00228         u8 elem_id; /* WLAN_EID_RSN */
00229         u8 len;
00230         u8 version[2]; /* little endian */
00231 } STRUCT_PACKED;
00232 
00233 
00234 #ifdef CONFIG_PEERKEY
00235 enum {
00236         STK_MUI_4WAY_STA_AP = 1,
00237         STK_MUI_4WAY_STAT_STA = 2,
00238         STK_MUI_GTK = 3,
00239         STK_MUI_SMK = 4
00240 };
00241 
00242 enum {
00243         STK_ERR_STA_NR = 1,
00244         STK_ERR_STA_NRSN = 2,
00245         STK_ERR_CPHR_NS = 3,
00246         STK_ERR_NO_STSL = 4
00247 };
00248 #endif /* CONFIG_PEERKEY */
00249 
00250 struct rsn_error_kde {
00251         be16 mui;
00252         be16 error_type;
00253 } STRUCT_PACKED;
00254 
00255 #ifdef CONFIG_IEEE80211W
00256 struct wpa_igtk_kde {
00257         u8 keyid[2];
00258         u8 pn[6];
00259         u8 igtk[WPA_IGTK_LEN];
00260 } STRUCT_PACKED;
00261 #endif /* CONFIG_IEEE80211W */
00262 
00263 #ifdef CONFIG_IEEE80211R
00264 struct rsn_mdie {
00265         u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
00266         u8 ft_capab;
00267 } STRUCT_PACKED;
00268 
00269 #define RSN_FT_CAPAB_FT_OVER_DS BIT(0)
00270 #define RSN_FT_CAPAB_FT_RESOURCE_REQ_SUPP BIT(1)
00271 
00272 struct rsn_ftie {
00273         u8 mic_control[2];
00274         u8 mic[16];
00275         u8 anonce[WPA_NONCE_LEN];
00276         u8 snonce[WPA_NONCE_LEN];
00277         /* followed by optional parameters */
00278 } STRUCT_PACKED;
00279 
00280 #define FTIE_SUBELEM_R1KH_ID 1
00281 #define FTIE_SUBELEM_GTK 2
00282 #define FTIE_SUBELEM_R0KH_ID 3
00283 #define FTIE_SUBELEM_IGTK 4
00284 
00285 struct rsn_rdie {
00286         u8 id;
00287         u8 descr_count;
00288         le16 status_code;
00289 } STRUCT_PACKED;
00290 
00291 #endif /* CONFIG_IEEE80211R */
00292 
00293 #ifdef _MSC_VER
00294 #pragma pack(pop)
00295 #endif /* _MSC_VER */
00296 
00297 
00298 int wpa_eapol_key_mic(const u8 *key, int ver, const u8 *buf, size_t len,
00299                       u8 *mic);
00300 void wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
00301                     const u8 *addr1, const u8 *addr2,
00302                     const u8 *nonce1, const u8 *nonce2,
00303                     u8 *ptk, size_t ptk_len, int use_sha256);
00304 
00305 #ifdef CONFIG_IEEE80211R
00306 int wpa_ft_mic(const u8 *kck, const u8 *sta_addr, const u8 *ap_addr,
00307                u8 transaction_seqnum, const u8 *mdie, size_t mdie_len,
00308                const u8 *ftie, size_t ftie_len,
00309                const u8 *rsnie, size_t rsnie_len,
00310                const u8 *ric, size_t ric_len, u8 *mic);
00311 void wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len,
00312                        const u8 *ssid, size_t ssid_len,
00313                        const u8 *mdid, const u8 *r0kh_id, size_t r0kh_id_len,
00314                        const u8 *s0kh_id, u8 *pmk_r0, u8 *pmk_r0_name);
00315 void wpa_derive_pmk_r1_name(const u8 *pmk_r0_name, const u8 *r1kh_id,
00316                             const u8 *s1kh_id, u8 *pmk_r1_name);
00317 void wpa_derive_pmk_r1(const u8 *pmk_r0, const u8 *pmk_r0_name,
00318                        const u8 *r1kh_id, const u8 *s1kh_id,
00319                        u8 *pmk_r1, u8 *pmk_r1_name);
00320 void wpa_pmk_r1_to_ptk(const u8 *pmk_r1, const u8 *snonce, const u8 *anonce,
00321                        const u8 *sta_addr, const u8 *bssid,
00322                        const u8 *pmk_r1_name,
00323                        u8 *ptk, size_t ptk_len, u8 *ptk_name);
00324 #endif /* CONFIG_IEEE80211R */
00325 
00326 struct wpa_ie_data {
00327         int proto;
00328         int pairwise_cipher;
00329         int group_cipher;
00330         int key_mgmt;
00331         int capabilities;
00332         size_t num_pmkid;
00333         const u8 *pmkid;
00334         int mgmt_group_cipher;
00335 };
00336 
00337 
00338 int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
00339                          struct wpa_ie_data *data);
00340 
00341 void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
00342                u8 *pmkid, int use_sha256);
00343 
00344 const char * wpa_cipher_txt(int cipher);
00345 const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
00346 int wpa_compare_rsn_ie(int ft_initial_assoc,
00347                        const u8 *ie1, size_t ie1len,
00348                        const u8 *ie2, size_t ie2len);
00349 int wpa_insert_pmkid(u8 *ies, size_t ies_len, const u8 *pmkid);
00350 
00351 #endif /* WPA_COMMON_H */


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:36