key.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 WEP_IV_LEN 4
  17. #define WEP_ICV_LEN 4
  18. #define ALG_TKIP_KEY_LEN 32
  19. #define ALG_CCMP_KEY_LEN 16
  20. #define CCMP_HDR_LEN 8
  21. #define CCMP_MIC_LEN 8
  22. #define CCMP_TK_LEN 16
  23. #define CCMP_PN_LEN 6
  24. #define TKIP_IV_LEN 8
  25. #define TKIP_ICV_LEN 4
  26. #define NUM_RX_DATA_QUEUES 17
  27. struct ieee80211_local;
  28. struct ieee80211_sub_if_data;
  29. struct sta_info;
  30. /**
  31. * enum ieee80211_internal_key_flags - internal key flags
  32. *
  33. * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
  34. * in the hardware for TX crypto hardware acceleration.
  35. * @KEY_FLAG_TODO_DELETE: Key is marked for deletion and will, after an
  36. * RCU grace period, no longer be reachable other than from the
  37. * todo list.
  38. * @KEY_FLAG_TODO_HWACCEL_ADD: Key needs to be added to hardware acceleration.
  39. * @KEY_FLAG_TODO_HWACCEL_REMOVE: Key needs to be removed from hardware
  40. * acceleration.
  41. * @KEY_FLAG_TODO_DEFKEY: Key is default key and debugfs needs to be updated.
  42. * @KEY_FLAG_TODO_ADD_DEBUGFS: Key needs to be added to debugfs.
  43. * @KEY_FLAG_TODO_DEFMGMTKEY: Key is default management key and debugfs needs
  44. * to be updated.
  45. */
  46. enum ieee80211_internal_key_flags {
  47. KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
  48. KEY_FLAG_TODO_DELETE = BIT(1),
  49. KEY_FLAG_TODO_HWACCEL_ADD = BIT(2),
  50. KEY_FLAG_TODO_HWACCEL_REMOVE = BIT(3),
  51. KEY_FLAG_TODO_DEFKEY = BIT(4),
  52. KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5),
  53. KEY_FLAG_TODO_DEFMGMTKEY = BIT(6),
  54. };
  55. struct tkip_ctx {
  56. u32 iv32;
  57. u16 iv16;
  58. u16 p1k[5];
  59. int initialized;
  60. };
  61. struct ieee80211_key {
  62. struct ieee80211_local *local;
  63. struct ieee80211_sub_if_data *sdata;
  64. struct sta_info *sta;
  65. /* for sdata list */
  66. struct list_head list;
  67. /* for todo list */
  68. struct list_head todo;
  69. /* protected by todo lock! */
  70. unsigned int flags;
  71. union {
  72. struct {
  73. /* last used TSC */
  74. struct tkip_ctx tx;
  75. /* last received RSC */
  76. struct tkip_ctx rx[NUM_RX_DATA_QUEUES];
  77. } tkip;
  78. struct {
  79. u8 tx_pn[6];
  80. u8 rx_pn[NUM_RX_DATA_QUEUES][6];
  81. struct crypto_cipher *tfm;
  82. u32 replays; /* dot11RSNAStatsCCMPReplays */
  83. /* scratch buffers for virt_to_page() (crypto API) */
  84. #ifndef AES_BLOCK_LEN
  85. #define AES_BLOCK_LEN 16
  86. #endif
  87. u8 tx_crypto_buf[6 * AES_BLOCK_LEN];
  88. u8 rx_crypto_buf[6 * AES_BLOCK_LEN];
  89. } ccmp;
  90. struct {
  91. u8 tx_pn[6];
  92. u8 rx_pn[6];
  93. struct crypto_cipher *tfm;
  94. u32 replays; /* dot11RSNAStatsCMACReplays */
  95. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  96. /* scratch buffers for virt_to_page() (crypto API) */
  97. u8 tx_crypto_buf[2 * AES_BLOCK_LEN];
  98. u8 rx_crypto_buf[2 * AES_BLOCK_LEN];
  99. } aes_cmac;
  100. } u;
  101. /* number of times this key has been used */
  102. int tx_rx_count;
  103. #ifdef CONFIG_MAC80211_DEBUGFS
  104. struct {
  105. struct dentry *stalink;
  106. struct dentry *dir;
  107. struct dentry *keylen;
  108. struct dentry *flags;
  109. struct dentry *keyidx;
  110. struct dentry *hw_key_idx;
  111. struct dentry *tx_rx_count;
  112. struct dentry *algorithm;
  113. struct dentry *tx_spec;
  114. struct dentry *rx_spec;
  115. struct dentry *replays;
  116. struct dentry *icverrors;
  117. struct dentry *key;
  118. struct dentry *ifindex;
  119. int cnt;
  120. } debugfs;
  121. #endif
  122. /*
  123. * key config, must be last because it contains key
  124. * material as variable length member
  125. */
  126. struct ieee80211_key_conf conf;
  127. };
  128. struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
  129. int idx,
  130. size_t key_len,
  131. const u8 *key_data,
  132. size_t seq_len, const u8 *seq);
  133. /*
  134. * Insert a key into data structures (sdata, sta if necessary)
  135. * to make it used, free old key.
  136. */
  137. void ieee80211_key_link(struct ieee80211_key *key,
  138. struct ieee80211_sub_if_data *sdata,
  139. struct sta_info *sta);
  140. void ieee80211_key_free(struct ieee80211_key *key);
  141. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
  142. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  143. int idx);
  144. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
  145. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
  146. void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
  147. void ieee80211_key_todo(void);
  148. #endif /* IEEE80211_KEY_H */