1138568Ssam/*-
2178354Ssam * Copyright (c) 2002-2008 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 *
14138568Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15138568Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16138568Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17138568Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18138568Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19138568Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20138568Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21138568Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22138568Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23138568Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24138568Ssam */
25138568Ssam
26138568Ssam#include <sys/cdefs.h>
27138568Ssam__FBSDID("$FreeBSD$");
28138568Ssam
29138568Ssam/*
30138568Ssam * IEEE 802.11 NULL crypto support.
31138568Ssam */
32178354Ssam#include "opt_wlan.h"
33178354Ssam
34138568Ssam#include <sys/param.h>
35283614Sglebius#include <sys/kernel.h>
36295126Sglebius#include <sys/malloc.h>
37283567Sglebius#include <sys/systm.h>
38138568Ssam#include <sys/mbuf.h>
39138568Ssam#include <sys/module.h>
40138568Ssam
41138568Ssam#include <sys/socket.h>
42138568Ssam
43138568Ssam#include <net/if.h>
44138568Ssam#include <net/if_media.h>
45138568Ssam#include <net/ethernet.h>
46138568Ssam
47138568Ssam#include <net80211/ieee80211_var.h>
48138568Ssam
49178354Ssamstatic	void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
50138568Ssamstatic	void none_detach(struct ieee80211_key *);
51138568Ssamstatic	int none_setkey(struct ieee80211_key *);
52288526Sadrianstatic	void none_setiv(struct ieee80211_key *, uint8_t *);
53288523Sadrianstatic	int none_encap(struct ieee80211_key *, struct mbuf *);
54147252Ssamstatic	int none_decap(struct ieee80211_key *, struct mbuf *, int);
55147045Ssamstatic	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
56147045Ssamstatic	int none_demic(struct ieee80211_key *, struct mbuf *, int);
57138568Ssam
58138568Ssamconst struct ieee80211_cipher ieee80211_cipher_none = {
59138568Ssam	.ic_name	= "NONE",
60138568Ssam	.ic_cipher	= IEEE80211_CIPHER_NONE,
61138568Ssam	.ic_header	= 0,
62138568Ssam	.ic_trailer	= 0,
63138568Ssam	.ic_miclen	= 0,
64138568Ssam	.ic_attach	= none_attach,
65138568Ssam	.ic_detach	= none_detach,
66138568Ssam	.ic_setkey	= none_setkey,
67288526Sadrian	.ic_setiv	= none_setiv,
68138568Ssam	.ic_encap	= none_encap,
69138568Ssam	.ic_decap	= none_decap,
70138568Ssam	.ic_enmic	= none_enmic,
71138568Ssam	.ic_demic	= none_demic,
72138568Ssam};
73138568Ssam
74138568Ssamstatic void *
75178354Ssamnone_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
76138568Ssam{
77178354Ssam	return vap;		/* 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
93288526Sadrianstatic void
94288526Sadriannone_setiv(struct ieee80211_key *k, uint8_t *ivp)
95288526Sadrian{
96288526Sadrian}
97288526Sadrian
98138568Ssamstatic int
99288523Sadriannone_encap(struct ieee80211_key *k, struct mbuf *m)
100138568Ssam{
101178354Ssam	struct ieee80211vap *vap = k->wk_private;
102138568Ssam#ifdef IEEE80211_DEBUG
103138568Ssam	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
104288523Sadrian	uint8_t keyid;
105138568Ssam
106288523Sadrian	keyid = ieee80211_crypto_get_keyid(vap, k);
107288523Sadrian
108138568Ssam	/*
109138568Ssam	 * The specified key is not setup; this can
110138568Ssam	 * happen, at least, when changing keys.
111138568Ssam	 */
112178354Ssam	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
113288523Sadrian	    "key id %u is not set (encap)", keyid);
114300232Savos#endif
115178354Ssam	vap->iv_stats.is_tx_badcipher++;
116138568Ssam	return 0;
117138568Ssam}
118138568Ssam
119138568Ssamstatic int
120147252Ssamnone_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
121138568Ssam{
122178354Ssam	struct ieee80211vap *vap = k->wk_private;
123138568Ssam#ifdef IEEE80211_DEBUG
124138568Ssam	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
125170530Ssam	const uint8_t *ivp = (const uint8_t *)&wh[1];
126138568Ssam#endif
127138568Ssam
128138568Ssam	/*
129138568Ssam	 * The specified key is not setup; this can
130138568Ssam	 * happen, at least, when changing keys.
131138568Ssam	 */
132138568Ssam	/* XXX useful to know dst too */
133178354Ssam	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
134178354Ssam	    "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
135178354Ssam	vap->iv_stats.is_rx_badkeyid++;
136138568Ssam	return 0;
137138568Ssam}
138138568Ssam
139138568Ssamstatic int
140147045Ssamnone_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
141138568Ssam{
142178354Ssam	struct ieee80211vap *vap = k->wk_private;
143138568Ssam
144178354Ssam	vap->iv_stats.is_tx_badcipher++;
145138568Ssam	return 0;
146138568Ssam}
147138568Ssam
148138568Ssamstatic int
149147045Ssamnone_demic(struct ieee80211_key *k, struct mbuf *m, int force)
150138568Ssam{
151178354Ssam	struct ieee80211vap *vap = k->wk_private;
152138568Ssam
153178354Ssam	vap->iv_stats.is_rx_badkeyid++;
154138568Ssam	return 0;
155138568Ssam}
156