Home | History | Annotate | Line # | Download | only in net80211
ieee80211_crypto_none.c revision 1.5
      1 /*-
      2  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. The name of the author may not be used to endorse or promote products
     14  *    derived from this software without specific prior written permission.
     15  *
     16  * Alternatively, this software may be distributed under the terms of the
     17  * GNU General Public License ("GPL") version 2 as published by the Free
     18  * Software Foundation.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifdef __FreeBSD__
     34 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.5 2005/06/10 16:11:24 sam Exp $");
     35 #endif
     36 #ifdef __NetBSD__
     37 __KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.5 2006/03/16 15:59:22 christos Exp $");
     38 #endif
     39 
     40 /*
     41  * IEEE 802.11 NULL crypto support.
     42  */
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/mbuf.h>
     46 
     47 #include <sys/socket.h>
     48 
     49 #include <net/if.h>
     50 #include <net/if_ether.h>
     51 #include <net/if_media.h>
     52 
     53 #include <net80211/ieee80211_var.h>
     54 
     55 static	void *none_attach(struct ieee80211com *, struct ieee80211_key *);
     56 static	void none_detach(struct ieee80211_key *);
     57 static	int none_setkey(struct ieee80211_key *);
     58 static	int none_encap(struct ieee80211_key *, struct mbuf *, u_int8_t);
     59 static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
     60 static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
     61 static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
     62 
     63 const struct ieee80211_cipher ieee80211_cipher_none = {
     64 	.ic_name	= "NONE",
     65 	.ic_cipher	= IEEE80211_CIPHER_NONE,
     66 	.ic_header	= 0,
     67 	.ic_trailer	= 0,
     68 	.ic_miclen	= 0,
     69 	.ic_attach	= none_attach,
     70 	.ic_detach	= none_detach,
     71 	.ic_setkey	= none_setkey,
     72 	.ic_encap	= none_encap,
     73 	.ic_decap	= none_decap,
     74 	.ic_enmic	= none_enmic,
     75 	.ic_demic	= none_demic,
     76 };
     77 
     78 static void *
     79 none_attach(struct ieee80211com *ic, struct ieee80211_key *k)
     80 {
     81 	return ic;		/* for diagnostics+stats */
     82 }
     83 
     84 static void
     85 none_detach(struct ieee80211_key *k)
     86 {
     87 	(void) k;
     88 }
     89 
     90 static int
     91 none_setkey(struct ieee80211_key *k)
     92 {
     93 	(void) k;
     94 	return 1;
     95 }
     96 
     97 static int
     98 none_encap(struct ieee80211_key *k, struct mbuf *m, u_int8_t keyid)
     99 {
    100 	struct ieee80211com *ic = k->wk_private;
    101 #ifdef IEEE80211_DEBUG
    102 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    103 #endif
    104 
    105 	/*
    106 	 * The specified key is not setup; this can
    107 	 * happen, at least, when changing keys.
    108 	 */
    109 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    110 		"[%s] key id %u is not set (encap)\n",
    111 		ether_sprintf(wh->i_addr1), keyid>>6);
    112 	ic->ic_stats.is_tx_badcipher++;
    113 	return 0;
    114 }
    115 
    116 static int
    117 none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
    118 {
    119 	struct ieee80211com *ic = k->wk_private;
    120 #ifdef IEEE80211_DEBUG
    121 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    122 	const u_int8_t *ivp = (const u_int8_t *)&wh[1];
    123 #endif
    124 
    125 	/*
    126 	 * The specified key is not setup; this can
    127 	 * happen, at least, when changing keys.
    128 	 */
    129 	/* XXX useful to know dst too */
    130 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    131 		"[%s] key id %u is not set (decap)\n",
    132 		ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6);
    133 	ic->ic_stats.is_rx_badkeyid++;
    134 	return 0;
    135 }
    136 
    137 static int
    138 none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
    139 {
    140 	struct ieee80211com *ic = k->wk_private;
    141 
    142 	ic->ic_stats.is_tx_badcipher++;
    143 	return 0;
    144 }
    145 
    146 static int
    147 none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
    148 {
    149 	struct ieee80211com *ic = k->wk_private;
    150 
    151 	ic->ic_stats.is_rx_badkeyid++;
    152 	return 0;
    153 }
    154