blob: fa592cb6bf9a8f1560fc9f30e8f43d13b3dbdddd [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001#include <linux/etherdevice.h>
John W. Linville274bfb82008-10-29 11:35:05 -04002#include <net/lib80211.h>
Dan Williams1ea893f2009-02-11 17:17:10 -05003#include <linux/if_arp.h>
Jouni Malinenff1d2762005-05-12 22:54:16 -04004
5#include "hostap_80211.h"
6#include "hostap.h"
Adrian Bunk5fad5a22006-01-14 03:09:34 +01007#include "hostap_ap.h"
8
9/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
10/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
11static unsigned char rfc1042_header[] =
12{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
13/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
14static unsigned char bridge_tunnel_header[] =
15{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
16/* No encapsulation header if EtherType < 0x600 (=length) */
Jouni Malinenff1d2762005-05-12 22:54:16 -040017
18void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
19 struct hostap_80211_rx_status *rx_stats)
20{
Dan Williams1ea893f2009-02-11 17:17:10 -050021 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -040022 u16 fc;
23
Dan Williams1ea893f2009-02-11 17:17:10 -050024 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -040025
26 printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
27 "jiffies=%ld\n",
28 name, rx_stats->signal, rx_stats->noise, rx_stats->rate,
29 skb->len, jiffies);
30
31 if (skb->len < 2)
32 return;
33
Dan Williams1ea893f2009-02-11 17:17:10 -050034 fc = le16_to_cpu(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -040035 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s",
Dan Williams1ea893f2009-02-11 17:17:10 -050036 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
37 (fc & IEEE80211_FCTL_STYPE) >> 4,
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -070038 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
39 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
Jouni Malinenff1d2762005-05-12 22:54:16 -040040
41 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
42 printk("\n");
43 return;
44 }
45
46 printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
Dan Williams1ea893f2009-02-11 17:17:10 -050047 le16_to_cpu(hdr->seq_ctrl));
Jouni Malinenff1d2762005-05-12 22:54:16 -040048
Johannes Berge1749612008-10-27 15:59:26 -070049 printk(KERN_DEBUG " A1=%pM", hdr->addr1);
50 printk(" A2=%pM", hdr->addr2);
51 printk(" A3=%pM", hdr->addr3);
Jouni Malinenff1d2762005-05-12 22:54:16 -040052 if (skb->len >= 30)
Johannes Berge1749612008-10-27 15:59:26 -070053 printk(" A4=%pM", hdr->addr4);
Jouni Malinenff1d2762005-05-12 22:54:16 -040054 printk("\n");
55}
56
57
58/* Send RX frame to netif with 802.11 (and possible prism) header.
59 * Called from hardware or software IRQ context. */
60int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
61 struct hostap_80211_rx_status *rx_stats, int type)
62{
63 struct hostap_interface *iface;
64 local_info_t *local;
65 int hdrlen, phdrlen, head_need, tail_need;
66 u16 fc;
67 int prism_header, ret;
Dan Williams1ea893f2009-02-11 17:17:10 -050068 struct ieee80211_hdr *fhdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -040069
70 iface = netdev_priv(dev);
71 local = iface->local;
Jouni Malinenff1d2762005-05-12 22:54:16 -040072
73 if (dev->type == ARPHRD_IEEE80211_PRISM) {
74 if (local->monitor_type == PRISM2_MONITOR_PRISM) {
75 prism_header = 1;
76 phdrlen = sizeof(struct linux_wlan_ng_prism_hdr);
77 } else { /* local->monitor_type == PRISM2_MONITOR_CAPHDR */
78 prism_header = 2;
79 phdrlen = sizeof(struct linux_wlan_ng_cap_hdr);
80 }
Pavel Roskin573b9332008-06-27 16:20:10 -040081 } else if (dev->type == ARPHRD_IEEE80211_RADIOTAP) {
82 prism_header = 3;
83 phdrlen = sizeof(struct hostap_radiotap_rx);
Jouni Malinenff1d2762005-05-12 22:54:16 -040084 } else {
85 prism_header = 0;
86 phdrlen = 0;
87 }
88
Dan Williams1ea893f2009-02-11 17:17:10 -050089 fhdr = (struct ieee80211_hdr *) skb->data;
90 fc = le16_to_cpu(fhdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -040091
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -070092 if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -040093 printk(KERN_DEBUG "%s: dropped management frame with header "
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -070094 "version %d\n", dev->name, fc & IEEE80211_FCTL_VERS);
Jouni Malinenff1d2762005-05-12 22:54:16 -040095 dev_kfree_skb_any(skb);
96 return 0;
97 }
98
Dan Williams1ea893f2009-02-11 17:17:10 -050099 hdrlen = hostap_80211_get_hdrlen(fhdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400100
101 /* check if there is enough room for extra data; if not, expand skb
102 * buffer to be large enough for the changes */
103 head_need = phdrlen;
104 tail_need = 0;
105#ifdef PRISM2_ADD_BOGUS_CRC
106 tail_need += 4;
107#endif /* PRISM2_ADD_BOGUS_CRC */
108
109 head_need -= skb_headroom(skb);
110 tail_need -= skb_tailroom(skb);
111
112 if (head_need > 0 || tail_need > 0) {
113 if (pskb_expand_head(skb, head_need > 0 ? head_need : 0,
114 tail_need > 0 ? tail_need : 0,
115 GFP_ATOMIC)) {
116 printk(KERN_DEBUG "%s: prism2_rx_80211 failed to "
117 "reallocate skb buffer\n", dev->name);
118 dev_kfree_skb_any(skb);
119 return 0;
120 }
121 }
122
123 /* We now have an skb with enough head and tail room, so just insert
124 * the extra data */
125
126#ifdef PRISM2_ADD_BOGUS_CRC
127 memset(skb_put(skb, 4), 0xff, 4); /* Prism2 strips CRC */
128#endif /* PRISM2_ADD_BOGUS_CRC */
129
130 if (prism_header == 1) {
131 struct linux_wlan_ng_prism_hdr *hdr;
132 hdr = (struct linux_wlan_ng_prism_hdr *)
133 skb_push(skb, phdrlen);
134 memset(hdr, 0, phdrlen);
135 hdr->msgcode = LWNG_CAP_DID_BASE;
136 hdr->msglen = sizeof(*hdr);
137 memcpy(hdr->devname, dev->name, sizeof(hdr->devname));
138#define LWNG_SETVAL(f,i,s,l,d) \
139hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \
140hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
141 LWNG_SETVAL(hosttime, 1, 0, 4, jiffies);
Brandon Enochs3e1d3932005-07-30 12:50:04 -0700142 LWNG_SETVAL(mactime, 2, 0, 4, rx_stats->mac_time);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400143 LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0);
144 LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0);
145 LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0);
146 LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal);
147 LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise);
148 LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5);
149 LWNG_SETVAL(istx, 9, 0, 4, 0);
150 LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen);
151#undef LWNG_SETVAL
152 } else if (prism_header == 2) {
153 struct linux_wlan_ng_cap_hdr *hdr;
154 hdr = (struct linux_wlan_ng_cap_hdr *)
155 skb_push(skb, phdrlen);
156 memset(hdr, 0, phdrlen);
157 hdr->version = htonl(LWNG_CAPHDR_VERSION);
158 hdr->length = htonl(phdrlen);
159 hdr->mactime = __cpu_to_be64(rx_stats->mac_time);
160 hdr->hosttime = __cpu_to_be64(jiffies);
161 hdr->phytype = htonl(4); /* dss_dot11_b */
162 hdr->channel = htonl(local->channel);
163 hdr->datarate = htonl(rx_stats->rate);
164 hdr->antenna = htonl(0); /* unknown */
165 hdr->priority = htonl(0); /* unknown */
166 hdr->ssi_type = htonl(3); /* raw */
167 hdr->ssi_signal = htonl(rx_stats->signal);
168 hdr->ssi_noise = htonl(rx_stats->noise);
169 hdr->preamble = htonl(0); /* unknown */
170 hdr->encoding = htonl(1); /* cck */
Pavel Roskin573b9332008-06-27 16:20:10 -0400171 } else if (prism_header == 3) {
172 struct hostap_radiotap_rx *hdr;
173 hdr = (struct hostap_radiotap_rx *)skb_push(skb, phdrlen);
174 memset(hdr, 0, phdrlen);
175 hdr->hdr.it_len = cpu_to_le16(phdrlen);
176 hdr->hdr.it_present =
177 cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
178 (1 << IEEE80211_RADIOTAP_CHANNEL) |
179 (1 << IEEE80211_RADIOTAP_RATE) |
180 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
181 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE));
182 hdr->tsft = cpu_to_le64(rx_stats->mac_time);
183 hdr->chan_freq = cpu_to_le16(freq_list[local->channel - 1]);
184 hdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_CCK |
185 IEEE80211_CHAN_2GHZ);
186 hdr->rate = rx_stats->rate / 5;
187 hdr->dbm_antsignal = rx_stats->signal;
188 hdr->dbm_antnoise = rx_stats->noise;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400189 }
190
191 ret = skb->len - phdrlen;
192 skb->dev = dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700193 skb_reset_mac_header(skb);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400194 skb_pull(skb, hdrlen);
195 if (prism_header)
196 skb_pull(skb, phdrlen);
197 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800198 skb->protocol = cpu_to_be16(ETH_P_802_2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400199 memset(skb->cb, 0, sizeof(skb->cb));
200 netif_rx(skb);
201
202 return ret;
203}
204
205
206/* Called only as a tasklet (software IRQ) */
207static void monitor_rx(struct net_device *dev, struct sk_buff *skb,
208 struct hostap_80211_rx_status *rx_stats)
209{
Jouni Malinenff1d2762005-05-12 22:54:16 -0400210 int len;
211
212 len = prism2_rx_80211(dev, skb, rx_stats, PRISM2_RX_MONITOR);
Stephen Hemminger4cfa8e42009-03-20 19:36:42 +0000213 dev->stats.rx_packets++;
214 dev->stats.rx_bytes += len;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400215}
216
217
218/* Called only as a tasklet (software IRQ) */
219static struct prism2_frag_entry *
220prism2_frag_cache_find(local_info_t *local, unsigned int seq,
221 unsigned int frag, u8 *src, u8 *dst)
222{
223 struct prism2_frag_entry *entry;
224 int i;
225
226 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
227 entry = &local->frag_cache[i];
228 if (entry->skb != NULL &&
229 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
230 printk(KERN_DEBUG "%s: expiring fragment cache entry "
231 "seq=%u last_frag=%u\n",
232 local->dev->name, entry->seq, entry->last_frag);
233 dev_kfree_skb(entry->skb);
234 entry->skb = NULL;
235 }
236
237 if (entry->skb != NULL && entry->seq == seq &&
238 (entry->last_frag + 1 == frag || frag == -1) &&
239 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
240 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
241 return entry;
242 }
243
244 return NULL;
245}
246
247
248/* Called only as a tasklet (software IRQ) */
249static struct sk_buff *
Dan Williams1ea893f2009-02-11 17:17:10 -0500250prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400251{
252 struct sk_buff *skb = NULL;
253 u16 sc;
254 unsigned int frag, seq;
255 struct prism2_frag_entry *entry;
256
Dan Williams1ea893f2009-02-11 17:17:10 -0500257 sc = le16_to_cpu(hdr->seq_ctrl);
258 frag = sc & IEEE80211_SCTL_FRAG;
259 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400260
261 if (frag == 0) {
262 /* Reserve enough space to fit maximum frame length */
263 skb = dev_alloc_skb(local->dev->mtu +
Dan Williams1ea893f2009-02-11 17:17:10 -0500264 sizeof(struct ieee80211_hdr) +
Jouni Malinenff1d2762005-05-12 22:54:16 -0400265 8 /* LLC */ +
266 2 /* alignment */ +
267 8 /* WEP */ + ETH_ALEN /* WDS */);
268 if (skb == NULL)
269 return NULL;
270
271 entry = &local->frag_cache[local->frag_next_idx];
272 local->frag_next_idx++;
273 if (local->frag_next_idx >= PRISM2_FRAG_CACHE_LEN)
274 local->frag_next_idx = 0;
275
276 if (entry->skb != NULL)
277 dev_kfree_skb(entry->skb);
278
279 entry->first_frag_time = jiffies;
280 entry->seq = seq;
281 entry->last_frag = frag;
282 entry->skb = skb;
283 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
284 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
285 } else {
286 /* received a fragment of a frame for which the head fragment
287 * should have already been received */
288 entry = prism2_frag_cache_find(local, seq, frag, hdr->addr2,
289 hdr->addr1);
290 if (entry != NULL) {
291 entry->last_frag = frag;
292 skb = entry->skb;
293 }
294 }
295
296 return skb;
297}
298
299
300/* Called only as a tasklet (software IRQ) */
301static int prism2_frag_cache_invalidate(local_info_t *local,
Dan Williams1ea893f2009-02-11 17:17:10 -0500302 struct ieee80211_hdr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400303{
304 u16 sc;
305 unsigned int seq;
306 struct prism2_frag_entry *entry;
307
Dan Williams1ea893f2009-02-11 17:17:10 -0500308 sc = le16_to_cpu(hdr->seq_ctrl);
309 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400310
311 entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1);
312
313 if (entry == NULL) {
314 printk(KERN_DEBUG "%s: could not invalidate fragment cache "
315 "entry (seq=%u)\n",
316 local->dev->name, seq);
317 return -1;
318 }
319
320 entry->skb = NULL;
321 return 0;
322}
323
324
325static struct hostap_bss_info *__hostap_get_bss(local_info_t *local, u8 *bssid,
326 u8 *ssid, size_t ssid_len)
327{
328 struct list_head *ptr;
329 struct hostap_bss_info *bss;
330
331 list_for_each(ptr, &local->bss_list) {
332 bss = list_entry(ptr, struct hostap_bss_info, list);
333 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
334 (ssid == NULL ||
335 (ssid_len == bss->ssid_len &&
336 memcmp(ssid, bss->ssid, ssid_len) == 0))) {
337 list_move(&bss->list, &local->bss_list);
338 return bss;
339 }
340 }
341
342 return NULL;
343}
344
345
346static struct hostap_bss_info *__hostap_add_bss(local_info_t *local, u8 *bssid,
347 u8 *ssid, size_t ssid_len)
348{
349 struct hostap_bss_info *bss;
350
351 if (local->num_bss_info >= HOSTAP_MAX_BSS_COUNT) {
352 bss = list_entry(local->bss_list.prev,
353 struct hostap_bss_info, list);
354 list_del(&bss->list);
355 local->num_bss_info--;
356 } else {
Julia Lawallaca8c6f2010-05-11 20:25:56 +0200357 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400358 if (bss == NULL)
359 return NULL;
360 }
361
362 memset(bss, 0, sizeof(*bss));
363 memcpy(bss->bssid, bssid, ETH_ALEN);
364 memcpy(bss->ssid, ssid, ssid_len);
365 bss->ssid_len = ssid_len;
366 local->num_bss_info++;
367 list_add(&bss->list, &local->bss_list);
368 return bss;
369}
370
371
372static void __hostap_expire_bss(local_info_t *local)
373{
374 struct hostap_bss_info *bss;
375
376 while (local->num_bss_info > 0) {
377 bss = list_entry(local->bss_list.prev,
378 struct hostap_bss_info, list);
379 if (!time_after(jiffies, bss->last_update + 60 * HZ))
380 break;
381
382 list_del(&bss->list);
383 local->num_bss_info--;
384 kfree(bss);
385 }
386}
387
388
389/* Both IEEE 802.11 Beacon and Probe Response frames have similar structure, so
390 * the same routine can be used to parse both of them. */
391static void hostap_rx_sta_beacon(local_info_t *local, struct sk_buff *skb,
392 int stype)
393{
394 struct hostap_ieee80211_mgmt *mgmt;
395 int left, chan = 0;
396 u8 *pos;
397 u8 *ssid = NULL, *wpa = NULL, *rsn = NULL;
398 size_t ssid_len = 0, wpa_len = 0, rsn_len = 0;
399 struct hostap_bss_info *bss;
400
401 if (skb->len < IEEE80211_MGMT_HDR_LEN + sizeof(mgmt->u.beacon))
402 return;
403
404 mgmt = (struct hostap_ieee80211_mgmt *) skb->data;
405 pos = mgmt->u.beacon.variable;
406 left = skb->len - (pos - skb->data);
407
408 while (left >= 2) {
409 if (2 + pos[1] > left)
410 return; /* parse failed */
411 switch (*pos) {
412 case WLAN_EID_SSID:
413 ssid = pos + 2;
414 ssid_len = pos[1];
415 break;
416 case WLAN_EID_GENERIC:
417 if (pos[1] >= 4 &&
418 pos[2] == 0x00 && pos[3] == 0x50 &&
419 pos[4] == 0xf2 && pos[5] == 1) {
420 wpa = pos;
421 wpa_len = pos[1] + 2;
422 }
423 break;
424 case WLAN_EID_RSN:
425 rsn = pos;
426 rsn_len = pos[1] + 2;
427 break;
428 case WLAN_EID_DS_PARAMS:
429 if (pos[1] >= 1)
430 chan = pos[2];
431 break;
432 }
433 left -= 2 + pos[1];
434 pos += 2 + pos[1];
435 }
436
437 if (wpa_len > MAX_WPA_IE_LEN)
438 wpa_len = MAX_WPA_IE_LEN;
439 if (rsn_len > MAX_WPA_IE_LEN)
440 rsn_len = MAX_WPA_IE_LEN;
441 if (ssid_len > sizeof(bss->ssid))
442 ssid_len = sizeof(bss->ssid);
443
444 spin_lock(&local->lock);
445 bss = __hostap_get_bss(local, mgmt->bssid, ssid, ssid_len);
446 if (bss == NULL)
447 bss = __hostap_add_bss(local, mgmt->bssid, ssid, ssid_len);
448 if (bss) {
449 bss->last_update = jiffies;
450 bss->count++;
451 bss->capab_info = le16_to_cpu(mgmt->u.beacon.capab_info);
452 if (wpa) {
453 memcpy(bss->wpa_ie, wpa, wpa_len);
454 bss->wpa_ie_len = wpa_len;
455 } else
456 bss->wpa_ie_len = 0;
457 if (rsn) {
458 memcpy(bss->rsn_ie, rsn, rsn_len);
459 bss->rsn_ie_len = rsn_len;
460 } else
461 bss->rsn_ie_len = 0;
462 bss->chan = chan;
463 }
464 __hostap_expire_bss(local);
465 spin_unlock(&local->lock);
466}
467
468
Arjan van de Ven858119e2006-01-14 13:20:43 -0800469static int
Jouni Malinenff1d2762005-05-12 22:54:16 -0400470hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
471 struct hostap_80211_rx_status *rx_stats, u16 type,
472 u16 stype)
473{
Dan Williams1ea893f2009-02-11 17:17:10 -0500474 if (local->iw_mode == IW_MODE_MASTER)
475 hostap_update_sta_ps(local, (struct ieee80211_hdr *) skb->data);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400476
Jouni Malinen4339d322005-08-14 19:08:44 -0700477 if (local->hostapd && type == IEEE80211_FTYPE_MGMT) {
478 if (stype == IEEE80211_STYPE_BEACON &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400479 local->iw_mode == IW_MODE_MASTER) {
480 struct sk_buff *skb2;
481 /* Process beacon frames also in kernel driver to
482 * update STA(AP) table statistics */
483 skb2 = skb_clone(skb, GFP_ATOMIC);
484 if (skb2)
485 hostap_rx(skb2->dev, skb2, rx_stats);
486 }
487
488 /* send management frames to the user space daemon for
489 * processing */
490 local->apdevstats.rx_packets++;
491 local->apdevstats.rx_bytes += skb->len;
492 if (local->apdev == NULL)
493 return -1;
494 prism2_rx_80211(local->apdev, skb, rx_stats, PRISM2_RX_MGMT);
495 return 0;
496 }
497
498 if (local->iw_mode == IW_MODE_MASTER) {
Jouni Malinen4339d322005-08-14 19:08:44 -0700499 if (type != IEEE80211_FTYPE_MGMT &&
500 type != IEEE80211_FTYPE_CTL) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400501 printk(KERN_DEBUG "%s: unknown management frame "
502 "(type=0x%02x, stype=0x%02x) dropped\n",
Jouni Malinen4339d322005-08-14 19:08:44 -0700503 skb->dev->name, type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400504 return -1;
505 }
506
507 hostap_rx(skb->dev, skb, rx_stats);
508 return 0;
Jouni Malinen4339d322005-08-14 19:08:44 -0700509 } else if (type == IEEE80211_FTYPE_MGMT &&
510 (stype == IEEE80211_STYPE_BEACON ||
511 stype == IEEE80211_STYPE_PROBE_RESP)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400512 hostap_rx_sta_beacon(local, skb, stype);
513 return -1;
Jouni Malinen4339d322005-08-14 19:08:44 -0700514 } else if (type == IEEE80211_FTYPE_MGMT &&
515 (stype == IEEE80211_STYPE_ASSOC_RESP ||
516 stype == IEEE80211_STYPE_REASSOC_RESP)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400517 /* Ignore (Re)AssocResp silently since these are not currently
518 * needed but are still received when WPA/RSN mode is enabled.
519 */
520 return -1;
521 } else {
522 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: dropped unhandled"
523 " management frame in non-Host AP mode (type=%d:%d)\n",
Jouni Malinen4339d322005-08-14 19:08:44 -0700524 skb->dev->name, type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400525 return -1;
526 }
527}
528
529
530/* Called only as a tasklet (software IRQ) */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800531static struct net_device *prism2_rx_get_wds(local_info_t *local,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400532 u8 *addr)
533{
534 struct hostap_interface *iface = NULL;
535 struct list_head *ptr;
536
537 read_lock_bh(&local->iface_lock);
538 list_for_each(ptr, &local->hostap_interfaces) {
539 iface = list_entry(ptr, struct hostap_interface, list);
540 if (iface->type == HOSTAP_INTERFACE_WDS &&
541 memcmp(iface->u.wds.remote_addr, addr, ETH_ALEN) == 0)
542 break;
543 iface = NULL;
544 }
545 read_unlock_bh(&local->iface_lock);
546
547 return iface ? iface->dev : NULL;
548}
549
550
Arjan van de Ven858119e2006-01-14 13:20:43 -0800551static int
Dan Williams1ea893f2009-02-11 17:17:10 -0500552hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr *hdr, u16 fc,
553 struct net_device **wds)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400554{
555 /* FIX: is this really supposed to accept WDS frames only in Master
556 * mode? What about Repeater or Managed with WDS frames? */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700557 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) !=
558 (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS) &&
559 (local->iw_mode != IW_MODE_MASTER || !(fc & IEEE80211_FCTL_TODS)))
Jouni Malinenff1d2762005-05-12 22:54:16 -0400560 return 0; /* not a WDS frame */
561
562 /* Possible WDS frame: either IEEE 802.11 compliant (if FromDS)
563 * or own non-standard frame with 4th address after payload */
564 if (memcmp(hdr->addr1, local->dev->dev_addr, ETH_ALEN) != 0 &&
565 (hdr->addr1[0] != 0xff || hdr->addr1[1] != 0xff ||
566 hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff ||
567 hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
568 /* RA (or BSSID) is not ours - drop */
Pavel Roskin15ea0eb2008-06-27 16:19:52 -0400569 PDEBUG(DEBUG_EXTRA2, "%s: received WDS frame with "
Johannes Berge1749612008-10-27 15:59:26 -0700570 "not own or broadcast %s=%pM\n",
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700571 local->dev->name,
572 fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID",
Johannes Berge1749612008-10-27 15:59:26 -0700573 hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400574 return -1;
575 }
576
577 /* check if the frame came from a registered WDS connection */
578 *wds = prism2_rx_get_wds(local, hdr->addr2);
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700579 if (*wds == NULL && fc & IEEE80211_FCTL_FROMDS &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400580 (local->iw_mode != IW_MODE_INFRA ||
581 !(local->wds_type & HOSTAP_WDS_AP_CLIENT) ||
582 memcmp(hdr->addr2, local->bssid, ETH_ALEN) != 0)) {
583 /* require that WDS link has been registered with TA or the
584 * frame is from current AP when using 'AP client mode' */
585 PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame "
Johannes Berge1749612008-10-27 15:59:26 -0700586 "from unknown TA=%pM\n",
587 local->dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400588 if (local->ap && local->ap->autom_ap_wds)
589 hostap_wds_link_oper(local, hdr->addr2, WDS_ADD);
590 return -1;
591 }
592
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700593 if (*wds && !(fc & IEEE80211_FCTL_FROMDS) && local->ap &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400594 hostap_is_sta_assoc(local->ap, hdr->addr2)) {
595 /* STA is actually associated with us even though it has a
596 * registered WDS link. Assume it is in 'AP client' mode.
597 * Since this is a 3-addr frame, assume it is not (bogus) WDS
598 * frame and process it like any normal ToDS frame from
599 * associated STA. */
600 *wds = NULL;
601 }
602
603 return 0;
604}
605
606
607static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
608{
609 struct net_device *dev = local->dev;
610 u16 fc, ethertype;
Dan Williams1ea893f2009-02-11 17:17:10 -0500611 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400612 u8 *pos;
613
614 if (skb->len < 24)
615 return 0;
616
Dan Williams1ea893f2009-02-11 17:17:10 -0500617 hdr = (struct ieee80211_hdr *) skb->data;
618 fc = le16_to_cpu(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400619
620 /* check that the frame is unicast frame to us */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700621 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
622 IEEE80211_FCTL_TODS &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400623 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
624 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
625 /* ToDS frame with own addr BSSID and DA */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700626 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
627 IEEE80211_FCTL_FROMDS &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400628 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
629 /* FromDS frame with own addr as DA */
630 } else
631 return 0;
632
633 if (skb->len < 24 + 8)
634 return 0;
635
636 /* check for port access entity Ethernet type */
637 pos = skb->data + 24;
638 ethertype = (pos[6] << 8) | pos[7];
639 if (ethertype == ETH_P_PAE)
640 return 1;
641
642 return 0;
643}
644
645
646/* Called only as a tasklet (software IRQ) */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800647static int
Jouni Malinenff1d2762005-05-12 22:54:16 -0400648hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
John W. Linville274bfb82008-10-29 11:35:05 -0400649 struct lib80211_crypt_data *crypt)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400650{
Dan Williams1ea893f2009-02-11 17:17:10 -0500651 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400652 int res, hdrlen;
653
654 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
655 return 0;
656
Dan Williams1ea893f2009-02-11 17:17:10 -0500657 hdr = (struct ieee80211_hdr *) skb->data;
658 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400659
660 if (local->tkip_countermeasures &&
661 strcmp(crypt->ops->name, "TKIP") == 0) {
662 if (net_ratelimit()) {
663 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
Johannes Berge1749612008-10-27 15:59:26 -0700664 "received packet from %pM\n",
665 local->dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400666 }
667 return -1;
668 }
669
670 atomic_inc(&crypt->refcnt);
671 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
672 atomic_dec(&crypt->refcnt);
673 if (res < 0) {
Johannes Berge1749612008-10-27 15:59:26 -0700674 printk(KERN_DEBUG "%s: decryption failed (SA=%pM) res=%d\n",
675 local->dev->name, hdr->addr2, res);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400676 local->comm_tallies.rx_discards_wep_undecryptable++;
677 return -1;
678 }
679
680 return res;
681}
682
683
684/* Called only as a tasklet (software IRQ) */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800685static int
Jouni Malinenff1d2762005-05-12 22:54:16 -0400686hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
John W. Linville274bfb82008-10-29 11:35:05 -0400687 int keyidx, struct lib80211_crypt_data *crypt)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400688{
Dan Williams1ea893f2009-02-11 17:17:10 -0500689 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400690 int res, hdrlen;
691
692 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
693 return 0;
694
Dan Williams1ea893f2009-02-11 17:17:10 -0500695 hdr = (struct ieee80211_hdr *) skb->data;
696 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400697
698 atomic_inc(&crypt->refcnt);
699 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
700 atomic_dec(&crypt->refcnt);
701 if (res < 0) {
702 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
Johannes Berge1749612008-10-27 15:59:26 -0700703 " (SA=%pM keyidx=%d)\n",
704 local->dev->name, hdr->addr2, keyidx);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400705 return -1;
706 }
707
708 return 0;
709}
710
711
712/* All received frames are sent to this function. @skb contains the frame in
713 * IEEE 802.11 format, i.e., in the format it was sent over air.
714 * This function is called only as a tasklet (software IRQ). */
715void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
716 struct hostap_80211_rx_status *rx_stats)
717{
718 struct hostap_interface *iface;
719 local_info_t *local;
Dan Williams1ea893f2009-02-11 17:17:10 -0500720 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400721 size_t hdrlen;
722 u16 fc, type, stype, sc;
723 struct net_device *wds = NULL;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400724 unsigned int frag;
725 u8 *payload;
726 struct sk_buff *skb2 = NULL;
727 u16 ethertype;
728 int frame_authorized = 0;
729 int from_assoc_ap = 0;
730 u8 dst[ETH_ALEN];
731 u8 src[ETH_ALEN];
John W. Linville274bfb82008-10-29 11:35:05 -0400732 struct lib80211_crypt_data *crypt = NULL;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400733 void *sta = NULL;
734 int keyidx = 0;
735
736 iface = netdev_priv(dev);
737 local = iface->local;
738 iface->stats.rx_packets++;
739 iface->stats.rx_bytes += skb->len;
740
741 /* dev is the master radio device; change this to be the default
742 * virtual interface (this may be changed to WDS device below) */
743 dev = local->ddev;
744 iface = netdev_priv(dev);
745
Dan Williams1ea893f2009-02-11 17:17:10 -0500746 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400747
748 if (skb->len < 10)
749 goto rx_dropped;
750
Dan Williams1ea893f2009-02-11 17:17:10 -0500751 fc = le16_to_cpu(hdr->frame_control);
752 type = fc & IEEE80211_FCTL_FTYPE;
753 stype = fc & IEEE80211_FCTL_STYPE;
754 sc = le16_to_cpu(hdr->seq_ctrl);
755 frag = sc & IEEE80211_SCTL_FRAG;
756 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400757
758 /* Put this code here so that we avoid duplicating it in all
759 * Rx paths. - Jean II */
760#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
761 /* If spy monitoring on */
762 if (iface->spy_data.spy_number > 0) {
763 struct iw_quality wstats;
764 wstats.level = rx_stats->signal;
765 wstats.noise = rx_stats->noise;
Jean Tourrilhesc28df162005-09-23 21:58:59 -0700766 wstats.updated = IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED
767 | IW_QUAL_QUAL_INVALID | IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400768 /* Update spy records */
769 wireless_spy_update(dev, hdr->addr2, &wstats);
770 }
771#endif /* IW_WIRELESS_SPY */
772 hostap_update_rx_stats(local->ap, hdr, rx_stats);
773
774 if (local->iw_mode == IW_MODE_MONITOR) {
775 monitor_rx(dev, skb, rx_stats);
776 return;
777 }
778
779 if (local->host_decrypt) {
780 int idx = 0;
781 if (skb->len >= hdrlen + 3)
782 idx = skb->data[hdrlen + 3] >> 6;
John W. Linville274bfb82008-10-29 11:35:05 -0400783 crypt = local->crypt_info.crypt[idx];
Jouni Malinenff1d2762005-05-12 22:54:16 -0400784 sta = NULL;
785
786 /* Use station specific key to override default keys if the
787 * receiver address is a unicast address ("individual RA"). If
788 * bcrx_sta_key parameter is set, station specific key is used
789 * even with broad/multicast targets (this is against IEEE
790 * 802.11, but makes it easier to use different keys with
791 * stations that do not support WEP key mapping). */
792
793 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
794 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
795 &sta);
796
797 /* allow NULL decrypt to indicate an station specific override
798 * for default encryption */
799 if (crypt && (crypt->ops == NULL ||
800 crypt->ops->decrypt_mpdu == NULL))
801 crypt = NULL;
802
Jeff Garzik831a1792005-08-25 20:59:10 -0400803 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400804#if 0
805 /* This seems to be triggered by some (multicast?)
806 * frames from other than current BSS, so just drop the
807 * frames silently instead of filling system log with
808 * these reports. */
809 printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
Johannes Berge1749612008-10-27 15:59:26 -0700810 " (SA=%pM)\n",
811 local->dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400812#endif
813 local->comm_tallies.rx_discards_wep_undecryptable++;
814 goto rx_dropped;
815 }
816 }
817
Jouni Malinen4339d322005-08-14 19:08:44 -0700818 if (type != IEEE80211_FTYPE_DATA) {
819 if (type == IEEE80211_FTYPE_MGMT &&
820 stype == IEEE80211_STYPE_AUTH &&
Jeff Garzik831a1792005-08-25 20:59:10 -0400821 fc & IEEE80211_FCTL_PROTECTED && local->host_decrypt &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400822 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
823 {
824 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
Johannes Berge1749612008-10-27 15:59:26 -0700825 "from %pM\n", dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400826 /* TODO: could inform hostapd about this so that it
827 * could send auth failure report */
828 goto rx_dropped;
829 }
830
831 if (hostap_rx_frame_mgmt(local, skb, rx_stats, type, stype))
832 goto rx_dropped;
833 else
834 goto rx_exit;
835 }
836
837 /* Data frame - extract src/dst addresses */
838 if (skb->len < IEEE80211_DATA_HDR3_LEN)
839 goto rx_dropped;
840
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700841 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
842 case IEEE80211_FCTL_FROMDS:
Jouni Malinenff1d2762005-05-12 22:54:16 -0400843 memcpy(dst, hdr->addr1, ETH_ALEN);
844 memcpy(src, hdr->addr3, ETH_ALEN);
845 break;
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700846 case IEEE80211_FCTL_TODS:
Jouni Malinenff1d2762005-05-12 22:54:16 -0400847 memcpy(dst, hdr->addr3, ETH_ALEN);
848 memcpy(src, hdr->addr2, ETH_ALEN);
849 break;
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700850 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
Jouni Malinenff1d2762005-05-12 22:54:16 -0400851 if (skb->len < IEEE80211_DATA_HDR4_LEN)
852 goto rx_dropped;
853 memcpy(dst, hdr->addr3, ETH_ALEN);
854 memcpy(src, hdr->addr4, ETH_ALEN);
855 break;
856 case 0:
857 memcpy(dst, hdr->addr1, ETH_ALEN);
858 memcpy(src, hdr->addr2, ETH_ALEN);
859 break;
860 }
861
862 if (hostap_rx_frame_wds(local, hdr, fc, &wds))
863 goto rx_dropped;
Stephen Hemminger4cfa8e42009-03-20 19:36:42 +0000864 if (wds)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400865 skb->dev = dev = wds;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400866
867 if (local->iw_mode == IW_MODE_MASTER && !wds &&
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700868 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
869 IEEE80211_FCTL_FROMDS &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400870 local->stadev &&
871 memcmp(hdr->addr2, local->assoc_ap_addr, ETH_ALEN) == 0) {
872 /* Frame from BSSID of the AP for which we are a client */
873 skb->dev = dev = local->stadev;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400874 from_assoc_ap = 1;
875 }
876
Jouni Malinenff1d2762005-05-12 22:54:16 -0400877 if ((local->iw_mode == IW_MODE_MASTER ||
878 local->iw_mode == IW_MODE_REPEAT) &&
879 !from_assoc_ap) {
880 switch (hostap_handle_sta_rx(local, dev, skb, rx_stats,
881 wds != NULL)) {
882 case AP_RX_CONTINUE_NOT_AUTHORIZED:
883 frame_authorized = 0;
884 break;
885 case AP_RX_CONTINUE:
886 frame_authorized = 1;
887 break;
888 case AP_RX_DROP:
889 goto rx_dropped;
890 case AP_RX_EXIT:
891 goto rx_exit;
892 }
893 }
894
895 /* Nullfunc frames may have PS-bit set, so they must be passed to
896 * hostap_handle_sta_rx() before being dropped here. */
Jouni Malinen4339d322005-08-14 19:08:44 -0700897 if (stype != IEEE80211_STYPE_DATA &&
898 stype != IEEE80211_STYPE_DATA_CFACK &&
899 stype != IEEE80211_STYPE_DATA_CFPOLL &&
900 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
901 if (stype != IEEE80211_STYPE_NULLFUNC)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400902 printk(KERN_DEBUG "%s: RX: dropped data frame "
903 "with no data (type=0x%02x, subtype=0x%02x)\n",
Jouni Malinen4339d322005-08-14 19:08:44 -0700904 dev->name, type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400905 goto rx_dropped;
906 }
907
908 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
909
Jeff Garzik831a1792005-08-25 20:59:10 -0400910 if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400911 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
912 goto rx_dropped;
Dan Williams1ea893f2009-02-11 17:17:10 -0500913 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400914
915 /* skb: hdr + (possibly fragmented) plaintext payload */
916
Jeff Garzik831a1792005-08-25 20:59:10 -0400917 if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700918 (frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400919 int flen;
920 struct sk_buff *frag_skb =
921 prism2_frag_cache_get(local, hdr);
922 if (!frag_skb) {
923 printk(KERN_DEBUG "%s: Rx cannot get skb from "
924 "fragment cache (morefrag=%d seq=%u frag=%u)\n",
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700925 dev->name, (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
Dan Williams1ea893f2009-02-11 17:17:10 -0500926 (sc & IEEE80211_SCTL_SEQ) >> 4, frag);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400927 goto rx_dropped;
928 }
929
930 flen = skb->len;
931 if (frag != 0)
932 flen -= hdrlen;
933
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700934 if (frag_skb->tail + flen > frag_skb->end) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400935 printk(KERN_WARNING "%s: host decrypted and "
936 "reassembled frame did not fit skb\n",
937 dev->name);
938 prism2_frag_cache_invalidate(local, hdr);
939 goto rx_dropped;
940 }
941
942 if (frag == 0) {
943 /* copy first fragment (including full headers) into
944 * beginning of the fragment cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300945 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen),
946 flen);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400947 } else {
948 /* append frame payload to the end of the fragment
949 * cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300950 skb_copy_from_linear_data_offset(skb, hdrlen,
951 skb_put(frag_skb,
952 flen), flen);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400953 }
954 dev_kfree_skb(skb);
955 skb = NULL;
956
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700957 if (fc & IEEE80211_FCTL_MOREFRAGS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400958 /* more fragments expected - leave the skb in fragment
959 * cache for now; it will be delivered to upper layers
960 * after all fragments have been received */
961 goto rx_exit;
962 }
963
964 /* this was the last fragment and the frame will be
965 * delivered, so remove skb from fragment cache */
966 skb = frag_skb;
Dan Williams1ea893f2009-02-11 17:17:10 -0500967 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400968 prism2_frag_cache_invalidate(local, hdr);
969 }
970
971 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
972 * encrypted/authenticated */
973
Jeff Garzik831a1792005-08-25 20:59:10 -0400974 if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400975 hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
976 goto rx_dropped;
977
Dan Williams1ea893f2009-02-11 17:17:10 -0500978 hdr = (struct ieee80211_hdr *) skb->data;
Jeff Garzik831a1792005-08-25 20:59:10 -0400979 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400980 if (local->ieee_802_1x &&
981 hostap_is_eapol_frame(local, skb)) {
982 /* pass unencrypted EAPOL frames even if encryption is
983 * configured */
984 PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X - passing "
985 "unencrypted EAPOL frame\n", local->dev->name);
986 } else {
987 printk(KERN_DEBUG "%s: encryption configured, but RX "
Johannes Berge1749612008-10-27 15:59:26 -0700988 "frame not encrypted (SA=%pM)\n",
989 local->dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400990 goto rx_dropped;
991 }
992 }
993
Jeff Garzik831a1792005-08-25 20:59:10 -0400994 if (local->drop_unencrypted && !(fc & IEEE80211_FCTL_PROTECTED) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400995 !hostap_is_eapol_frame(local, skb)) {
996 if (net_ratelimit()) {
997 printk(KERN_DEBUG "%s: dropped unencrypted RX data "
Johannes Berge1749612008-10-27 15:59:26 -0700998 "frame from %pM (drop_unencrypted=1)\n",
999 dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001000 }
1001 goto rx_dropped;
1002 }
1003
1004 /* skb: hdr + (possible reassembled) full plaintext payload */
1005
1006 payload = skb->data + hdrlen;
1007 ethertype = (payload[6] << 8) | payload[7];
1008
1009 /* If IEEE 802.1X is used, check whether the port is authorized to send
1010 * the received frame. */
1011 if (local->ieee_802_1x && local->iw_mode == IW_MODE_MASTER) {
1012 if (ethertype == ETH_P_PAE) {
1013 PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X frame\n",
1014 dev->name);
1015 if (local->hostapd && local->apdev) {
1016 /* Send IEEE 802.1X frames to the user
1017 * space daemon for processing */
1018 prism2_rx_80211(local->apdev, skb, rx_stats,
1019 PRISM2_RX_MGMT);
1020 local->apdevstats.rx_packets++;
1021 local->apdevstats.rx_bytes += skb->len;
1022 goto rx_exit;
1023 }
1024 } else if (!frame_authorized) {
1025 printk(KERN_DEBUG "%s: dropped frame from "
1026 "unauthorized port (IEEE 802.1X): "
1027 "ethertype=0x%04x\n",
1028 dev->name, ethertype);
1029 goto rx_dropped;
1030 }
1031 }
1032
1033 /* convert hdr + possible LLC headers into Ethernet header */
1034 if (skb->len - hdrlen >= 8 &&
1035 ((memcmp(payload, rfc1042_header, 6) == 0 &&
1036 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1037 memcmp(payload, bridge_tunnel_header, 6) == 0)) {
1038 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1039 * replace EtherType */
1040 skb_pull(skb, hdrlen + 6);
1041 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1042 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1043 } else {
Al Viro8a9faf32007-12-21 03:30:16 -05001044 __be16 len;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001045 /* Leave Ethernet header part of hdr and full payload */
1046 skb_pull(skb, hdrlen);
1047 len = htons(skb->len);
1048 memcpy(skb_push(skb, 2), &len, 2);
1049 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1050 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1051 }
1052
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07001053 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
1054 IEEE80211_FCTL_TODS) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -04001055 skb->len >= ETH_HLEN + ETH_ALEN) {
1056 /* Non-standard frame: get addr4 from its bogus location after
1057 * the payload */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001058 skb_copy_from_linear_data_offset(skb, skb->len - ETH_ALEN,
1059 skb->data + ETH_ALEN,
1060 ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001061 skb_trim(skb, skb->len - ETH_ALEN);
1062 }
1063
Stephen Hemminger4cfa8e42009-03-20 19:36:42 +00001064 dev->stats.rx_packets++;
1065 dev->stats.rx_bytes += skb->len;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001066
1067 if (local->iw_mode == IW_MODE_MASTER && !wds &&
1068 local->ap->bridge_packets) {
1069 if (dst[0] & 0x01) {
1070 /* copy multicast frame both to the higher layers and
1071 * to the wireless media */
1072 local->ap->bridged_multicast++;
1073 skb2 = skb_clone(skb, GFP_ATOMIC);
1074 if (skb2 == NULL)
1075 printk(KERN_DEBUG "%s: skb_clone failed for "
1076 "multicast frame\n", dev->name);
1077 } else if (hostap_is_sta_authorized(local->ap, dst)) {
1078 /* send frame directly to the associated STA using
1079 * wireless media and not passing to higher layers */
1080 local->ap->bridged_unicast++;
1081 skb2 = skb;
1082 skb = NULL;
1083 }
1084 }
1085
1086 if (skb2 != NULL) {
1087 /* send to wireless media */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001088 skb2->dev = dev;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001089 skb2->protocol = cpu_to_be16(ETH_P_802_3);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001090 skb_reset_mac_header(skb2);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -07001091 skb_reset_network_header(skb2);
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07001092 /* skb2->network_header += ETH_HLEN; */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001093 dev_queue_xmit(skb2);
1094 }
1095
1096 if (skb) {
1097 skb->protocol = eth_type_trans(skb, dev);
1098 memset(skb->cb, 0, sizeof(skb->cb));
Jouni Malinenff1d2762005-05-12 22:54:16 -04001099 netif_rx(skb);
1100 }
1101
1102 rx_exit:
1103 if (sta)
1104 hostap_handle_sta_release(sta);
1105 return;
1106
1107 rx_dropped:
1108 dev_kfree_skb(skb);
1109
Stephen Hemminger4cfa8e42009-03-20 19:36:42 +00001110 dev->stats.rx_dropped++;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001111 goto rx_exit;
1112}
1113
1114
1115EXPORT_SYMBOL(hostap_80211_rx);