key.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. enum ieee80211_internal_tkip_state {
  56. TKIP_STATE_NOT_INIT,
  57. TKIP_STATE_PHASE1_DONE,
  58. TKIP_STATE_PHASE1_HW_UPLOADED,
  59. };
  60. struct tkip_ctx {
  61. u32 iv32;
  62. u16 iv16;
  63. u16 p1k[5];
  64. enum ieee80211_internal_tkip_state state;
  65. };
  66. struct ieee80211_key {
  67. struct ieee80211_local *local;
  68. struct ieee80211_sub_if_data *sdata;
  69. struct sta_info *sta;
  70. /* for sdata list */
  71. struct list_head list;
  72. /* for todo list */
  73. struct list_head todo;
  74. /* protected by todo lock! */
  75. unsigned int flags;
  76. union {
  77. struct {
  78. /* last used TSC */
  79. struct tkip_ctx tx;
  80. /* last received RSC */
  81. struct tkip_ctx rx[NUM_RX_DATA_QUEUES];
  82. } tkip;
  83. struct {
  84. u8 tx_pn[6];
  85. u8 rx_pn[NUM_RX_DATA_QUEUES][6];
  86. struct crypto_cipher *tfm;
  87. u32 replays; /* dot11RSNAStatsCCMPReplays */
  88. /* scratch buffers for virt_to_page() (crypto API) */
  89. #ifndef AES_BLOCK_LEN
  90. #define AES_BLOCK_LEN 16
  91. #endif
  92. u8 tx_crypto_buf[6 * AES_BLOCK_LEN];
  93. u8 rx_crypto_buf[6 * AES_BLOCK_LEN];
  94. } ccmp;
  95. struct {
  96. u8 tx_pn[6];
  97. u8 rx_pn[6];
  98. struct crypto_cipher *tfm;
  99. u32 replays; /* dot11RSNAStatsCMACReplays */
  100. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  101. /* scratch buffers for virt_to_page() (crypto API) */
  102. u8 tx_crypto_buf[2 * AES_BLOCK_LEN];
  103. u8 rx_crypto_buf[2 * AES_BLOCK_LEN];
  104. } aes_cmac;
  105. } u;
  106. /* number of times this key has been used */
  107. int tx_rx_count;
  108. #ifdef CONFIG_MAC80211_DEBUGFS
  109. struct {
  110. struct dentry *stalink;
  111. struct dentry *dir;
  112. int cnt;
  113. } debugfs;
  114. #endif
  115. /*
  116. * key config, must be last because it contains key
  117. * material as variable length member
  118. */
  119. struct ieee80211_key_conf conf;
  120. };
  121. struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
  122. int idx,
  123. size_t key_len,
  124. const u8 *key_data,
  125. size_t seq_len, const u8 *seq);
  126. /*
  127. * Insert a key into data structures (sdata, sta if necessary)
  128. * to make it used, free old key.
  129. */
  130. void ieee80211_key_link(struct ieee80211_key *key,
  131. struct ieee80211_sub_if_data *sdata,
  132. struct sta_info *sta);
  133. void ieee80211_key_free(struct ieee80211_key *key);
  134. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
  135. void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
  136. int idx);
  137. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
  138. void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
  139. void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
  140. void ieee80211_key_todo(void);
  141. #endif /* IEEE80211_KEY_H */