1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
7 #ifndef __RTW_SECURITY_H_
8 #define __RTW_SECURITY_H_
10 #include <osdep_service.h>
11 #include <drv_types.h>
13 #define _NO_PRIVACY_ 0x0
16 #define _TKIP_WTMIC_ 0x3
19 #define _WEP_WPA_MIXED_ 0x07 /* WEP + WPA */
22 #define is_wep_enc(alg) (((alg) == _WEP40_) || ((alg) == _WEP104_))
24 #define _WPA_IE_ID_ 0xdd
25 #define _WPA2_IE_ID_ 0x30
27 #define SHA256_MAC_LEN 32
28 #define AES_BLOCK_SIZE 16
29 #define AES_PRIV_SIZE (4 * 44)
32 ENCRYP_PROTOCOL_OPENSYS, /* open system */
33 ENCRYP_PROTOCOL_WEP, /* WEP */
34 ENCRYP_PROTOCOL_WPA, /* WPA */
35 ENCRYP_PROTOCOL_WPA2, /* WPA2 */
36 ENCRYP_PROTOCOL_WAPI, /* WAPI: Not support in this version */
40 #ifndef Ndis802_11AuthModeWPA2
41 #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
44 #ifndef Ndis802_11AuthModeWPA2PSK
45 #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
51 #ifdef __LITTLE_ENDIAN
63 #elif defined(__BIG_ENDIAN)
83 struct rt_pmkid_list {
92 struct security_priv {
93 u32 dot11AuthAlgrthm; /* 802.11 auth, could be open,
94 * shared, 8021x and authswitch
96 u32 dot11PrivacyAlgrthm; /* This specify the privacy for
97 * shared auth. algorithm.
100 u32 dot11PrivacyKeyIndex; /* this is only valid for legendary
101 * wep, 0~3 for key id.(tx key index)
103 union Keytype dot11DefKey[4]; /* this is only valid for def. key */
104 u32 dot11DefKeylen[4];
105 u32 dot118021XGrpPrivacy; /* This specify the privacy algthm.
108 u32 dot118021XGrpKeyid; /* key id used for Grp Key
111 union Keytype dot118021XGrpKey[4]; /* 802.1x Group Key,
114 union Keytype dot118021XGrptxmickey[4];
115 union Keytype dot118021XGrprxmickey[4];
116 union pn48 dot11Grptxpn; /* PN48 used for Grp Key xmit.*/
117 union pn48 dot11Grprxpn; /* PN48 used for Grp Key recv.*/
118 #ifdef CONFIG_88EU_AP_MODE
119 /* extend security capabilities for AP_MODE */
120 unsigned int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
121 unsigned int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
122 unsigned int wpa_group_cipher;
123 unsigned int wpa2_group_cipher;
124 unsigned int wpa_pairwise_cipher;
125 unsigned int wpa2_pairwise_cipher;
127 u8 wps_ie[MAX_WPS_IE_LEN];/* added in assoc req */
132 u8 bgrpkey_handshake;
133 s32 hw_decrypted;/* if the rx packets is hw_decrypted==false,i
134 * it means the hw has not been ready.
137 /* keeps the auth_type & enc_status from upper layer
138 * ioctl(wpa_supplicant or wzc)
140 u32 ndisauthtype; /* NDIS_802_11_AUTHENTICATION_MODE */
141 u32 ndisencryptstatus; /* NDIS_802_11_ENCRYPTION_STATUS */
142 struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
143 struct ndis_802_11_wep ndiswep;
145 u8 szofcapability[256]; /* for wpa2 usage */
146 u8 oidassociation[512]; /* for wpa/wpa2 usage */
147 u8 authenticator_ie[256]; /* store ap security information element */
148 u8 supplicant_ie[256]; /* store sta security information element */
150 /* for tkip countermeasure */
151 u32 last_mic_err_time;
152 u8 btkip_countermeasure;
153 u8 btkip_wait_report;
154 u32 btkip_countermeasure_time;
157 /* For WPA2 Pre-Authentication. */
159 struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
161 u8 bWepDefaultKeyIdxSet;
164 #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
166 switch (psecuritypriv->dot11AuthAlgrthm) { \
167 case dot11AuthAlgrthm_Open: \
168 case dot11AuthAlgrthm_Shared: \
169 case dot11AuthAlgrthm_Auto: \
170 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
172 case dot11AuthAlgrthm_8021X: \
174 encry_algo = (u8)psecuritypriv->dot118021XGrpPrivacy;\
176 encry_algo = (u8)psta->dot118021XPrivacy; \
178 case dot11AuthAlgrthm_WAPI: \
179 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
184 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt) \
211 #define GET_TKIP_PN(iv, dot11txpn) \
213 dot11txpn._byte_.TSC0 = iv[2]; \
214 dot11txpn._byte_.TSC1 = iv[0]; \
215 dot11txpn._byte_.TSC2 = iv[4]; \
216 dot11txpn._byte_.TSC3 = iv[5]; \
217 dot11txpn._byte_.TSC4 = iv[6]; \
218 dot11txpn._byte_.TSC5 = iv[7]; \
221 #define ROL32(A, n) (((A) << (n)) | (((A) >> (32 - (n))) & ((1UL << (n)) - 1)))
222 #define ROR32(A, n) ROL32((A), 32 - (n))
225 u32 K0, K1; /* Key */
226 u32 L, R; /* Current state */
227 u32 M; /* Message accumulator (single word) */
228 u32 nBytesInM; /* # bytes in M */
231 void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key);
232 void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b);
233 void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
234 void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst);
235 void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len,
236 u8 *Miccode, u8 priority);
237 u32 rtw_aes_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
238 u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
239 void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
240 u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
241 u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
242 int rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
244 #endif /* __RTL871X_SECURITY_H_ */