Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /******************************************************************************
0003  *
0004  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
0005  *
0006  * Modifications for inclusion into the Linux staging tree are
0007  * Copyright(c) 2010 Larry Finger. All rights reserved.
0008  *
0009  * Contact information:
0010  * WLAN FAE <wlanfae@realtek.com>
0011  * Larry Finger <Larry.Finger@lwfinger.net>
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;        /* 802.11 auth, could be open, shared,
0081                      * 8021x and authswitch
0082                      */
0083     u32 PrivacyAlgrthm;     /* This specify the privacy for shared
0084                      * auth. algorithm.
0085                      */
0086     u32 PrivacyKeyIndex;        /* this is only valid for legendary
0087                      * wep, 0~3 for key id.
0088                      */
0089     union Keytype DefKey[4];    /* this is only valid for def. key */
0090     u32 DefKeylen[4];
0091     u32 XGrpPrivacy;        /* This specify the privacy algthm.
0092                      * used for Grp key
0093                      */
0094     u32 XGrpKeyid;          /* key id used for Grp Key */
0095     union Keytype   XGrpKey[2]; /* 802.1x Group Key, for
0096                      * inx0 and inx1
0097                      */
0098     union Keytype   XGrptxmickey[2];
0099     union Keytype   XGrprxmickey[2];
0100     union pn48 Grptxpn;     /* PN48 used for Grp Key xmit. */
0101     union pn48 Grprxpn;     /* PN48 used for Grp Key recv. */
0102     u8 wps_hw_pbc_pressed;/*for hw pbc pressed*/
0103     u8 wps_phase;/*for wps*/
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; /* from registry_priv */
0112     s32 sw_decrypt; /* from registry_priv */
0113     s32 hw_decrypted;   /* if the rx packets is hw_decrypted==false,
0114                  * it means the hw has not been ready.
0115                  */
0116     u32 ndisauthtype;   /* keeps the auth_type & enc_status from upper
0117                  * layer ioctl(wpa_supplicant or wzc)
0118                  */
0119     u32 ndisencryptstatus;
0120     struct wlan_bssid_ex sec_bss;  /* for joinbss (h2c buffer) usage */
0121     struct NDIS_802_11_WEP ndiswep;
0122     u8 assoc_info[600];
0123     u8 szofcapability[256]; /* for wpa2 usage */
0124     u8 oidassociation[512]; /* for wpa/wpa2 usage */
0125     u8 authenticator_ie[256];  /* store ap security information element */
0126     u8 supplicant_ie[256];  /* store sta security information element */
0127     /* for tkip countermeasure */
0128     u32 last_mic_err_time;
0129     u8  btkip_countermeasure;
0130     u8  btkip_wait_report;
0131     u32 btkip_countermeasure_time;
0132     /*-------------------------------------------------------------------
0133      * For WPA2 Pre-Authentication.
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;         /* Key */
0193     u32  L, R;           /* Current state */
0194     u32  M;              /* Message accumulator (single word) */
0195     u32  nBytesInM;      /* # bytes in M */
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  /*__RTL871X_SECURITY_H_ */
0218