blob: 8b47d3a51cf8a4f04eeee4ff7fb0be60025a0670 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
John W. Linville7e272fc2008-09-24 18:13:14 -04002/*
3 * lib80211.h -- common bits for IEEE802.11 wireless drivers
4 *
5 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
6 *
John W. Linville274bfb82008-10-29 11:35:05 -04007 * 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 *
John W. Linville7e272fc2008-09-24 18:13:14 -040022 */
23
24#ifndef LIB80211_H
25#define LIB80211_H
26
John W. Linville274bfb82008-10-29 11:35:05 -040027#include <linux/types.h>
28#include <linux/list.h>
Arun Sharma600634972011-07-26 16:09:06 -070029#include <linux/atomic.h>
John W. Linville274bfb82008-10-29 11:35:05 -040030#include <linux/if.h>
31#include <linux/skbuff.h>
John W. Linville72118012008-09-30 21:43:03 -040032#include <linux/ieee80211.h>
Rami Rosena1eb5fe2008-11-19 09:37:43 +020033#include <linux/timer.h>
David Howells6bbefe82013-04-10 21:13:23 +010034#include <linux/seq_file.h>
35
John W. Linville274bfb82008-10-29 11:35:05 -040036#define NUM_WEP_KEYS 4
37
38enum {
39 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
40};
41
Paul Gortmakerde477252011-05-26 13:46:22 -040042struct module;
43
John W. Linville274bfb82008-10-29 11:35:05 -040044struct lib80211_crypto_ops {
45 const char *name;
46 struct list_head list;
47
48 /* init new crypto context (e.g., allocate private data space,
49 * select IV, etc.); returns NULL on failure or pointer to allocated
50 * private data on success */
51 void *(*init) (int keyidx);
52
53 /* deinitialize crypto context and free allocated private data */
54 void (*deinit) (void *priv);
55
John W. Linville274bfb82008-10-29 11:35:05 -040056 /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
57 * value from decrypt_mpdu is passed as the keyidx value for
58 * decrypt_msdu. skb must have enough head and tail room for the
59 * encryption; if not, error will be returned; these functions are
60 * called for all MPDUs (i.e., fragments).
61 */
62 int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
63 int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
64
65 /* These functions are called for full MSDUs, i.e. full frames.
66 * These can be NULL if full MSDU operations are not needed. */
67 int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
68 int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
69 void *priv);
70
71 int (*set_key) (void *key, int len, u8 * seq, void *priv);
72 int (*get_key) (void *key, int len, u8 * seq, void *priv);
73
74 /* procfs handler for printing out key information and possible
75 * statistics */
David Howells6bbefe82013-04-10 21:13:23 +010076 void (*print_stats) (struct seq_file *m, void *priv);
John W. Linville274bfb82008-10-29 11:35:05 -040077
78 /* Crypto specific flag get/set for configuration settings */
79 unsigned long (*get_flags) (void *priv);
80 unsigned long (*set_flags) (unsigned long flags, void *priv);
81
82 /* maximum number of bytes added by encryption; encrypt buf is
83 * allocated with extra_prefix_len bytes, copy of in_buf, and
84 * extra_postfix_len; encrypt need not use all this space, but
85 * the result must start at the beginning of the buffer and correct
86 * length must be returned */
87 int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
88 int extra_msdu_prefix_len, extra_msdu_postfix_len;
89
90 struct module *owner;
91};
92
93struct lib80211_crypt_data {
94 struct list_head list; /* delayed deletion list */
95 struct lib80211_crypto_ops *ops;
96 void *priv;
97 atomic_t refcnt;
98};
99
100struct lib80211_crypt_info {
101 char *name;
102 /* Most clients will already have a lock,
103 so just point to that. */
104 spinlock_t *lock;
105
106 struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
107 int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
108 struct list_head crypt_deinit_list;
109 struct timer_list crypt_deinit_timer;
110 int crypt_quiesced;
111};
112
John W. Linville2ba4b322008-11-11 16:00:06 -0500113int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
114 spinlock_t *lock);
115void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
John W. Linville274bfb82008-10-29 11:35:05 -0400116int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
117int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
118struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
John W. Linville274bfb82008-10-29 11:35:05 -0400119void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
120 struct lib80211_crypt_data **crypt);
John W. Linville274bfb82008-10-29 11:35:05 -0400121
John W. Linville7e272fc2008-09-24 18:13:14 -0400122#endif /* LIB80211_H */