ieee80211_crypto_none.c revision 147252
1138568Ssam/*-
2139530Ssam * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3138568Ssam * All rights reserved.
4138568Ssam *
5138568Ssam * Redistribution and use in source and binary forms, with or without
6138568Ssam * modification, are permitted provided that the following conditions
7138568Ssam * are met:
8138568Ssam * 1. Redistributions of source code must retain the above copyright
9138568Ssam *    notice, this list of conditions and the following disclaimer.
10138568Ssam * 2. Redistributions in binary form must reproduce the above copyright
11138568Ssam *    notice, this list of conditions and the following disclaimer in the
12138568Ssam *    documentation and/or other materials provided with the distribution.
13138568Ssam * 3. The name of the author may not be used to endorse or promote products
14138568Ssam *    derived from this software without specific prior written permission.
15138568Ssam *
16138568Ssam * Alternatively, this software may be distributed under the terms of the
17138568Ssam * GNU General Public License ("GPL") version 2 as published by the Free
18138568Ssam * Software Foundation.
19138568Ssam *
20138568Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21138568Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22138568Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23138568Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24138568Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25138568Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26138568Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27138568Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28138568Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29138568Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30138568Ssam */
31138568Ssam
32138568Ssam#include <sys/cdefs.h>
33138568Ssam__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_crypto_none.c 147252 2005-06-10 16:11:24Z sam $");
34138568Ssam
35138568Ssam/*
36138568Ssam * IEEE 802.11 NULL crypto support.
37138568Ssam */
38138568Ssam#include <sys/param.h>
39138568Ssam#include <sys/systm.h>
40138568Ssam#include <sys/mbuf.h>
41138568Ssam#include <sys/module.h>
42138568Ssam
43138568Ssam#include <sys/socket.h>
44138568Ssam
45138568Ssam#include <net/if.h>
46138568Ssam#include <net/if_media.h>
47138568Ssam#include <net/ethernet.h>
48138568Ssam
49138568Ssam#include <net80211/ieee80211_var.h>
50138568Ssam
51138568Ssamstatic	void *none_attach(struct ieee80211com *, struct ieee80211_key *);
52138568Ssamstatic	void none_detach(struct ieee80211_key *);
53138568Ssamstatic	int none_setkey(struct ieee80211_key *);
54138568Ssamstatic	int none_encap(struct ieee80211_key *, struct mbuf *, u_int8_t);
55147252Ssamstatic	int none_decap(struct ieee80211_key *, struct mbuf *, int);
56147045Ssamstatic	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
57147045Ssamstatic	int none_demic(struct ieee80211_key *, struct mbuf *, int);
58138568Ssam
59138568Ssamconst struct ieee80211_cipher ieee80211_cipher_none = {
60138568Ssam	.ic_name	= "NONE",
61138568Ssam	.ic_cipher	= IEEE80211_CIPHER_NONE,
62138568Ssam	.ic_header	= 0,
63138568Ssam	.ic_trailer	= 0,
64138568Ssam	.ic_miclen	= 0,
65138568Ssam	.ic_attach	= none_attach,
66138568Ssam	.ic_detach	= none_detach,
67138568Ssam	.ic_setkey	= none_setkey,
68138568Ssam	.ic_encap	= none_encap,
69138568Ssam	.ic_decap	= none_decap,
70138568Ssam	.ic_enmic	= none_enmic,
71138568Ssam	.ic_demic	= none_demic,
72138568Ssam};
73138568Ssam
74138568Ssamstatic void *
75138568Ssamnone_attach(struct ieee80211com *ic, struct ieee80211_key *k)
76138568Ssam{
77138568Ssam	return ic;		/* for diagnostics+stats */
78138568Ssam}
79138568Ssam
80138568Ssamstatic void
81138568Ssamnone_detach(struct ieee80211_key *k)
82138568Ssam{
83138568Ssam	(void) k;
84138568Ssam}
85138568Ssam
86138568Ssamstatic int
87138568Ssamnone_setkey(struct ieee80211_key *k)
88138568Ssam{
89138568Ssam	(void) k;
90138568Ssam	return 1;
91138568Ssam}
92138568Ssam
93138568Ssamstatic int
94138568Ssamnone_encap(struct ieee80211_key *k, struct mbuf *m, u_int8_t keyid)
95138568Ssam{
96138568Ssam	struct ieee80211com *ic = k->wk_private;
97138568Ssam#ifdef IEEE80211_DEBUG
98138568Ssam	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
99138568Ssam#endif
100138568Ssam
101138568Ssam	/*
102138568Ssam	 * The specified key is not setup; this can
103138568Ssam	 * happen, at least, when changing keys.
104138568Ssam	 */
105138568Ssam	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
106139510Ssam		"[%s] key id %u is not set (encap)\n",
107138568Ssam		ether_sprintf(wh->i_addr1), keyid>>6);
108138568Ssam	ic->ic_stats.is_tx_badcipher++;
109138568Ssam	return 0;
110138568Ssam}
111138568Ssam
112138568Ssamstatic int
113147252Ssamnone_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
114138568Ssam{
115138568Ssam	struct ieee80211com *ic = k->wk_private;
116138568Ssam#ifdef IEEE80211_DEBUG
117138568Ssam	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
118138568Ssam	const u_int8_t *ivp = (const u_int8_t *)&wh[1];
119138568Ssam#endif
120138568Ssam
121138568Ssam	/*
122138568Ssam	 * The specified key is not setup; this can
123138568Ssam	 * happen, at least, when changing keys.
124138568Ssam	 */
125138568Ssam	/* XXX useful to know dst too */
126138568Ssam	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
127139510Ssam		"[%s] key id %u is not set (decap)\n",
128138568Ssam		ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6);
129138568Ssam	ic->ic_stats.is_rx_badkeyid++;
130138568Ssam	return 0;
131138568Ssam}
132138568Ssam
133138568Ssamstatic int
134147045Ssamnone_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
135138568Ssam{
136138568Ssam	struct ieee80211com *ic = k->wk_private;
137138568Ssam
138138568Ssam	ic->ic_stats.is_tx_badcipher++;
139138568Ssam	return 0;
140138568Ssam}
141138568Ssam
142138568Ssamstatic int
143147045Ssamnone_demic(struct ieee80211_key *k, struct mbuf *m, int force)
144138568Ssam{
145138568Ssam	struct ieee80211com *ic = k->wk_private;
146138568Ssam
147138568Ssam	ic->ic_stats.is_rx_badkeyid++;
148138568Ssam	return 0;
149138568Ssam}
150