0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef __RTL871X_SECURITY_H_
0015 #define __RTL871X_SECURITY_H_
0016
0017 #include "osdep_service.h"
0018 #include "drv_types.h"
0019
0020 #define _NO_PRIVACY_ 0x0
0021 #define _WEP40_ 0x1
0022 #define _TKIP_ 0x2
0023 #define _TKIP_WTMIC_ 0x3
0024 #define _AES_ 0x4
0025 #define _WEP104_ 0x5
0026
0027 #define _WPA_IE_ID_ 0xdd
0028 #define _WPA2_IE_ID_ 0x30
0029
0030 #ifndef Ndis802_11AuthModeWPA2
0031 #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
0032 #endif
0033
0034 #ifndef Ndis802_11AuthModeWPA2PSK
0035 #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
0036 #endif
0037
0038 union pn48 {
0039 u64 val;
0040 #if defined(__BIG_ENDIAN)
0041 struct {
0042 u8 TSC7;
0043 u8 TSC6;
0044 u8 TSC5;
0045 u8 TSC4;
0046 u8 TSC3;
0047 u8 TSC2;
0048 u8 TSC1;
0049 u8 TSC0;
0050 } _byte_;
0051 #else
0052 struct {
0053 u8 TSC0;
0054 u8 TSC1;
0055 u8 TSC2;
0056 u8 TSC3;
0057 u8 TSC4;
0058 u8 TSC5;
0059 u8 TSC6;
0060 u8 TSC7;
0061 } _byte_;
0062 #endif
0063 };
0064
0065 union Keytype {
0066 u8 skey[16];
0067 u32 lkey[4];
0068 };
0069
0070 struct RT_PMKID_LIST {
0071 u8 bUsed;
0072 u8 Bssid[6];
0073 u8 PMKID[16];
0074 u8 SsidBuf[33];
0075 u8 *ssid_octet;
0076 u16 ssid_length;
0077 };
0078
0079 struct security_priv {
0080 u32 AuthAlgrthm;
0081
0082
0083 u32 PrivacyAlgrthm;
0084
0085
0086 u32 PrivacyKeyIndex;
0087
0088
0089 union Keytype DefKey[4];
0090 u32 DefKeylen[4];
0091 u32 XGrpPrivacy;
0092
0093
0094 u32 XGrpKeyid;
0095 union Keytype XGrpKey[2];
0096
0097
0098 union Keytype XGrptxmickey[2];
0099 union Keytype XGrprxmickey[2];
0100 union pn48 Grptxpn;
0101 union pn48 Grprxpn;
0102 u8 wps_hw_pbc_pressed;
0103 u8 wps_phase;
0104 u8 wps_ie[MAX_WPA_IE_LEN << 2];
0105 int wps_ie_len;
0106 u8 binstallGrpkey;
0107 u8 busetkipkey;
0108 struct timer_list tkip_timer;
0109 u8 bcheck_grpkey;
0110 u8 bgrpkey_handshake;
0111 s32 sw_encrypt;
0112 s32 sw_decrypt;
0113 s32 hw_decrypted;
0114
0115
0116 u32 ndisauthtype;
0117
0118
0119 u32 ndisencryptstatus;
0120 struct wlan_bssid_ex sec_bss;
0121 struct NDIS_802_11_WEP ndiswep;
0122 u8 assoc_info[600];
0123 u8 szofcapability[256];
0124 u8 oidassociation[512];
0125 u8 authenticator_ie[256];
0126 u8 supplicant_ie[256];
0127
0128 u32 last_mic_err_time;
0129 u8 btkip_countermeasure;
0130 u8 btkip_wait_report;
0131 u32 btkip_countermeasure_time;
0132
0133
0134
0135
0136 struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
0137 u8 PMKIDIndex;
0138 };
0139
0140 #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
0141 do { \
0142 switch (psecuritypriv->AuthAlgrthm) { \
0143 case 0: \
0144 case 1: \
0145 case 3: \
0146 encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
0147 break; \
0148 case 2: \
0149 if (bmcst) \
0150 encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
0151 else \
0152 encry_algo = (u8)psta->XPrivacy; \
0153 break; \
0154 } \
0155 } while (0)
0156 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
0157 do {\
0158 switch (encrypt) { \
0159 case _WEP40_: \
0160 case _WEP104_: \
0161 iv_len = 4; \
0162 icv_len = 4; \
0163 break; \
0164 case _TKIP_: \
0165 iv_len = 8; \
0166 icv_len = 4; \
0167 break; \
0168 case _AES_: \
0169 iv_len = 8; \
0170 icv_len = 8; \
0171 break; \
0172 default: \
0173 iv_len = 0; \
0174 icv_len = 0; \
0175 break; \
0176 } \
0177 } while (0)
0178 #define GET_TKIP_PN(iv, txpn) \
0179 do {\
0180 txpn._byte_.TSC0 = iv[2];\
0181 txpn._byte_.TSC1 = iv[0];\
0182 txpn._byte_.TSC2 = iv[4];\
0183 txpn._byte_.TSC3 = iv[5];\
0184 txpn._byte_.TSC4 = iv[6];\
0185 txpn._byte_.TSC5 = iv[7];\
0186 } while (0)
0187
0188 #define ROL32(A, n) (((A) << (n)) | (((A) >> (32 - (n))) & ((1UL << (n)) - 1)))
0189 #define ROR32(A, n) ROL32((A), 32 - (n))
0190
0191 struct mic_data {
0192 u32 K0, K1;
0193 u32 L, R;
0194 u32 M;
0195 u32 nBytesInM;
0196 };
0197
0198 void seccalctkipmic(
0199 u8 *key,
0200 u8 *header,
0201 u8 *data,
0202 u32 data_len,
0203 u8 *Miccode,
0204 u8 priority);
0205
0206 void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
0207 void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
0208 void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
0209 u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
0210 u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
0211 void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
0212 void r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
0213 void r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
0214 void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
0215 void r8712_use_tkipkey_handler(struct timer_list *t);
0216
0217 #endif
0218