key.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 WEP_IV_LEN 4
  19. #define WEP_ICV_LEN 4
  20. #define ALG_CCMP_KEY_LEN 16
  21. #define CCMP_HDR_LEN 8
  22. #define CCMP_MIC_LEN 8
  23. #define CCMP_TK_LEN 16
  24. #define CCMP_PN_LEN 6
  25. #define TKIP_IV_LEN 8
  26. #define TKIP_ICV_LEN 4
  27. #define CMAC_PN_LEN 6
  28. struct ieee80211_local;
  29. struct ieee80211_sub_if_data;
  30. struct sta_info;
  31. /**
  32. * enum ieee80211_internal_key_flags - internal key flags
  33. *
  34. * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
  35. * in the hardware for TX crypto hardware acceleration.
  36. * @KEY_FLAG_TAINTED: Key is tainted and packets should be dropped.
  37. */
  38. enum ieee80211_internal_key_flags {
  39. KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
  40. KEY_FLAG_TAINTED = BIT(1),
  41. };
  42. enum ieee80211_internal_tkip_state {
  43. TKIP_STATE_NOT_INIT,
  44. TKIP_STATE_PHASE1_DONE,
  45. TKIP_STATE_PHASE1_HW_UPLOADED,
  46. };
  47. struct tkip_ctx {
  48. u32 iv32; /* current iv32 */
  49. u16 iv16; /* current iv16 */
  50. u16 p1k[5]; /* p1k cache */
  51. u32 p1k_iv32; /* iv32 for which p1k computed */
  52. enum ieee80211_internal_tkip_state state;
  53. };
  54. struct ieee80211_key {
  55. struct ieee80211_local *local;
  56. struct ieee80211_sub_if_data *sdata;
  57. struct sta_info *sta;
  58. /* for sdata list */
  59. struct list_head list;
  60. /* protected by key mutex */
  61. unsigned int flags;
  62. union {
  63. struct {
  64. /* protects tx context */
  65. spinlock_t txlock;
  66. /* last used TSC */
  67. struct tkip_ctx tx;
  68. /* last received RSC */
  69. struct tkip_ctx rx[IEEE80211_NUM_TIDS];
  70. } tkip;
  71. struct {
  72. atomic64_t tx_pn;
  73. /*
  74. * Last received packet number. The first
  75. * IEEE80211_NUM_TIDS counters are used with Data
  76. * frames and the last counter is used with Robust
  77. * Management frames.
  78. */
  79. u8 rx_pn[IEEE80211_NUM_TIDS + 1][CCMP_PN_LEN];
  80. struct crypto_cipher *tfm;
  81. u32 replays; /* dot11RSNAStatsCCMPReplays */
  82. } ccmp;
  83. struct {
  84. atomic64_t tx_pn;
  85. u8 rx_pn[CMAC_PN_LEN];
  86. struct crypto_cipher *tfm;
  87. u32 replays; /* dot11RSNAStatsCMACReplays */
  88. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  89. } aes_cmac;
  90. } u;
  91. /* number of times this key has been used */
  92. int tx_rx_count;
  93. #ifdef CONFIG_MAC80211_DEBUGFS
  94. struct {
  95. struct dentry *stalink;
  96. struct dentry *dir;
  97. int cnt;
  98. } debugfs;
  99. #endif
  100. /*
  101. * key config, must be last because it contains key
  102. * material as variable length member
  103. */
  104. struct ieee80211_key_conf conf;
  105. };
  106. struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
  107. const u8 *key_data,
  108. size_t seq_len, const u8 *seq);
  109. /*
  110. * Insert a key into data structures (sdata, sta if necessary)
  111. * to make it used, free old key.
  112. */
  113. int __must_check ieee80211_key_link(struct ieee80211_key *key,
  114. struct ieee80211_sub_if_data *sdata,
  115. struct sta_info *sta);
  116. void __ieee80211_key_free(struct ieee80211_key *key);
  117. void ieee80211_key_free(struct ieee80211_local *local,
  118. struct ieee80211_key *key);
  119. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
  120. bool uni, bool multi);
  121. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  122. int idx);
  123. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
  124. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
  125. void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
  126. #define key_mtx_dereference(local, ref) \
  127. rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx)))
  128. #endif /* IEEE80211_KEY_H */