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