lib80211.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * lib80211.h -- common bits for IEEE802.11 wireless drivers
  4. *
  5. * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
  6. *
  7. * Some bits copied from old ieee80211 component, w/ original copyright
  8. * notices below:
  9. *
  10. * Original code based on Host AP (software wireless LAN access point) driver
  11. * for Intersil Prism2/2.5/3.
  12. *
  13. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  14. * <j@w1.fi>
  15. * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
  16. *
  17. * Adaption to a generic IEEE 802.11 stack by James Ketrenos
  18. * <jketreno@linux.intel.com>
  19. *
  20. * Copyright (c) 2004, Intel Corporation
  21. *
  22. */
  23. #ifndef LIB80211_H
  24. #define LIB80211_H
  25. #include <linux/types.h>
  26. #include <linux/list.h>
  27. #include <linux/atomic.h>
  28. #include <linux/if.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/ieee80211.h>
  31. #include <linux/timer.h>
  32. #include <linux/seq_file.h>
  33. #define NUM_WEP_KEYS 4
  34. enum {
  35. IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
  36. };
  37. struct module;
  38. struct lib80211_crypto_ops {
  39. const char *name;
  40. struct list_head list;
  41. /* init new crypto context (e.g., allocate private data space,
  42. * select IV, etc.); returns NULL on failure or pointer to allocated
  43. * private data on success */
  44. void *(*init) (int keyidx);
  45. /* deinitialize crypto context and free allocated private data */
  46. void (*deinit) (void *priv);
  47. /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
  48. * value from decrypt_mpdu is passed as the keyidx value for
  49. * decrypt_msdu. skb must have enough head and tail room for the
  50. * encryption; if not, error will be returned; these functions are
  51. * called for all MPDUs (i.e., fragments).
  52. */
  53. int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
  54. int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
  55. /* These functions are called for full MSDUs, i.e. full frames.
  56. * These can be NULL if full MSDU operations are not needed. */
  57. int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
  58. int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
  59. void *priv);
  60. int (*set_key) (void *key, int len, u8 * seq, void *priv);
  61. int (*get_key) (void *key, int len, u8 * seq, void *priv);
  62. /* procfs handler for printing out key information and possible
  63. * statistics */
  64. void (*print_stats) (struct seq_file *m, void *priv);
  65. /* Crypto specific flag get/set for configuration settings */
  66. unsigned long (*get_flags) (void *priv);
  67. unsigned long (*set_flags) (unsigned long flags, void *priv);
  68. /* maximum number of bytes added by encryption; encrypt buf is
  69. * allocated with extra_prefix_len bytes, copy of in_buf, and
  70. * extra_postfix_len; encrypt need not use all this space, but
  71. * the result must start at the beginning of the buffer and correct
  72. * length must be returned */
  73. int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
  74. int extra_msdu_prefix_len, extra_msdu_postfix_len;
  75. struct module *owner;
  76. };
  77. struct lib80211_crypt_data {
  78. struct list_head list; /* delayed deletion list */
  79. struct lib80211_crypto_ops *ops;
  80. void *priv;
  81. atomic_t refcnt;
  82. };
  83. struct lib80211_crypt_info {
  84. char *name;
  85. /* Most clients will already have a lock,
  86. so just point to that. */
  87. spinlock_t *lock;
  88. struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
  89. int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
  90. struct list_head crypt_deinit_list;
  91. struct timer_list crypt_deinit_timer;
  92. int crypt_quiesced;
  93. };
  94. int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
  95. spinlock_t *lock);
  96. void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
  97. int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
  98. int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
  99. struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
  100. void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
  101. struct lib80211_crypt_data **crypt);
  102. #endif /* LIB80211_H */