Home | History | Annotate | Line # | Download | only in net80211
ieee80211_crypto_none.c revision 1.7.46.1
      1       1.1    dyoung /*-
      2  1.7.46.1     skrll  * Copyright (c) 2002-2007 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  *
     14       1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     15       1.1    dyoung  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     16       1.1    dyoung  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     17       1.1    dyoung  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     18       1.1    dyoung  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     19       1.1    dyoung  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     20       1.1    dyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     21       1.1    dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22       1.1    dyoung  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23       1.1    dyoung  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24       1.1    dyoung  */
     25       1.1    dyoung 
     26       1.1    dyoung #include <sys/cdefs.h>
     27       1.2    dyoung #ifdef __FreeBSD__
     28  1.7.46.1     skrll __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.7 2007/06/11 03:36:54 sam Exp $");
     29       1.2    dyoung #endif
     30       1.2    dyoung #ifdef __NetBSD__
     31       1.7  christos __KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.7.46.1 2008/02/22 16:50:25 skrll Exp $");
     32       1.2    dyoung #endif
     33       1.1    dyoung 
     34       1.1    dyoung /*
     35       1.1    dyoung  * IEEE 802.11 NULL crypto support.
     36       1.1    dyoung  */
     37       1.1    dyoung #include <sys/param.h>
     38       1.1    dyoung #include <sys/systm.h>
     39       1.1    dyoung #include <sys/mbuf.h>
     40       1.1    dyoung 
     41       1.1    dyoung #include <sys/socket.h>
     42       1.1    dyoung 
     43       1.1    dyoung #include <net/if.h>
     44       1.5  christos #include <net/if_ether.h>
     45       1.1    dyoung #include <net/if_media.h>
     46       1.1    dyoung 
     47       1.1    dyoung #include <net80211/ieee80211_var.h>
     48       1.1    dyoung 
     49       1.1    dyoung static	void *none_attach(struct ieee80211com *, struct ieee80211_key *);
     50       1.1    dyoung static	void none_detach(struct ieee80211_key *);
     51       1.1    dyoung static	int none_setkey(struct ieee80211_key *);
     52  1.7.46.1     skrll static	int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t);
     53       1.3    dyoung static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
     54       1.3    dyoung static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
     55       1.3    dyoung static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
     56       1.1    dyoung 
     57       1.1    dyoung const struct ieee80211_cipher ieee80211_cipher_none = {
     58       1.1    dyoung 	.ic_name	= "NONE",
     59       1.1    dyoung 	.ic_cipher	= IEEE80211_CIPHER_NONE,
     60       1.1    dyoung 	.ic_header	= 0,
     61       1.1    dyoung 	.ic_trailer	= 0,
     62       1.1    dyoung 	.ic_miclen	= 0,
     63       1.1    dyoung 	.ic_attach	= none_attach,
     64       1.1    dyoung 	.ic_detach	= none_detach,
     65       1.1    dyoung 	.ic_setkey	= none_setkey,
     66       1.1    dyoung 	.ic_encap	= none_encap,
     67       1.1    dyoung 	.ic_decap	= none_decap,
     68       1.1    dyoung 	.ic_enmic	= none_enmic,
     69       1.1    dyoung 	.ic_demic	= none_demic,
     70       1.1    dyoung };
     71       1.1    dyoung 
     72       1.1    dyoung static void *
     73       1.7  christos none_attach(struct ieee80211com *ic, struct ieee80211_key *k)
     74       1.1    dyoung {
     75       1.1    dyoung 	return ic;		/* for diagnostics+stats */
     76       1.1    dyoung }
     77       1.1    dyoung 
     78       1.1    dyoung static void
     79       1.1    dyoung none_detach(struct ieee80211_key *k)
     80       1.1    dyoung {
     81       1.1    dyoung 	(void) k;
     82       1.1    dyoung }
     83       1.1    dyoung 
     84       1.1    dyoung static int
     85       1.1    dyoung none_setkey(struct ieee80211_key *k)
     86       1.1    dyoung {
     87       1.1    dyoung 	(void) k;
     88       1.1    dyoung 	return 1;
     89       1.1    dyoung }
     90       1.1    dyoung 
     91       1.1    dyoung static int
     92  1.7.46.1     skrll none_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid)
     93       1.1    dyoung {
     94       1.1    dyoung 	struct ieee80211com *ic = k->wk_private;
     95       1.1    dyoung #ifdef IEEE80211_DEBUG
     96       1.1    dyoung 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
     97       1.1    dyoung #endif
     98       1.1    dyoung 
     99       1.1    dyoung 	/*
    100       1.1    dyoung 	 * The specified key is not setup; this can
    101       1.1    dyoung 	 * happen, at least, when changing keys.
    102       1.1    dyoung 	 */
    103       1.1    dyoung 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    104       1.1    dyoung 		"[%s] key id %u is not set (encap)\n",
    105       1.1    dyoung 		ether_sprintf(wh->i_addr1), keyid>>6);
    106       1.1    dyoung 	ic->ic_stats.is_tx_badcipher++;
    107       1.1    dyoung 	return 0;
    108       1.1    dyoung }
    109       1.1    dyoung 
    110       1.1    dyoung static int
    111       1.7  christos none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
    112       1.1    dyoung {
    113       1.1    dyoung 	struct ieee80211com *ic = k->wk_private;
    114       1.1    dyoung #ifdef IEEE80211_DEBUG
    115       1.1    dyoung 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    116  1.7.46.1     skrll 	const uint8_t *ivp = (const uint8_t *)&wh[1];
    117       1.1    dyoung #endif
    118       1.1    dyoung 
    119       1.1    dyoung 	/*
    120       1.1    dyoung 	 * The specified key is not setup; this can
    121       1.1    dyoung 	 * happen, at least, when changing keys.
    122       1.1    dyoung 	 */
    123       1.1    dyoung 	/* XXX useful to know dst too */
    124       1.1    dyoung 	IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO,
    125       1.1    dyoung 		"[%s] key id %u is not set (decap)\n",
    126       1.1    dyoung 		ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6);
    127       1.1    dyoung 	ic->ic_stats.is_rx_badkeyid++;
    128       1.1    dyoung 	return 0;
    129       1.1    dyoung }
    130       1.1    dyoung 
    131       1.1    dyoung static int
    132       1.7  christos none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
    133       1.1    dyoung {
    134       1.1    dyoung 	struct ieee80211com *ic = k->wk_private;
    135       1.1    dyoung 
    136       1.1    dyoung 	ic->ic_stats.is_tx_badcipher++;
    137       1.1    dyoung 	return 0;
    138       1.1    dyoung }
    139       1.1    dyoung 
    140       1.1    dyoung static int
    141       1.7  christos none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
    142       1.1    dyoung {
    143       1.1    dyoung 	struct ieee80211com *ic = k->wk_private;
    144       1.1    dyoung 
    145       1.1    dyoung 	ic->ic_stats.is_rx_badkeyid++;
    146       1.1    dyoung 	return 0;
    147       1.1    dyoung }
    148