rtl871x_security.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * Modifications for inclusion into the Linux staging tree are
  19. * Copyright(c) 2010 Larry Finger. All rights reserved.
  20. *
  21. * Contact information:
  22. * WLAN FAE <wlanfae@realtek.com>
  23. * Larry Finger <Larry.Finger@lwfinger.net>
  24. *
  25. ******************************************************************************/
  26. #ifndef __RTL871X_SECURITY_H_
  27. #define __RTL871X_SECURITY_H_
  28. #include "osdep_service.h"
  29. #include "drv_types.h"
  30. #define _NO_PRIVACY_ 0x0
  31. #define _WEP40_ 0x1
  32. #define _TKIP_ 0x2
  33. #define _TKIP_WTMIC_ 0x3
  34. #define _AES_ 0x4
  35. #define _WEP104_ 0x5
  36. #define _WPA_IE_ID_ 0xdd
  37. #define _WPA2_IE_ID_ 0x30
  38. #ifndef Ndis802_11AuthModeWPA2
  39. #define Ndis802_11AuthModeWPA2 (Ndis802_11AuthModeWPANone + 1)
  40. #endif
  41. #ifndef Ndis802_11AuthModeWPA2PSK
  42. #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2)
  43. #endif
  44. union pn48 {
  45. u64 val;
  46. #if defined(__BIG_ENDIAN)
  47. struct {
  48. u8 TSC7;
  49. u8 TSC6;
  50. u8 TSC5;
  51. u8 TSC4;
  52. u8 TSC3;
  53. u8 TSC2;
  54. u8 TSC1;
  55. u8 TSC0;
  56. } _byte_;
  57. #else
  58. struct {
  59. u8 TSC0;
  60. u8 TSC1;
  61. u8 TSC2;
  62. u8 TSC3;
  63. u8 TSC4;
  64. u8 TSC5;
  65. u8 TSC6;
  66. u8 TSC7;
  67. } _byte_;
  68. #endif
  69. };
  70. union Keytype {
  71. u8 skey[16];
  72. u32 lkey[4];
  73. };
  74. struct 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. struct security_priv {
  83. u32 AuthAlgrthm; /* 802.11 auth, could be open, shared,
  84. * 8021x and authswitch */
  85. u32 PrivacyAlgrthm; /* This specify the privacy for shared
  86. * auth. algorithm. */
  87. u32 PrivacyKeyIndex; /* this is only valid for legendary
  88. * wep, 0~3 for key id. */
  89. union Keytype DefKey[4]; /* this is only valid for def. key */
  90. u32 DefKeylen[4];
  91. u32 XGrpPrivacy; /* This specify the privacy algthm.
  92. * used for Grp key */
  93. u32 XGrpKeyid; /* key id used for Grp Key */
  94. union Keytype XGrpKey[2]; /* 802.1x Group Key, for
  95. * inx0 and inx1 */
  96. union Keytype XGrptxmickey[2];
  97. union Keytype XGrprxmickey[2];
  98. union pn48 Grptxpn; /* PN48 used for Grp Key xmit. */
  99. union pn48 Grprxpn; /* PN48 used for Grp Key recv. */
  100. u8 wps_hw_pbc_pressed;/*for hw pbc pressed*/
  101. u8 wps_phase;/*for wps*/
  102. u8 wps_ie[MAX_WPA_IE_LEN<<2];
  103. int wps_ie_len;
  104. u8 binstallGrpkey;
  105. u8 busetkipkey;
  106. struct timer_list tkip_timer;
  107. u8 bcheck_grpkey;
  108. u8 bgrpkey_handshake;
  109. s32 sw_encrypt; /* from registry_priv */
  110. s32 sw_decrypt; /* from registry_priv */
  111. s32 hw_decrypted; /* if the rx packets is hw_decrypted==false,
  112. * it means the hw has not been ready. */
  113. u32 ndisauthtype; /* keeps the auth_type & enc_status from upper
  114. * layer ioctl(wpa_supplicant or wzc) */
  115. u32 ndisencryptstatus;
  116. struct wlan_bssid_ex sec_bss; /* for joinbss (h2c buffer) usage */
  117. struct NDIS_802_11_WEP ndiswep;
  118. u8 assoc_info[600];
  119. u8 szofcapability[256]; /* for wpa2 usage */
  120. u8 oidassociation[512]; /* for wpa/wpa2 usage */
  121. u8 authenticator_ie[256]; /* store ap security information element */
  122. u8 supplicant_ie[256]; /* store sta security information element */
  123. /* for tkip countermeasure */
  124. u32 last_mic_err_time;
  125. u8 btkip_countermeasure;
  126. u8 btkip_wait_report;
  127. u32 btkip_countermeasure_time;
  128. /*-------------------------------------------------------------------
  129. * For WPA2 Pre-Authentication.
  130. *------------------------------------------------------------------ */
  131. struct RT_PMKID_LIST PMKIDList[NUM_PMKID_CACHE];
  132. u8 PMKIDIndex;
  133. };
  134. #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst) \
  135. do { \
  136. switch (psecuritypriv->AuthAlgrthm) { \
  137. case 0: \
  138. case 1: \
  139. case 3: \
  140. encry_algo = (u8)psecuritypriv->PrivacyAlgrthm; \
  141. break; \
  142. case 2: \
  143. if (bmcst) \
  144. encry_algo = (u8)psecuritypriv->XGrpPrivacy; \
  145. else \
  146. encry_algo = (u8)psta->XPrivacy; \
  147. break; \
  148. } \
  149. } while (0)
  150. #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\
  151. do {\
  152. switch (encrypt) { \
  153. case _WEP40_: \
  154. case _WEP104_: \
  155. iv_len = 4; \
  156. icv_len = 4; \
  157. break; \
  158. case _TKIP_: \
  159. iv_len = 8; \
  160. icv_len = 4; \
  161. break; \
  162. case _AES_: \
  163. iv_len = 8; \
  164. icv_len = 8; \
  165. break; \
  166. default: \
  167. iv_len = 0; \
  168. icv_len = 0; \
  169. break; \
  170. } \
  171. } while (0)
  172. #define GET_TKIP_PN(iv, txpn) \
  173. do {\
  174. txpn._byte_.TSC0 = iv[2];\
  175. txpn._byte_.TSC1 = iv[0];\
  176. txpn._byte_.TSC2 = iv[4];\
  177. txpn._byte_.TSC3 = iv[5];\
  178. txpn._byte_.TSC4 = iv[6];\
  179. txpn._byte_.TSC5 = iv[7];\
  180. } while (0)
  181. #define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
  182. #define ROR32(A, n) ROL32((A), 32 - (n))
  183. struct mic_data {
  184. u32 K0, K1; /* Key */
  185. u32 L, R; /* Current state */
  186. u32 M; /* Message accumulator (single word) */
  187. u32 nBytesInM; /* # bytes in M */
  188. };
  189. void seccalctkipmic(
  190. u8 *key,
  191. u8 *header,
  192. u8 *data,
  193. u32 data_len,
  194. u8 *Miccode,
  195. u8 priority);
  196. void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
  197. void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
  198. void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
  199. u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
  200. u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
  201. void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
  202. u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
  203. u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
  204. void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
  205. void r8712_use_tkipkey_handler(unsigned long data);
  206. #endif /*__RTL871X_SECURITY_H_ */