2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Sun elects to license this software under the BSD license.
9 * See README for more details.
16 #include <libdllink.h>
22 #define BIT(n) (1 << (n))
24 #define WPA_CIPHER_NONE BIT(0)
25 #define WPA_CIPHER_WEP40 BIT(1)
26 #define WPA_CIPHER_WEP104 BIT(2)
27 #define WPA_CIPHER_TKIP BIT(3)
28 #define WPA_CIPHER_CCMP BIT(4)
30 #define WPA_KEY_MGMT_IEEE8021X BIT(0)
31 #define WPA_KEY_MGMT_PSK BIT(1)
32 #define WPA_KEY_MGMT_NONE BIT(2)
33 #define WPA_KEY_MGMT_IEEE8021X_NO_WPA BIT(3)
35 #define WPA_PROTO_WPA BIT(0)
36 #define WPA_PROTO_RSN BIT(1)
39 struct ieee802_1x_hdr
{
43 /* followed by length octets of data */
47 #define EAPOL_VERSION 2
49 enum { IEEE802_1X_TYPE_EAP_PACKET
= 0,
50 IEEE802_1X_TYPE_EAPOL_START
= 1,
51 IEEE802_1X_TYPE_EAPOL_LOGOFF
= 2,
52 IEEE802_1X_TYPE_EAPOL_KEY
= 3,
53 IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
= 4
56 enum { EAPOL_KEY_TYPE_RC4
= 1,
57 EAPOL_KEY_TYPE_RSN
= 2,
58 EAPOL_KEY_TYPE_WPA
= 254
61 #define WPA_NONCE_LEN 32
62 #define WPA_REPLAY_COUNTER_LEN 8
63 #define MAX_PSK_LENGTH 64
64 #define WPA_PMK_LEN 32
67 struct wpa_eapol_key
{
71 uint8_t replay_counter
[WPA_REPLAY_COUNTER_LEN
];
72 uint8_t key_nonce
[WPA_NONCE_LEN
];
75 uint8_t key_id
[8]; /* Reserved in IEEE 802.11i/RSN */
77 uint16_t key_data_length
;
78 /* followed by key_data_length bytes of key_data */
82 #define WPA_KEY_INFO_TYPE_MASK (BIT(0) | BIT(1) | BIT(2))
83 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
84 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
85 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1: Pairwise, 0: Group key */
86 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
87 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
88 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
89 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
90 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
91 #define WPA_KEY_INFO_ACK BIT(7)
92 #define WPA_KEY_INFO_MIC BIT(8)
93 #define WPA_KEY_INFO_SECURE BIT(9)
94 #define WPA_KEY_INFO_ERROR BIT(10)
95 #define WPA_KEY_INFO_REQUEST BIT(11)
96 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12) /* IEEE 802.11i/RSN only */
98 #define WPA_CAPABILITY_PREAUTH BIT(0)
100 #define GENERIC_INFO_ELEM 0xdd
101 #define RSN_INFO_ELEM 0x30
103 #define MAX_LOGBUF 4096
104 #define MAX_SCANRESULTS 64
107 REASON_UNSPECIFIED
= 1,
108 REASON_DEAUTH_LEAVING
= 3,
109 REASON_INVALID_IE
= 13,
110 REASON_MICHAEL_MIC_FAILURE
= 14,
111 REASON_4WAY_HANDSHAKE_TIMEOUT
= 15,
112 REASON_GROUP_KEY_UPDATE_TIMEOUT
= 16,
113 REASON_IE_IN_4WAY_DIFFERS
= 17,
114 REASON_GROUP_CIPHER_NOT_VALID
= 18,
115 REASON_PAIRWISE_CIPHER_NOT_VALID
= 19,
116 REASON_AKMP_NOT_VALID
= 20,
117 REASON_UNSUPPORTED_RSN_IE_VERSION
= 21,
118 REASON_INVALID_RSN_IE_CAPAB
= 22,
119 REASON_IEEE_802_1X_AUTH_FAILED
= 23,
120 REASON_CIPHER_SUITE_REJECTED
= 24
129 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
130 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
132 struct rsn_pmksa_cache
{
133 struct rsn_pmksa_cache
*next
;
134 uint8_t pmkid
[PMKID_LEN
];
135 uint8_t pmk
[PMK_LEN
];
137 int akmp
; /* WPA_KEY_MGMT_* */
138 uint8_t aa
[IEEE80211_ADDR_LEN
];
141 struct rsn_pmksa_candidate
{
142 struct rsn_pmksa_candidate
*next
;
143 uint8_t bssid
[IEEE80211_ADDR_LEN
];
149 uint8_t mic_key
[16]; /* EAPOL-Key MIC Key (MK) */
150 uint8_t encr_key
[16]; /* EAPOL-Key Encryption Key (EK) */
151 uint8_t tk1
[16]; /* Temporal Key 1 (TK1) */
153 uint8_t tk2
[16]; /* Temporal Key 2 (TK2) */
155 uint8_t tx_mic_key
[8];
156 uint8_t rx_mic_key
[8];
163 struct wpa_supplicant
{
164 struct l2_packet_data
*l2
;
165 unsigned char own_addr
[IEEE80211_ADDR_LEN
];
167 /* The handle required for libdladm calls */
168 dladm_handle_t handle
;
170 datalink_id_t linkid
;
171 char kname
[DLADM_SECOBJ_NAME_MAX
];
173 uint8_t pmk
[PMK_LEN
];
175 uint8_t snonce
[WPA_NONCE_LEN
];
176 uint8_t anonce
[WPA_NONCE_LEN
];
177 /* ANonce from the last 1/4 msg */
179 struct wpa_ptk ptk
, tptk
;
180 int ptk_set
, tptk_set
;
183 struct wpa_config
*conf
;
185 uint8_t request_counter
[WPA_REPLAY_COUNTER_LEN
];
186 uint8_t rx_replay_counter
[WPA_REPLAY_COUNTER_LEN
];
187 int rx_replay_counter_set
;
189 uint8_t bssid
[IEEE80211_ADDR_LEN
];
190 int reassociate
; /* reassociation requested */
193 size_t ap_wpa_ie_len
;
196 * Selected configuration
197 * based on Beacon/ProbeResp WPA IE
204 struct wpa_driver_ops
*driver
;
216 struct rsn_pmksa_cache
*pmksa
; /* PMKSA cache */
217 int pmksa_count
; /* number of entries in PMKSA cache */
218 struct rsn_pmksa_cache
*cur_pmksa
; /* current PMKSA entry */
219 struct rsn_pmksa_candidate
*pmksa_candidates
;
222 * number of EAPOL packets received after the
223 * previous association event
236 /* WPA configuration */
241 uint8_t bssid
[IEEE80211_ADDR_LEN
];
244 uint8_t psk
[PMK_LEN
];
248 /* Bitfields of allowed Pairwise/Group Ciphers, WPA_CIPHER_* */
253 int proto
; /* Bitfield of allowed protocols (WPA_PROTO_*) */
257 struct wpa_ssid
*ssid
; /* global network list */
262 struct wpa_config
*wpa_config_read(void *);
263 void wpa_config_free(struct wpa_config
*);
266 * Debugging function - conditional printf and hex dump.
267 * Driver wrappers can use these for debugging purposes.
269 enum { MSG_MSGDUMP
, MSG_DEBUG
, MSG_INFO
, MSG_WARNING
, MSG_ERROR
};
271 void wpa_printf(int, char *, ...);
272 void wpa_hexdump(int, const char *, const uint8_t *, size_t);
274 void wpa_event_handler(void *, wpa_event_type
);
275 void wpa_supplicant_rx_eapol(void *, unsigned char *, unsigned char *, size_t);
277 void wpa_supplicant_scan(void *, void *);
278 void wpa_supplicant_req_scan(struct wpa_supplicant
*, int, int);
280 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*, int, int);
281 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*);
282 void wpa_supplicant_disassociate(struct wpa_supplicant
*, int);
284 void pmksa_cache_free(struct wpa_supplicant
*);
285 void pmksa_candidate_free(struct wpa_supplicant
*);
286 struct rsn_pmksa_cache
*pmksa_cache_get(struct wpa_supplicant
*,
287 uint8_t *, uint8_t *);
289 int wpa_parse_wpa_ie(struct wpa_supplicant
*, uint8_t *,
290 size_t, struct wpa_ie_data
*);
291 int wpa_gen_wpa_ie(struct wpa_supplicant
*, uint8_t *);
297 #endif /* __WPA_IMPL_H */