xref: /linux/include/net/lib80211.h (revision 9410645520e9b820069761f3450ef6661418e279)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
27e272fcfSJohn W. Linville /*
37e272fcfSJohn W. Linville  * lib80211.h -- common bits for IEEE802.11 wireless drivers
47e272fcfSJohn W. Linville  *
57e272fcfSJohn W. Linville  * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
67e272fcfSJohn W. Linville  *
7274bfb8dSJohn W. Linville  * Some bits copied from old ieee80211 component, w/ original copyright
8274bfb8dSJohn W. Linville  * notices below:
9274bfb8dSJohn W. Linville  *
10274bfb8dSJohn W. Linville  * Original code based on Host AP (software wireless LAN access point) driver
11274bfb8dSJohn W. Linville  * for Intersil Prism2/2.5/3.
12274bfb8dSJohn W. Linville  *
13274bfb8dSJohn W. Linville  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
14274bfb8dSJohn W. Linville  * <j@w1.fi>
15274bfb8dSJohn W. Linville  * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
16274bfb8dSJohn W. Linville  *
17274bfb8dSJohn W. Linville  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
18274bfb8dSJohn W. Linville  * <jketreno@linux.intel.com>
19274bfb8dSJohn W. Linville  *
20274bfb8dSJohn W. Linville  * Copyright (c) 2004, Intel Corporation
21274bfb8dSJohn W. Linville  *
227e272fcfSJohn W. Linville  */
237e272fcfSJohn W. Linville 
247e272fcfSJohn W. Linville #ifndef LIB80211_H
257e272fcfSJohn W. Linville #define LIB80211_H
267e272fcfSJohn W. Linville 
27274bfb8dSJohn W. Linville #include <linux/types.h>
28274bfb8dSJohn W. Linville #include <linux/list.h>
2960063497SArun Sharma #include <linux/atomic.h>
30274bfb8dSJohn W. Linville #include <linux/if.h>
31274bfb8dSJohn W. Linville #include <linux/skbuff.h>
3272118015SJohn W. Linville #include <linux/ieee80211.h>
33a1eb5fe3SRami Rosen #include <linux/timer.h>
346bbefe86SDavid Howells #include <linux/seq_file.h>
356bbefe86SDavid Howells 
36274bfb8dSJohn W. Linville #define NUM_WEP_KEYS	4
37274bfb8dSJohn W. Linville 
38274bfb8dSJohn W. Linville enum {
39274bfb8dSJohn W. Linville 	IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
40274bfb8dSJohn W. Linville };
41274bfb8dSJohn W. Linville 
42de477254SPaul Gortmaker struct module;
43de477254SPaul Gortmaker 
44274bfb8dSJohn W. Linville struct lib80211_crypto_ops {
45274bfb8dSJohn W. Linville 	const char *name;
46274bfb8dSJohn W. Linville 	struct list_head list;
47274bfb8dSJohn W. Linville 
48274bfb8dSJohn W. Linville 	/* init new crypto context (e.g., allocate private data space,
49274bfb8dSJohn W. Linville 	 * select IV, etc.); returns NULL on failure or pointer to allocated
50274bfb8dSJohn W. Linville 	 * private data on success */
51274bfb8dSJohn W. Linville 	void *(*init) (int keyidx);
52274bfb8dSJohn W. Linville 
53274bfb8dSJohn W. Linville 	/* deinitialize crypto context and free allocated private data */
54274bfb8dSJohn W. Linville 	void (*deinit) (void *priv);
55274bfb8dSJohn W. Linville 
56274bfb8dSJohn W. Linville 	/* encrypt/decrypt return < 0 on error or >= 0 on success. The return
57274bfb8dSJohn W. Linville 	 * value from decrypt_mpdu is passed as the keyidx value for
58274bfb8dSJohn W. Linville 	 * decrypt_msdu. skb must have enough head and tail room for the
59274bfb8dSJohn W. Linville 	 * encryption; if not, error will be returned; these functions are
60274bfb8dSJohn W. Linville 	 * called for all MPDUs (i.e., fragments).
61274bfb8dSJohn W. Linville 	 */
62274bfb8dSJohn W. Linville 	int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
63274bfb8dSJohn W. Linville 	int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
64274bfb8dSJohn W. Linville 
65274bfb8dSJohn W. Linville 	/* These functions are called for full MSDUs, i.e. full frames.
66274bfb8dSJohn W. Linville 	 * These can be NULL if full MSDU operations are not needed. */
67274bfb8dSJohn W. Linville 	int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
68274bfb8dSJohn W. Linville 	int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
69274bfb8dSJohn W. Linville 			     void *priv);
70274bfb8dSJohn W. Linville 
71274bfb8dSJohn W. Linville 	int (*set_key) (void *key, int len, u8 * seq, void *priv);
72274bfb8dSJohn W. Linville 	int (*get_key) (void *key, int len, u8 * seq, void *priv);
73274bfb8dSJohn W. Linville 
74274bfb8dSJohn W. Linville 	/* procfs handler for printing out key information and possible
75274bfb8dSJohn W. Linville 	 * statistics */
766bbefe86SDavid Howells 	void (*print_stats) (struct seq_file *m, void *priv);
77274bfb8dSJohn W. Linville 
78274bfb8dSJohn W. Linville 	/* Crypto specific flag get/set for configuration settings */
79274bfb8dSJohn W. Linville 	unsigned long (*get_flags) (void *priv);
80274bfb8dSJohn W. Linville 	unsigned long (*set_flags) (unsigned long flags, void *priv);
81274bfb8dSJohn W. Linville 
82274bfb8dSJohn W. Linville 	/* maximum number of bytes added by encryption; encrypt buf is
83274bfb8dSJohn W. Linville 	 * allocated with extra_prefix_len bytes, copy of in_buf, and
84274bfb8dSJohn W. Linville 	 * extra_postfix_len; encrypt need not use all this space, but
85274bfb8dSJohn W. Linville 	 * the result must start at the beginning of the buffer and correct
86274bfb8dSJohn W. Linville 	 * length must be returned */
87274bfb8dSJohn W. Linville 	int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
88274bfb8dSJohn W. Linville 	int extra_msdu_prefix_len, extra_msdu_postfix_len;
89274bfb8dSJohn W. Linville 
90274bfb8dSJohn W. Linville 	struct module *owner;
91274bfb8dSJohn W. Linville };
92274bfb8dSJohn W. Linville 
93274bfb8dSJohn W. Linville struct lib80211_crypt_data {
94274bfb8dSJohn W. Linville 	struct list_head list;	/* delayed deletion list */
95*3a3d1afdSChristophe JAILLET 	const struct lib80211_crypto_ops *ops;
96274bfb8dSJohn W. Linville 	void *priv;
97274bfb8dSJohn W. Linville 	atomic_t refcnt;
98274bfb8dSJohn W. Linville };
99274bfb8dSJohn W. Linville 
100274bfb8dSJohn W. Linville struct lib80211_crypt_info {
101274bfb8dSJohn W. Linville 	char *name;
102274bfb8dSJohn W. Linville 	/* Most clients will already have a lock,
103274bfb8dSJohn W. Linville 	   so just point to that. */
104274bfb8dSJohn W. Linville 	spinlock_t *lock;
105274bfb8dSJohn W. Linville 
106274bfb8dSJohn W. Linville 	struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
107274bfb8dSJohn W. Linville 	int tx_keyidx;		/* default TX key index (crypt[tx_keyidx]) */
108274bfb8dSJohn W. Linville 	struct list_head crypt_deinit_list;
109274bfb8dSJohn W. Linville 	struct timer_list crypt_deinit_timer;
110274bfb8dSJohn W. Linville 	int crypt_quiesced;
111274bfb8dSJohn W. Linville };
112274bfb8dSJohn W. Linville 
1132ba4b32eSJohn W. Linville int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
1142ba4b32eSJohn W. Linville                                 spinlock_t *lock);
1152ba4b32eSJohn W. Linville void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
116*3a3d1afdSChristophe JAILLET int lib80211_register_crypto_ops(const struct lib80211_crypto_ops *ops);
117*3a3d1afdSChristophe JAILLET int lib80211_unregister_crypto_ops(const struct lib80211_crypto_ops *ops);
118*3a3d1afdSChristophe JAILLET const struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
119274bfb8dSJohn W. Linville void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
120274bfb8dSJohn W. Linville 				    struct lib80211_crypt_data **crypt);
121274bfb8dSJohn W. Linville 
1227e272fcfSJohn W. Linville #endif /* LIB80211_H */
123