1 /******************************************************************************
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
25 ******************************************************************************/
26 #ifndef __RTL871X_SECURITY_H_
27 #define __RTL871X_SECURITY_H_
29 #include "osdep_service.h"
30 #include "drv_types.h"
32 #define _NO_PRIVACY_ 0x0
35 #define _TKIP_WTMIC_ 0x3
39 #define _WPA_IE_ID_ 0xdd
40 #define _WPA2_IE_ID_ 0x30
42 #ifndef Ndis802_11AuthModeWPA2
43 #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
46 #ifndef Ndis802_11AuthModeWPA2PSK
47 #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
52 #if defined(__BIG_ENDIAN)
82 struct RT_PMKID_LIST {
91 struct security_priv {
92 u32 AuthAlgrthm; /* 802.11 auth, could be open, shared,
93 * 8021x and authswitch
95 u32 PrivacyAlgrthm; /* This specify the privacy for shared
98 u32 PrivacyKeyIndex; /* this is only valid for legendary
99 * wep, 0~3 for key id.
101 union Keytype DefKey[4]; /* this is only valid for def. key */
103 u32 XGrpPrivacy; /* This specify the privacy algthm.
106 u32 XGrpKeyid; /* key id used for Grp Key */
107 union Keytype XGrpKey[2]; /* 802.1x Group Key, for
110 union Keytype XGrptxmickey[2];
111 union Keytype XGrprxmickey[2];
112 union pn48 Grptxpn; /* PN48 used for Grp Key xmit. */
113 union pn48 Grprxpn; /* PN48 used for Grp Key recv. */
114 u8 wps_hw_pbc_pressed;/*for hw pbc pressed*/
115 u8 wps_phase;/*for wps*/
116 u8 wps_ie[MAX_WPA_IE_LEN<<2];
120 struct timer_list tkip_timer;
122 u8 bgrpkey_handshake;
123 s32 sw_encrypt; /* from registry_priv */
124 s32 sw_decrypt; /* from registry_priv */
125 s32 hw_decrypted; /* if the rx packets is hw_decrypted==false,
126 * it means the hw has not been ready.
128 u32 ndisauthtype; /* keeps the auth_type & enc_status from upper
129 * layer ioctl(wpa_supplicant or wzc)
131 u32 ndisencryptstatus;
132 struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
133 struct NDIS_802_11_WEP ndiswep;
135 u8 szofcapability[256]; /* for wpa2 usage */
136 u8 oidassociation[512]; /* for wpa/wpa2 usage */
137 u8 authenticator_ie[256]; /* store ap security information element */
138 u8 supplicant_ie[256]; /* store sta security information element */
139 /* for tkip countermeasure */
140 u32 last_mic_err_time;
141 u8 btkip_countermeasure;
142 u8 btkip_wait_report;
143 u32 btkip_countermeasure_time;
144 /*-------------------------------------------------------------------
145 * For WPA2 Pre-Authentication.
146 *------------------------------------------------------------------
148 struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
152 #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
154 switch (psecuritypriv->AuthAlgrthm) { \
158 encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
162 encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
164 encry_algo = (u8)psta->XPrivacy; \
168 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
190 #define GET_TKIP_PN(iv, txpn) \
192 txpn._byte_.TSC0 = iv[2];\
193 txpn._byte_.TSC1 = iv[0];\
194 txpn._byte_.TSC2 = iv[4];\
195 txpn._byte_.TSC3 = iv[5];\
196 txpn._byte_.TSC4 = iv[6];\
197 txpn._byte_.TSC5 = iv[7];\
200 #define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
201 #define ROR32(A, n) ROL32((A), 32 - (n))
204 u32 K0, K1; /* Key */
205 u32 L, R; /* Current state */
206 u32 M; /* Message accumulator (single word) */
207 u32 nBytesInM; /* # bytes in M */
218 void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
219 void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
220 void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
221 u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
222 u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
223 void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
224 u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
225 u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
226 void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
227 void r8712_use_tkipkey_handler(unsigned long data);
229 #endif /*__RTL871X_SECURITY_H_ */