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