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