diff options
Diffstat (limited to 'drivers/net/wireless/hostap/hostap_crypt.c')
-rw-r--r-- | drivers/net/wireless/hostap/hostap_crypt.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/drivers/net/wireless/hostap/hostap_crypt.c b/drivers/net/wireless/hostap/hostap_crypt.c new file mode 100644 index 000000000000..de5390d502f1 --- /dev/null +++ b/drivers/net/wireless/hostap/hostap_crypt.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * Host AP crypto routines | ||
3 | * | ||
4 | * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. See README and COPYING for | ||
9 | * more details. | ||
10 | */ | ||
11 | |||
12 | struct hostap_crypto_alg { | ||
13 | struct list_head list; | ||
14 | struct hostap_crypto_ops *ops; | ||
15 | }; | ||
16 | |||
17 | |||
18 | struct hostap_crypto { | ||
19 | struct list_head algs; | ||
20 | spinlock_t lock; | ||
21 | }; | ||
22 | |||
23 | static struct hostap_crypto *hcrypt; | ||
24 | |||
25 | |||
26 | int hostap_register_crypto_ops(struct hostap_crypto_ops *ops) | ||
27 | { | ||
28 | unsigned long flags; | ||
29 | struct hostap_crypto_alg *alg; | ||
30 | |||
31 | if (hcrypt == NULL) | ||
32 | return -1; | ||
33 | |||
34 | alg = (struct hostap_crypto_alg *) kmalloc(sizeof(*alg), GFP_KERNEL); | ||
35 | if (alg == NULL) | ||
36 | return -ENOMEM; | ||
37 | |||
38 | memset(alg, 0, sizeof(*alg)); | ||
39 | alg->ops = ops; | ||
40 | |||
41 | spin_lock_irqsave(&hcrypt->lock, flags); | ||
42 | list_add(&alg->list, &hcrypt->algs); | ||
43 | spin_unlock_irqrestore(&hcrypt->lock, flags); | ||
44 | |||
45 | printk(KERN_DEBUG "hostap_crypt: registered algorithm '%s'\n", | ||
46 | ops->name); | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | |||
52 | int hostap_unregister_crypto_ops(struct hostap_crypto_ops *ops) | ||
53 | { | ||
54 | unsigned long flags; | ||
55 | struct list_head *ptr; | ||
56 | struct hostap_crypto_alg *del_alg = NULL; | ||
57 | |||
58 | if (hcrypt == NULL) | ||
59 | return -1; | ||
60 | |||
61 | spin_lock_irqsave(&hcrypt->lock, flags); | ||
62 | for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { | ||
63 | struct hostap_crypto_alg *alg = | ||
64 | (struct hostap_crypto_alg *) ptr; | ||
65 | if (alg->ops == ops) { | ||
66 | list_del(&alg->list); | ||
67 | del_alg = alg; | ||
68 | break; | ||
69 | } | ||
70 | } | ||
71 | spin_unlock_irqrestore(&hcrypt->lock, flags); | ||
72 | |||
73 | if (del_alg) { | ||
74 | printk(KERN_DEBUG "hostap_crypt: unregistered algorithm " | ||
75 | "'%s'\n", ops->name); | ||
76 | kfree(del_alg); | ||
77 | } | ||
78 | |||
79 | return del_alg ? 0 : -1; | ||
80 | } | ||
81 | |||
82 | |||
83 | struct hostap_crypto_ops * hostap_get_crypto_ops(const char *name) | ||
84 | { | ||
85 | unsigned long flags; | ||
86 | struct list_head *ptr; | ||
87 | struct hostap_crypto_alg *found_alg = NULL; | ||
88 | |||
89 | if (hcrypt == NULL) | ||
90 | return NULL; | ||
91 | |||
92 | spin_lock_irqsave(&hcrypt->lock, flags); | ||
93 | for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { | ||
94 | struct hostap_crypto_alg *alg = | ||
95 | (struct hostap_crypto_alg *) ptr; | ||
96 | if (strcmp(alg->ops->name, name) == 0) { | ||
97 | found_alg = alg; | ||
98 | break; | ||
99 | } | ||
100 | } | ||
101 | spin_unlock_irqrestore(&hcrypt->lock, flags); | ||
102 | |||
103 | if (found_alg) | ||
104 | return found_alg->ops; | ||
105 | else | ||
106 | return NULL; | ||
107 | } | ||
108 | |||
109 | |||
110 | static void * hostap_crypt_null_init(int keyidx) { return (void *) 1; } | ||
111 | static void hostap_crypt_null_deinit(void *priv) {} | ||
112 | |||
113 | static struct hostap_crypto_ops hostap_crypt_null = { | ||
114 | .name = "NULL", | ||
115 | .init = hostap_crypt_null_init, | ||
116 | .deinit = hostap_crypt_null_deinit, | ||
117 | .encrypt_mpdu = NULL, | ||
118 | .decrypt_mpdu = NULL, | ||
119 | .encrypt_msdu = NULL, | ||
120 | .decrypt_msdu = NULL, | ||
121 | .set_key = NULL, | ||
122 | .get_key = NULL, | ||
123 | .extra_prefix_len = 0, | ||
124 | .extra_postfix_len = 0 | ||
125 | }; | ||
126 | |||
127 | |||
128 | static int __init hostap_crypto_init(void) | ||
129 | { | ||
130 | hcrypt = (struct hostap_crypto *) kmalloc(sizeof(*hcrypt), GFP_KERNEL); | ||
131 | if (hcrypt == NULL) | ||
132 | return -ENOMEM; | ||
133 | |||
134 | memset(hcrypt, 0, sizeof(*hcrypt)); | ||
135 | INIT_LIST_HEAD(&hcrypt->algs); | ||
136 | spin_lock_init(&hcrypt->lock); | ||
137 | |||
138 | (void) hostap_register_crypto_ops(&hostap_crypt_null); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | |||
144 | static void __exit hostap_crypto_deinit(void) | ||
145 | { | ||
146 | struct list_head *ptr, *n; | ||
147 | |||
148 | if (hcrypt == NULL) | ||
149 | return; | ||
150 | |||
151 | for (ptr = hcrypt->algs.next, n = ptr->next; ptr != &hcrypt->algs; | ||
152 | ptr = n, n = ptr->next) { | ||
153 | struct hostap_crypto_alg *alg = | ||
154 | (struct hostap_crypto_alg *) ptr; | ||
155 | list_del(ptr); | ||
156 | printk(KERN_DEBUG "hostap_crypt: unregistered algorithm " | ||
157 | "'%s' (deinit)\n", alg->ops->name); | ||
158 | kfree(alg); | ||
159 | } | ||
160 | |||
161 | kfree(hcrypt); | ||
162 | } | ||
163 | |||
164 | |||
165 | EXPORT_SYMBOL(hostap_register_crypto_ops); | ||
166 | EXPORT_SYMBOL(hostap_unregister_crypto_ops); | ||
167 | EXPORT_SYMBOL(hostap_get_crypto_ops); | ||