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