2 * bcmwpa.h - interface definitions of shared WPA-related functions
4 * Copyright (C) 2010, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: bcmwpa.h,v 13.44.12.7 2010-11-30 06:26:15 Exp $
18 #include <proto/wpa.h>
19 #if defined(BCMSUP_PSK) || defined(BCMSUPPL) || defined(MFP)
20 #include <proto/eapol.h>
22 #include <proto/802.11.h>
24 #include <proto/p2p.h>
26 #include <bcmcrypto/rc4.h>
29 /* Field sizes for WPA key hierarchy */
30 #define WPA_MIC_KEY_LEN 16
31 #define WPA_ENCR_KEY_LEN 16
32 #define WPA_TEMP_ENCR_KEY_LEN 16
33 #define WPA_TEMP_TX_KEY_LEN 8
34 #define WPA_TEMP_RX_KEY_LEN 8
37 #if defined(BCMEXTCCX)
38 #define WEP128_PTK_LEN 48
39 #define WEP128_TK_LEN 13
40 #define WEP1_PTK_LEN 48
42 #define CKIP_PTK_LEN 48
43 #define CKIP_TK_LEN 16
45 #define TKIP_PTK_LEN 64
46 #define TKIP_TK_LEN 32
47 #define AES_PTK_LEN 48
50 /* limits for pre-shared key lengths */
51 #define WPA_MIN_PSK_LEN 8
52 #define WPA_MAX_PSK_LEN 64
54 #define WPA_KEY_DATA_LEN_256 256 /* allocation size of 256 for temp data pointer. */
55 #define WPA_KEY_DATA_LEN_128 128 /* allocation size of 128 for temp data pointer. */
57 #define WLC_SW_KEYS(wlc, bsscfg) ((((wlc)->wsec_swkeys) || \
58 ((bsscfg)->wsec & WSEC_SWFLAG)))
61 #define WSEC_WEP_ENABLED(wsec) ((wsec) & WEP_ENABLED)
62 #define WSEC_TKIP_ENABLED(wsec) ((wsec) & TKIP_ENABLED)
63 #define WSEC_AES_ENABLED(wsec) ((wsec) & AES_ENABLED)
65 #define WSEC_ENABLED(wsec) ((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED | SMS4_ENABLED))
66 #else /* BCMWAPI_WPI */
67 #define WSEC_ENABLED(wsec) ((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))
68 #endif /* BCMWAPI_WPI */
69 #define WSEC_SES_OW_ENABLED(wsec) ((wsec) & SES_OW_ENABLED)
70 #define IS_WPA_AUTH(auth) ((auth) == WPA_AUTH_NONE || \
71 (auth) == WPA_AUTH_UNSPECIFIED || \
72 (auth) == WPA_AUTH_PSK)
73 #define INCLUDES_WPA_AUTH(auth) \
74 ((auth) & (WPA_AUTH_NONE | WPA_AUTH_UNSPECIFIED | WPA_AUTH_PSK))
76 #if defined(BCMEXTCCX)
77 #define IS_WPA2_AUTH(auth) ((auth) == WPA2_AUTH_UNSPECIFIED || \
78 (auth) == WPA2_AUTH_PSK || \
79 (auth) == WPA2_AUTH_CCKM || \
80 (auth) == BRCM_AUTH_PSK || \
81 (auth) == BRCM_AUTH_DPT)
82 #define INCLUDES_WPA2_AUTH(auth) \
83 ((auth) & (WPA2_AUTH_UNSPECIFIED | \
89 #define IS_WPA2_AUTH(auth) ((auth) == WPA2_AUTH_UNSPECIFIED || \
90 (auth) == WPA2_AUTH_PSK || \
91 (auth) == BRCM_AUTH_PSK || \
92 (auth) == BRCM_AUTH_DPT)
93 #define INCLUDES_WPA2_AUTH(auth) \
94 ((auth) & (WPA2_AUTH_UNSPECIFIED | \
101 #if defined(BCMEXTCCX)
102 #define IS_CCKM_AUTH(auth) ((auth) == WPA_AUTH_CCKM || (auth) == WPA2_AUTH_CCKM)
103 #define INCLUDES_CCKM_AUTH(auth) ((auth) & (WPA_AUTH_CCKM | WPA2_AUTH_CCKM))
106 #define IS_WPA_AKM(akm) ((akm) == RSN_AKM_NONE || \
107 (akm) == RSN_AKM_UNSPECIFIED || \
108 (akm) == RSN_AKM_PSK)
109 #define IS_WPA2_AKM(akm) ((akm) == RSN_AKM_UNSPECIFIED || \
110 (akm) == RSN_AKM_PSK)
111 #define IS_FBT_AKM(akm) ((akm) == RSN_AKM_FBT_1X || \
112 (akm) == RSN_AKM_FBT_PSK)
113 #define IS_MFP_AKM(akm) ((akm) == RSN_AKM_MFP_1X || \
114 (akm) == RSN_AKM_MFP_PSK)
116 /* Broadcom(OUI) authenticated key managment suite */
117 #define BRCM_AKM_NONE 0
118 #define BRCM_AKM_PSK 1 /* Proprietary PSK AKM */
119 #define BRCM_AKM_DPT 2 /* Proprietary DPT PSK AKM */
121 #define IS_BRCM_AKM(akm) ((akm) == BRCM_AKM_PSK)
126 /* convert wsec to WPA mcast cipher. algo is needed only when WEP is enabled. */
127 #define WPA_MCAST_CIPHER(wsec, algo) (WSEC_WEP_ENABLED(wsec) ? \
128 ((algo) == CRYPTO_ALGO_WEP128 ? WPA_CIPHER_WEP_104 : WPA_CIPHER_WEP_40) : \
129 WSEC_TKIP_ENABLED(wsec) ? WPA_CIPHER_TKIP : \
130 WSEC_AES_ENABLED(wsec) ? WPA_CIPHER_AES_CCM : \
133 #define WPS_ATID_SEL_REGISTRAR 0x1041
135 #define WPS_IE_FIXED_LEN 6
137 /* WiFi WPS Attribute fixed portion */
138 typedef struct wps_at_fixed
{
144 #define WPS_AT_FIXED_LEN 4
146 #define wps_ie_fixed_t wpa_ie_fixed_t
148 /* Return address of max or min array depending first argument.
149 * Return NULL in case of a draw.
151 extern uint8
*BCMROMFN(wpa_array_cmp
)(int max_array
, uint8
*x
, uint8
*y
, uint len
);
153 /* Increment the array argument */
154 extern void BCMROMFN(wpa_incr_array
)(uint8
*array
, uint len
);
156 /* Convert WPA IE cipher suite to locally used value */
157 extern bool BCMROMFN(wpa_cipher
)(wpa_suite_t
*suite
, ushort
*cipher
, bool wep_ok
);
159 /* Look for a WPA IE; return it's address if found, NULL otherwise */
160 extern wpa_ie_fixed_t
*BCMROMFN(bcm_find_wpaie
)(uint8
*parse
, uint len
);
161 extern wme_ie_t
*bcm_find_wmeie(uint8
*parse
, uint len
, uint8 subtype
, uint8 subtype_len
);
162 /* Look for a WPS IE; return it's address if found, NULL otherwise */
163 extern wps_ie_fixed_t
*bcm_find_wpsie(uint8
*parse
, uint len
);
164 extern wps_at_fixed_t
*bcm_wps_find_at(wps_at_fixed_t
*at
, int len
, uint16 id
);
166 /* Look for a WiFi P2P IE; return it's address if found, NULL otherwise */
167 extern wifi_p2p_ie_t
*bcm_find_p2pie(uint8
*parse
, uint len
);
170 /* Check whether the given IE has the specific OUI and the specific type. */
171 extern bool bcm_has_ie(uint8
*ie
, uint8
**tlvs
, uint
*tlvs_len
,
172 const uint8
*oui
, int oui_len
, uint8 type
);
174 /* Check whether pointed-to IE looks like WPA. */
175 #define bcm_is_wpa_ie(ie, tlvs, len) bcm_has_ie(ie, tlvs, len, \
176 (const uint8 *)WPA_OUI, WPA_OUI_LEN, WPA_OUI_TYPE)
177 /* Check whether pointed-to IE looks like WME. */
178 #define bcm_is_wme_ie(ie, tlvs, len) bcm_has_ie(ie, tlvs, len, \
179 (const uint8 *)WME_OUI, WME_OUI_LEN, WME_OUI_TYPE)
180 /* Check whether pointed-to IE looks like WPS. */
181 #define bcm_is_wps_ie(ie, tlvs, len) bcm_has_ie(ie, tlvs, len, \
182 (const uint8 *)WPS_OUI, WPS_OUI_LEN, WPS_OUI_TYPE)
184 /* Check whether the given IE looks like WFA P2P IE. */
185 #define bcm_is_p2p_ie(ie, tlvs, len) bcm_has_ie(ie, tlvs, len, \
186 (const uint8 *)WFA_OUI, WFA_OUI_LEN, WFA_OUI_TYPE_P2P)
189 /* Convert WPA2 IE cipher suite to locally used value */
190 extern bool BCMROMFN(wpa2_cipher
)(wpa_suite_t
*suite
, ushort
*cipher
, bool wep_ok
);
192 #if defined(BCMSUP_PSK) || defined(BCMSUPPL)
193 /* Look for an encapsulated GTK; return it's address if found, NULL otherwise */
194 extern eapol_wpa2_encap_data_t
*BCMROMFN(wpa_find_gtk_encap
)(uint8
*parse
, uint len
);
196 /* Check whether pointed-to IE looks like an encapsulated GTK. */
197 extern bool BCMROMFN(wpa_is_gtk_encap
)(uint8
*ie
, uint8
**tlvs
, uint
*tlvs_len
);
199 /* Look for encapsulated key data; return it's address if found, NULL otherwise */
200 extern eapol_wpa2_encap_data_t
*BCMROMFN(wpa_find_kde
)(uint8
*parse
, uint len
, uint8 type
);
201 #endif /* defined(BCMSUP_PSK) || defined(BCMSUPPL) */
204 extern eapol_wpa2_encap_data_t
*BCMROMFN(wpa_find_igtk_encap
)(uint8
*parse
, uint len
);
208 /* Calculate a pair-wise transient key */
209 extern void BCMROMFN(wpa_calc_ptk
)(struct ether_addr
*auth_ea
, struct ether_addr
*sta_ea
,
210 uint8
*anonce
, uint8
* snonce
, uint8
*pmk
, uint pmk_len
,
211 uint8
*ptk
, uint ptk_len
);
213 /* Compute Message Integrity Code (MIC) over EAPOL message */
214 extern bool BCMROMFN(wpa_make_mic
)(eapol_header_t
*eapol
, uint key_desc
, uint8
*mic_key
,
217 /* Check MIC of EAPOL message */
218 extern bool BCMROMFN(wpa_check_mic
)(eapol_header_t
*eapol
, uint key_desc
, uint8
*mic_key
);
220 /* Calculate PMKID */
221 extern void BCMROMFN(wpa_calc_pmkid
)(struct ether_addr
*auth_ea
, struct ether_addr
*sta_ea
,
222 uint8
*pmk
, uint pmk_len
, uint8
*pmkid
, uint8
*data
, uint8
*digest
);
224 /* Calculate PMKR0 for FT association */
225 extern void wpa_calc_pmkR0(uchar
*ssid
, int ssid_len
, uint16 mdid
, uint8
*r0kh
,
226 uint r0kh_len
, struct ether_addr
*sta_ea
,
227 uint8
*pmk
, uint pmk_len
, uint8
*pmkid
, uint8
*pmkr0name
);
229 /* Calculate PMKR1 for FT association */
230 extern void wpa_calc_pmkR1(struct ether_addr
*r1kh
, struct ether_addr
*sta_ea
,
231 uint8
*pmk
, uint pmk_len
, uint8
*pmkr0name
, uint8
*pmkid
, uint8
*pmkr1name
);
233 /* Calculate PTK for FT association */
234 extern void wpa_calc_ft_ptk(struct ether_addr
*bssid
, struct ether_addr
*sta_ea
,
235 uint8
*anonce
, uint8
* snonce
, uint8
*pmk
, uint pmk_len
,
236 uint8
*ptk
, uint ptk_len
);
238 /* Encrypt key data for a WPA key message */
239 extern bool wpa_encr_key_data(eapol_wpa_key_header_t
*body
, uint16 key_info
,
240 uint8
*ekey
, uint8
*gtk
, uint8
*data
, uint8
*encrkey
, rc4_ks_t
*rc4key
);
242 /* Decrypt key data from a WPA key message */
243 extern bool BCMROMFN(wpa_decr_key_data
)(eapol_wpa_key_header_t
*body
, uint16 key_info
,
244 uint8
*ekey
, uint8
*gtk
, uint8
*data
, uint8
*encrkey
, rc4_ks_t
*rc4key
);
246 /* Decrypt a group transient key from a WPA key message */
247 extern bool BCMROMFN(wpa_decr_gtk
)(eapol_wpa_key_header_t
*body
, uint16 key_info
,
248 uint8
*ekey
, uint8
*gtk
, uint8
*data
, uint8
*encrkey
, rc4_ks_t
*rc4key
);
249 #endif /* BCMSUP_PSK */
251 extern bool BCMROMFN(bcmwpa_akm2WPAauth
)(uint8
*akm
, uint32
*auth
, bool sta_iswpa
);
253 extern bool BCMROMFN(bcmwpa_cipher2wsec
)(uint8
*cipher
, uint32
*wsec
);
255 #if defined(MFP) || defined(WLFBT)
256 /* Calculate PMKID */
257 extern void kdf_calc_pmkid(struct ether_addr
*auth_ea
, struct ether_addr
*sta_ea
,
258 uint8
*pmk
, uint pmk_len
, uint8
*pmkid
, uint8
*data
, uint8
*digest
);
259 extern void kdf_calc_ptk(struct ether_addr
*auth_ea
, struct ether_addr
*sta_ea
,
260 uint8
*anonce
, uint8
* snonce
, uint8
*pmk
, uint pmk_len
,
261 uint8
*ptk
, uint ptk_len
);
264 #endif /* _BCMWPA_H_ */