xref: /freebsd/sys/net80211/ieee80211_crypto_none.c (revision ef0d8f6351ef193da64ddcc50f012140d89c66c5)
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>
3581c04d11SGleb Smirnoff #include <sys/kernel.h>
366fe391f4SGleb Smirnoff #include <sys/systm.h>
378a1b9b6aSSam Leffler #include <sys/mbuf.h>
388a1b9b6aSSam Leffler #include <sys/module.h>
398a1b9b6aSSam Leffler 
408a1b9b6aSSam Leffler #include <sys/socket.h>
418a1b9b6aSSam Leffler 
428a1b9b6aSSam Leffler #include <net/if.h>
438a1b9b6aSSam Leffler #include <net/if_media.h>
448a1b9b6aSSam Leffler #include <net/ethernet.h>
458a1b9b6aSSam Leffler 
468a1b9b6aSSam Leffler #include <net80211/ieee80211_var.h>
478a1b9b6aSSam Leffler 
48b032f27cSSam Leffler static	void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
498a1b9b6aSSam Leffler static	void none_detach(struct ieee80211_key *);
508a1b9b6aSSam Leffler static	int none_setkey(struct ieee80211_key *);
51*ef0d8f63SAdrian Chadd static	int none_encap(struct ieee80211_key *, struct mbuf *);
522cc12adeSSam Leffler static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
5396d88463SSam Leffler static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
5496d88463SSam Leffler static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
558a1b9b6aSSam Leffler 
568a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = {
578a1b9b6aSSam Leffler 	.ic_name	= "NONE",
588a1b9b6aSSam Leffler 	.ic_cipher	= IEEE80211_CIPHER_NONE,
598a1b9b6aSSam Leffler 	.ic_header	= 0,
608a1b9b6aSSam Leffler 	.ic_trailer	= 0,
618a1b9b6aSSam Leffler 	.ic_miclen	= 0,
628a1b9b6aSSam Leffler 	.ic_attach	= none_attach,
638a1b9b6aSSam Leffler 	.ic_detach	= none_detach,
648a1b9b6aSSam Leffler 	.ic_setkey	= none_setkey,
658a1b9b6aSSam Leffler 	.ic_encap	= none_encap,
668a1b9b6aSSam Leffler 	.ic_decap	= none_decap,
678a1b9b6aSSam Leffler 	.ic_enmic	= none_enmic,
688a1b9b6aSSam Leffler 	.ic_demic	= none_demic,
698a1b9b6aSSam Leffler };
708a1b9b6aSSam Leffler 
718a1b9b6aSSam Leffler static void *
72b032f27cSSam Leffler none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
738a1b9b6aSSam Leffler {
74b032f27cSSam Leffler 	return vap;		/* for diagnostics+stats */
758a1b9b6aSSam Leffler }
768a1b9b6aSSam Leffler 
778a1b9b6aSSam Leffler static void
788a1b9b6aSSam Leffler none_detach(struct ieee80211_key *k)
798a1b9b6aSSam Leffler {
808a1b9b6aSSam Leffler 	(void) k;
818a1b9b6aSSam Leffler }
828a1b9b6aSSam Leffler 
838a1b9b6aSSam Leffler static int
848a1b9b6aSSam Leffler none_setkey(struct ieee80211_key *k)
858a1b9b6aSSam Leffler {
868a1b9b6aSSam Leffler 	(void) k;
878a1b9b6aSSam Leffler 	return 1;
888a1b9b6aSSam Leffler }
898a1b9b6aSSam Leffler 
908a1b9b6aSSam Leffler static int
91*ef0d8f63SAdrian Chadd none_encap(struct ieee80211_key *k, struct mbuf *m)
928a1b9b6aSSam Leffler {
93b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
948a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
958a1b9b6aSSam Leffler 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
968a1b9b6aSSam Leffler #endif
97*ef0d8f63SAdrian Chadd 	uint8_t keyid;
98*ef0d8f63SAdrian Chadd 
99*ef0d8f63SAdrian Chadd 	keyid = ieee80211_crypto_get_keyid(vap, k);
1008a1b9b6aSSam Leffler 
1018a1b9b6aSSam Leffler 	/*
1028a1b9b6aSSam Leffler 	 * The specified key is not setup; this can
1038a1b9b6aSSam Leffler 	 * happen, at least, when changing keys.
1048a1b9b6aSSam Leffler 	 */
105b032f27cSSam Leffler 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
106*ef0d8f63SAdrian Chadd 	    "key id %u is not set (encap)", keyid);
107b032f27cSSam Leffler 	vap->iv_stats.is_tx_badcipher++;
1088a1b9b6aSSam Leffler 	return 0;
1098a1b9b6aSSam Leffler }
1108a1b9b6aSSam Leffler 
1118a1b9b6aSSam Leffler static int
1122cc12adeSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
1138a1b9b6aSSam Leffler {
114b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1158a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
1168a1b9b6aSSam Leffler 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
11768e8e04eSSam Leffler 	const uint8_t *ivp = (const uint8_t *)&wh[1];
1188a1b9b6aSSam Leffler #endif
1198a1b9b6aSSam Leffler 
1208a1b9b6aSSam Leffler 	/*
1218a1b9b6aSSam Leffler 	 * The specified key is not setup; this can
1228a1b9b6aSSam Leffler 	 * happen, at least, when changing keys.
1238a1b9b6aSSam Leffler 	 */
1248a1b9b6aSSam Leffler 	/* XXX useful to know dst too */
125b032f27cSSam Leffler 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
126b032f27cSSam Leffler 	    "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
127b032f27cSSam Leffler 	vap->iv_stats.is_rx_badkeyid++;
1288a1b9b6aSSam Leffler 	return 0;
1298a1b9b6aSSam Leffler }
1308a1b9b6aSSam Leffler 
1318a1b9b6aSSam Leffler static int
13296d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
1338a1b9b6aSSam Leffler {
134b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1358a1b9b6aSSam Leffler 
136b032f27cSSam Leffler 	vap->iv_stats.is_tx_badcipher++;
1378a1b9b6aSSam Leffler 	return 0;
1388a1b9b6aSSam Leffler }
1398a1b9b6aSSam Leffler 
1408a1b9b6aSSam Leffler static int
14196d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
1428a1b9b6aSSam Leffler {
143b032f27cSSam Leffler 	struct ieee80211vap *vap = k->wk_private;
1448a1b9b6aSSam Leffler 
145b032f27cSSam Leffler 	vap->iv_stats.is_rx_badkeyid++;
1468a1b9b6aSSam Leffler 	return 0;
1478a1b9b6aSSam Leffler }
148