blob: fa952e17975b4142973018721a215f2fa4025e2a [file] [log] [blame]
Ali Bahar0e54f602011-08-23 13:53:37 +08001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 *
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.
8 *
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
12 * more details.
13 *
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
17 *
Ali Baharb4f62092011-08-23 13:53:38 +080018 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
Ali Bahar0e54f602011-08-23 13:53:37 +080024 *
25 ******************************************************************************/
Larry Finger2865d422010-08-20 10:15:30 -050026#ifndef __RTL871X_SECURITY_H_
27#define __RTL871X_SECURITY_H_
28
29#include "osdep_service.h"
30#include "drv_types.h"
31
32#define _NO_PRIVACY_ 0x0
33#define _WEP40_ 0x1
34#define _TKIP_ 0x2
35#define _TKIP_WTMIC_ 0x3
36#define _AES_ 0x4
37#define _WEP104_ 0x5
38
39#define _WPA_IE_ID_ 0xdd
40#define _WPA2_IE_ID_ 0x30
41
42#ifndef Ndis802_11AuthModeWPA2
43#define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
44#endif
45
46#ifndef Ndis802_11AuthModeWPA2PSK
47#define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
48#endif
Javier M. Mellid05937582011-04-02 03:01:49 +020049
Larry Finger2865d422010-08-20 10:15:30 -050050union pn48 {
51 u64 val;
52#if defined(__BIG_ENDIAN)
Javier M. Mellid05937582011-04-02 03:01:49 +020053 struct {
54 u8 TSC7;
55 u8 TSC6;
56 u8 TSC5;
57 u8 TSC4;
58 u8 TSC3;
59 u8 TSC2;
60 u8 TSC1;
61 u8 TSC0;
62 } _byte_;
Larry Finger2865d422010-08-20 10:15:30 -050063#else
Javier M. Mellid05937582011-04-02 03:01:49 +020064 struct {
65 u8 TSC0;
66 u8 TSC1;
67 u8 TSC2;
68 u8 TSC3;
69 u8 TSC4;
70 u8 TSC5;
71 u8 TSC6;
72 u8 TSC7;
73 } _byte_;
Larry Finger2865d422010-08-20 10:15:30 -050074#endif
75};
76
77union Keytype {
78 u8 skey[16];
79 u32 lkey[4];
80};
81
82struct RT_PMKID_LIST {
83 u8 bUsed;
84 u8 Bssid[6];
85 u8 PMKID[16];
86 u8 SsidBuf[33];
87 u8 *ssid_octet;
88 u16 ssid_length;
89};
90
91struct security_priv {
92 u32 AuthAlgrthm; /* 802.11 auth, could be open, shared,
Raphaël Beamontebef611a2016-09-09 11:31:45 -040093 * 8021x and authswitch
94 */
Larry Finger2865d422010-08-20 10:15:30 -050095 u32 PrivacyAlgrthm; /* This specify the privacy for shared
Raphaël Beamontebef611a2016-09-09 11:31:45 -040096 * auth. algorithm.
97 */
Larry Finger2865d422010-08-20 10:15:30 -050098 u32 PrivacyKeyIndex; /* this is only valid for legendary
Raphaël Beamontebef611a2016-09-09 11:31:45 -040099 * wep, 0~3 for key id.
100 */
Larry Finger2865d422010-08-20 10:15:30 -0500101 union Keytype DefKey[4]; /* this is only valid for def. key */
102 u32 DefKeylen[4];
103 u32 XGrpPrivacy; /* This specify the privacy algthm.
Raphaël Beamontebef611a2016-09-09 11:31:45 -0400104 * used for Grp key
105 */
Larry Finger2865d422010-08-20 10:15:30 -0500106 u32 XGrpKeyid; /* key id used for Grp Key */
107 union Keytype XGrpKey[2]; /* 802.1x Group Key, for
Raphaël Beamontebef611a2016-09-09 11:31:45 -0400108 * inx0 and inx1
109 */
Larry Finger2865d422010-08-20 10:15:30 -0500110 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];
117 int wps_ie_len;
118 u8 binstallGrpkey;
119 u8 busetkipkey;
120 struct timer_list tkip_timer;
121 u8 bcheck_grpkey;
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,
Raphaël Beamontebef611a2016-09-09 11:31:45 -0400126 * it means the hw has not been ready.
127 */
Larry Finger2865d422010-08-20 10:15:30 -0500128 u32 ndisauthtype; /* keeps the auth_type & enc_status from upper
Raphaël Beamontebef611a2016-09-09 11:31:45 -0400129 * layer ioctl(wpa_supplicant or wzc)
130 */
Larry Finger2865d422010-08-20 10:15:30 -0500131 u32 ndisencryptstatus;
132 struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
133 struct NDIS_802_11_WEP ndiswep;
134 u8 assoc_info[600];
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.
Raphaël Beamontebef611a2016-09-09 11:31:45 -0400146 *------------------------------------------------------------------
147 **/
Larry Finger2865d422010-08-20 10:15:30 -0500148 struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
149 u8 PMKIDIndex;
150};
151
152#define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
153do { \
154 switch (psecuritypriv->AuthAlgrthm) { \
155 case 0: \
156 case 1: \
157 case 3: \
158 encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
159 break; \
160 case 2: \
161 if (bmcst) \
162 encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
163 else \
164 encry_algo = (u8)psta->XPrivacy; \
165 break; \
166 } \
167} while (0)
168#define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
169do {\
170 switch (encrypt) { \
171 case _WEP40_: \
172 case _WEP104_: \
173 iv_len = 4; \
174 icv_len = 4; \
175 break; \
176 case _TKIP_: \
177 iv_len = 8; \
178 icv_len = 4; \
179 break; \
180 case _AES_: \
181 iv_len = 8; \
182 icv_len = 8; \
183 break; \
184 default: \
185 iv_len = 0; \
186 icv_len = 0; \
187 break; \
188 } \
189} while (0)
190#define GET_TKIP_PN(iv, txpn) \
191do {\
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];\
198} while (0)
199
200#define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
201#define ROR32(A, n) ROL32((A), 32 - (n))
202
203struct mic_data {
204 u32 K0, K1; /* Key */
205 u32 L, R; /* Current state */
206 u32 M; /* Message accumulator (single word) */
207 u32 nBytesInM; /* # bytes in M */
208};
209
210void seccalctkipmic(
Javier M. Mellid05937582011-04-02 03:01:49 +0200211 u8 *key,
212 u8 *header,
213 u8 *data,
214 u32 data_len,
215 u8 *Miccode,
Larry Finger2865d422010-08-20 10:15:30 -0500216 u8 priority);
217
Przemo Firsztc07f9722012-12-10 23:21:19 +0000218void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
219void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
220void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
Larry Finger2865d422010-08-20 10:15:30 -0500221u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
222u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
223void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
224u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
225u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
226void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
Vaishali Thakkare922df72015-03-03 22:34:22 +0530227void r8712_use_tkipkey_handler(unsigned long data);
Larry Finger2865d422010-08-20 10:15:30 -0500228
229#endif /*__RTL871X_SECURITY_H_ */
230