remove ieee80211_wx_{get,set}_auth()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ieee80211 / ieee80211_crypt.c
CommitLineData
b453872c
JG
1/*
2 * Host AP crypto routines
3 *
85d32e7b 4 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
b453872c
JG
5 * Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. See README and COPYING for
10 * more details.
11 *
12 */
13
e3305626 14#include <linux/errno.h>
b453872c
JG
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/slab.h>
e3305626 18#include <linux/string.h>
b453872c
JG
19#include <net/ieee80211.h>
20
21MODULE_AUTHOR("Jouni Malinen");
22MODULE_DESCRIPTION("HostAP crypto");
23MODULE_LICENSE("GPL");
24
25struct ieee80211_crypto_alg {
26 struct list_head list;
27 struct ieee80211_crypto_ops *ops;
28};
29
e3305626
CH
30static LIST_HEAD(ieee80211_crypto_algs);
31static DEFINE_SPINLOCK(ieee80211_crypto_lock);
b453872c 32
0edd5b44 33void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
b453872c 34{
d6529237 35 struct ieee80211_crypt_data *entry, *next;
20d64713 36 unsigned long flags;
b453872c 37
20d64713 38 spin_lock_irqsave(&ieee->lock, flags);
d6529237 39 list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
b453872c
JG
40 if (atomic_read(&entry->refcnt) != 0 && !force)
41 continue;
42
e3305626 43 list_del(&entry->list);
b453872c
JG
44
45 if (entry->ops) {
46 entry->ops->deinit(entry->priv);
47 module_put(entry->ops->owner);
48 }
49 kfree(entry);
50 }
0ad0c3c6
JK
51 spin_unlock_irqrestore(&ieee->lock, flags);
52}
53
54/* After this, crypt_deinit_list won't accept new members */
55void ieee80211_crypt_quiescing(struct ieee80211_device *ieee)
56{
57 unsigned long flags;
58
59 spin_lock_irqsave(&ieee->lock, flags);
60 ieee->crypt_quiesced = 1;
20d64713 61 spin_unlock_irqrestore(&ieee->lock, flags);
b453872c
JG
62}
63
64void ieee80211_crypt_deinit_handler(unsigned long data)
65{
66 struct ieee80211_device *ieee = (struct ieee80211_device *)data;
0ad0c3c6 67 unsigned long flags;
b453872c 68
b453872c 69 ieee80211_crypt_deinit_entries(ieee, 0);
0ad0c3c6
JK
70
71 spin_lock_irqsave(&ieee->lock, flags);
72 if (!list_empty(&ieee->crypt_deinit_list) && !ieee->crypt_quiesced) {
b453872c
JG
73 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
74 "deletion list\n", ieee->dev->name);
75 ieee->crypt_deinit_timer.expires = jiffies + HZ;
76 add_timer(&ieee->crypt_deinit_timer);
77 }
0ad0c3c6 78 spin_unlock_irqrestore(&ieee->lock, flags);
b453872c
JG
79}
80
81void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee,
82 struct ieee80211_crypt_data **crypt)
83{
84 struct ieee80211_crypt_data *tmp;
85 unsigned long flags;
86
87 if (*crypt == NULL)
88 return;
89
90 tmp = *crypt;
91 *crypt = NULL;
92
93 /* must not run ops->deinit() while there may be pending encrypt or
94 * decrypt operations. Use a list of delayed deinits to avoid needing
95 * locking. */
96
97 spin_lock_irqsave(&ieee->lock, flags);
0ad0c3c6
JK
98 if (!ieee->crypt_quiesced) {
99 list_add(&tmp->list, &ieee->crypt_deinit_list);
100 if (!timer_pending(&ieee->crypt_deinit_timer)) {
101 ieee->crypt_deinit_timer.expires = jiffies + HZ;
102 add_timer(&ieee->crypt_deinit_timer);
103 }
b453872c
JG
104 }
105 spin_unlock_irqrestore(&ieee->lock, flags);
106}
107
108int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
109{
110 unsigned long flags;
111 struct ieee80211_crypto_alg *alg;
112
0da974f4 113 alg = kzalloc(sizeof(*alg), GFP_KERNEL);
b453872c
JG
114 if (alg == NULL)
115 return -ENOMEM;
116
b453872c
JG
117 alg->ops = ops;
118
e3305626
CH
119 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
120 list_add(&alg->list, &ieee80211_crypto_algs);
121 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
b453872c
JG
122
123 printk(KERN_DEBUG "ieee80211_crypt: registered algorithm '%s'\n",
124 ops->name);
125
126 return 0;
127}
128
129int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops)
130{
e3305626 131 struct ieee80211_crypto_alg *alg;
b453872c 132 unsigned long flags;
b453872c 133
e3305626
CH
134 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
135 list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
136 if (alg->ops == ops)
137 goto found;
b453872c 138 }
e3305626
CH
139 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
140 return -EINVAL;
141
d6529237 142 found:
e3305626 143 printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
d6529237 144 "'%s'\n", ops->name);
e3305626
CH
145 list_del(&alg->list);
146 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
147 kfree(alg);
148 return 0;
b453872c
JG
149}
150
0edd5b44 151struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name)
b453872c 152{
e3305626 153 struct ieee80211_crypto_alg *alg;
b453872c 154 unsigned long flags;
e3305626
CH
155
156 spin_lock_irqsave(&ieee80211_crypto_lock, flags);
157 list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
158 if (strcmp(alg->ops->name, name) == 0)
159 goto found;
b453872c 160 }
e3305626
CH
161 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
162 return NULL;
b453872c 163
d6529237 164 found:
e3305626
CH
165 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
166 return alg->ops;
b453872c
JG
167}
168
6eb6edf0 169static void *ieee80211_crypt_null_init(int keyidx)
0edd5b44
JG
170{
171 return (void *)1;
172}
e3305626 173
0edd5b44
JG
174static void ieee80211_crypt_null_deinit(void *priv)
175{
176}
b453872c
JG
177
178static struct ieee80211_crypto_ops ieee80211_crypt_null = {
74079fdc
JK
179 .name = "NULL",
180 .init = ieee80211_crypt_null_init,
181 .deinit = ieee80211_crypt_null_deinit,
74079fdc 182 .owner = THIS_MODULE,
b453872c
JG
183};
184
b453872c
JG
185static int __init ieee80211_crypto_init(void)
186{
e3305626 187 return ieee80211_register_crypto_ops(&ieee80211_crypt_null);
b453872c
JG
188}
189
b453872c
JG
190static void __exit ieee80211_crypto_deinit(void)
191{
e3305626
CH
192 ieee80211_unregister_crypto_ops(&ieee80211_crypt_null);
193 BUG_ON(!list_empty(&ieee80211_crypto_algs));
b453872c
JG
194}
195
196EXPORT_SYMBOL(ieee80211_crypt_deinit_entries);
197EXPORT_SYMBOL(ieee80211_crypt_deinit_handler);
198EXPORT_SYMBOL(ieee80211_crypt_delayed_deinit);
0ad0c3c6 199EXPORT_SYMBOL(ieee80211_crypt_quiescing);
b453872c
JG
200
201EXPORT_SYMBOL(ieee80211_register_crypto_ops);
202EXPORT_SYMBOL(ieee80211_unregister_crypto_ops);
203EXPORT_SYMBOL(ieee80211_get_crypto_ops);
204
205module_init(ieee80211_crypto_init);
206module_exit(ieee80211_crypto_deinit);