]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net80211/ieee80211_crypto_none.c
bhnd(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.git] / sys / net80211 / ieee80211_crypto_none.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2002-2008 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 /*
32  * IEEE 802.11 NULL crypto support.
33  */
34 #include "opt_wlan.h"
35
36 #include <sys/param.h>
37 #include <sys/kernel.h> 
38 #include <sys/malloc.h> 
39 #include <sys/systm.h> 
40 #include <sys/mbuf.h>   
41 #include <sys/module.h>
42
43 #include <sys/socket.h>
44
45 #include <net/if.h>
46 #include <net/if_media.h>
47 #include <net/ethernet.h>
48
49 #include <net80211/ieee80211_var.h>
50
51 static  void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
52 static  void none_detach(struct ieee80211_key *);
53 static  int none_setkey(struct ieee80211_key *);
54 static  void none_setiv(struct ieee80211_key *, uint8_t *);
55 static  int none_encap(struct ieee80211_key *, struct mbuf *);
56 static  int none_decap(struct ieee80211_key *, struct mbuf *, int);
57 static  int none_enmic(struct ieee80211_key *, struct mbuf *, int);
58 static  int none_demic(struct ieee80211_key *, struct mbuf *, int);
59
60 const struct ieee80211_cipher ieee80211_cipher_none = {
61         .ic_name        = "NONE",
62         .ic_cipher      = IEEE80211_CIPHER_NONE,
63         .ic_header      = 0,
64         .ic_trailer     = 0,
65         .ic_miclen      = 0,
66         .ic_attach      = none_attach,
67         .ic_detach      = none_detach,
68         .ic_setkey      = none_setkey,
69         .ic_setiv       = none_setiv,
70         .ic_encap       = none_encap,
71         .ic_decap       = none_decap,
72         .ic_enmic       = none_enmic,
73         .ic_demic       = none_demic,
74 };
75
76 static void *
77 none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
78 {
79         return vap;             /* for diagnostics+stats */
80 }
81
82 static void
83 none_detach(struct ieee80211_key *k)
84 {
85         (void) k;
86 }
87
88 static int
89 none_setkey(struct ieee80211_key *k)
90 {
91         (void) k;
92         return 1;
93 }
94
95 static void
96 none_setiv(struct ieee80211_key *k, uint8_t *ivp)
97 {
98 }
99
100 static int
101 none_encap(struct ieee80211_key *k, struct mbuf *m)
102 {
103         struct ieee80211vap *vap = k->wk_private;
104 #ifdef IEEE80211_DEBUG
105         struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
106         uint8_t keyid;
107
108         keyid = ieee80211_crypto_get_keyid(vap, k);
109
110         /*
111          * The specified key is not setup; this can
112          * happen, at least, when changing keys.
113          */
114         IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
115             "key id %u is not set (encap)", keyid);
116 #endif
117         vap->iv_stats.is_tx_badcipher++;
118         return 0;
119 }
120
121 static int
122 none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
123 {
124         struct ieee80211vap *vap = k->wk_private;
125 #ifdef IEEE80211_DEBUG
126         struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
127         const uint8_t *ivp = (const uint8_t *)&wh[1];
128 #endif
129
130         /*
131          * The specified key is not setup; this can
132          * happen, at least, when changing keys.
133          */
134         /* XXX useful to know dst too */
135         IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
136             "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
137         vap->iv_stats.is_rx_badkeyid++;
138         return 0;
139 }
140
141 static int
142 none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
143 {
144         struct ieee80211vap *vap = k->wk_private;
145
146         vap->iv_stats.is_tx_badcipher++;
147         return 0;
148 }
149
150 static int
151 none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
152 {
153         struct ieee80211vap *vap = k->wk_private;
154
155         vap->iv_stats.is_rx_badkeyid++;
156         return 0;
157 }