huge madwifi update - use a madwifi-ng-refcount snapshot as base, includes lots of...
[openwrt/svn-archive/archive.git] / package / madwifi / patches / 309-micfail_detect.patch
1 diff -urN madwifi-ng-refcount-r2313-20070505.old/ath/if_ath.c madwifi-ng-refcount-r2313-20070505.dev/ath/if_ath.c
2 --- madwifi-ng-refcount-r2313-20070505.old/ath/if_ath.c 2007-05-13 18:17:56.785936264 +0200
3 +++ madwifi-ng-refcount-r2313-20070505.dev/ath/if_ath.c 2007-05-13 18:17:56.878922128 +0200
4 @@ -5640,6 +5640,7 @@
5 u_int phyerr;
6 int processed = 0, early_stop = 0;
7 int rx_limit = dev->quota;
8 + int mic_fail = 0;
9
10 /* Let the 802.11 layer know about the new noise floor */
11 ic->ic_channoise = sc->sc_channoise;
12 @@ -5734,32 +5735,16 @@
13 }
14 if (ds->ds_rxstat.rs_status & HAL_RXERR_MIC) {
15 sc->sc_stats.ast_rx_badmic++;
16 - /*
17 - * Do minimal work required to hand off
18 - * the 802.11 header for notification.
19 - */
20 - /* XXX frag's and QoS frames */
21 - len = ds->ds_rxstat.rs_datalen;
22 - if (len >= sizeof (struct ieee80211_frame)) {
23 - bus_dma_sync_single(sc->sc_bdev,
24 - bf->bf_skbaddr, len,
25 - BUS_DMA_FROMDEVICE);
26 -#if 0
27 -/* XXX revalidate MIC, lookup ni to find VAP */
28 - ieee80211_notify_michael_failure(ic,
29 - (struct ieee80211_frame *) skb->data,
30 - sc->sc_splitmic ?
31 - ds->ds_rxstat.rs_keyix - 32 :
32 - ds->ds_rxstat.rs_keyix
33 - );
34 -#endif
35 - }
36 + mic_fail = 1;
37 }
38 /*
39 * Reject error frames if we have no vaps that
40 * are operating in monitor mode.
41 */
42 - if(sc->sc_nmonvaps == 0) goto rx_next;
43 + if ((ds->ds_rxstat.rs_status & ~HAL_RXERR_MIC) &&
44 + ((ds->ds_rxstat.rs_status &~ HAL_RXERR_DECRYPT) ||
45 + (sc->sc_ic.ic_opmode != IEEE80211_M_MONITOR)))
46 + goto rx_next;
47 }
48 rx_accept:
49 /*
50 @@ -5843,6 +5828,20 @@
51 ds->ds_rxstat.rs_rssi);
52 }
53
54 + /* MIC failure. Drop the packet in any case */
55 + if (mic_fail) {
56 + ni = ieee80211_find_rxnode(ic,
57 + (const struct ieee80211_frame_min *) skb->data);
58 + if (ni != NULL) {
59 + ieee80211_check_mic(ni, skb);
60 + ieee80211_unref_node(&ni);
61 + }
62 + dev_kfree_skb_any(skb);
63 + skb = NULL;
64 + mic_fail = 0;
65 + goto rx_next;
66 + }
67 +
68 /*
69 * Locate the node for sender, track state, and then
70 * pass the (referenced) node up to the 802.11 layer
71 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_ccmp.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_ccmp.c
72 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_ccmp.c 2007-04-13 07:53:25.000000000 +0200
73 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_ccmp.c 2007-05-13 18:17:56.879921976 +0200
74 @@ -78,7 +78,7 @@
75 static int ccmp_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
76 static int ccmp_decap(struct ieee80211_key *, struct sk_buff *, int);
77 static int ccmp_enmic(struct ieee80211_key *, struct sk_buff *, int);
78 -static int ccmp_demic(struct ieee80211_key *, struct sk_buff *, int);
79 +static int ccmp_demic(struct ieee80211_key *, struct sk_buff *, int, int);
80
81 static const struct ieee80211_cipher ccmp = {
82 .ic_name = "AES-CCM",
83 @@ -298,7 +298,7 @@
84 * Verify and strip MIC from the frame.
85 */
86 static int
87 -ccmp_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
88 +ccmp_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
89 {
90 return 1;
91 }
92 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto.h madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto.h
93 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto.h 2007-04-25 22:29:55.000000000 +0200
94 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto.h 2007-05-13 18:17:56.880921824 +0200
95 @@ -145,7 +145,7 @@
96 int (*ic_encap)(struct ieee80211_key *, struct sk_buff *, u_int8_t);
97 int (*ic_decap)(struct ieee80211_key *, struct sk_buff *, int);
98 int (*ic_enmic)(struct ieee80211_key *, struct sk_buff *, int);
99 - int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int);
100 + int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int, int);
101 };
102 extern const struct ieee80211_cipher ieee80211_cipher_none;
103
104 @@ -163,10 +163,10 @@
105 */
106 static __inline int
107 ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k,
108 - struct sk_buff *skb, int hdrlen)
109 + struct sk_buff *skb, int hdrlen, int force)
110 {
111 const struct ieee80211_cipher *cip = k->wk_cipher;
112 - return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen) : 1);
113 + return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen, force) : 1);
114 }
115
116 /*
117 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_none.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_none.c
118 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_none.c 2006-09-20 10:45:13.000000000 +0200
119 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_none.c 2007-05-13 18:17:56.880921824 +0200
120 @@ -52,7 +52,7 @@
121 static int none_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
122 static int none_decap(struct ieee80211_key *, struct sk_buff *, int);
123 static int none_enmic(struct ieee80211_key *, struct sk_buff *, int);
124 -static int none_demic(struct ieee80211_key *, struct sk_buff *, int);
125 +static int none_demic(struct ieee80211_key *, struct sk_buff *, int, int);
126
127 const struct ieee80211_cipher ieee80211_cipher_none = {
128 .ic_name = "NONE",
129 @@ -137,7 +137,7 @@
130 }
131
132 static int
133 -none_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
134 +none_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
135 {
136 struct ieee80211vap *vap = k->wk_private;
137
138 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_tkip.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_tkip.c
139 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_tkip.c 2007-01-30 04:51:52.000000000 +0100
140 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_tkip.c 2007-05-13 18:17:56.880921824 +0200
141 @@ -57,7 +57,7 @@
142 static int tkip_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
143 static int tkip_enmic(struct ieee80211_key *, struct sk_buff *, int);
144 static int tkip_decap(struct ieee80211_key *, struct sk_buff *, int);
145 -static int tkip_demic(struct ieee80211_key *, struct sk_buff *, int);
146 +static int tkip_demic(struct ieee80211_key *, struct sk_buff *, int, int);
147
148 static const struct ieee80211_cipher tkip = {
149 .ic_name = "TKIP",
150 @@ -339,7 +339,7 @@
151 * Verify and strip MIC from the frame.
152 */
153 static int
154 -tkip_demic(struct ieee80211_key *k, struct sk_buff *skb0, int hdrlen)
155 +tkip_demic(struct ieee80211_key *k, struct sk_buff *skb0, int hdrlen, int force)
156 {
157 struct tkip_ctx *ctx = k->wk_private;
158 struct sk_buff *skb;
159 @@ -355,7 +355,7 @@
160 }
161 wh = (struct ieee80211_frame *) skb0->data;
162 /* NB: skb left pointing at last in chain */
163 - if (k->wk_flags & IEEE80211_KEY_SWMIC) {
164 + if ((k->wk_flags & IEEE80211_KEY_SWMIC) || force) {
165 struct ieee80211vap *vap = ctx->tc_vap;
166 u8 mic[IEEE80211_WEP_MICLEN];
167 u8 mic0[IEEE80211_WEP_MICLEN];
168 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_wep.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_wep.c
169 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_crypto_wep.c 2006-09-20 10:45:13.000000000 +0200
170 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_crypto_wep.c 2007-05-13 18:17:56.881921672 +0200
171 @@ -54,7 +54,7 @@
172 static int wep_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
173 static int wep_decap(struct ieee80211_key *, struct sk_buff *, int);
174 static int wep_enmic(struct ieee80211_key *, struct sk_buff *, int);
175 -static int wep_demic(struct ieee80211_key *, struct sk_buff *, int);
176 +static int wep_demic(struct ieee80211_key *, struct sk_buff *, int, int);
177
178 static const struct ieee80211_cipher wep = {
179 .ic_name = "WEP",
180 @@ -244,7 +244,7 @@
181 * Verify and strip MIC from the frame.
182 */
183 static int
184 -wep_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
185 +wep_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
186 {
187 return 1;
188 }
189 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_input.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_input.c
190 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_input.c 2007-05-13 18:17:56.786936112 +0200
191 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_input.c 2007-05-13 18:17:56.883921368 +0200
192 @@ -654,7 +654,7 @@
193 * Next strip any MSDU crypto bits.
194 */
195 if (key != NULL &&
196 - !ieee80211_crypto_demic(vap, key, skb, hdrspace)) {
197 + !ieee80211_crypto_demic(vap, key, skb, hdrspace, 0)) {
198 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
199 ni->ni_macaddr, "data", "%s", "demic error");
200 IEEE80211_NODE_STAT(ni, rx_demicfail);
201 @@ -3734,6 +3734,47 @@
202 }
203 #endif
204
205 +/*
206 + * Process a frame w/ hw detected MIC failure.
207 + * The frame will be dropped in any case.
208 + */
209 +void
210 +ieee80211_check_mic(struct ieee80211_node *ni, struct sk_buff *skb)
211 +{
212 + struct ieee80211vap *vap = ni->ni_vap;
213 +
214 + struct ieee80211_frame *wh;
215 + struct ieee80211_key *key;
216 + int hdrspace;
217 + struct ieee80211com *ic = vap->iv_ic;
218 +
219 + if (skb->len < sizeof(struct ieee80211_frame_min)) {
220 + IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
221 + ni->ni_macaddr, NULL,
222 + "too short (1): len %u", skb->len);
223 + vap->iv_stats.is_rx_tooshort++;
224 + return;
225 + }
226 +
227 + wh = (struct ieee80211_frame *)skb->data;
228 +
229 + hdrspace = ieee80211_hdrspace(ic, wh);
230 + key = ieee80211_crypto_decap(ni, skb, hdrspace);
231 + if (key == NULL) {
232 + /* NB: stats+msgs handled in crypto_decap */
233 + IEEE80211_NODE_STAT(ni, rx_wepfail);
234 + return;
235 + }
236 +
237 + if (!ieee80211_crypto_demic(vap, key, skb, hdrspace, 1)) {
238 + IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
239 + ni->ni_macaddr, "data", "%s", "demic error");
240 + IEEE80211_NODE_STAT(ni, rx_demicfail);
241 + }
242 + return;
243 +}
244 +EXPORT_SYMBOL(ieee80211_check_mic);
245 +
246 #ifdef IEEE80211_DEBUG
247 /*
248 * Debugging support.
249 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_linux.c madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_linux.c
250 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_linux.c 2007-04-25 22:29:55.000000000 +0200
251 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_linux.c 2007-05-13 18:17:56.883921368 +0200
252 @@ -309,8 +309,8 @@
253
254 /* TODO: needed parameters: count, keyid, key type, src address, TSC */
255 snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=%s)", tag,
256 - keyix, IEEE80211_IS_MULTICAST(wh->i_addr1) ? "broad" : "uni",
257 - ether_sprintf(wh->i_addr1));
258 + keyix, IEEE80211_IS_MULTICAST(wh->i_addr2) ? "broad" : "uni",
259 + ether_sprintf(wh->i_addr2));
260 memset(&wrqu, 0, sizeof(wrqu));
261 wrqu.data.length = strlen(buf);
262 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
263 diff -urN madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_proto.h madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_proto.h
264 --- madwifi-ng-refcount-r2313-20070505.old/net80211/ieee80211_proto.h 2007-05-13 18:17:56.579967576 +0200
265 +++ madwifi-ng-refcount-r2313-20070505.dev/net80211/ieee80211_proto.h 2007-05-13 18:17:56.884921216 +0200
266 @@ -91,6 +91,7 @@
267 void ieee80211_set11gbasicrates(struct ieee80211_rateset *, enum ieee80211_phymode);
268 enum ieee80211_phymode ieee80211_get11gbasicrates(struct ieee80211_rateset *);
269 void ieee80211_send_pspoll(struct ieee80211_node *);
270 +void ieee80211_check_mic(struct ieee80211_node *, struct sk_buff *);
271
272 /*
273 * Return the size of the 802.11 header for a management or data frame.