1
2
3
4#ifndef __RTW_SECURITY_H_
5#define __RTW_SECURITY_H_
6
7#include "osdep_service.h"
8#include "drv_types.h"
9#include <crypto/arc4.h>
10
11#define _NO_PRIVACY_ 0x0
12#define _WEP40_ 0x1
13#define _TKIP_ 0x2
14#define _TKIP_WTMIC_ 0x3
15#define _AES_ 0x4
16#define _WEP104_ 0x5
17#define _SMS4_ 0x06
18
19#define _WPA_IE_ID_ 0xdd
20#define _WPA2_IE_ID_ 0x30
21
22enum {
23 ENCRYP_PROTOCOL_OPENSYS,
24 ENCRYP_PROTOCOL_WEP,
25 ENCRYP_PROTOCOL_WPA,
26 ENCRYP_PROTOCOL_WPA2,
27 ENCRYP_PROTOCOL_WAPI,
28 ENCRYP_PROTOCOL_MAX
29};
30
31#ifndef Ndis802_11AuthModeWPA2
32#define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
33#endif
34
35#ifndef Ndis802_11AuthModeWPA2PSK
36#define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
37#endif
38
39union pn48 {
40 u64 val;
41
42#ifdef __LITTLE_ENDIAN
43 struct {
44 u8 TSC0;
45 u8 TSC1;
46 u8 TSC2;
47 u8 TSC3;
48 u8 TSC4;
49 u8 TSC5;
50 u8 TSC6;
51 u8 TSC7;
52 } _byte_;
53
54#elif defined(__BIG_ENDIAN)
55
56 struct {
57 u8 TSC7;
58 u8 TSC6;
59 u8 TSC5;
60 u8 TSC4;
61 u8 TSC3;
62 u8 TSC2;
63 u8 TSC1;
64 u8 TSC0;
65 } _byte_;
66#endif
67};
68
69union Keytype {
70 u8 skey[16];
71 u32 lkey[4];
72};
73
74struct rt_pmkid_list {
75 u8 bUsed;
76 u8 Bssid[6];
77 u8 PMKID[16];
78 u8 SsidBuf[33];
79 u8 *ssid_octet;
80 u16 ssid_length;
81};
82
83struct security_priv {
84 u32 dot11AuthAlgrthm;
85
86 u32 dot11PrivacyAlgrthm;
87
88
89 u32 dot11PrivacyKeyIndex;
90
91 union Keytype dot11DefKey[4];
92 u32 dot11DefKeylen[4];
93 u32 dot118021XGrpPrivacy;
94
95 u32 dot118021XGrpKeyid;
96
97 union Keytype dot118021XGrpKey[4];
98
99 union Keytype dot118021XGrptxmickey[4];
100 union Keytype dot118021XGrprxmickey[4];
101 union pn48 dot11Grptxpn;
102 union pn48 dot11Grprxpn;
103
104 struct arc4_ctx xmit_arc4_ctx;
105 struct arc4_ctx recv_arc4_ctx;
106
107
108 unsigned int dot8021xalg;
109 unsigned int wpa_psk;
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];
115 int wps_ie_len;
116 u8 binstallGrpkey;
117 u8 busetkipkey;
118 u8 bcheck_grpkey;
119 u8 bgrpkey_handshake;
120 s32 sw_encrypt;
121 s32 sw_decrypt;
122 s32 hw_decrypted;
123
124
125
126
127 u32 ndisauthtype;
128 u32 ndisencryptstatus;
129 struct wlan_bssid_ex sec_bss;
130 struct ndis_802_11_wep ndiswep;
131 u8 assoc_info[600];
132 u8 szofcapability[256];
133 u8 oidassociation[512];
134 u8 authenticator_ie[256];
135 u8 supplicant_ie[256];
136
137
138 u32 last_mic_err_time;
139 u8 btkip_countermeasure;
140 u8 btkip_wait_report;
141 u32 btkip_countermeasure_time;
142
143
144
145
146 struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
147 u8 PMKIDIndex;
148 u8 bWepDefaultKeyIdxSet;
149};
150
151#define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
152do { \
153 switch (psecuritypriv->dot11AuthAlgrthm) { \
154 case dot11AuthAlgrthm_Open: \
155 case dot11AuthAlgrthm_Shared: \
156 case dot11AuthAlgrthm_Auto: \
157 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
158 break; \
159 case dot11AuthAlgrthm_8021X: \
160 if (bmcst) \
161 encry_algo = (u8)psecuritypriv->dot118021XGrpPrivacy;\
162 else \
163 encry_algo = (u8)psta->dot118021XPrivacy; \
164 break; \
165 case dot11AuthAlgrthm_WAPI: \
166 encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm; \
167 break; \
168 } \
169} while (0)
170
171#define SET_ICE_IV_LEN(iv_len, icv_len, encrypt) \
172do { \
173 switch (encrypt) { \
174 case _WEP40_: \
175 case _WEP104_: \
176 iv_len = 4; \
177 icv_len = 4; \
178 break; \
179 case _TKIP_: \
180 iv_len = 8; \
181 icv_len = 4; \
182 break; \
183 case _AES_: \
184 iv_len = 8; \
185 icv_len = 8; \
186 break; \
187 case _SMS4_: \
188 iv_len = 18; \
189 icv_len = 16; \
190 break; \
191 default: \
192 iv_len = 0; \
193 icv_len = 0; \
194 break; \
195 } \
196} while (0)
197
198#define GET_TKIP_PN(iv, dot11txpn) \
199do { \
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]; \
206} while (0)
207
208#define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
209#define ROR32(A, n) ROL32((A), 32-(n))
210
211struct mic_data {
212 u32 K0, K1;
213 u32 L, R;
214 u32 M;
215 u32 nBytesInM;
216};
217
218void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key);
219void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b);
220void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
221void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst);
222void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len,
223 u8 *Miccode, u8 priority);
224u32 rtw_aes_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
225u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
226void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
227u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
228u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
229void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
230
231#endif
232