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