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