key.h 3.8 KB

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