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