/drivers/staging/rtl8712/rtl871x_security.h

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C Header · 197 lines · 170 code · 16 blank · 11 comment · 7 complexity · 9b9d5857bf2cb3d783f50a8664579649 MD5 · raw file

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