Skip to content

Commit f0706e8

Browse files
Jiri Bencdavem330
authored andcommitted
[MAC80211]: Add mac80211 wireless stack.
Add mac80211, the IEEE 802.11 software MAC layer. Signed-off-by: Jiri Benc <jbenc@suse.cz> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent a9de8ce commit f0706e8

34 files changed

Lines changed: 16110 additions & 2 deletions

‎include/net/mac80211.h‎

Lines changed: 1045 additions & 0 deletions
Large diffs are not rendered by default.

‎net/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ config FIB_RULES
220220
menu "Wireless"
221221

222222
source "net/wireless/Kconfig"
223+
source "net/mac80211/Kconfig"
223224
source "net/ieee80211/Kconfig"
224225

225226
endmenu

‎net/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ obj-$(CONFIG_ECONET) += econet/
4545
obj-$(CONFIG_VLAN_8021Q) += 8021q/
4646
obj-$(CONFIG_IP_DCCP) += dccp/
4747
obj-$(CONFIG_IP_SCTP) += sctp/
48+
obj-y += wireless/
49+
obj-$(CONFIG_MAC80211) += mac80211/
4850
obj-$(CONFIG_IEEE80211) += ieee80211/
4951
obj-$(CONFIG_TIPC) += tipc/
5052
obj-$(CONFIG_NETLABEL) += netlabel/
@@ -53,5 +55,3 @@ obj-$(CONFIG_IUCV) += iucv/
5355
ifeq ($(CONFIG_NET),y)
5456
obj-$(CONFIG_SYSCTL) += sysctl_net.o
5557
endif
56-
57-
obj-y += wireless/

‎net/mac80211/Kconfig‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
config MAC80211
2+
tristate "Generic IEEE 802.11 Networking Stack (mac80211)"
3+
depends on EXPERIMENTAL
4+
select CRYPTO
5+
select CRYPTO_ECB
6+
select CRYPTO_ARC4
7+
select CRYPTO_AES
8+
select CRC32
9+
select WIRELESS_EXT
10+
select CFG80211
11+
select NET_SCH_FIFO
12+
---help---
13+
This option enables the hardware independent IEEE 802.11
14+
networking stack.
15+
16+
config MAC80211_LEDS
17+
bool "Enable LED triggers"
18+
depends on MAC80211 && LEDS_TRIGGERS
19+
---help---
20+
This option enables a few LED triggers for different
21+
packet receive/transmit events.
22+
23+
config MAC80211_DEBUG
24+
bool "Enable debugging output"
25+
depends on MAC80211
26+
---help---
27+
This option will enable debug tracing output for the
28+
ieee80211 network stack.
29+
30+
If you are not trying to debug or develop the ieee80211
31+
subsystem, you most likely want to say N here.
32+
33+
config MAC80211_VERBOSE_DEBUG
34+
bool "Verbose debugging output"
35+
depends on MAC80211_DEBUG
36+
37+
config MAC80211_LOWTX_FRAME_DUMP
38+
bool "Debug frame dumping"
39+
depends on MAC80211_DEBUG
40+
---help---
41+
Selecting this option will cause the stack to
42+
print a message for each frame that is handed
43+
to the lowlevel driver for transmission. This
44+
message includes all MAC addresses and the
45+
frame control field.
46+
47+
If unsure, say N and insert the debugging code
48+
you require into the driver you are debugging.
49+
50+
config TKIP_DEBUG
51+
bool "TKIP debugging"
52+
depends on MAC80211_DEBUG
53+
54+
config MAC80211_DEBUG_COUNTERS
55+
bool "Extra statistics for TX/RX debugging"
56+
depends on MAC80211_DEBUG
57+
58+
config MAC80211_IBSS_DEBUG
59+
bool "Support for IBSS testing"
60+
depends on MAC80211_DEBUG
61+
---help---
62+
Say Y here if you intend to debug the IBSS code.
63+
64+
config MAC80211_VERBOSE_PS_DEBUG
65+
bool "Verbose powersave mode debugging"
66+
depends on MAC80211_DEBUG
67+
---help---
68+
Say Y here to print out verbose powersave
69+
mode debug messages.

‎net/mac80211/Makefile‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
obj-$(CONFIG_MAC80211) += mac80211.o rc80211_simple.o
2+
3+
mac80211-objs-$(CONFIG_MAC80211_LEDS) += ieee80211_led.o
4+
5+
mac80211-objs := \
6+
ieee80211.o \
7+
ieee80211_ioctl.o \
8+
sta_info.o \
9+
wep.o \
10+
wpa.o \
11+
ieee80211_sta.o \
12+
ieee80211_iface.o \
13+
ieee80211_rate.o \
14+
michael.o \
15+
tkip.o \
16+
aes_ccm.o \
17+
wme.o \
18+
ieee80211_cfg.o \
19+
$(mac80211-objs-y)

‎net/mac80211/aes_ccm.c‎

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright 2003-2004, Instant802 Networks, Inc.
3+
* Copyright 2005-2006, Devicescape Software, Inc.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*/
9+
10+
#include <linux/types.h>
11+
#include <linux/crypto.h>
12+
#include <linux/err.h>
13+
#include <asm/scatterlist.h>
14+
15+
#include <net/mac80211.h>
16+
#include "ieee80211_key.h"
17+
#include "aes_ccm.h"
18+
19+
20+
static void ieee80211_aes_encrypt(struct crypto_cipher *tfm,
21+
const u8 pt[16], u8 ct[16])
22+
{
23+
crypto_cipher_encrypt_one(tfm, ct, pt);
24+
}
25+
26+
27+
static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
28+
u8 *b, u8 *s_0, u8 *a)
29+
{
30+
int i;
31+
32+
ieee80211_aes_encrypt(tfm, b_0, b);
33+
34+
/* Extra Authenticate-only data (always two AES blocks) */
35+
for (i = 0; i < AES_BLOCK_LEN; i++)
36+
aad[i] ^= b[i];
37+
ieee80211_aes_encrypt(tfm, aad, b);
38+
39+
aad += AES_BLOCK_LEN;
40+
41+
for (i = 0; i < AES_BLOCK_LEN; i++)
42+
aad[i] ^= b[i];
43+
ieee80211_aes_encrypt(tfm, aad, a);
44+
45+
/* Mask out bits from auth-only-b_0 */
46+
b_0[0] &= 0x07;
47+
48+
/* S_0 is used to encrypt T (= MIC) */
49+
b_0[14] = 0;
50+
b_0[15] = 0;
51+
ieee80211_aes_encrypt(tfm, b_0, s_0);
52+
}
53+
54+
55+
void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
56+
u8 *b_0, u8 *aad, u8 *data, size_t data_len,
57+
u8 *cdata, u8 *mic)
58+
{
59+
int i, j, last_len, num_blocks;
60+
u8 *pos, *cpos, *b, *s_0, *e;
61+
62+
b = scratch;
63+
s_0 = scratch + AES_BLOCK_LEN;
64+
e = scratch + 2 * AES_BLOCK_LEN;
65+
66+
num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
67+
last_len = data_len % AES_BLOCK_LEN;
68+
aes_ccm_prepare(tfm, b_0, aad, b, s_0, b);
69+
70+
/* Process payload blocks */
71+
pos = data;
72+
cpos = cdata;
73+
for (j = 1; j <= num_blocks; j++) {
74+
int blen = (j == num_blocks && last_len) ?
75+
last_len : AES_BLOCK_LEN;
76+
77+
/* Authentication followed by encryption */
78+
for (i = 0; i < blen; i++)
79+
b[i] ^= pos[i];
80+
ieee80211_aes_encrypt(tfm, b, b);
81+
82+
b_0[14] = (j >> 8) & 0xff;
83+
b_0[15] = j & 0xff;
84+
ieee80211_aes_encrypt(tfm, b_0, e);
85+
for (i = 0; i < blen; i++)
86+
*cpos++ = *pos++ ^ e[i];
87+
}
88+
89+
for (i = 0; i < CCMP_MIC_LEN; i++)
90+
mic[i] = b[i] ^ s_0[i];
91+
}
92+
93+
94+
int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
95+
u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
96+
u8 *mic, u8 *data)
97+
{
98+
int i, j, last_len, num_blocks;
99+
u8 *pos, *cpos, *b, *s_0, *a;
100+
101+
b = scratch;
102+
s_0 = scratch + AES_BLOCK_LEN;
103+
a = scratch + 2 * AES_BLOCK_LEN;
104+
105+
num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
106+
last_len = data_len % AES_BLOCK_LEN;
107+
aes_ccm_prepare(tfm, b_0, aad, b, s_0, a);
108+
109+
/* Process payload blocks */
110+
cpos = cdata;
111+
pos = data;
112+
for (j = 1; j <= num_blocks; j++) {
113+
int blen = (j == num_blocks && last_len) ?
114+
last_len : AES_BLOCK_LEN;
115+
116+
/* Decryption followed by authentication */
117+
b_0[14] = (j >> 8) & 0xff;
118+
b_0[15] = j & 0xff;
119+
ieee80211_aes_encrypt(tfm, b_0, b);
120+
for (i = 0; i < blen; i++) {
121+
*pos = *cpos++ ^ b[i];
122+
a[i] ^= *pos++;
123+
}
124+
125+
ieee80211_aes_encrypt(tfm, a, a);
126+
}
127+
128+
for (i = 0; i < CCMP_MIC_LEN; i++) {
129+
if ((mic[i] ^ s_0[i]) != a[i])
130+
return -1;
131+
}
132+
133+
return 0;
134+
}
135+
136+
137+
struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[])
138+
{
139+
struct crypto_cipher *tfm;
140+
141+
tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
142+
if (IS_ERR(tfm))
143+
return NULL;
144+
145+
crypto_cipher_setkey(tfm, key, ALG_CCMP_KEY_LEN);
146+
147+
return tfm;
148+
}
149+
150+
151+
void ieee80211_aes_key_free(struct crypto_cipher *tfm)
152+
{
153+
if (tfm)
154+
crypto_free_cipher(tfm);
155+
}

‎net/mac80211/aes_ccm.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2003-2004, Instant802 Networks, Inc.
3+
* Copyright 2006, Devicescape Software, Inc.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*/
9+
10+
#ifndef AES_CCM_H
11+
#define AES_CCM_H
12+
13+
#include <linux/crypto.h>
14+
15+
#define AES_BLOCK_LEN 16
16+
17+
struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[]);
18+
void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
19+
u8 *b_0, u8 *aad, u8 *data, size_t data_len,
20+
u8 *cdata, u8 *mic);
21+
int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
22+
u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
23+
u8 *mic, u8 *data);
24+
void ieee80211_aes_key_free(struct crypto_cipher *tfm);
25+
26+
#endif /* AES_CCM_H */

0 commit comments

Comments
 (0)