Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * lib80211.h -- common bits for IEEE802.11 wireless drivers
0004  *
0005  * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
0006  *
0007  * Some bits copied from old ieee80211 component, w/ original copyright
0008  * notices below:
0009  *
0010  * Original code based on Host AP (software wireless LAN access point) driver
0011  * for Intersil Prism2/2.5/3.
0012  *
0013  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
0014  * <j@w1.fi>
0015  * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
0016  *
0017  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
0018  * <jketreno@linux.intel.com>
0019  *
0020  * Copyright (c) 2004, Intel Corporation
0021  *
0022  */
0023 
0024 #ifndef LIB80211_H
0025 #define LIB80211_H
0026 
0027 #include <linux/types.h>
0028 #include <linux/list.h>
0029 #include <linux/atomic.h>
0030 #include <linux/if.h>
0031 #include <linux/skbuff.h>
0032 #include <linux/ieee80211.h>
0033 #include <linux/timer.h>
0034 #include <linux/seq_file.h>
0035 
0036 #define NUM_WEP_KEYS    4
0037 
0038 enum {
0039     IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
0040 };
0041 
0042 struct module;
0043 
0044 struct lib80211_crypto_ops {
0045     const char *name;
0046     struct list_head list;
0047 
0048     /* init new crypto context (e.g., allocate private data space,
0049      * select IV, etc.); returns NULL on failure or pointer to allocated
0050      * private data on success */
0051     void *(*init) (int keyidx);
0052 
0053     /* deinitialize crypto context and free allocated private data */
0054     void (*deinit) (void *priv);
0055 
0056     /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
0057      * value from decrypt_mpdu is passed as the keyidx value for
0058      * decrypt_msdu. skb must have enough head and tail room for the
0059      * encryption; if not, error will be returned; these functions are
0060      * called for all MPDUs (i.e., fragments).
0061      */
0062     int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
0063     int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
0064 
0065     /* These functions are called for full MSDUs, i.e. full frames.
0066      * These can be NULL if full MSDU operations are not needed. */
0067     int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
0068     int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
0069                  void *priv);
0070 
0071     int (*set_key) (void *key, int len, u8 * seq, void *priv);
0072     int (*get_key) (void *key, int len, u8 * seq, void *priv);
0073 
0074     /* procfs handler for printing out key information and possible
0075      * statistics */
0076     void (*print_stats) (struct seq_file *m, void *priv);
0077 
0078     /* Crypto specific flag get/set for configuration settings */
0079     unsigned long (*get_flags) (void *priv);
0080     unsigned long (*set_flags) (unsigned long flags, void *priv);
0081 
0082     /* maximum number of bytes added by encryption; encrypt buf is
0083      * allocated with extra_prefix_len bytes, copy of in_buf, and
0084      * extra_postfix_len; encrypt need not use all this space, but
0085      * the result must start at the beginning of the buffer and correct
0086      * length must be returned */
0087     int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
0088     int extra_msdu_prefix_len, extra_msdu_postfix_len;
0089 
0090     struct module *owner;
0091 };
0092 
0093 struct lib80211_crypt_data {
0094     struct list_head list;  /* delayed deletion list */
0095     struct lib80211_crypto_ops *ops;
0096     void *priv;
0097     atomic_t refcnt;
0098 };
0099 
0100 struct lib80211_crypt_info {
0101     char *name;
0102     /* Most clients will already have a lock,
0103        so just point to that. */
0104     spinlock_t *lock;
0105 
0106     struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
0107     int tx_keyidx;      /* default TX key index (crypt[tx_keyidx]) */
0108     struct list_head crypt_deinit_list;
0109     struct timer_list crypt_deinit_timer;
0110     int crypt_quiesced;
0111 };
0112 
0113 int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
0114                                 spinlock_t *lock);
0115 void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
0116 int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
0117 int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
0118 struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
0119 void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
0120                     struct lib80211_crypt_data **crypt);
0121 
0122 #endif /* LIB80211_H */