Home | History | Annotate | Line # | Download | only in net80211
ieee80211_crypto_none.c revision 1.8.4.2
      1 /*	$NetBSD: ieee80211_crypto_none.c,v 1.8.4.2 2018/07/12 16:35:34 phil 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 __FreeBSD__
     32 __FBSDID("$FreeBSD$");
     33 #endif
     34 
     35 /*
     36  * IEEE 802.11 NULL crypto support.
     37  */
     38 #include "opt_wlan.h"
     39 
     40 #include <sys/param.h>
     41 #include <sys/kernel.h>
     42 #include <sys/malloc.h>
     43 #include <sys/systm.h>
     44 #include <sys/mbuf.h>
     45 #include <sys/module.h>
     46 
     47 #include <sys/socket.h>
     48 
     49 #include <net/if.h>
     50 #include <net/if_media.h>
     51 #ifdef __FreeBSD__
     52 #include <net/ethernet.h>
     53 #endif
     54 #ifdef __NetBSD__
     55 #include <net/route.h>
     56 #endif
     57 
     58 #include <net80211/ieee80211_var.h>
     59 
     60 static	void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
     61 static	void none_detach(struct ieee80211_key *);
     62 static	int none_setkey(struct ieee80211_key *);
     63 static	void none_setiv(struct ieee80211_key *, uint8_t *);
     64 static	int none_encap(struct ieee80211_key *, struct mbuf *);
     65 static	int none_decap(struct ieee80211_key *, struct mbuf *, int);
     66 static	int none_enmic(struct ieee80211_key *, struct mbuf *, int);
     67 static	int none_demic(struct ieee80211_key *, struct mbuf *, int);
     68 
     69 const struct ieee80211_cipher ieee80211_cipher_none = {
     70 	.ic_name	= "NONE",
     71 	.ic_cipher	= IEEE80211_CIPHER_NONE,
     72 	.ic_header	= 0,
     73 	.ic_trailer	= 0,
     74 	.ic_miclen	= 0,
     75 	.ic_attach	= none_attach,
     76 	.ic_detach	= none_detach,
     77 	.ic_setkey	= none_setkey,
     78 	.ic_setiv	= none_setiv,
     79 	.ic_encap	= none_encap,
     80 	.ic_decap	= none_decap,
     81 	.ic_enmic	= none_enmic,
     82 	.ic_demic	= none_demic,
     83 };
     84 
     85 static void *
     86 none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
     87 {
     88 	return vap;		/* for diagnostics+stats */
     89 }
     90 
     91 static void
     92 none_detach(struct ieee80211_key *k)
     93 {
     94 	(void) k;
     95 }
     96 
     97 static int
     98 none_setkey(struct ieee80211_key *k)
     99 {
    100 	(void) k;
    101 	return 1;
    102 }
    103 
    104 static void
    105 none_setiv(struct ieee80211_key *k, uint8_t *ivp)
    106 {
    107 }
    108 
    109 static int
    110 none_encap(struct ieee80211_key *k, struct mbuf *m)
    111 {
    112 	struct ieee80211vap *vap = k->wk_private;
    113 #ifdef IEEE80211_DEBUG
    114 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    115 	uint8_t keyid;
    116 
    117 	keyid = ieee80211_crypto_get_keyid(vap, k);
    118 
    119 	/*
    120 	 * The specified key is not setup; this can
    121 	 * happen, at least, when changing keys.
    122 	 */
    123 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
    124 	    "key id %u is not set (encap)", keyid);
    125 #endif
    126 	vap->iv_stats.is_tx_badcipher++;
    127 	return 0;
    128 }
    129 
    130 static int
    131 none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
    132 {
    133 	struct ieee80211vap *vap = k->wk_private;
    134 #ifdef IEEE80211_DEBUG
    135 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
    136 	const uint8_t *ivp = (const uint8_t *)&wh[1];
    137 #endif
    138 
    139 	/*
    140 	 * The specified key is not setup; this can
    141 	 * happen, at least, when changing keys.
    142 	 */
    143 	/* XXX useful to know dst too */
    144 	IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
    145 	    "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
    146 	vap->iv_stats.is_rx_badkeyid++;
    147 	return 0;
    148 }
    149 
    150 static int
    151 none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
    152 {
    153 	struct ieee80211vap *vap = k->wk_private;
    154 
    155 	vap->iv_stats.is_tx_badcipher++;
    156 	return 0;
    157 }
    158 
    159 static int
    160 none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
    161 {
    162 	struct ieee80211vap *vap = k->wk_private;
    163 
    164 	vap->iv_stats.is_rx_badkeyid++;
    165 	return 0;
    166 }
    167