Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
[linux-btrfs-devel.git] / drivers / staging / rtl8712 / rtl871x_security.h
blobbff71d2aae98e30e3c30df4d97a652825d9e63a7
1 #ifndef __RTL871X_SECURITY_H_
2 #define __RTL871X_SECURITY_H_
4 #include "osdep_service.h"
5 #include "drv_types.h"
7 #define _NO_PRIVACY_ 0x0
8 #define _WEP40_ 0x1
9 #define _TKIP_ 0x2
10 #define _TKIP_WTMIC_ 0x3
11 #define _AES_ 0x4
12 #define _WEP104_ 0x5
14 #define _WPA_IE_ID_ 0xdd
15 #define _WPA2_IE_ID_ 0x30
17 #ifndef Ndis802_11AuthModeWPA2
18 #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
19 #endif
21 #ifndef Ndis802_11AuthModeWPA2PSK
22 #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
23 #endif
25 union pn48 {
26 u64 val;
27 #if defined(__BIG_ENDIAN)
28 struct {
29 u8 TSC7;
30 u8 TSC6;
31 u8 TSC5;
32 u8 TSC4;
33 u8 TSC3;
34 u8 TSC2;
35 u8 TSC1;
36 u8 TSC0;
37 } _byte_;
38 #else
39 struct {
40 u8 TSC0;
41 u8 TSC1;
42 u8 TSC2;
43 u8 TSC3;
44 u8 TSC4;
45 u8 TSC5;
46 u8 TSC6;
47 u8 TSC7;
48 } _byte_;
49 #endif
52 union Keytype {
53 u8 skey[16];
54 u32 lkey[4];
57 struct RT_PMKID_LIST {
58 u8 bUsed;
59 u8 Bssid[6];
60 u8 PMKID[16];
61 u8 SsidBuf[33];
62 u8 *ssid_octet;
63 u16 ssid_length;
66 struct security_priv {
67 u32 AuthAlgrthm; /* 802.11 auth, could be open, shared,
68 * 8021x and authswitch */
69 u32 PrivacyAlgrthm; /* This specify the privacy for shared
70 * auth. algorithm. */
71 u32 PrivacyKeyIndex; /* this is only valid for legendary
72 * wep, 0~3 for key id. */
73 union Keytype DefKey[4]; /* this is only valid for def. key */
74 u32 DefKeylen[4];
75 u32 XGrpPrivacy; /* This specify the privacy algthm.
76 * used for Grp key */
77 u32 XGrpKeyid; /* key id used for Grp Key */
78 union Keytype XGrpKey[2]; /* 802.1x Group Key, for
79 * inx0 and inx1 */
80 union Keytype XGrptxmickey[2];
81 union Keytype XGrprxmickey[2];
82 union pn48 Grptxpn; /* PN48 used for Grp Key xmit. */
83 union pn48 Grprxpn; /* PN48 used for Grp Key recv. */
84 u8 wps_hw_pbc_pressed;/*for hw pbc pressed*/
85 u8 wps_phase;/*for wps*/
86 u8 wps_ie[MAX_WPA_IE_LEN<<2];
87 int wps_ie_len;
88 u8 binstallGrpkey;
89 u8 busetkipkey;
90 struct timer_list tkip_timer;
91 u8 bcheck_grpkey;
92 u8 bgrpkey_handshake;
93 s32 sw_encrypt; /* from registry_priv */
94 s32 sw_decrypt; /* from registry_priv */
95 s32 hw_decrypted; /* if the rx packets is hw_decrypted==false,
96 * it means the hw has not been ready. */
97 u32 ndisauthtype; /* keeps the auth_type & enc_status from upper
98 * layer ioctl(wpa_supplicant or wzc) */
99 u32 ndisencryptstatus;
100 struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
101 struct NDIS_802_11_WEP ndiswep;
102 u8 assoc_info[600];
103 u8 szofcapability[256]; /* for wpa2 usage */
104 u8 oidassociation[512]; /* for wpa/wpa2 usage */
105 u8 authenticator_ie[256]; /* store ap security information element */
106 u8 supplicant_ie[256]; /* store sta security information element */
107 /* for tkip countermeasure */
108 u32 last_mic_err_time;
109 u8 btkip_countermeasure;
110 u8 btkip_wait_report;
111 u32 btkip_countermeasure_time;
112 /*-------------------------------------------------------------------
113 * For WPA2 Pre-Authentication.
114 *------------------------------------------------------------------ */
115 struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
116 u8 PMKIDIndex;
119 #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
120 do { \
121 switch (psecuritypriv->AuthAlgrthm) { \
122 case 0: \
123 case 1: \
124 case 3: \
125 encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
126 break; \
127 case 2: \
128 if (bmcst) \
129 encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
130 else \
131 encry_algo = (u8)psta->XPrivacy; \
132 break; \
134 } while (0)
135 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
136 do {\
137 switch (encrypt) { \
138 case _WEP40_: \
139 case _WEP104_: \
140 iv_len = 4; \
141 icv_len = 4; \
142 break; \
143 case _TKIP_: \
144 iv_len = 8; \
145 icv_len = 4; \
146 break; \
147 case _AES_: \
148 iv_len = 8; \
149 icv_len = 8; \
150 break; \
151 default: \
152 iv_len = 0; \
153 icv_len = 0; \
154 break; \
156 } while (0)
157 #define GET_TKIP_PN(iv, txpn) \
158 do {\
159 txpn._byte_.TSC0 = iv[2];\
160 txpn._byte_.TSC1 = iv[0];\
161 txpn._byte_.TSC2 = iv[4];\
162 txpn._byte_.TSC3 = iv[5];\
163 txpn._byte_.TSC4 = iv[6];\
164 txpn._byte_.TSC5 = iv[7];\
165 } while (0)
167 #define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
168 #define ROR32(A, n) ROL32((A), 32 - (n))
170 struct mic_data {
171 u32 K0, K1; /* Key */
172 u32 L, R; /* Current state */
173 u32 M; /* Message accumulator (single word) */
174 u32 nBytesInM; /* # bytes in M */
177 void seccalctkipmic(
178 u8 *key,
179 u8 *header,
180 u8 *data,
181 u32 data_len,
182 u8 *Miccode,
183 u8 priority);
185 void r8712_secmicsetkey(struct mic_data *pmicdata, u8 * key);
186 void r8712_secmicappend(struct mic_data *pmicdata, u8 * src, u32 nBytes);
187 void r8712_secgetmic(struct mic_data *pmicdata, u8 * dst);
188 u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
189 u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
190 void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
191 u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
192 u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
193 void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
194 void r8712_use_tkipkey_handler(void *FunctionContext);
196 #endif /*__RTL871X_SECURITY_H_ */