ieee80211_key.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* ALG_TKIP
  17. * struct ieee80211_key::key is encoded as a 256-bit (32 byte) data block:
  18. * Temporal Encryption Key (128 bits)
  19. * Temporal Authenticator Tx MIC Key (64 bits)
  20. * Temporal Authenticator Rx MIC Key (64 bits)
  21. */
  22. #define WEP_IV_LEN 4
  23. #define WEP_ICV_LEN 4
  24. #define ALG_TKIP_KEY_LEN 32
  25. /* Starting offsets for each key */
  26. #define ALG_TKIP_TEMP_ENCR_KEY 0
  27. #define ALG_TKIP_TEMP_AUTH_TX_MIC_KEY 16
  28. #define ALG_TKIP_TEMP_AUTH_RX_MIC_KEY 24
  29. #define TKIP_IV_LEN 8
  30. #define TKIP_ICV_LEN 4
  31. #define ALG_CCMP_KEY_LEN 16
  32. #define CCMP_HDR_LEN 8
  33. #define CCMP_MIC_LEN 8
  34. #define CCMP_TK_LEN 16
  35. #define CCMP_PN_LEN 6
  36. #define NUM_RX_DATA_QUEUES 17
  37. struct ieee80211_local;
  38. struct ieee80211_sub_if_data;
  39. struct sta_info;
  40. /**
  41. * enum ieee80211_internal_key_flags - internal key flags
  42. *
  43. * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
  44. * in the hardware for TX crypto hardware acceleration.
  45. * @KEY_FLAG_REMOVE_FROM_HARDWARE: Indicates to the key code that this
  46. * key is present in the hardware (but it cannot be used for
  47. * hardware acceleration any more!)
  48. */
  49. enum ieee80211_internal_key_flags {
  50. KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
  51. KEY_FLAG_REMOVE_FROM_HARDWARE = BIT(1),
  52. };
  53. struct ieee80211_key {
  54. struct ieee80211_local *local;
  55. struct ieee80211_sub_if_data *sdata;
  56. struct sta_info *sta;
  57. struct list_head list;
  58. unsigned int flags;
  59. union {
  60. struct {
  61. /* last used TSC */
  62. u32 iv32;
  63. u16 iv16;
  64. u16 p1k[5];
  65. int tx_initialized;
  66. /* last received RSC */
  67. u32 iv32_rx[NUM_RX_DATA_QUEUES];
  68. u16 iv16_rx[NUM_RX_DATA_QUEUES];
  69. u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
  70. int rx_initialized[NUM_RX_DATA_QUEUES];
  71. } tkip;
  72. struct {
  73. u8 tx_pn[6];
  74. u8 rx_pn[NUM_RX_DATA_QUEUES][6];
  75. struct crypto_cipher *tfm;
  76. u32 replays; /* dot11RSNAStatsCCMPReplays */
  77. /* scratch buffers for virt_to_page() (crypto API) */
  78. #ifndef AES_BLOCK_LEN
  79. #define AES_BLOCK_LEN 16
  80. #endif
  81. u8 tx_crypto_buf[6 * AES_BLOCK_LEN];
  82. u8 rx_crypto_buf[6 * AES_BLOCK_LEN];
  83. } ccmp;
  84. } u;
  85. /* number of times this key has been used */
  86. int tx_rx_count;
  87. #ifdef CONFIG_MAC80211_DEBUGFS
  88. struct {
  89. struct dentry *stalink;
  90. struct dentry *dir;
  91. struct dentry *keylen;
  92. struct dentry *flags;
  93. struct dentry *keyidx;
  94. struct dentry *hw_key_idx;
  95. struct dentry *tx_rx_count;
  96. struct dentry *algorithm;
  97. struct dentry *tx_spec;
  98. struct dentry *rx_spec;
  99. struct dentry *replays;
  100. struct dentry *key;
  101. struct dentry *ifindex;
  102. } debugfs;
  103. #endif
  104. /*
  105. * key config, must be last because it contains key
  106. * material as variable length member
  107. */
  108. struct ieee80211_key_conf conf;
  109. };
  110. struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
  111. int idx,
  112. size_t key_len,
  113. const u8 *key_data);
  114. /*
  115. * Insert a key into data structures (sdata, sta if necessary)
  116. * to make it used, free old key.
  117. */
  118. void 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_key *key);
  122. void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, 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. #endif /* IEEE80211_KEY_H */