update madwifi
[linux-2.6/zen-sources.git] / drivers / net / wireless / madwifi / net80211 / ieee80211_crypto.h
blob4274e1e1427b3374dc8a306c363b72d3d4b25999
1 /*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $Id: ieee80211_crypto.h 3756 2008-07-06 02:31:09Z mentor $
34 #ifndef _NET80211_IEEE80211_CRYPTO_H_
35 #define _NET80211_IEEE80211_CRYPTO_H_
38 * 802.11 protocol crypto-related definitions.
40 #define IEEE80211_KEYBUF_SIZE 16
41 #define IEEE80211_MICBUF_SIZE (8 + 8) /* space for both TX & RX keys */
42 #define IEEE80211_TID_SIZE 17 /* total number of TIDs */
45 * Old WEP-style key. Deprecated.
47 struct ieee80211_wepkey {
48 u_int wk_len; /* key length in bytes */
49 u_int8_t wk_key[IEEE80211_KEYBUF_SIZE];
52 struct ieee80211_cipher;
55 * Crypto key state. There is sufficient room for all supported
56 * ciphers (see below). The underlying ciphers are handled
57 * separately through loadable cipher modules that register with
58 * the generic crypto support. A key has a reference to an instance
59 * of the cipher; any per-key state is hung off wk_private by the
60 * cipher when it is attached. Ciphers are automatically called
61 * to detach and cleanup any such state when the key is deleted.
63 * The generic crypto support handles encap/decap of cipher-related
64 * frame contents for both hardware- and software-based implementations.
65 * A key requiring software crypto support is automatically flagged and
66 * the cipher is expected to honor this and do the necessary work.
67 * Ciphers such as TKIP may also support mixed hardware/software
68 * encrypt/decrypt and MIC processing.
71 typedef u_int16_t ieee80211_keyix_t;
73 /* XXX pack better? */
74 /* XXX 48-bit rsc/tsc */
75 struct ieee80211_key {
76 u_int8_t wk_keylen; /* key length in bytes */
77 u_int8_t wk_flags;
78 #define IEEE80211_KEY_XMIT 0x01 /* key used for xmit */
79 #define IEEE80211_KEY_RECV 0x02 /* key used for recv */
80 #define IEEE80211_KEY_GROUP 0x04 /* key used for WPA group operation */
81 #define IEEE80211_KEY_SWCRYPT 0x10 /* host-based encrypt/decrypt */
82 #define IEEE80211_KEY_SWMIC 0x20 /* host-based enmic/demic */
83 #define IEEE80211_KEY_TXRX (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV)
84 ieee80211_keyix_t wk_keyix; /* key index */
85 u_int8_t wk_key[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
86 #define wk_txmic wk_key+IEEE80211_KEYBUF_SIZE+0 /* XXX can't () right */
87 #define wk_rxmic wk_key+IEEE80211_KEYBUF_SIZE+8 /* XXX can't () right */
88 u_int64_t wk_keyrsc[IEEE80211_TID_SIZE]; /* key receive sequence counter */
89 u_int64_t wk_keytsc; /* key transmit sequence counter */
90 const struct ieee80211_cipher *wk_cipher;
91 void *wk_private; /* private cipher state */
93 #define IEEE80211_KEY_COMMON /* common flags passed in by apps */\
94 (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV | IEEE80211_KEY_GROUP)
97 * NB: these values are ordered carefully; there are lots of
98 * of implications in any reordering. In particular beware
99 * that 4 is not used to avoid conflicting with IEEE80211_F_PRIVACY.
101 #define IEEE80211_CIPHER_WEP 0
102 #define IEEE80211_CIPHER_TKIP 1
103 #define IEEE80211_CIPHER_AES_OCB 2
104 #define IEEE80211_CIPHER_AES_CCM 3
105 #define IEEE80211_CIPHER_CKIP 5
106 #define IEEE80211_CIPHER_NONE 6 /* pseudo value */
108 #define IEEE80211_CIPHER_MAX (IEEE80211_CIPHER_NONE + 1)
110 #define IEEE80211_KEYIX_NONE ((ieee80211_keyix_t)-1)
112 #if defined(__KERNEL__) || defined(_KERNEL)
114 struct ieee80211com;
115 struct ieee80211vap;
116 struct ieee80211_node;
117 struct sk_buff;
119 void ieee80211_crypto_attach(struct ieee80211com *);
120 void ieee80211_crypto_detach(struct ieee80211com *);
121 void ieee80211_crypto_vattach(struct ieee80211vap *);
122 void ieee80211_crypto_vdetach(struct ieee80211vap *);
123 int ieee80211_crypto_newkey(struct ieee80211vap *, int, int,
124 struct ieee80211_key *);
125 int ieee80211_crypto_delkey(struct ieee80211vap *, struct ieee80211_key *,
126 struct ieee80211_node *);
127 int ieee80211_crypto_setkey(struct ieee80211vap *, struct ieee80211_key *,
128 const u_int8_t macaddr[IEEE80211_ADDR_LEN], struct ieee80211_node *);
129 void ieee80211_crypto_delglobalkeys(struct ieee80211vap *);
132 * Template for a supported cipher. Ciphers register with the
133 * crypto code and are typically loaded as separate modules
134 * (the null cipher is always present).
135 * XXX may need refcnts
137 struct ieee80211_cipher {
138 const char *ic_name; /* printable name */
139 u_int ic_cipher; /* IEEE80211_CIPHER_* */
140 u_int ic_header; /* size of privacy header (bytes) */
141 u_int ic_trailer; /* size of privacy trailer (bytes) */
142 u_int ic_miclen; /* size of mic trailer (bytes) */
143 void *(*ic_attach)(struct ieee80211vap *, struct ieee80211_key *);
144 void (*ic_detach)(struct ieee80211_key *);
145 int (*ic_setkey)(struct ieee80211_key *);
146 int (*ic_encap)(struct ieee80211_key *, struct sk_buff *, u_int8_t);
147 int (*ic_decap)(struct ieee80211_key *, struct sk_buff *, int);
148 int (*ic_enmic)(struct ieee80211_key *, struct sk_buff *, int);
149 int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int, int);
151 extern const struct ieee80211_cipher ieee80211_cipher_none;
153 void ieee80211_crypto_register(const struct ieee80211_cipher *);
154 void ieee80211_crypto_unregister(const struct ieee80211_cipher *);
155 int ieee80211_crypto_available(struct ieee80211vap *, u_int);
157 struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211_node *,
158 struct sk_buff *);
159 struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211_node *,
160 struct sk_buff *, int);
163 * Check and remove any MIC.
165 static __inline int
166 ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k,
167 struct sk_buff *skb, int hdrlen, int force_sw)
169 const struct ieee80211_cipher *cip = k->wk_cipher;
170 return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen, force_sw) : 1);
174 * Add any MIC.
176 static __inline int
177 ieee80211_crypto_enmic(struct ieee80211vap *vap, struct ieee80211_key *k,
178 struct sk_buff *skb, int force_sw)
180 const struct ieee80211_cipher *cip = k->wk_cipher;
181 return (cip->ic_miclen > 0 ? cip->ic_enmic(k, skb, force_sw) : 1);
185 * Reset key state to an unused state. The crypto
186 * key allocation mechanism ensures other state (e.g.
187 * key data) is properly setup before a key is used.
189 static __inline void
190 ieee80211_crypto_resetkey(struct ieee80211vap *vap, struct ieee80211_key *k,
191 ieee80211_keyix_t ix)
193 k->wk_cipher = &ieee80211_cipher_none;;
194 k->wk_private = k->wk_cipher->ic_attach(vap, k);
195 k->wk_keyix = ix;
196 k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
200 * Crypto-related notification methods.
202 void ieee80211_notify_replay_failure(struct ieee80211vap *,
203 const struct ieee80211_frame *, const struct ieee80211_key *,
204 u_int64_t rsc);
205 void ieee80211_notify_michael_failure(struct ieee80211vap *,
206 const struct ieee80211_frame *, ieee80211_keyix_t keyix);
207 #endif /* defined(__KERNEL__) || defined(_KERNEL) */
208 #endif /* _NET80211_IEEE80211_CRYPTO_H_ */