add performance improvement for madwifi on low-memory systems
[openwrt.git] / package / madwifi / patches / 309-micfail_detect.patch
1 Index: madwifi-trunk-r3314/ath/if_ath.c
2 ===================================================================
3 --- madwifi-trunk-r3314.orig/ath/if_ath.c 2008-02-20 21:55:41.314256342 +0100
4 +++ madwifi-trunk-r3314/ath/if_ath.c 2008-02-20 21:56:10.819937775 +0100
5 @@ -6443,6 +6443,7 @@
6 int type;
7 u_int phyerr;
8 u_int processed = 0, early_stop = 0;
9 + u_int mic_fail = 0;
10
11 DPRINTF(sc, ATH_DEBUG_RX_PROC, "invoked\n");
12 process_rx_again:
13 @@ -6544,24 +6545,8 @@
14 }
15 if (rs->rs_status & HAL_RXERR_MIC) {
16 sc->sc_stats.ast_rx_badmic++;
17 - /*
18 - * Do minimal work required to hand off
19 - * the 802.11 header for notification.
20 - */
21 - /* XXX frag's and QoS frames */
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 - rs->rs_keyix - 32 : rs->rs_keyix
32 - );
33 -#endif
34 - }
35 + mic_fail = 1;
36 + goto rx_accept;
37 }
38 /*
39 * Reject error frames if we have no vaps that
40 @@ -6600,8 +6585,9 @@
41 /*
42 * Finished monitor mode handling, now reject
43 * error frames before passing to other vaps
44 + * Ignore MIC failures here, as we need to recheck them
45 */
46 - if (rs->rs_status != 0) {
47 + if (rs->rs_status & ~(HAL_RXERR_MIC | HAL_RXERR_DECRYPT)) {
48 ieee80211_dev_kfree_skb(&skb);
49 goto rx_next;
50 }
51 @@ -6609,6 +6595,26 @@
52 /* remove the CRC */
53 skb_trim(skb, skb->len - IEEE80211_CRC_LEN);
54
55 + if (mic_fail) {
56 + /* Ignore control frames which are reported with mic error */
57 + if ((((struct ieee80211_frame *)skb->data)->i_fc[0] &
58 + IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL)
59 + goto drop_micfail;
60 +
61 + ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
62 +
63 + if (ni && ni->ni_table) {
64 + ieee80211_check_mic(ni, skb);
65 + ieee80211_unref_node(&ni);
66 + }
67 +
68 +drop_micfail:
69 + dev_kfree_skb_any(skb);
70 + skb = NULL;
71 + mic_fail = 0;
72 + goto rx_next;
73 + }
74 +
75 /*
76 * From this point on we assume the frame is at least
77 * as large as ieee80211_frame_min; verify that.
78 @@ -6621,6 +6627,7 @@
79 goto rx_next;
80 }
81
82 + /* MIC failure. Drop the packet in any case */
83 /*
84 * Normal receive.
85 */
86 Index: madwifi-trunk-r3314/net80211/ieee80211_crypto_ccmp.c
87 ===================================================================
88 --- madwifi-trunk-r3314.orig/net80211/ieee80211_crypto_ccmp.c 2008-02-20 21:52:06.822033125 +0100
89 +++ madwifi-trunk-r3314/net80211/ieee80211_crypto_ccmp.c 2008-02-20 21:55:45.302483625 +0100
90 @@ -73,7 +73,7 @@
91 static int ccmp_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
92 static int ccmp_decap(struct ieee80211_key *, struct sk_buff *, int);
93 static int ccmp_enmic(struct ieee80211_key *, struct sk_buff *, int);
94 -static int ccmp_demic(struct ieee80211_key *, struct sk_buff *, int);
95 +static int ccmp_demic(struct ieee80211_key *, struct sk_buff *, int, int);
96
97 static const struct ieee80211_cipher ccmp = {
98 .ic_name = "AES-CCM",
99 @@ -308,7 +308,7 @@
100 * Verify and strip MIC from the frame.
101 */
102 static int
103 -ccmp_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
104 +ccmp_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
105 {
106 return 1;
107 }
108 Index: madwifi-trunk-r3314/net80211/ieee80211_crypto.h
109 ===================================================================
110 --- madwifi-trunk-r3314.orig/net80211/ieee80211_crypto.h 2008-02-20 21:50:40.149093918 +0100
111 +++ madwifi-trunk-r3314/net80211/ieee80211_crypto.h 2008-02-20 21:55:45.310484070 +0100
112 @@ -145,7 +145,7 @@
113 int (*ic_encap)(struct ieee80211_key *, struct sk_buff *, u_int8_t);
114 int (*ic_decap)(struct ieee80211_key *, struct sk_buff *, int);
115 int (*ic_enmic)(struct ieee80211_key *, struct sk_buff *, int);
116 - int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int);
117 + int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int, int);
118 };
119 extern const struct ieee80211_cipher ieee80211_cipher_none;
120
121 @@ -163,10 +163,10 @@
122 */
123 static __inline int
124 ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k,
125 - struct sk_buff *skb, int hdrlen)
126 + struct sk_buff *skb, int hdrlen, int force)
127 {
128 const struct ieee80211_cipher *cip = k->wk_cipher;
129 - return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen) : 1);
130 + return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen, force) : 1);
131 }
132
133 /*
134 Index: madwifi-trunk-r3314/net80211/ieee80211_crypto_none.c
135 ===================================================================
136 --- madwifi-trunk-r3314.orig/net80211/ieee80211_crypto_none.c 2008-02-20 21:50:40.153094148 +0100
137 +++ madwifi-trunk-r3314/net80211/ieee80211_crypto_none.c 2008-02-20 21:55:45.314484297 +0100
138 @@ -52,7 +52,7 @@
139 static int none_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
140 static int none_decap(struct ieee80211_key *, struct sk_buff *, int);
141 static int none_enmic(struct ieee80211_key *, struct sk_buff *, int);
142 -static int none_demic(struct ieee80211_key *, struct sk_buff *, int);
143 +static int none_demic(struct ieee80211_key *, struct sk_buff *, int, int);
144
145 const struct ieee80211_cipher ieee80211_cipher_none = {
146 .ic_name = "NONE",
147 @@ -137,7 +137,7 @@
148 }
149
150 static int
151 -none_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
152 +none_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
153 {
154 struct ieee80211vap *vap = k->wk_private;
155
156 Index: madwifi-trunk-r3314/net80211/ieee80211_crypto_tkip.c
157 ===================================================================
158 --- madwifi-trunk-r3314.orig/net80211/ieee80211_crypto_tkip.c 2008-02-20 21:50:40.161094600 +0100
159 +++ madwifi-trunk-r3314/net80211/ieee80211_crypto_tkip.c 2008-02-20 21:55:45.314484297 +0100
160 @@ -57,7 +57,7 @@
161 static int tkip_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
162 static int tkip_enmic(struct ieee80211_key *, struct sk_buff *, int);
163 static int tkip_decap(struct ieee80211_key *, struct sk_buff *, int);
164 -static int tkip_demic(struct ieee80211_key *, struct sk_buff *, int);
165 +static int tkip_demic(struct ieee80211_key *, struct sk_buff *, int, int);
166
167 static const struct ieee80211_cipher tkip = {
168 .ic_name = "TKIP",
169 @@ -339,7 +339,7 @@
170 * Verify and strip MIC from the frame.
171 */
172 static int
173 -tkip_demic(struct ieee80211_key *k, struct sk_buff *skb0, int hdrlen)
174 +tkip_demic(struct ieee80211_key *k, struct sk_buff *skb0, int hdrlen, int force)
175 {
176 struct tkip_ctx *ctx = k->wk_private;
177 struct sk_buff *skb;
178 @@ -355,7 +355,7 @@
179 }
180 wh = (struct ieee80211_frame *) skb0->data;
181 /* NB: skb left pointing at last in chain */
182 - if (k->wk_flags & IEEE80211_KEY_SWMIC) {
183 + if ((k->wk_flags & IEEE80211_KEY_SWMIC) || force) {
184 struct ieee80211vap *vap = ctx->tc_vap;
185 u8 mic[IEEE80211_WEP_MICLEN];
186 u8 mic0[IEEE80211_WEP_MICLEN];
187 Index: madwifi-trunk-r3314/net80211/ieee80211_crypto_wep.c
188 ===================================================================
189 --- madwifi-trunk-r3314.orig/net80211/ieee80211_crypto_wep.c 2008-02-20 21:50:40.169095058 +0100
190 +++ madwifi-trunk-r3314/net80211/ieee80211_crypto_wep.c 2008-02-20 21:55:45.314484297 +0100
191 @@ -54,7 +54,7 @@
192 static int wep_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
193 static int wep_decap(struct ieee80211_key *, struct sk_buff *, int);
194 static int wep_enmic(struct ieee80211_key *, struct sk_buff *, int);
195 -static int wep_demic(struct ieee80211_key *, struct sk_buff *, int);
196 +static int wep_demic(struct ieee80211_key *, struct sk_buff *, int, int);
197
198 static const struct ieee80211_cipher wep = {
199 .ic_name = "WEP",
200 @@ -244,7 +244,7 @@
201 * Verify and strip MIC from the frame.
202 */
203 static int
204 -wep_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen)
205 +wep_demic(struct ieee80211_key *k, struct sk_buff *skb, int hdrlen, int force)
206 {
207 return 1;
208 }
209 Index: madwifi-trunk-r3314/net80211/ieee80211_input.c
210 ===================================================================
211 --- madwifi-trunk-r3314.orig/net80211/ieee80211_input.c 2008-02-20 21:55:41.318256570 +0100
212 +++ madwifi-trunk-r3314/net80211/ieee80211_input.c 2008-02-20 21:55:45.318484528 +0100
213 @@ -669,7 +669,7 @@
214 * Next strip any MSDU crypto bits.
215 */
216 if (key != NULL &&
217 - !ieee80211_crypto_demic(vap, key, skb, hdrspace)) {
218 + !ieee80211_crypto_demic(vap, key, skb, hdrspace, 0)) {
219 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
220 ni->ni_macaddr, "data", "%s", "demic error");
221 IEEE80211_NODE_STAT(ni, rx_demicfail);
222 @@ -4293,6 +4293,47 @@
223 }
224 #endif
225
226 +/*
227 + * Process a frame w/ hw detected MIC failure.
228 + * The frame will be dropped in any case.
229 + */
230 +void
231 +ieee80211_check_mic(struct ieee80211_node *ni, struct sk_buff *skb)
232 +{
233 + struct ieee80211vap *vap = ni->ni_vap;
234 +
235 + struct ieee80211_frame *wh;
236 + struct ieee80211_key *key;
237 + int hdrspace;
238 + struct ieee80211com *ic = vap->iv_ic;
239 +
240 + if (skb->len < sizeof(struct ieee80211_frame_min)) {
241 + IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
242 + ni->ni_macaddr, NULL,
243 + "too short (1): len %u", skb->len);
244 + vap->iv_stats.is_rx_tooshort++;
245 + return;
246 + }
247 +
248 + wh = (struct ieee80211_frame *)skb->data;
249 +
250 + hdrspace = ieee80211_hdrspace(ic, wh);
251 + key = ieee80211_crypto_decap(ni, skb, hdrspace);
252 + if (key == NULL) {
253 + /* NB: stats+msgs handled in crypto_decap */
254 + IEEE80211_NODE_STAT(ni, rx_wepfail);
255 + return;
256 + }
257 +
258 + if (!ieee80211_crypto_demic(vap, key, skb, hdrspace, 1)) {
259 + IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
260 + ni->ni_macaddr, "data", "%s", "demic error");
261 + IEEE80211_NODE_STAT(ni, rx_demicfail);
262 + }
263 + return;
264 +}
265 +EXPORT_SYMBOL(ieee80211_check_mic);
266 +
267 #ifdef IEEE80211_DEBUG
268 /*
269 * Debugging support.
270 Index: madwifi-trunk-r3314/net80211/ieee80211_proto.h
271 ===================================================================
272 --- madwifi-trunk-r3314.orig/net80211/ieee80211_proto.h 2008-02-20 21:50:40.185095969 +0100
273 +++ madwifi-trunk-r3314/net80211/ieee80211_proto.h 2008-02-20 21:55:45.318484528 +0100
274 @@ -90,6 +90,7 @@
275 void ieee80211_set11gbasicrates(struct ieee80211_rateset *, enum ieee80211_phymode);
276 enum ieee80211_phymode ieee80211_get11gbasicrates(struct ieee80211_rateset *);
277 void ieee80211_send_pspoll(struct ieee80211_node *);
278 +void ieee80211_check_mic(struct ieee80211_node *, struct sk_buff *);
279
280 /*
281 * Return the size of the 802.11 header for a management or data frame.
282 Index: madwifi-trunk-r3314/net80211/ieee80211_linux.c
283 ===================================================================
284 --- madwifi-trunk-r3314.orig/net80211/ieee80211_linux.c 2008-02-20 21:52:06.810032443 +0100
285 +++ madwifi-trunk-r3314/net80211/ieee80211_linux.c 2008-02-20 21:55:45.318484528 +0100
286 @@ -337,8 +337,8 @@
287 /* TODO: needed parameters: count, keyid, key type, src address, TSC */
288 snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=" MAC_FMT ")", tag,
289 k->wk_keyix,
290 - IEEE80211_IS_MULTICAST(wh->i_addr1) ? "broad" : "uni",
291 - MAC_ADDR(wh->i_addr1));
292 + IEEE80211_IS_MULTICAST(wh->i_addr2) ? "broad" : "uni",
293 + MAC_ADDR(wh->i_addr2));
294 memset(&wrqu, 0, sizeof(wrqu));
295 wrqu.data.length = strlen(buf);
296 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
297 Index: madwifi-trunk-r3314/net80211/ieee80211_output.c
298 ===================================================================
299 --- madwifi-trunk-r3314.orig/net80211/ieee80211_output.c 2008-02-20 21:50:40.197096654 +0100
300 +++ madwifi-trunk-r3314/net80211/ieee80211_output.c 2008-02-20 21:55:45.326484992 +0100
301 @@ -1074,13 +1074,16 @@
302 cip = (struct ieee80211_cipher *) key->wk_cipher;
303 ciphdrsize = cip->ic_header;
304 tailsize += (cip->ic_trailer + cip->ic_miclen);
305 +
306 + /* add the 8 bytes MIC length */
307 + if (cip->ic_cipher == IEEE80211_CIPHER_TKIP)
308 + pktlen += IEEE80211_WEP_MICLEN;
309 }
310
311 pdusize = vap->iv_fragthreshold - (hdrsize_nopad + ciphdrsize);
312 fragcnt = *framecnt =
313 - ((pktlen - (hdrsize_nopad + ciphdrsize)) / pdusize) +
314 - (((pktlen - (hdrsize_nopad + ciphdrsize)) %
315 - pdusize == 0) ? 0 : 1);
316 + ((pktlen - hdrsize_nopad) / pdusize) +
317 + (((pktlen - hdrsize_nopad) % pdusize == 0) ? 0 : 1);
318
319 /*
320 * Allocate sk_buff for each subsequent fragment; First fragment
321 Index: madwifi-trunk-r3314/net80211/ieee80211_node.c
322 ===================================================================
323 --- madwifi-trunk-r3314.orig/net80211/ieee80211_node.c 2008-02-20 21:55:41.318256570 +0100
324 +++ madwifi-trunk-r3314/net80211/ieee80211_node.c 2008-02-20 21:55:45.326484992 +0100
325 @@ -2261,11 +2261,13 @@
326 /* From this point onwards we can no longer find the node,
327 * so no more references are generated
328 */
329 - ieee80211_remove_wds_addr(nt, ni->ni_macaddr);
330 - ieee80211_del_wds_node(nt, ni);
331 - IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
332 - node_table_leave_locked(nt, ni);
333 - IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
334 + if (nt) {
335 + ieee80211_remove_wds_addr(nt, ni->ni_macaddr);
336 + ieee80211_del_wds_node(nt, ni);
337 + IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
338 + node_table_leave_locked(nt, ni);
339 + IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
340 + }
341
342 /*
343 * If node wasn't previously associated all
This page took 0.056515 seconds and 5 git commands to generate.