xref: /freebsd/sys/net80211/ieee80211_crypto_none.c (revision 81c04d11091b4fe7aa91cd8eafd5de0705735fb5)
18a1b9b6aSSam Leffler /*-
2b032f27cSSam Leffler  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
38a1b9b6aSSam Leffler  * All rights reserved.
48a1b9b6aSSam Leffler  *
58a1b9b6aSSam Leffler  * Redistribution and use in source and binary forms, with or without
68a1b9b6aSSam Leffler  * modification, are permitted provided that the following conditions
78a1b9b6aSSam Leffler  * are met:
88a1b9b6aSSam Leffler  * 1. Redistributions of source code must retain the above copyright
98a1b9b6aSSam Leffler  *    notice, this list of conditions and the following disclaimer.
108a1b9b6aSSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
118a1b9b6aSSam Leffler  *    notice, this list of conditions and the following disclaimer in the
128a1b9b6aSSam Leffler  *    documentation and/or other materials provided with the distribution.
138a1b9b6aSSam Leffler  *
148a1b9b6aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
158a1b9b6aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
168a1b9b6aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
178a1b9b6aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
188a1b9b6aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
198a1b9b6aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
208a1b9b6aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
218a1b9b6aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228a1b9b6aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
238a1b9b6aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248a1b9b6aSSam Leffler  */
258a1b9b6aSSam Leffler 
268a1b9b6aSSam Leffler #include <sys/cdefs.h>
278a1b9b6aSSam Leffler __FBSDID("$FreeBSD$");
288a1b9b6aSSam Leffler 
298a1b9b6aSSam Leffler /*
308a1b9b6aSSam Leffler  * IEEE 802.11 NULL crypto support.
318a1b9b6aSSam Leffler  */
32b032f27cSSam Leffler #include "opt_wlan.h"
33b032f27cSSam Leffler 
348a1b9b6aSSam Leffler #include <sys/param.h>
358a1b9b6aSSam Leffler #include <sys/systm.h>
36*81c04d11SGleb Smirnoff #include <sys/counter.h>
37*81c04d11SGleb Smirnoff #include <sys/kernel.h>
388a1b9b6aSSam Leffler #include <sys/mbuf.h>
398a1b9b6aSSam Leffler #include <sys/module.h>
408a1b9b6aSSam Leffler 
418a1b9b6aSSam Leffler #include <sys/socket.h>
428a1b9b6aSSam Leffler 
438a1b9b6aSSam Leffler #include <net/if.h>
448a1b9b6aSSam Leffler #include <net/if_media.h>
458a1b9b6aSSam Leffler #include <net/ethernet.h>
468a1b9b6aSSam Leffler 
478a1b9b6aSSam Leffler #include <net80211/ieee80211_var.h>
488a1b9b6aSSam Leffler 
49b032f27cSSam Leffler static	void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
508a1b9b6aSSam Leffler static	void none_detach(struct ieee80211_key *);
518a1b9b6aSSam Leffler static	int none_setkey(struct ieee80211_key *);
5268e8e04eSSam Leffler static	int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t);
532cc12adeSSam Leffler static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
5496d88463SSam Leffler static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
5596d88463SSam Leffler static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
568a1b9b6aSSam Leffler 
578a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = {
588a1b9b6aSSam Leffler 	.ic_name	= "NONE",
598a1b9b6aSSam Leffler 	.ic_cipher	= IEEE80211_CIPHER_NONE,
608a1b9b6aSSam Leffler 	.ic_header	= 0,
618a1b9b6aSSam Leffler 	.ic_trailer	= 0,
628a1b9b6aSSam Leffler 	.ic_miclen	= 0,
638a1b9b6aSSam Leffler 	.ic_attach	= none_attach,
648a1b9b6aSSam Leffler 	.ic_detach	= none_detach,
658a1b9b6aSSam Leffler 	.ic_setkey	= none_setkey,
668a1b9b6aSSam Leffler 	.ic_encap	= none_encap,
678a1b9b6aSSam Leffler 	.ic_decap	= none_decap,
688a1b9b6aSSam Leffler 	.ic_enmic	= none_enmic,
698a1b9b6aSSam Leffler 	.ic_demic	= none_demic,
708a1b9b6aSSam Leffler };
718a1b9b6aSSam Leffler 
728a1b9b6aSSam Leffler static void *
73b032f27cSSam Leffler none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
748a1b9b6aSSam Leffler {
75b032f27cSSam Leffler 	return vap;		/* for diagnostics+stats */
768a1b9b6aSSam Leffler }
778a1b9b6aSSam Leffler 
788a1b9b6aSSam Leffler static void
798a1b9b6aSSam Leffler none_detach(struct ieee80211_key *k)
808a1b9b6aSSam Leffler {
818a1b9b6aSSam Leffler 	(void) k;
828a1b9b6aSSam Leffler }
838a1b9b6aSSam Leffler 
848a1b9b6aSSam Leffler static int
858a1b9b6aSSam Leffler none_setkey(struct ieee80211_key *k)
868a1b9b6aSSam Leffler {
878a1b9b6aSSam Leffler 	(void) k;
888a1b9b6aSSam Leffler 	return 1;
898a1b9b6aSSam Leffler }
908a1b9b6aSSam Leffler 
918a1b9b6aSSam Leffler static int
9268e8e04eSSam Leffler none_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid)
938a1b9b6aSSam Leffler {
94b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
958a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
968a1b9b6aSSam Leffler 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
978a1b9b6aSSam Leffler #endif
988a1b9b6aSSam Leffler 
998a1b9b6aSSam Leffler 	/*
1008a1b9b6aSSam Leffler 	 * The specified key is not setup; this can
1018a1b9b6aSSam Leffler 	 * happen, at least, when changing keys.
1028a1b9b6aSSam Leffler 	 */
103b032f27cSSam Leffler 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
104b032f27cSSam Leffler 	    "key id %u is not set (encap)", keyid>>6);
105b032f27cSSam Leffler 	vap->iv_stats.is_tx_badcipher++;
1068a1b9b6aSSam Leffler 	return 0;
1078a1b9b6aSSam Leffler }
1088a1b9b6aSSam Leffler 
1098a1b9b6aSSam Leffler static int
1102cc12adeSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
1118a1b9b6aSSam Leffler {
112b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1138a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
1148a1b9b6aSSam Leffler 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
11568e8e04eSSam Leffler 	const uint8_t *ivp = (const uint8_t *)&wh[1];
1168a1b9b6aSSam Leffler #endif
1178a1b9b6aSSam Leffler 
1188a1b9b6aSSam Leffler 	/*
1198a1b9b6aSSam Leffler 	 * The specified key is not setup; this can
1208a1b9b6aSSam Leffler 	 * happen, at least, when changing keys.
1218a1b9b6aSSam Leffler 	 */
1228a1b9b6aSSam Leffler 	/* XXX useful to know dst too */
123b032f27cSSam Leffler 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
124b032f27cSSam Leffler 	    "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
125b032f27cSSam Leffler 	vap->iv_stats.is_rx_badkeyid++;
1268a1b9b6aSSam Leffler 	return 0;
1278a1b9b6aSSam Leffler }
1288a1b9b6aSSam Leffler 
1298a1b9b6aSSam Leffler static int
13096d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
1318a1b9b6aSSam Leffler {
132b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1338a1b9b6aSSam Leffler 
134b032f27cSSam Leffler 	vap->iv_stats.is_tx_badcipher++;
1358a1b9b6aSSam Leffler 	return 0;
1368a1b9b6aSSam Leffler }
1378a1b9b6aSSam Leffler 
1388a1b9b6aSSam Leffler static int
13996d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
1408a1b9b6aSSam Leffler {
141b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1428a1b9b6aSSam Leffler 
143b032f27cSSam Leffler 	vap->iv_stats.is_rx_badkeyid++;
1448a1b9b6aSSam Leffler 	return 0;
1458a1b9b6aSSam Leffler }
146