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