wlan - Update wlan from Adrian / FreeBSD
[dragonfly.git] / sys / netproto / 802_11 / wlan / ieee80211_crypto_none.c
CommitLineData
32176cfd
RP
1/*-
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
841ab66c
SZ
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.
841ab66c
SZ
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.
841ab66c
SZ
24 */
25
085ff963
MD
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD$");
28
841ab66c
SZ
29/*
30 * IEEE 802.11 NULL crypto support.
31 */
32176cfd
RP
32#include "opt_wlan.h"
33
841ab66c 34#include <sys/param.h>
32176cfd 35#include <sys/kernel.h>
841ab66c
SZ
36#include <sys/systm.h>
37#include <sys/mbuf.h>
38#include <sys/module.h>
39
40#include <sys/socket.h>
41
42#include <net/if.h>
841ab66c
SZ
43#include <net/if_media.h>
44#include <net/ethernet.h>
45
46#include <netproto/802_11/ieee80211_var.h>
47
32176cfd
RP
48static void *none_attach(struct ieee80211vap *, struct ieee80211_key *);
49static void none_detach(struct ieee80211_key *);
50static int none_setkey(struct ieee80211_key *);
51static int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t);
52static int none_decap(struct ieee80211_key *, struct mbuf *, int);
53static int none_enmic(struct ieee80211_key *, struct mbuf *, int);
54static int none_demic(struct ieee80211_key *, struct mbuf *, int);
841ab66c
SZ
55
56const struct ieee80211_cipher ieee80211_cipher_none = {
57 .ic_name = "NONE",
58 .ic_cipher = IEEE80211_CIPHER_NONE,
59 .ic_header = 0,
60 .ic_trailer = 0,
61 .ic_miclen = 0,
32176cfd
RP
62 .ic_attach = none_attach,
63 .ic_detach = none_detach,
64 .ic_setkey = none_setkey,
65 .ic_encap = none_encap,
66 .ic_decap = none_decap,
67 .ic_enmic = none_enmic,
68 .ic_demic = none_demic,
841ab66c
SZ
69};
70
71static void *
32176cfd 72none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)
841ab66c 73{
32176cfd 74 return vap; /* for diagnostics+stats */
841ab66c
SZ
75}
76
77static void
32176cfd 78none_detach(struct ieee80211_key *k)
841ab66c
SZ
79{
80 (void) k;
81}
82
83static int
32176cfd 84none_setkey(struct ieee80211_key *k)
841ab66c
SZ
85{
86 (void) k;
87 return 1;
88}
89
90static int
32176cfd 91none_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid)
841ab66c 92{
32176cfd 93 struct ieee80211vap *vap = k->wk_private;
841ab66c
SZ
94#ifdef IEEE80211_DEBUG
95 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
96#endif
97
98 /*
99 * The specified key is not setup; this can
100 * happen, at least, when changing keys.
101 */
32176cfd
RP
102 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,
103 "key id %u is not set (encap)", keyid>>6);
104 vap->iv_stats.is_tx_badcipher++;
841ab66c
SZ
105 return 0;
106}
107
108static int
32176cfd 109none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)
841ab66c 110{
32176cfd 111 struct ieee80211vap *vap = k->wk_private;
841ab66c
SZ
112#ifdef IEEE80211_DEBUG
113 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
114 const uint8_t *ivp = (const uint8_t *)&wh[1];
115#endif
116
117 /*
118 * The specified key is not setup; this can
119 * happen, at least, when changing keys.
120 */
121 /* XXX useful to know dst too */
32176cfd
RP
122 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
123 "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);
124 vap->iv_stats.is_rx_badkeyid++;
841ab66c
SZ
125 return 0;
126}
127
6bd66811 128static int
32176cfd 129none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)
6bd66811 130{
32176cfd 131 struct ieee80211vap *vap = k->wk_private;
6bd66811 132
32176cfd 133 vap->iv_stats.is_tx_badcipher++;
6bd66811
SZ
134 return 0;
135}
136
841ab66c 137static int
32176cfd 138none_demic(struct ieee80211_key *k, struct mbuf *m, int force)
841ab66c 139{
32176cfd 140 struct ieee80211vap *vap = k->wk_private;
841ab66c 141
32176cfd 142 vap->iv_stats.is_rx_badkeyid++;
6bd66811
SZ
143 return 0;
144}