Home | History | Annotate | Line # | Download | only in net80211
ieee80211_crypto_none.c revision 1.4.6.1
      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.3  dyoung __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.5 2005/06/10 16:11:24 sam Exp $");
     35      1.2  dyoung #endif
     36      1.2  dyoung #ifdef __NetBSD__
     37  1.4.6.1  simonb __KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.4.6.1 2006/04/22 11:40:08 simonb 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.4.6.1  simonb #include <net/if_ether.h>
     51      1.1  dyoung #include <net/if_media.h>
     52      1.1  dyoung 
     53      1.1  dyoung #include <net80211/ieee80211_var.h>
     54      1.1  dyoung 
     55      1.1  dyoung static	void *none_attach(struct ieee80211com *, struct ieee80211_key *);
     56      1.1  dyoung static	void none_detach(struct ieee80211_key *);
     57      1.1  dyoung static	int none_setkey(struct ieee80211_key *);
     58      1.1  dyoung static	int none_encap(struct ieee80211_key *, struct mbuf *, u_int8_t);
     59      1.3  dyoung static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
     60      1.3  dyoung static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
     61      1.3  dyoung static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
     62      1.1  dyoung 
     63      1.1  dyoung const struct ieee80211_cipher ieee80211_cipher_none = {
     64      1.1  dyoung 	.ic_name	= "NONE",
     65      1.1  dyoung 	.ic_cipher	= IEEE80211_CIPHER_NONE,
     66      1.1  dyoung 	.ic_header	= 0,
     67      1.1  dyoung 	.ic_trailer	= 0,
     68      1.1  dyoung 	.ic_miclen	= 0,
     69      1.1  dyoung 	.ic_attach	= none_attach,
     70      1.1  dyoung 	.ic_detach	= none_detach,
     71      1.1  dyoung 	.ic_setkey	= none_setkey,
     72      1.1  dyoung 	.ic_encap	= none_encap,
     73      1.1  dyoung 	.ic_decap	= none_decap,
     74      1.1  dyoung 	.ic_enmic	= none_enmic,
     75      1.1  dyoung 	.ic_demic	= none_demic,
     76      1.1  dyoung };
     77      1.1  dyoung 
     78      1.1  dyoung static void *
     79      1.1  dyoung none_attach(struct ieee80211com *ic, struct ieee80211_key *k)
     80      1.1  dyoung {
     81      1.1  dyoung 	return ic;		/* for diagnostics+stats */
     82      1.1  dyoung }
     83      1.1  dyoung 
     84      1.1  dyoung static void
     85      1.1  dyoung none_detach(struct ieee80211_key *k)
     86      1.1  dyoung {
     87      1.1  dyoung 	(void) k;
     88      1.1  dyoung }
     89      1.1  dyoung 
     90      1.1  dyoung static int
     91      1.1  dyoung none_setkey(struct ieee80211_key *k)
     92      1.1  dyoung {
     93      1.1  dyoung 	(void) k;
     94      1.1  dyoung 	return 1;
     95      1.1  dyoung }
     96      1.1  dyoung 
     97      1.1  dyoung static int
     98      1.1  dyoung none_encap(struct ieee80211_key *k, struct mbuf *m, u_int8_t keyid)
     99      1.1  dyoung {
    100      1.1  dyoung 	struct ieee80211com *ic = k->wk_private;
    101      1.1  dyoung #ifdef IEEE80211_DEBUG
    102      1.1  dyoung 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    103      1.1  dyoung #endif
    104      1.1  dyoung 
    105      1.1  dyoung 	/*
    106      1.1  dyoung 	 * The specified key is not setup; this can
    107      1.1  dyoung 	 * happen, at least, when changing keys.
    108      1.1  dyoung 	 */
    109      1.1  dyoung 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    110      1.1  dyoung 		"[%s] key id %u is not set (encap)\n",
    111      1.1  dyoung 		ether_sprintf(wh->i_addr1), keyid>>6);
    112      1.1  dyoung 	ic->ic_stats.is_tx_badcipher++;
    113      1.1  dyoung 	return 0;
    114      1.1  dyoung }
    115      1.1  dyoung 
    116      1.1  dyoung static int
    117      1.3  dyoung none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
    118      1.1  dyoung {
    119      1.1  dyoung 	struct ieee80211com *ic = k->wk_private;
    120      1.1  dyoung #ifdef IEEE80211_DEBUG
    121      1.1  dyoung 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    122      1.1  dyoung 	const u_int8_t *ivp = (const u_int8_t *)&wh[1];
    123      1.1  dyoung #endif
    124      1.1  dyoung 
    125      1.1  dyoung 	/*
    126      1.1  dyoung 	 * The specified key is not setup; this can
    127      1.1  dyoung 	 * happen, at least, when changing keys.
    128      1.1  dyoung 	 */
    129      1.1  dyoung 	/* XXX useful to know dst too */
    130      1.1  dyoung 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    131      1.1  dyoung 		"[%s] key id %u is not set (decap)\n",
    132      1.1  dyoung 		ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6);
    133      1.1  dyoung 	ic->ic_stats.is_rx_badkeyid++;
    134      1.1  dyoung 	return 0;
    135      1.1  dyoung }
    136      1.1  dyoung 
    137      1.1  dyoung static int
    138      1.3  dyoung none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
    139      1.1  dyoung {
    140      1.1  dyoung 	struct ieee80211com *ic = k->wk_private;
    141      1.1  dyoung 
    142      1.1  dyoung 	ic->ic_stats.is_tx_badcipher++;
    143      1.1  dyoung 	return 0;
    144      1.1  dyoung }
    145      1.1  dyoung 
    146      1.1  dyoung static int
    147      1.3  dyoung none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
    148      1.1  dyoung {
    149      1.1  dyoung 	struct ieee80211com *ic = k->wk_private;
    150      1.1  dyoung 
    151      1.1  dyoung 	ic->ic_stats.is_rx_badkeyid++;
    152      1.1  dyoung 	return 0;
    153      1.1  dyoung }
    154