key.h 3.7 KB

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