<net/if.h>: Do not include <net/if_var.h> for _KERNEL
[dragonfly.git] / sys / netproto / 802_11 / wlan / ieee80211_crypto_none.c
1 /*-
2  * Copyright (c) 2002-2008 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 "opt_wlan.h"
33
34 #include <sys/param.h>
35 #include <sys/kernel.h> 
36 #include <sys/malloc.h> 
37 #include <sys/systm.h> 
38 #include <sys/mbuf.h>   
39 #include <sys/module.h>
40
41 #include <sys/socket.h>
42
43 #include <net/if.h>
44 #include <net/if_var.h>
45 #include <net/if_media.h>
46 #include <net/ethernet.h>
47
48 #include <netproto/802_11/ieee80211_var.h>
49
50 static  void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
51 static  void none_detach(struct ieee80211_key *);
52 static  int none_setkey(struct ieee80211_key *);
53 static  void none_setiv(struct ieee80211_key *, uint8_t *);
54 static  int none_encap(struct ieee80211_key *, struct mbuf *);
55 static  int none_decap(struct ieee80211_key *, struct mbuf *, int);
56 static  int none_enmic(struct ieee80211_key *, struct mbuf *, int);
57 static  int none_demic(struct ieee80211_key *, struct mbuf *, int);
58
59 const struct ieee80211_cipher ieee80211_cipher_none = {
60         .ic_name        = "NONE",
61         .ic_cipher      = IEEE80211_CIPHER_NONE,
62         .ic_header      = 0,
63         .ic_trailer     = 0,
64         .ic_miclen      = 0,
65         .ic_attach      = none_attach,
66         .ic_detach      = none_detach,
67         .ic_setkey      = none_setkey,
68         .ic_setiv       = none_setiv,
69         .ic_encap       = none_encap,
70         .ic_decap       = none_decap,
71         .ic_enmic       = none_enmic,
72         .ic_demic       = none_demic,
73 };
74
75 static void *
76 none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
77 {
78         return vap;             /* for diagnostics+stats */
79 }
80
81 static void
82 none_detach(struct ieee80211_key *k)
83 {
84         (void) k;
85 }
86
87 static int
88 none_setkey(struct ieee80211_key *k)
89 {
90         (void) k;
91         return 1;
92 }
93
94 static void
95 none_setiv(struct ieee80211_key *k, uint8_t *ivp)
96 {
97 }
98
99 static int
100 none_encap(struct ieee80211_key *k, struct mbuf *m)
101 {
102         struct ieee80211vap *vap = k->wk_private;
103 #ifdef IEEE80211_DEBUG
104         struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
105 #endif
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         vap->iv_stats.is_tx_badcipher++;
117         return 0;
118 }
119
120 static int
121 none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
122 {
123         struct ieee80211vap *vap = k->wk_private;
124 #ifdef IEEE80211_DEBUG
125         struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
126         const uint8_t *ivp = (const uint8_t *)&wh[1];
127 #endif
128
129         /*
130          * The specified key is not setup; this can
131          * happen, at least, when changing keys.
132          */
133         /* XXX useful to know dst too */
134         IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
135             "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
136         vap->iv_stats.is_rx_badkeyid++;
137         return 0;
138 }
139
140 static int
141 none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
142 {
143         struct ieee80211vap *vap = k->wk_private;
144
145         vap->iv_stats.is_tx_badcipher++;
146         return 0;
147 }
148
149 static int
150 none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
151 {
152         struct ieee80211vap *vap = k->wk_private;
153
154         vap->iv_stats.is_rx_badkeyid++;
155         return 0;
156 }