diff options
author | David Kilroy <kilroyd@googlemail.com> | 2009-02-04 18:05:51 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-02-13 13:44:13 -0500 |
commit | 4adb474b6b7e26e1318acab5e98864aa78f9b233 (patch) | |
tree | 741b26b984fd63b4e892cfeb7640794d7be509dd /drivers | |
parent | fb791b1cfb74937332a22d6bf06eed7866fbcc3c (diff) |
orinoco: Move MIC helpers into new file
No functional change.
Signed-off-by: David Kilroy <kilroyd@googlemail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wireless/orinoco/Makefile | 2 | ||||
-rw-r--r-- | drivers/net/wireless/orinoco/main.c | 76 | ||||
-rw-r--r-- | drivers/net/wireless/orinoco/mic.c | 79 | ||||
-rw-r--r-- | drivers/net/wireless/orinoco/mic.h | 22 |
4 files changed, 105 insertions, 74 deletions
diff --git a/drivers/net/wireless/orinoco/Makefile b/drivers/net/wireless/orinoco/Makefile index efde451a687d..9d3ef2941229 100644 --- a/drivers/net/wireless/orinoco/Makefile +++ b/drivers/net/wireless/orinoco/Makefile | |||
@@ -1,7 +1,7 @@ | |||
1 | # | 1 | # |
2 | # Makefile for the orinoco wireless device drivers. | 2 | # Makefile for the orinoco wireless device drivers. |
3 | # | 3 | # |
4 | orinoco-objs := main.o scan.o | 4 | orinoco-objs := main.o mic.o scan.o |
5 | 5 | ||
6 | obj-$(CONFIG_HERMES) += orinoco.o hermes.o hermes_dld.o | 6 | obj-$(CONFIG_HERMES) += orinoco.o hermes.o hermes_dld.o |
7 | obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o | 7 | obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o |
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c index 1063f8cc84e6..f0454440dd7b 100644 --- a/drivers/net/wireless/orinoco/main.c +++ b/drivers/net/wireless/orinoco/main.c | |||
@@ -90,12 +90,10 @@ | |||
90 | #include <linux/ieee80211.h> | 90 | #include <linux/ieee80211.h> |
91 | #include <net/iw_handler.h> | 91 | #include <net/iw_handler.h> |
92 | 92 | ||
93 | #include <linux/scatterlist.h> | ||
94 | #include <linux/crypto.h> | ||
95 | |||
96 | #include "hermes_rid.h" | 93 | #include "hermes_rid.h" |
97 | #include "hermes_dld.h" | 94 | #include "hermes_dld.h" |
98 | #include "scan.h" | 95 | #include "scan.h" |
96 | #include "mic.h" | ||
99 | 97 | ||
100 | #include "orinoco.h" | 98 | #include "orinoco.h" |
101 | 99 | ||
@@ -255,74 +253,6 @@ static int __orinoco_program_rids(struct net_device *dev); | |||
255 | static void __orinoco_set_multicast_list(struct net_device *dev); | 253 | static void __orinoco_set_multicast_list(struct net_device *dev); |
256 | 254 | ||
257 | /********************************************************************/ | 255 | /********************************************************************/ |
258 | /* Michael MIC crypto setup */ | ||
259 | /********************************************************************/ | ||
260 | #define MICHAEL_MIC_LEN 8 | ||
261 | static int orinoco_mic_init(struct orinoco_private *priv) | ||
262 | { | ||
263 | priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | ||
264 | if (IS_ERR(priv->tx_tfm_mic)) { | ||
265 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | ||
266 | "crypto API michael_mic\n"); | ||
267 | priv->tx_tfm_mic = NULL; | ||
268 | return -ENOMEM; | ||
269 | } | ||
270 | |||
271 | priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | ||
272 | if (IS_ERR(priv->rx_tfm_mic)) { | ||
273 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | ||
274 | "crypto API michael_mic\n"); | ||
275 | priv->rx_tfm_mic = NULL; | ||
276 | return -ENOMEM; | ||
277 | } | ||
278 | |||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | static void orinoco_mic_free(struct orinoco_private *priv) | ||
283 | { | ||
284 | if (priv->tx_tfm_mic) | ||
285 | crypto_free_hash(priv->tx_tfm_mic); | ||
286 | if (priv->rx_tfm_mic) | ||
287 | crypto_free_hash(priv->rx_tfm_mic); | ||
288 | } | ||
289 | |||
290 | static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, | ||
291 | u8 *da, u8 *sa, u8 priority, | ||
292 | u8 *data, size_t data_len, u8 *mic) | ||
293 | { | ||
294 | struct hash_desc desc; | ||
295 | struct scatterlist sg[2]; | ||
296 | u8 hdr[ETH_HLEN + 2]; /* size of header + padding */ | ||
297 | |||
298 | if (tfm_michael == NULL) { | ||
299 | printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); | ||
300 | return -1; | ||
301 | } | ||
302 | |||
303 | /* Copy header into buffer. We need the padding on the end zeroed */ | ||
304 | memcpy(&hdr[0], da, ETH_ALEN); | ||
305 | memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN); | ||
306 | hdr[ETH_ALEN*2] = priority; | ||
307 | hdr[ETH_ALEN*2+1] = 0; | ||
308 | hdr[ETH_ALEN*2+2] = 0; | ||
309 | hdr[ETH_ALEN*2+3] = 0; | ||
310 | |||
311 | /* Use scatter gather to MIC header and data in one go */ | ||
312 | sg_init_table(sg, 2); | ||
313 | sg_set_buf(&sg[0], hdr, sizeof(hdr)); | ||
314 | sg_set_buf(&sg[1], data, data_len); | ||
315 | |||
316 | if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN)) | ||
317 | return -1; | ||
318 | |||
319 | desc.tfm = tfm_michael; | ||
320 | desc.flags = 0; | ||
321 | return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr), | ||
322 | mic); | ||
323 | } | ||
324 | |||
325 | /********************************************************************/ | ||
326 | /* Internal helper functions */ | 256 | /* Internal helper functions */ |
327 | /********************************************************************/ | 257 | /********************************************************************/ |
328 | 258 | ||
@@ -1001,7 +931,7 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev) | |||
1001 | len = MICHAEL_MIC_LEN; | 931 | len = MICHAEL_MIC_LEN; |
1002 | } | 932 | } |
1003 | 933 | ||
1004 | michael_mic(priv->tx_tfm_mic, | 934 | orinoco_mic(priv->tx_tfm_mic, |
1005 | priv->tkip_key[priv->tx_key].tx_mic, | 935 | priv->tkip_key[priv->tx_key].tx_mic, |
1006 | eh->h_dest, eh->h_source, 0 /* priority */, | 936 | eh->h_dest, eh->h_source, 0 /* priority */, |
1007 | skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic); | 937 | skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic); |
@@ -1479,7 +1409,7 @@ static void orinoco_rx(struct net_device *dev, | |||
1479 | skb_trim(skb, skb->len - MICHAEL_MIC_LEN); | 1409 | skb_trim(skb, skb->len - MICHAEL_MIC_LEN); |
1480 | length -= MICHAEL_MIC_LEN; | 1410 | length -= MICHAEL_MIC_LEN; |
1481 | 1411 | ||
1482 | michael_mic(priv->rx_tfm_mic, | 1412 | orinoco_mic(priv->rx_tfm_mic, |
1483 | priv->tkip_key[key_id].rx_mic, | 1413 | priv->tkip_key[key_id].rx_mic, |
1484 | desc->addr1, | 1414 | desc->addr1, |
1485 | src, | 1415 | src, |
diff --git a/drivers/net/wireless/orinoco/mic.c b/drivers/net/wireless/orinoco/mic.c new file mode 100644 index 000000000000..c03e7f54d1b8 --- /dev/null +++ b/drivers/net/wireless/orinoco/mic.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* Orinoco MIC helpers | ||
2 | * | ||
3 | * See copyright notice in main.c | ||
4 | */ | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/string.h> | ||
7 | #include <linux/if_ether.h> | ||
8 | #include <linux/scatterlist.h> | ||
9 | #include <linux/crypto.h> | ||
10 | |||
11 | #include "orinoco.h" | ||
12 | #include "mic.h" | ||
13 | |||
14 | /********************************************************************/ | ||
15 | /* Michael MIC crypto setup */ | ||
16 | /********************************************************************/ | ||
17 | int orinoco_mic_init(struct orinoco_private *priv) | ||
18 | { | ||
19 | priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | ||
20 | if (IS_ERR(priv->tx_tfm_mic)) { | ||
21 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | ||
22 | "crypto API michael_mic\n"); | ||
23 | priv->tx_tfm_mic = NULL; | ||
24 | return -ENOMEM; | ||
25 | } | ||
26 | |||
27 | priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | ||
28 | if (IS_ERR(priv->rx_tfm_mic)) { | ||
29 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | ||
30 | "crypto API michael_mic\n"); | ||
31 | priv->rx_tfm_mic = NULL; | ||
32 | return -ENOMEM; | ||
33 | } | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | void orinoco_mic_free(struct orinoco_private *priv) | ||
39 | { | ||
40 | if (priv->tx_tfm_mic) | ||
41 | crypto_free_hash(priv->tx_tfm_mic); | ||
42 | if (priv->rx_tfm_mic) | ||
43 | crypto_free_hash(priv->rx_tfm_mic); | ||
44 | } | ||
45 | |||
46 | int orinoco_mic(struct crypto_hash *tfm_michael, u8 *key, | ||
47 | u8 *da, u8 *sa, u8 priority, | ||
48 | u8 *data, size_t data_len, u8 *mic) | ||
49 | { | ||
50 | struct hash_desc desc; | ||
51 | struct scatterlist sg[2]; | ||
52 | u8 hdr[ETH_HLEN + 2]; /* size of header + padding */ | ||
53 | |||
54 | if (tfm_michael == NULL) { | ||
55 | printk(KERN_WARNING "orinoco_mic: tfm_michael == NULL\n"); | ||
56 | return -1; | ||
57 | } | ||
58 | |||
59 | /* Copy header into buffer. We need the padding on the end zeroed */ | ||
60 | memcpy(&hdr[0], da, ETH_ALEN); | ||
61 | memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN); | ||
62 | hdr[ETH_ALEN*2] = priority; | ||
63 | hdr[ETH_ALEN*2+1] = 0; | ||
64 | hdr[ETH_ALEN*2+2] = 0; | ||
65 | hdr[ETH_ALEN*2+3] = 0; | ||
66 | |||
67 | /* Use scatter gather to MIC header and data in one go */ | ||
68 | sg_init_table(sg, 2); | ||
69 | sg_set_buf(&sg[0], hdr, sizeof(hdr)); | ||
70 | sg_set_buf(&sg[1], data, data_len); | ||
71 | |||
72 | if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN)) | ||
73 | return -1; | ||
74 | |||
75 | desc.tfm = tfm_michael; | ||
76 | desc.flags = 0; | ||
77 | return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr), | ||
78 | mic); | ||
79 | } | ||
diff --git a/drivers/net/wireless/orinoco/mic.h b/drivers/net/wireless/orinoco/mic.h new file mode 100644 index 000000000000..04d05bc566d6 --- /dev/null +++ b/drivers/net/wireless/orinoco/mic.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* Orinoco MIC helpers | ||
2 | * | ||
3 | * See copyright notice in main.c | ||
4 | */ | ||
5 | #ifndef _ORINOCO_MIC_H_ | ||
6 | #define _ORINOCO_MIC_H_ | ||
7 | |||
8 | #include <linux/types.h> | ||
9 | |||
10 | #define MICHAEL_MIC_LEN 8 | ||
11 | |||
12 | /* Forward declarations */ | ||
13 | struct orinoco_private; | ||
14 | struct crypto_hash; | ||
15 | |||
16 | int orinoco_mic_init(struct orinoco_private *priv); | ||
17 | void orinoco_mic_free(struct orinoco_private *priv); | ||
18 | int orinoco_mic(struct crypto_hash *tfm_michael, u8 *key, | ||
19 | u8 *da, u8 *sa, u8 priority, | ||
20 | u8 *data, size_t data_len, u8 *mic); | ||
21 | |||
22 | #endif /* ORINOCO_MIC_H */ | ||