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