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