key.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright 2002-2004, Instant802 Networks, Inc.
  3. * Copyright 2005, Devicescape Software, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef IEEE80211_KEY_H
  10. #define IEEE80211_KEY_H
  11. #include <linux/types.h>
  12. #include <linux/list.h>
  13. #include <linux/crypto.h>
  14. #include <linux/rcupdate.h>
  15. #include <net/mac80211.h>
  16. #define NUM_DEFAULT_KEYS 4
  17. #define NUM_DEFAULT_MGMT_KEYS 2
  18. #define MAX_PN_LEN 16
  19. struct ieee80211_local;
  20. struct ieee80211_sub_if_data;
  21. struct sta_info;
  22. /**
  23. * enum ieee80211_internal_key_flags - internal key flags
  24. *
  25. * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
  26. * in the hardware for TX crypto hardware acceleration.
  27. * @KEY_FLAG_TAINTED: Key is tainted and packets should be dropped.
  28. * @KEY_FLAG_CIPHER_SCHEME: This key is for a hardware cipher scheme
  29. */
  30. enum ieee80211_internal_key_flags {
  31. KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
  32. KEY_FLAG_TAINTED = BIT(1),
  33. KEY_FLAG_CIPHER_SCHEME = BIT(2),
  34. };
  35. enum ieee80211_internal_tkip_state {
  36. TKIP_STATE_NOT_INIT,
  37. TKIP_STATE_PHASE1_DONE,
  38. TKIP_STATE_PHASE1_HW_UPLOADED,
  39. };
  40. struct tkip_ctx {
  41. u32 iv32; /* current iv32 */
  42. u16 iv16; /* current iv16 */
  43. u16 p1k[5]; /* p1k cache */
  44. u32 p1k_iv32; /* iv32 for which p1k computed */
  45. enum ieee80211_internal_tkip_state state;
  46. };
  47. struct ieee80211_key {
  48. struct ieee80211_local *local;
  49. struct ieee80211_sub_if_data *sdata;
  50. struct sta_info *sta;
  51. /* for sdata list */
  52. struct list_head list;
  53. /* protected by key mutex */
  54. unsigned int flags;
  55. union {
  56. struct {
  57. /* protects tx context */
  58. spinlock_t txlock;
  59. /* last used TSC */
  60. struct tkip_ctx tx;
  61. /* last received RSC */
  62. struct tkip_ctx rx[IEEE80211_NUM_TIDS];
  63. /* number of mic failures */
  64. u32 mic_failures;
  65. } tkip;
  66. struct {
  67. atomic64_t tx_pn;
  68. /*
  69. * Last received packet number. The first
  70. * IEEE80211_NUM_TIDS counters are used with Data
  71. * frames and the last counter is used with Robust
  72. * Management frames.
  73. */
  74. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
  75. struct crypto_aead *tfm;
  76. u32 replays; /* dot11RSNAStatsCCMPReplays */
  77. } ccmp;
  78. struct {
  79. atomic64_t tx_pn;
  80. u8 rx_pn[IEEE80211_CMAC_PN_LEN];
  81. struct crypto_cipher *tfm;
  82. u32 replays; /* dot11RSNAStatsCMACReplays */
  83. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  84. } aes_cmac;
  85. struct {
  86. atomic64_t tx_pn;
  87. u8 rx_pn[IEEE80211_GMAC_PN_LEN];
  88. struct crypto_aead *tfm;
  89. u32 replays; /* dot11RSNAStatsCMACReplays */
  90. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  91. } aes_gmac;
  92. struct {
  93. atomic64_t tx_pn;
  94. /* Last received packet number. The first
  95. * IEEE80211_NUM_TIDS counters are used with Data
  96. * frames and the last counter is used with Robust
  97. * Management frames.
  98. */
  99. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_GCMP_PN_LEN];
  100. struct crypto_aead *tfm;
  101. u32 replays; /* dot11RSNAStatsGCMPReplays */
  102. } gcmp;
  103. struct {
  104. /* generic cipher scheme */
  105. u8 rx_pn[IEEE80211_NUM_TIDS + 1][MAX_PN_LEN];
  106. } gen;
  107. } u;
  108. /* number of times this key has been used */
  109. int tx_rx_count;
  110. #ifdef CONFIG_MAC80211_DEBUGFS
  111. struct {
  112. struct dentry *stalink;
  113. struct dentry *dir;
  114. int cnt;
  115. } debugfs;
  116. #endif
  117. /*
  118. * key config, must be last because it contains key
  119. * material as variable length member
  120. */
  121. struct ieee80211_key_conf conf;
  122. };
  123. struct ieee80211_key *
  124. ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
  125. const u8 *key_data,
  126. size_t seq_len, const u8 *seq,
  127. const struct ieee80211_cipher_scheme *cs);
  128. /*
  129. * Insert a key into data structures (sdata, sta if necessary)
  130. * to make it used, free old key. On failure, also free the new key.
  131. */
  132. int ieee80211_key_link(struct ieee80211_key *key,
  133. struct ieee80211_sub_if_data *sdata,
  134. struct sta_info *sta);
  135. void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom);
  136. void ieee80211_key_free_unused(struct ieee80211_key *key);
  137. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
  138. bool uni, bool multi);
  139. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  140. int idx);
  141. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
  142. bool force_synchronize);
  143. void ieee80211_free_sta_keys(struct ieee80211_local *local,
  144. struct sta_info *sta);
  145. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
  146. void ieee80211_reset_crypto_tx_tailroom(struct ieee80211_sub_if_data *sdata);
  147. #define key_mtx_dereference(local, ref) \
  148. rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx)))
  149. void ieee80211_delayed_tailroom_dec(struct work_struct *wk);
  150. #endif /* IEEE80211_KEY_H */