00001
00016 #ifndef WPA_COMMON_H
00017 #define WPA_COMMON_H
00018
00019 #define WPA_MAX_SSID_LEN 32
00020
00021
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
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
00072
00073
00074
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
00088 #ifdef CONFIG_IEEE80211W
00089 #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
00090 #endif
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
00106
00107 #ifdef CONFIG_IEEE80211W
00108 #define WPA_IGTK_LEN 16
00109 #endif
00110
00111
00112
00113 #define WPA_CAPABILITY_PREAUTH BIT(0)
00114 #define WPA_CAPABILITY_NO_PAIRWISE BIT(1)
00115
00116
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
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
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)
00135
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)
00139 #define WPA_KEY_INFO_TXRX BIT(6)
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)
00146 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
00147
00148
00149 struct wpa_eapol_key {
00150 u8 type;
00151
00152 u8 key_info[2];
00153 u8 key_length[2];
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];
00159 u8 key_mic[16];
00160 u8 key_data_length[2];
00161
00162 } STRUCT_PACKED;
00163
00169 struct wpa_ptk {
00170 u8 kck[16];
00171 u8 kek[16];
00172 u8 tk1[16];
00173 union {
00174 u8 tk2[16];
00175 struct {
00176 u8 tx_mic_key[8];
00177 u8 rx_mic_key[8];
00178 } auth;
00179 } u;
00180 } STRUCT_PACKED;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 struct wpa_ie_hdr {
00198 u8 elem_id;
00199 u8 len;
00200 u8 oui[4];
00201 u8 version[2];
00202 } STRUCT_PACKED;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 struct rsn_ie_hdr {
00230 u8 elem_id;
00231 u8 len;
00232 u8 version[2];
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
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
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
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
00294
00295 #ifdef _MSC_VER
00296 #pragma pack(pop)
00297 #endif
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
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
00350