1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
4 #ifndef __RTW_SECURITY_H_
5 #define __RTW_SECURITY_H_
7 #include "osdep_service.h"
9 #include <crypto/arc4.h>
11 #define _NO_PRIVACY_ 0x0
14 #define _TKIP_WTMIC_ 0x3
19 #define _WPA_IE_ID_ 0xdd
20 #define _WPA2_IE_ID_ 0x30
23 ENCRYP_PROTOCOL_OPENSYS, /* open system */
24 ENCRYP_PROTOCOL_WEP, /* WEP */
25 ENCRYP_PROTOCOL_WPA, /* WPA */
26 ENCRYP_PROTOCOL_WPA2, /* WPA2 */
27 ENCRYP_PROTOCOL_WAPI, /* WAPI: Not support in this version */
31 #ifndef Ndis802_11AuthModeWPA2
32 #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
35 #ifndef Ndis802_11AuthModeWPA2PSK
36 #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
42 #ifdef __LITTLE_ENDIAN
54 #elif defined(__BIG_ENDIAN)
74 struct rt_pmkid_list {
83 struct security_priv {
84 u32 dot11AuthAlgrthm; /* 802.11 auth, could be open,
85 * shared, 8021x and authswitch */
86 u32 dot11PrivacyAlgrthm; /* This specify the privacy for
87 * shared auth. algorithm. */
89 u32 dot11PrivacyKeyIndex; /* this is only valid for legendary
90 * wep, 0~3 for key id.(tx key index) */
91 union Keytype dot11DefKey[4]; /* this is only valid for def. key */
92 u32 dot11DefKeylen[4];
93 u32 dot118021XGrpPrivacy; /* This specify the privacy algthm.
95 u32 dot118021XGrpKeyid; /* key id used for Grp Key
97 union Keytype dot118021XGrpKey[4]; /* 802.1x Group Key,
98 * for inx0 and inx1 */
99 union Keytype dot118021XGrptxmickey[4];
100 union Keytype dot118021XGrprxmickey[4];
101 union pn48 dot11Grptxpn; /* PN48 used for Grp Key xmit.*/
102 union pn48 dot11Grprxpn; /* PN48 used for Grp Key recv.*/
104 struct arc4_ctx xmit_arc4_ctx;
105 struct arc4_ctx recv_arc4_ctx;
107 /* extend security capabilities for AP_MODE */
108 unsigned int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
109 unsigned int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
110 unsigned int wpa_group_cipher;
111 unsigned int wpa2_group_cipher;
112 unsigned int wpa_pairwise_cipher;
113 unsigned int wpa2_pairwise_cipher;
114 u8 wps_ie[MAX_WPS_IE_LEN];/* added in assoc req */
119 u8 bgrpkey_handshake;
120 s32 sw_encrypt;/* from registry_priv */
121 s32 sw_decrypt;/* from registry_priv */
122 s32 hw_decrypted;/* if the rx packets is hw_decrypted==false,i
123 * it means the hw has not been ready. */
125 /* keeps the auth_type & enc_status from upper layer
126 * ioctl(wpa_supplicant or wzc) */
127 u32 ndisauthtype; /* NDIS_802_11_AUTHENTICATION_MODE */
128 u32 ndisencryptstatus; /* NDIS_802_11_ENCRYPTION_STATUS */
129 struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
130 struct ndis_802_11_wep ndiswep;
132 u8 szofcapability[256]; /* for wpa2 usage */
133 u8 oidassociation[512]; /* for wpa/wpa2 usage */
134 u8 authenticator_ie[256]; /* store ap security information element */
135 u8 supplicant_ie[256]; /* store sta security information element */
137 /* for tkip countermeasure */
138 u32 last_mic_err_time;
139 u8 btkip_countermeasure;
140 u8 btkip_wait_report;
141 u32 btkip_countermeasure_time;
144 /* For WPA2 Pre-Authentication. */
146 struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
148 u8 bWepDefaultKeyIdxSet;
151 #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
153 switch (psecuritypriv->dot11AuthAlgrthm) { \
154 case dot11AuthAlgrthm_Open: \
155 case dot11AuthAlgrthm_Shared: \
156 case dot11AuthAlgrthm_Auto: \
157 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
159 case dot11AuthAlgrthm_8021X: \
161 encry_algo = (u8)psecuritypriv->dot118021XGrpPrivacy;\
163 encry_algo = (u8)psta->dot118021XPrivacy; \
165 case dot11AuthAlgrthm_WAPI: \
166 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
171 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt) \
198 #define GET_TKIP_PN(iv, dot11txpn) \
200 dot11txpn._byte_.TSC0 = iv[2]; \
201 dot11txpn._byte_.TSC1 = iv[0]; \
202 dot11txpn._byte_.TSC2 = iv[4]; \
203 dot11txpn._byte_.TSC3 = iv[5]; \
204 dot11txpn._byte_.TSC4 = iv[6]; \
205 dot11txpn._byte_.TSC5 = iv[7]; \
208 #define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
209 #define ROR32(A, n) ROL32((A), 32-(n))
212 u32 K0, K1; /* Key */
213 u32 L, R; /* Current state */
214 u32 M; /* Message accumulator (single word) */
215 u32 nBytesInM; /* # bytes in M */
218 void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key);
219 void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b);
220 void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
221 void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst);
222 void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len,
223 u8 *Miccode, u8 priority);
224 u32 rtw_aes_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
225 u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
226 void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
227 u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
228 u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
229 void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
231 #endif /* __RTL871X_SECURITY_H_ */