ieee80211_crypto_none.c revision 1.1 1 1.1 dyoung /*-
2 1.1 dyoung * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 1.1 dyoung * All rights reserved.
4 1.1 dyoung *
5 1.1 dyoung * Redistribution and use in source and binary forms, with or without
6 1.1 dyoung * modification, are permitted provided that the following conditions
7 1.1 dyoung * are met:
8 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
9 1.1 dyoung * notice, this list of conditions and the following disclaimer.
10 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
12 1.1 dyoung * documentation and/or other materials provided with the distribution.
13 1.1 dyoung * 3. The name of the author may not be used to endorse or promote products
14 1.1 dyoung * derived from this software without specific prior written permission.
15 1.1 dyoung *
16 1.1 dyoung * Alternatively, this software may be distributed under the terms of the
17 1.1 dyoung * GNU General Public License ("GPL") version 2 as published by the Free
18 1.1 dyoung * Software Foundation.
19 1.1 dyoung *
20 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 dyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 dyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 dyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 dyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 dyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 dyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 dyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 dyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 dyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 dyoung */
31 1.1 dyoung
32 1.1 dyoung #include <sys/cdefs.h>
33 1.1 dyoung __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.3 2004/12/31 22:42:38 sam Exp $");
34 1.1 dyoung
35 1.1 dyoung /*
36 1.1 dyoung * IEEE 802.11 NULL crypto support.
37 1.1 dyoung */
38 1.1 dyoung #include <sys/param.h>
39 1.1 dyoung #include <sys/systm.h>
40 1.1 dyoung #include <sys/mbuf.h>
41 1.1 dyoung #include <sys/module.h>
42 1.1 dyoung
43 1.1 dyoung #include <sys/socket.h>
44 1.1 dyoung
45 1.1 dyoung #include <net/if.h>
46 1.1 dyoung #include <net/if_media.h>
47 1.1 dyoung #include <net/ethernet.h>
48 1.1 dyoung
49 1.1 dyoung #include <net80211/ieee80211_var.h>
50 1.1 dyoung
51 1.1 dyoung static void *none_attach(struct ieee80211com *, struct ieee80211_key *);
52 1.1 dyoung static void none_detach(struct ieee80211_key *);
53 1.1 dyoung static int none_setkey(struct ieee80211_key *);
54 1.1 dyoung static int none_encap(struct ieee80211_key *, struct mbuf *, u_int8_t);
55 1.1 dyoung static int none_decap(struct ieee80211_key *, struct mbuf *);
56 1.1 dyoung static int none_enmic(struct ieee80211_key *, struct mbuf *);
57 1.1 dyoung static int none_demic(struct ieee80211_key *, struct mbuf *);
58 1.1 dyoung
59 1.1 dyoung const struct ieee80211_cipher ieee80211_cipher_none = {
60 1.1 dyoung .ic_name = "NONE",
61 1.1 dyoung .ic_cipher = IEEE80211_CIPHER_NONE,
62 1.1 dyoung .ic_header = 0,
63 1.1 dyoung .ic_trailer = 0,
64 1.1 dyoung .ic_miclen = 0,
65 1.1 dyoung .ic_attach = none_attach,
66 1.1 dyoung .ic_detach = none_detach,
67 1.1 dyoung .ic_setkey = none_setkey,
68 1.1 dyoung .ic_encap = none_encap,
69 1.1 dyoung .ic_decap = none_decap,
70 1.1 dyoung .ic_enmic = none_enmic,
71 1.1 dyoung .ic_demic = none_demic,
72 1.1 dyoung };
73 1.1 dyoung
74 1.1 dyoung static void *
75 1.1 dyoung none_attach(struct ieee80211com *ic, struct ieee80211_key *k)
76 1.1 dyoung {
77 1.1 dyoung return ic; /* for diagnostics+stats */
78 1.1 dyoung }
79 1.1 dyoung
80 1.1 dyoung static void
81 1.1 dyoung none_detach(struct ieee80211_key *k)
82 1.1 dyoung {
83 1.1 dyoung (void) k;
84 1.1 dyoung }
85 1.1 dyoung
86 1.1 dyoung static int
87 1.1 dyoung none_setkey(struct ieee80211_key *k)
88 1.1 dyoung {
89 1.1 dyoung (void) k;
90 1.1 dyoung return 1;
91 1.1 dyoung }
92 1.1 dyoung
93 1.1 dyoung static int
94 1.1 dyoung none_encap(struct ieee80211_key *k, struct mbuf *m, u_int8_t keyid)
95 1.1 dyoung {
96 1.1 dyoung struct ieee80211com *ic = k->wk_private;
97 1.1 dyoung #ifdef IEEE80211_DEBUG
98 1.1 dyoung struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
99 1.1 dyoung #endif
100 1.1 dyoung
101 1.1 dyoung /*
102 1.1 dyoung * The specified key is not setup; this can
103 1.1 dyoung * happen, at least, when changing keys.
104 1.1 dyoung */
105 1.1 dyoung IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
106 1.1 dyoung "[%s] key id %u is not set (encap)\n",
107 1.1 dyoung ether_sprintf(wh->i_addr1), keyid>>6);
108 1.1 dyoung ic->ic_stats.is_tx_badcipher++;
109 1.1 dyoung return 0;
110 1.1 dyoung }
111 1.1 dyoung
112 1.1 dyoung static int
113 1.1 dyoung none_decap(struct ieee80211_key *k, struct mbuf *m)
114 1.1 dyoung {
115 1.1 dyoung struct ieee80211com *ic = k->wk_private;
116 1.1 dyoung #ifdef IEEE80211_DEBUG
117 1.1 dyoung struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
118 1.1 dyoung const u_int8_t *ivp = (const u_int8_t *)&wh[1];
119 1.1 dyoung #endif
120 1.1 dyoung
121 1.1 dyoung /*
122 1.1 dyoung * The specified key is not setup; this can
123 1.1 dyoung * happen, at least, when changing keys.
124 1.1 dyoung */
125 1.1 dyoung /* XXX useful to know dst too */
126 1.1 dyoung IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
127 1.1 dyoung "[%s] key id %u is not set (decap)\n",
128 1.1 dyoung ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6);
129 1.1 dyoung ic->ic_stats.is_rx_badkeyid++;
130 1.1 dyoung return 0;
131 1.1 dyoung }
132 1.1 dyoung
133 1.1 dyoung static int
134 1.1 dyoung none_enmic(struct ieee80211_key *k, struct mbuf *m)
135 1.1 dyoung {
136 1.1 dyoung struct ieee80211com *ic = k->wk_private;
137 1.1 dyoung
138 1.1 dyoung ic->ic_stats.is_tx_badcipher++;
139 1.1 dyoung return 0;
140 1.1 dyoung }
141 1.1 dyoung
142 1.1 dyoung static int
143 1.1 dyoung none_demic(struct ieee80211_key *k, struct mbuf *m)
144 1.1 dyoung {
145 1.1 dyoung struct ieee80211com *ic = k->wk_private;
146 1.1 dyoung
147 1.1 dyoung ic->ic_stats.is_rx_badkeyid++;
148 1.1 dyoung return 0;
149 1.1 dyoung }
150