1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#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
49
50union pn48 {
51 u64 val;
52#if defined(__BIG_ENDIAN)
53 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_;
63#else
64 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_;
74#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;
93
94 u32 PrivacyAlgrthm;
95
96 u32 PrivacyKeyIndex;
97
98 union Keytype DefKey[4];
99 u32 DefKeylen[4];
100 u32 XGrpPrivacy;
101
102 u32 XGrpKeyid;
103 union Keytype XGrpKey[2];
104
105 union Keytype XGrptxmickey[2];
106 union Keytype XGrprxmickey[2];
107 union pn48 Grptxpn;
108 union pn48 Grprxpn;
109 u8 wps_hw_pbc_pressed;
110 u8 wps_phase;
111 u8 wps_ie[MAX_WPA_IE_LEN<<2];
112 int wps_ie_len;
113 u8 binstallGrpkey;
114 u8 busetkipkey;
115 struct timer_list tkip_timer;
116 u8 bcheck_grpkey;
117 u8 bgrpkey_handshake;
118 s32 sw_encrypt;
119 s32 sw_decrypt;
120 s32 hw_decrypted;
121
122 u32 ndisauthtype;
123
124 u32 ndisencryptstatus;
125 struct wlan_bssid_ex sec_bss;
126 struct NDIS_802_11_WEP ndiswep;
127 u8 assoc_info[600];
128 u8 szofcapability[256];
129 u8 oidassociation[512];
130 u8 authenticator_ie[256];
131 u8 supplicant_ie[256];
132
133 u32 last_mic_err_time;
134 u8 btkip_countermeasure;
135 u8 btkip_wait_report;
136 u32 btkip_countermeasure_time;
137
138
139
140 struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
141 u8 PMKIDIndex;
142};
143
144#define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
145do { \
146 switch (psecuritypriv->AuthAlgrthm) { \
147 case 0: \
148 case 1: \
149 case 3: \
150 encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
151 break; \
152 case 2: \
153 if (bmcst) \
154 encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
155 else \
156 encry_algo = (u8)psta->XPrivacy; \
157 break; \
158 } \
159} while (0)
160#define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
161do {\
162 switch (encrypt) { \
163 case _WEP40_: \
164 case _WEP104_: \
165 iv_len = 4; \
166 icv_len = 4; \
167 break; \
168 case _TKIP_: \
169 iv_len = 8; \
170 icv_len = 4; \
171 break; \
172 case _AES_: \
173 iv_len = 8; \
174 icv_len = 8; \
175 break; \
176 default: \
177 iv_len = 0; \
178 icv_len = 0; \
179 break; \
180 } \
181} while (0)
182#define GET_TKIP_PN(iv, txpn) \
183do {\
184 txpn._byte_.TSC0 = iv[2];\
185 txpn._byte_.TSC1 = iv[0];\
186 txpn._byte_.TSC2 = iv[4];\
187 txpn._byte_.TSC3 = iv[5];\
188 txpn._byte_.TSC4 = iv[6];\
189 txpn._byte_.TSC5 = iv[7];\
190} while (0)
191
192#define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
193#define ROR32(A, n) ROL32((A), 32 - (n))
194
195struct mic_data {
196 u32 K0, K1;
197 u32 L, R;
198 u32 M;
199 u32 nBytesInM;
200};
201
202void seccalctkipmic(
203 u8 *key,
204 u8 *header,
205 u8 *data,
206 u32 data_len,
207 u8 *Miccode,
208 u8 priority);
209
210void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
211void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
212void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
213u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
214u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
215void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
216u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
217u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
218void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
219void r8712_use_tkipkey_handler(void *FunctionContext);
220
221#endif
222
223