wpa_common.h

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

Generated on Sat Nov 21 23:16:49 2009 for hostapd by  doxygen 1.6.1