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