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