Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | #include <linux/etherdevice.h> |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 2 | #include <net/ieee80211_crypt.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3 | |
| 4 | #include "hostap_80211.h" |
| 5 | #include "hostap.h" |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 6 | #include "hostap_ap.h" |
| 7 | |
| 8 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 9 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
| 10 | static unsigned char rfc1042_header[] = |
| 11 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 12 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
| 13 | static unsigned char bridge_tunnel_header[] = |
| 14 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 15 | /* No encapsulation header if EtherType < 0x600 (=length) */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 16 | |
| 17 | void hostap_dump_rx_80211(const char *name, struct sk_buff *skb, |
| 18 | struct hostap_80211_rx_status *rx_stats) |
| 19 | { |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 20 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 21 | u16 fc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 22 | DECLARE_MAC_BUF(mac); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 23 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 24 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 25 | |
| 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 | |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 34 | fc = le16_to_cpu(hdr->frame_ctl); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 35 | printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 36 | fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4, |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 37 | fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "", |
| 38 | fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : ""); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 39 | |
| 40 | if (skb->len < IEEE80211_DATA_HDR3_LEN) { |
| 41 | printk("\n"); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id), |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 46 | le16_to_cpu(hdr->seq_ctl)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 47 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 48 | printk(KERN_DEBUG " A1=%s", print_mac(mac, hdr->addr1)); |
| 49 | printk(" A2=%s", print_mac(mac, hdr->addr2)); |
| 50 | printk(" A3=%s", print_mac(mac, hdr->addr3)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 51 | if (skb->len >= 30) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 52 | printk(" A4=%s", print_mac(mac, hdr->addr4)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 53 | printk("\n"); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /* Send RX frame to netif with 802.11 (and possible prism) header. |
| 58 | * Called from hardware or software IRQ context. */ |
| 59 | int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb, |
| 60 | struct hostap_80211_rx_status *rx_stats, int type) |
| 61 | { |
| 62 | struct hostap_interface *iface; |
| 63 | local_info_t *local; |
| 64 | int hdrlen, phdrlen, head_need, tail_need; |
| 65 | u16 fc; |
| 66 | int prism_header, ret; |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 67 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 68 | |
| 69 | iface = netdev_priv(dev); |
| 70 | local = iface->local; |
| 71 | dev->last_rx = jiffies; |
| 72 | |
| 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 | } |
| 81 | } else { |
| 82 | prism_header = 0; |
| 83 | phdrlen = 0; |
| 84 | } |
| 85 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 86 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 87 | fc = le16_to_cpu(hdr->frame_ctl); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 88 | |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 89 | if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 90 | printk(KERN_DEBUG "%s: dropped management frame with header " |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 91 | "version %d\n", dev->name, fc & IEEE80211_FCTL_VERS); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 92 | dev_kfree_skb_any(skb); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | hdrlen = hostap_80211_get_hdrlen(fc); |
| 97 | |
| 98 | /* check if there is enough room for extra data; if not, expand skb |
| 99 | * buffer to be large enough for the changes */ |
| 100 | head_need = phdrlen; |
| 101 | tail_need = 0; |
| 102 | #ifdef PRISM2_ADD_BOGUS_CRC |
| 103 | tail_need += 4; |
| 104 | #endif /* PRISM2_ADD_BOGUS_CRC */ |
| 105 | |
| 106 | head_need -= skb_headroom(skb); |
| 107 | tail_need -= skb_tailroom(skb); |
| 108 | |
| 109 | if (head_need > 0 || tail_need > 0) { |
| 110 | if (pskb_expand_head(skb, head_need > 0 ? head_need : 0, |
| 111 | tail_need > 0 ? tail_need : 0, |
| 112 | GFP_ATOMIC)) { |
| 113 | printk(KERN_DEBUG "%s: prism2_rx_80211 failed to " |
| 114 | "reallocate skb buffer\n", dev->name); |
| 115 | dev_kfree_skb_any(skb); |
| 116 | return 0; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /* We now have an skb with enough head and tail room, so just insert |
| 121 | * the extra data */ |
| 122 | |
| 123 | #ifdef PRISM2_ADD_BOGUS_CRC |
| 124 | memset(skb_put(skb, 4), 0xff, 4); /* Prism2 strips CRC */ |
| 125 | #endif /* PRISM2_ADD_BOGUS_CRC */ |
| 126 | |
| 127 | if (prism_header == 1) { |
| 128 | struct linux_wlan_ng_prism_hdr *hdr; |
| 129 | hdr = (struct linux_wlan_ng_prism_hdr *) |
| 130 | skb_push(skb, phdrlen); |
| 131 | memset(hdr, 0, phdrlen); |
| 132 | hdr->msgcode = LWNG_CAP_DID_BASE; |
| 133 | hdr->msglen = sizeof(*hdr); |
| 134 | memcpy(hdr->devname, dev->name, sizeof(hdr->devname)); |
| 135 | #define LWNG_SETVAL(f,i,s,l,d) \ |
| 136 | hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \ |
| 137 | hdr->f.status = s; hdr->f.len = l; hdr->f.data = d |
| 138 | LWNG_SETVAL(hosttime, 1, 0, 4, jiffies); |
Brandon Enochs | 3e1d393 | 2005-07-30 12:50:04 -0700 | [diff] [blame] | 139 | LWNG_SETVAL(mactime, 2, 0, 4, rx_stats->mac_time); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 140 | LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0); |
| 141 | LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0); |
| 142 | LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0); |
| 143 | LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal); |
| 144 | LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise); |
| 145 | LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5); |
| 146 | LWNG_SETVAL(istx, 9, 0, 4, 0); |
| 147 | LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen); |
| 148 | #undef LWNG_SETVAL |
| 149 | } else if (prism_header == 2) { |
| 150 | struct linux_wlan_ng_cap_hdr *hdr; |
| 151 | hdr = (struct linux_wlan_ng_cap_hdr *) |
| 152 | skb_push(skb, phdrlen); |
| 153 | memset(hdr, 0, phdrlen); |
| 154 | hdr->version = htonl(LWNG_CAPHDR_VERSION); |
| 155 | hdr->length = htonl(phdrlen); |
| 156 | hdr->mactime = __cpu_to_be64(rx_stats->mac_time); |
| 157 | hdr->hosttime = __cpu_to_be64(jiffies); |
| 158 | hdr->phytype = htonl(4); /* dss_dot11_b */ |
| 159 | hdr->channel = htonl(local->channel); |
| 160 | hdr->datarate = htonl(rx_stats->rate); |
| 161 | hdr->antenna = htonl(0); /* unknown */ |
| 162 | hdr->priority = htonl(0); /* unknown */ |
| 163 | hdr->ssi_type = htonl(3); /* raw */ |
| 164 | hdr->ssi_signal = htonl(rx_stats->signal); |
| 165 | hdr->ssi_noise = htonl(rx_stats->noise); |
| 166 | hdr->preamble = htonl(0); /* unknown */ |
| 167 | hdr->encoding = htonl(1); /* cck */ |
| 168 | } |
| 169 | |
| 170 | ret = skb->len - phdrlen; |
| 171 | skb->dev = dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 172 | skb_reset_mac_header(skb); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 173 | skb_pull(skb, hdrlen); |
| 174 | if (prism_header) |
| 175 | skb_pull(skb, phdrlen); |
| 176 | skb->pkt_type = PACKET_OTHERHOST; |
| 177 | skb->protocol = __constant_htons(ETH_P_802_2); |
| 178 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 179 | netif_rx(skb); |
| 180 | |
| 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /* Called only as a tasklet (software IRQ) */ |
| 186 | static void monitor_rx(struct net_device *dev, struct sk_buff *skb, |
| 187 | struct hostap_80211_rx_status *rx_stats) |
| 188 | { |
| 189 | struct net_device_stats *stats; |
| 190 | int len; |
| 191 | |
| 192 | len = prism2_rx_80211(dev, skb, rx_stats, PRISM2_RX_MONITOR); |
| 193 | stats = hostap_get_stats(dev); |
| 194 | stats->rx_packets++; |
| 195 | stats->rx_bytes += len; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /* Called only as a tasklet (software IRQ) */ |
| 200 | static struct prism2_frag_entry * |
| 201 | prism2_frag_cache_find(local_info_t *local, unsigned int seq, |
| 202 | unsigned int frag, u8 *src, u8 *dst) |
| 203 | { |
| 204 | struct prism2_frag_entry *entry; |
| 205 | int i; |
| 206 | |
| 207 | for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) { |
| 208 | entry = &local->frag_cache[i]; |
| 209 | if (entry->skb != NULL && |
| 210 | time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
| 211 | printk(KERN_DEBUG "%s: expiring fragment cache entry " |
| 212 | "seq=%u last_frag=%u\n", |
| 213 | local->dev->name, entry->seq, entry->last_frag); |
| 214 | dev_kfree_skb(entry->skb); |
| 215 | entry->skb = NULL; |
| 216 | } |
| 217 | |
| 218 | if (entry->skb != NULL && entry->seq == seq && |
| 219 | (entry->last_frag + 1 == frag || frag == -1) && |
| 220 | memcmp(entry->src_addr, src, ETH_ALEN) == 0 && |
| 221 | memcmp(entry->dst_addr, dst, ETH_ALEN) == 0) |
| 222 | return entry; |
| 223 | } |
| 224 | |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | /* Called only as a tasklet (software IRQ) */ |
| 230 | static struct sk_buff * |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 231 | prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 232 | { |
| 233 | struct sk_buff *skb = NULL; |
| 234 | u16 sc; |
| 235 | unsigned int frag, seq; |
| 236 | struct prism2_frag_entry *entry; |
| 237 | |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 238 | sc = le16_to_cpu(hdr->seq_ctl); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 239 | frag = WLAN_GET_SEQ_FRAG(sc); |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 240 | seq = WLAN_GET_SEQ_SEQ(sc) >> 4; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 241 | |
| 242 | if (frag == 0) { |
| 243 | /* Reserve enough space to fit maximum frame length */ |
| 244 | skb = dev_alloc_skb(local->dev->mtu + |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 245 | sizeof(struct ieee80211_hdr_4addr) + |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 246 | 8 /* LLC */ + |
| 247 | 2 /* alignment */ + |
| 248 | 8 /* WEP */ + ETH_ALEN /* WDS */); |
| 249 | if (skb == NULL) |
| 250 | return NULL; |
| 251 | |
| 252 | entry = &local->frag_cache[local->frag_next_idx]; |
| 253 | local->frag_next_idx++; |
| 254 | if (local->frag_next_idx >= PRISM2_FRAG_CACHE_LEN) |
| 255 | local->frag_next_idx = 0; |
| 256 | |
| 257 | if (entry->skb != NULL) |
| 258 | dev_kfree_skb(entry->skb); |
| 259 | |
| 260 | entry->first_frag_time = jiffies; |
| 261 | entry->seq = seq; |
| 262 | entry->last_frag = frag; |
| 263 | entry->skb = skb; |
| 264 | memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); |
| 265 | memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); |
| 266 | } else { |
| 267 | /* received a fragment of a frame for which the head fragment |
| 268 | * should have already been received */ |
| 269 | entry = prism2_frag_cache_find(local, seq, frag, hdr->addr2, |
| 270 | hdr->addr1); |
| 271 | if (entry != NULL) { |
| 272 | entry->last_frag = frag; |
| 273 | skb = entry->skb; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | return skb; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /* Called only as a tasklet (software IRQ) */ |
| 282 | static int prism2_frag_cache_invalidate(local_info_t *local, |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 283 | struct ieee80211_hdr_4addr *hdr) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 284 | { |
| 285 | u16 sc; |
| 286 | unsigned int seq; |
| 287 | struct prism2_frag_entry *entry; |
| 288 | |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 289 | sc = le16_to_cpu(hdr->seq_ctl); |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 290 | seq = WLAN_GET_SEQ_SEQ(sc) >> 4; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 291 | |
| 292 | entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1); |
| 293 | |
| 294 | if (entry == NULL) { |
| 295 | printk(KERN_DEBUG "%s: could not invalidate fragment cache " |
| 296 | "entry (seq=%u)\n", |
| 297 | local->dev->name, seq); |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | entry->skb = NULL; |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | static struct hostap_bss_info *__hostap_get_bss(local_info_t *local, u8 *bssid, |
| 307 | u8 *ssid, size_t ssid_len) |
| 308 | { |
| 309 | struct list_head *ptr; |
| 310 | struct hostap_bss_info *bss; |
| 311 | |
| 312 | list_for_each(ptr, &local->bss_list) { |
| 313 | bss = list_entry(ptr, struct hostap_bss_info, list); |
| 314 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && |
| 315 | (ssid == NULL || |
| 316 | (ssid_len == bss->ssid_len && |
| 317 | memcmp(ssid, bss->ssid, ssid_len) == 0))) { |
| 318 | list_move(&bss->list, &local->bss_list); |
| 319 | return bss; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | static struct hostap_bss_info *__hostap_add_bss(local_info_t *local, u8 *bssid, |
| 328 | u8 *ssid, size_t ssid_len) |
| 329 | { |
| 330 | struct hostap_bss_info *bss; |
| 331 | |
| 332 | if (local->num_bss_info >= HOSTAP_MAX_BSS_COUNT) { |
| 333 | bss = list_entry(local->bss_list.prev, |
| 334 | struct hostap_bss_info, list); |
| 335 | list_del(&bss->list); |
| 336 | local->num_bss_info--; |
| 337 | } else { |
| 338 | bss = (struct hostap_bss_info *) |
| 339 | kmalloc(sizeof(*bss), GFP_ATOMIC); |
| 340 | if (bss == NULL) |
| 341 | return NULL; |
| 342 | } |
| 343 | |
| 344 | memset(bss, 0, sizeof(*bss)); |
| 345 | memcpy(bss->bssid, bssid, ETH_ALEN); |
| 346 | memcpy(bss->ssid, ssid, ssid_len); |
| 347 | bss->ssid_len = ssid_len; |
| 348 | local->num_bss_info++; |
| 349 | list_add(&bss->list, &local->bss_list); |
| 350 | return bss; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | static void __hostap_expire_bss(local_info_t *local) |
| 355 | { |
| 356 | struct hostap_bss_info *bss; |
| 357 | |
| 358 | while (local->num_bss_info > 0) { |
| 359 | bss = list_entry(local->bss_list.prev, |
| 360 | struct hostap_bss_info, list); |
| 361 | if (!time_after(jiffies, bss->last_update + 60 * HZ)) |
| 362 | break; |
| 363 | |
| 364 | list_del(&bss->list); |
| 365 | local->num_bss_info--; |
| 366 | kfree(bss); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /* Both IEEE 802.11 Beacon and Probe Response frames have similar structure, so |
| 372 | * the same routine can be used to parse both of them. */ |
| 373 | static void hostap_rx_sta_beacon(local_info_t *local, struct sk_buff *skb, |
| 374 | int stype) |
| 375 | { |
| 376 | struct hostap_ieee80211_mgmt *mgmt; |
| 377 | int left, chan = 0; |
| 378 | u8 *pos; |
| 379 | u8 *ssid = NULL, *wpa = NULL, *rsn = NULL; |
| 380 | size_t ssid_len = 0, wpa_len = 0, rsn_len = 0; |
| 381 | struct hostap_bss_info *bss; |
| 382 | |
| 383 | if (skb->len < IEEE80211_MGMT_HDR_LEN + sizeof(mgmt->u.beacon)) |
| 384 | return; |
| 385 | |
| 386 | mgmt = (struct hostap_ieee80211_mgmt *) skb->data; |
| 387 | pos = mgmt->u.beacon.variable; |
| 388 | left = skb->len - (pos - skb->data); |
| 389 | |
| 390 | while (left >= 2) { |
| 391 | if (2 + pos[1] > left) |
| 392 | return; /* parse failed */ |
| 393 | switch (*pos) { |
| 394 | case WLAN_EID_SSID: |
| 395 | ssid = pos + 2; |
| 396 | ssid_len = pos[1]; |
| 397 | break; |
| 398 | case WLAN_EID_GENERIC: |
| 399 | if (pos[1] >= 4 && |
| 400 | pos[2] == 0x00 && pos[3] == 0x50 && |
| 401 | pos[4] == 0xf2 && pos[5] == 1) { |
| 402 | wpa = pos; |
| 403 | wpa_len = pos[1] + 2; |
| 404 | } |
| 405 | break; |
| 406 | case WLAN_EID_RSN: |
| 407 | rsn = pos; |
| 408 | rsn_len = pos[1] + 2; |
| 409 | break; |
| 410 | case WLAN_EID_DS_PARAMS: |
| 411 | if (pos[1] >= 1) |
| 412 | chan = pos[2]; |
| 413 | break; |
| 414 | } |
| 415 | left -= 2 + pos[1]; |
| 416 | pos += 2 + pos[1]; |
| 417 | } |
| 418 | |
| 419 | if (wpa_len > MAX_WPA_IE_LEN) |
| 420 | wpa_len = MAX_WPA_IE_LEN; |
| 421 | if (rsn_len > MAX_WPA_IE_LEN) |
| 422 | rsn_len = MAX_WPA_IE_LEN; |
| 423 | if (ssid_len > sizeof(bss->ssid)) |
| 424 | ssid_len = sizeof(bss->ssid); |
| 425 | |
| 426 | spin_lock(&local->lock); |
| 427 | bss = __hostap_get_bss(local, mgmt->bssid, ssid, ssid_len); |
| 428 | if (bss == NULL) |
| 429 | bss = __hostap_add_bss(local, mgmt->bssid, ssid, ssid_len); |
| 430 | if (bss) { |
| 431 | bss->last_update = jiffies; |
| 432 | bss->count++; |
| 433 | bss->capab_info = le16_to_cpu(mgmt->u.beacon.capab_info); |
| 434 | if (wpa) { |
| 435 | memcpy(bss->wpa_ie, wpa, wpa_len); |
| 436 | bss->wpa_ie_len = wpa_len; |
| 437 | } else |
| 438 | bss->wpa_ie_len = 0; |
| 439 | if (rsn) { |
| 440 | memcpy(bss->rsn_ie, rsn, rsn_len); |
| 441 | bss->rsn_ie_len = rsn_len; |
| 442 | } else |
| 443 | bss->rsn_ie_len = 0; |
| 444 | bss->chan = chan; |
| 445 | } |
| 446 | __hostap_expire_bss(local); |
| 447 | spin_unlock(&local->lock); |
| 448 | } |
| 449 | |
| 450 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 451 | static int |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 452 | hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb, |
| 453 | struct hostap_80211_rx_status *rx_stats, u16 type, |
| 454 | u16 stype) |
| 455 | { |
| 456 | if (local->iw_mode == IW_MODE_MASTER) { |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 457 | hostap_update_sta_ps(local, (struct ieee80211_hdr_4addr *) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 458 | skb->data); |
| 459 | } |
| 460 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 461 | if (local->hostapd && type == IEEE80211_FTYPE_MGMT) { |
| 462 | if (stype == IEEE80211_STYPE_BEACON && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 463 | local->iw_mode == IW_MODE_MASTER) { |
| 464 | struct sk_buff *skb2; |
| 465 | /* Process beacon frames also in kernel driver to |
| 466 | * update STA(AP) table statistics */ |
| 467 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 468 | if (skb2) |
| 469 | hostap_rx(skb2->dev, skb2, rx_stats); |
| 470 | } |
| 471 | |
| 472 | /* send management frames to the user space daemon for |
| 473 | * processing */ |
| 474 | local->apdevstats.rx_packets++; |
| 475 | local->apdevstats.rx_bytes += skb->len; |
| 476 | if (local->apdev == NULL) |
| 477 | return -1; |
| 478 | prism2_rx_80211(local->apdev, skb, rx_stats, PRISM2_RX_MGMT); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | if (local->iw_mode == IW_MODE_MASTER) { |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 483 | if (type != IEEE80211_FTYPE_MGMT && |
| 484 | type != IEEE80211_FTYPE_CTL) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 485 | printk(KERN_DEBUG "%s: unknown management frame " |
| 486 | "(type=0x%02x, stype=0x%02x) dropped\n", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 487 | skb->dev->name, type >> 2, stype >> 4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 488 | return -1; |
| 489 | } |
| 490 | |
| 491 | hostap_rx(skb->dev, skb, rx_stats); |
| 492 | return 0; |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 493 | } else if (type == IEEE80211_FTYPE_MGMT && |
| 494 | (stype == IEEE80211_STYPE_BEACON || |
| 495 | stype == IEEE80211_STYPE_PROBE_RESP)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 496 | hostap_rx_sta_beacon(local, skb, stype); |
| 497 | return -1; |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 498 | } else if (type == IEEE80211_FTYPE_MGMT && |
| 499 | (stype == IEEE80211_STYPE_ASSOC_RESP || |
| 500 | stype == IEEE80211_STYPE_REASSOC_RESP)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 501 | /* Ignore (Re)AssocResp silently since these are not currently |
| 502 | * needed but are still received when WPA/RSN mode is enabled. |
| 503 | */ |
| 504 | return -1; |
| 505 | } else { |
| 506 | printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: dropped unhandled" |
| 507 | " management frame in non-Host AP mode (type=%d:%d)\n", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 508 | skb->dev->name, type >> 2, stype >> 4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 509 | return -1; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 | /* Called only as a tasklet (software IRQ) */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 515 | static struct net_device *prism2_rx_get_wds(local_info_t *local, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 516 | u8 *addr) |
| 517 | { |
| 518 | struct hostap_interface *iface = NULL; |
| 519 | struct list_head *ptr; |
| 520 | |
| 521 | read_lock_bh(&local->iface_lock); |
| 522 | list_for_each(ptr, &local->hostap_interfaces) { |
| 523 | iface = list_entry(ptr, struct hostap_interface, list); |
| 524 | if (iface->type == HOSTAP_INTERFACE_WDS && |
| 525 | memcmp(iface->u.wds.remote_addr, addr, ETH_ALEN) == 0) |
| 526 | break; |
| 527 | iface = NULL; |
| 528 | } |
| 529 | read_unlock_bh(&local->iface_lock); |
| 530 | |
| 531 | return iface ? iface->dev : NULL; |
| 532 | } |
| 533 | |
| 534 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 535 | static int |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 536 | hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 537 | u16 fc, struct net_device **wds) |
| 538 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 539 | DECLARE_MAC_BUF(mac); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 540 | /* FIX: is this really supposed to accept WDS frames only in Master |
| 541 | * mode? What about Repeater or Managed with WDS frames? */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 542 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) != |
| 543 | (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS) && |
| 544 | (local->iw_mode != IW_MODE_MASTER || !(fc & IEEE80211_FCTL_TODS))) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 545 | return 0; /* not a WDS frame */ |
| 546 | |
| 547 | /* Possible WDS frame: either IEEE 802.11 compliant (if FromDS) |
| 548 | * or own non-standard frame with 4th address after payload */ |
| 549 | if (memcmp(hdr->addr1, local->dev->dev_addr, ETH_ALEN) != 0 && |
| 550 | (hdr->addr1[0] != 0xff || hdr->addr1[1] != 0xff || |
| 551 | hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff || |
| 552 | hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) { |
| 553 | /* RA (or BSSID) is not ours - drop */ |
| 554 | PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 555 | "not own or broadcast %s=%s\n", |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 556 | local->dev->name, |
| 557 | fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 558 | print_mac(mac, hdr->addr1)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 559 | return -1; |
| 560 | } |
| 561 | |
| 562 | /* check if the frame came from a registered WDS connection */ |
| 563 | *wds = prism2_rx_get_wds(local, hdr->addr2); |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 564 | if (*wds == NULL && fc & IEEE80211_FCTL_FROMDS && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 565 | (local->iw_mode != IW_MODE_INFRA || |
| 566 | !(local->wds_type & HOSTAP_WDS_AP_CLIENT) || |
| 567 | memcmp(hdr->addr2, local->bssid, ETH_ALEN) != 0)) { |
| 568 | /* require that WDS link has been registered with TA or the |
| 569 | * frame is from current AP when using 'AP client mode' */ |
| 570 | PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 571 | "from unknown TA=%s\n", |
| 572 | local->dev->name, print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 573 | if (local->ap && local->ap->autom_ap_wds) |
| 574 | hostap_wds_link_oper(local, hdr->addr2, WDS_ADD); |
| 575 | return -1; |
| 576 | } |
| 577 | |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 578 | if (*wds && !(fc & IEEE80211_FCTL_FROMDS) && local->ap && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 579 | hostap_is_sta_assoc(local->ap, hdr->addr2)) { |
| 580 | /* STA is actually associated with us even though it has a |
| 581 | * registered WDS link. Assume it is in 'AP client' mode. |
| 582 | * Since this is a 3-addr frame, assume it is not (bogus) WDS |
| 583 | * frame and process it like any normal ToDS frame from |
| 584 | * associated STA. */ |
| 585 | *wds = NULL; |
| 586 | } |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | |
| 592 | static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb) |
| 593 | { |
| 594 | struct net_device *dev = local->dev; |
| 595 | u16 fc, ethertype; |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 596 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 597 | u8 *pos; |
| 598 | |
| 599 | if (skb->len < 24) |
| 600 | return 0; |
| 601 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 602 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 603 | fc = le16_to_cpu(hdr->frame_ctl); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 604 | |
| 605 | /* check that the frame is unicast frame to us */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 606 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 607 | IEEE80211_FCTL_TODS && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 608 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 && |
| 609 | memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { |
| 610 | /* ToDS frame with own addr BSSID and DA */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 611 | } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 612 | IEEE80211_FCTL_FROMDS && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 613 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { |
| 614 | /* FromDS frame with own addr as DA */ |
| 615 | } else |
| 616 | return 0; |
| 617 | |
| 618 | if (skb->len < 24 + 8) |
| 619 | return 0; |
| 620 | |
| 621 | /* check for port access entity Ethernet type */ |
| 622 | pos = skb->data + 24; |
| 623 | ethertype = (pos[6] << 8) | pos[7]; |
| 624 | if (ethertype == ETH_P_PAE) |
| 625 | return 1; |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | |
| 631 | /* Called only as a tasklet (software IRQ) */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 632 | static int |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 633 | hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb, |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 634 | struct ieee80211_crypt_data *crypt) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 635 | { |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 636 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 637 | int res, hdrlen; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 638 | DECLARE_MAC_BUF(mac); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 639 | |
| 640 | if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) |
| 641 | return 0; |
| 642 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 643 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 644 | hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 645 | |
| 646 | if (local->tkip_countermeasures && |
| 647 | strcmp(crypt->ops->name, "TKIP") == 0) { |
| 648 | if (net_ratelimit()) { |
| 649 | printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 650 | "received packet from %s\n", |
| 651 | local->dev->name, print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 652 | } |
| 653 | return -1; |
| 654 | } |
| 655 | |
| 656 | atomic_inc(&crypt->refcnt); |
| 657 | res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); |
| 658 | atomic_dec(&crypt->refcnt); |
| 659 | if (res < 0) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 660 | printk(KERN_DEBUG "%s: decryption failed (SA=%s" |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 661 | ") res=%d\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 662 | local->dev->name, print_mac(mac, hdr->addr2), res); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 663 | local->comm_tallies.rx_discards_wep_undecryptable++; |
| 664 | return -1; |
| 665 | } |
| 666 | |
| 667 | return res; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | /* Called only as a tasklet (software IRQ) */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 672 | static int |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 673 | hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb, |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 674 | int keyidx, struct ieee80211_crypt_data *crypt) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 675 | { |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 676 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 677 | int res, hdrlen; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 678 | DECLARE_MAC_BUF(mac); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 679 | |
| 680 | if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) |
| 681 | return 0; |
| 682 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 683 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 684 | hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 685 | |
| 686 | atomic_inc(&crypt->refcnt); |
| 687 | res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); |
| 688 | atomic_dec(&crypt->refcnt); |
| 689 | if (res < 0) { |
| 690 | printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 691 | " (SA=%s keyidx=%d)\n", |
| 692 | local->dev->name, print_mac(mac, hdr->addr2), keyidx); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 693 | return -1; |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | /* All received frames are sent to this function. @skb contains the frame in |
| 701 | * IEEE 802.11 format, i.e., in the format it was sent over air. |
| 702 | * This function is called only as a tasklet (software IRQ). */ |
| 703 | void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb, |
| 704 | struct hostap_80211_rx_status *rx_stats) |
| 705 | { |
| 706 | struct hostap_interface *iface; |
| 707 | local_info_t *local; |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 708 | struct ieee80211_hdr_4addr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 709 | size_t hdrlen; |
| 710 | u16 fc, type, stype, sc; |
| 711 | struct net_device *wds = NULL; |
| 712 | struct net_device_stats *stats; |
| 713 | unsigned int frag; |
| 714 | u8 *payload; |
| 715 | struct sk_buff *skb2 = NULL; |
| 716 | u16 ethertype; |
| 717 | int frame_authorized = 0; |
| 718 | int from_assoc_ap = 0; |
| 719 | u8 dst[ETH_ALEN]; |
| 720 | u8 src[ETH_ALEN]; |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 721 | struct ieee80211_crypt_data *crypt = NULL; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 722 | void *sta = NULL; |
| 723 | int keyidx = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 724 | DECLARE_MAC_BUF(mac); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 725 | |
| 726 | iface = netdev_priv(dev); |
| 727 | local = iface->local; |
| 728 | iface->stats.rx_packets++; |
| 729 | iface->stats.rx_bytes += skb->len; |
| 730 | |
| 731 | /* dev is the master radio device; change this to be the default |
| 732 | * virtual interface (this may be changed to WDS device below) */ |
| 733 | dev = local->ddev; |
| 734 | iface = netdev_priv(dev); |
| 735 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 736 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 737 | stats = hostap_get_stats(dev); |
| 738 | |
| 739 | if (skb->len < 10) |
| 740 | goto rx_dropped; |
| 741 | |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 742 | fc = le16_to_cpu(hdr->frame_ctl); |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 743 | type = WLAN_FC_GET_TYPE(fc); |
| 744 | stype = WLAN_FC_GET_STYPE(fc); |
Jouni Malinen | c0f72ca | 2005-08-14 19:08:43 -0700 | [diff] [blame] | 745 | sc = le16_to_cpu(hdr->seq_ctl); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 746 | frag = WLAN_GET_SEQ_FRAG(sc); |
| 747 | hdrlen = hostap_80211_get_hdrlen(fc); |
| 748 | |
| 749 | /* Put this code here so that we avoid duplicating it in all |
| 750 | * Rx paths. - Jean II */ |
| 751 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ |
| 752 | /* If spy monitoring on */ |
| 753 | if (iface->spy_data.spy_number > 0) { |
| 754 | struct iw_quality wstats; |
| 755 | wstats.level = rx_stats->signal; |
| 756 | wstats.noise = rx_stats->noise; |
Jean Tourrilhes | c28df16 | 2005-09-23 21:58:59 -0700 | [diff] [blame] | 757 | wstats.updated = IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED |
| 758 | | IW_QUAL_QUAL_INVALID | IW_QUAL_DBM; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 759 | /* Update spy records */ |
| 760 | wireless_spy_update(dev, hdr->addr2, &wstats); |
| 761 | } |
| 762 | #endif /* IW_WIRELESS_SPY */ |
| 763 | hostap_update_rx_stats(local->ap, hdr, rx_stats); |
| 764 | |
| 765 | if (local->iw_mode == IW_MODE_MONITOR) { |
| 766 | monitor_rx(dev, skb, rx_stats); |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | if (local->host_decrypt) { |
| 771 | int idx = 0; |
| 772 | if (skb->len >= hdrlen + 3) |
| 773 | idx = skb->data[hdrlen + 3] >> 6; |
| 774 | crypt = local->crypt[idx]; |
| 775 | sta = NULL; |
| 776 | |
| 777 | /* Use station specific key to override default keys if the |
| 778 | * receiver address is a unicast address ("individual RA"). If |
| 779 | * bcrx_sta_key parameter is set, station specific key is used |
| 780 | * even with broad/multicast targets (this is against IEEE |
| 781 | * 802.11, but makes it easier to use different keys with |
| 782 | * stations that do not support WEP key mapping). */ |
| 783 | |
| 784 | if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) |
| 785 | (void) hostap_handle_sta_crypto(local, hdr, &crypt, |
| 786 | &sta); |
| 787 | |
| 788 | /* allow NULL decrypt to indicate an station specific override |
| 789 | * for default encryption */ |
| 790 | if (crypt && (crypt->ops == NULL || |
| 791 | crypt->ops->decrypt_mpdu == NULL)) |
| 792 | crypt = NULL; |
| 793 | |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 794 | if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 795 | #if 0 |
| 796 | /* This seems to be triggered by some (multicast?) |
| 797 | * frames from other than current BSS, so just drop the |
| 798 | * frames silently instead of filling system log with |
| 799 | * these reports. */ |
| 800 | printk(KERN_DEBUG "%s: WEP decryption failed (not set)" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 801 | " (SA=%s)\n", |
| 802 | local->dev->name, print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 803 | #endif |
| 804 | local->comm_tallies.rx_discards_wep_undecryptable++; |
| 805 | goto rx_dropped; |
| 806 | } |
| 807 | } |
| 808 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 809 | if (type != IEEE80211_FTYPE_DATA) { |
| 810 | if (type == IEEE80211_FTYPE_MGMT && |
| 811 | stype == IEEE80211_STYPE_AUTH && |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 812 | fc & IEEE80211_FCTL_PROTECTED && local->host_decrypt && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 813 | (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0) |
| 814 | { |
| 815 | printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 816 | "from %s\n", dev->name, |
| 817 | print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 818 | /* TODO: could inform hostapd about this so that it |
| 819 | * could send auth failure report */ |
| 820 | goto rx_dropped; |
| 821 | } |
| 822 | |
| 823 | if (hostap_rx_frame_mgmt(local, skb, rx_stats, type, stype)) |
| 824 | goto rx_dropped; |
| 825 | else |
| 826 | goto rx_exit; |
| 827 | } |
| 828 | |
| 829 | /* Data frame - extract src/dst addresses */ |
| 830 | if (skb->len < IEEE80211_DATA_HDR3_LEN) |
| 831 | goto rx_dropped; |
| 832 | |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 833 | switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { |
| 834 | case IEEE80211_FCTL_FROMDS: |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 835 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 836 | memcpy(src, hdr->addr3, ETH_ALEN); |
| 837 | break; |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 838 | case IEEE80211_FCTL_TODS: |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 839 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 840 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 841 | break; |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 842 | case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 843 | if (skb->len < IEEE80211_DATA_HDR4_LEN) |
| 844 | goto rx_dropped; |
| 845 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 846 | memcpy(src, hdr->addr4, ETH_ALEN); |
| 847 | break; |
| 848 | case 0: |
| 849 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 850 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 851 | break; |
| 852 | } |
| 853 | |
| 854 | if (hostap_rx_frame_wds(local, hdr, fc, &wds)) |
| 855 | goto rx_dropped; |
| 856 | if (wds) { |
| 857 | skb->dev = dev = wds; |
| 858 | stats = hostap_get_stats(dev); |
| 859 | } |
| 860 | |
| 861 | if (local->iw_mode == IW_MODE_MASTER && !wds && |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 862 | (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 863 | IEEE80211_FCTL_FROMDS && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 864 | local->stadev && |
| 865 | memcmp(hdr->addr2, local->assoc_ap_addr, ETH_ALEN) == 0) { |
| 866 | /* Frame from BSSID of the AP for which we are a client */ |
| 867 | skb->dev = dev = local->stadev; |
| 868 | stats = hostap_get_stats(dev); |
| 869 | from_assoc_ap = 1; |
| 870 | } |
| 871 | |
| 872 | dev->last_rx = jiffies; |
| 873 | |
| 874 | if ((local->iw_mode == IW_MODE_MASTER || |
| 875 | local->iw_mode == IW_MODE_REPEAT) && |
| 876 | !from_assoc_ap) { |
| 877 | switch (hostap_handle_sta_rx(local, dev, skb, rx_stats, |
| 878 | wds != NULL)) { |
| 879 | case AP_RX_CONTINUE_NOT_AUTHORIZED: |
| 880 | frame_authorized = 0; |
| 881 | break; |
| 882 | case AP_RX_CONTINUE: |
| 883 | frame_authorized = 1; |
| 884 | break; |
| 885 | case AP_RX_DROP: |
| 886 | goto rx_dropped; |
| 887 | case AP_RX_EXIT: |
| 888 | goto rx_exit; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | /* Nullfunc frames may have PS-bit set, so they must be passed to |
| 893 | * hostap_handle_sta_rx() before being dropped here. */ |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 894 | if (stype != IEEE80211_STYPE_DATA && |
| 895 | stype != IEEE80211_STYPE_DATA_CFACK && |
| 896 | stype != IEEE80211_STYPE_DATA_CFPOLL && |
| 897 | stype != IEEE80211_STYPE_DATA_CFACKPOLL) { |
| 898 | if (stype != IEEE80211_STYPE_NULLFUNC) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 899 | printk(KERN_DEBUG "%s: RX: dropped data frame " |
| 900 | "with no data (type=0x%02x, subtype=0x%02x)\n", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 901 | dev->name, type >> 2, stype >> 4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 902 | goto rx_dropped; |
| 903 | } |
| 904 | |
| 905 | /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ |
| 906 | |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 907 | if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 908 | (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0) |
| 909 | goto rx_dropped; |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 910 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 911 | |
| 912 | /* skb: hdr + (possibly fragmented) plaintext payload */ |
| 913 | |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 914 | if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 915 | (frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 916 | int flen; |
| 917 | struct sk_buff *frag_skb = |
| 918 | prism2_frag_cache_get(local, hdr); |
| 919 | if (!frag_skb) { |
| 920 | printk(KERN_DEBUG "%s: Rx cannot get skb from " |
| 921 | "fragment cache (morefrag=%d seq=%u frag=%u)\n", |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 922 | dev->name, (fc & IEEE80211_FCTL_MOREFRAGS) != 0, |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 923 | WLAN_GET_SEQ_SEQ(sc) >> 4, frag); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 924 | goto rx_dropped; |
| 925 | } |
| 926 | |
| 927 | flen = skb->len; |
| 928 | if (frag != 0) |
| 929 | flen -= hdrlen; |
| 930 | |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 931 | if (frag_skb->tail + flen > frag_skb->end) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 932 | printk(KERN_WARNING "%s: host decrypted and " |
| 933 | "reassembled frame did not fit skb\n", |
| 934 | dev->name); |
| 935 | prism2_frag_cache_invalidate(local, hdr); |
| 936 | goto rx_dropped; |
| 937 | } |
| 938 | |
| 939 | if (frag == 0) { |
| 940 | /* copy first fragment (including full headers) into |
| 941 | * beginning of the fragment cache skb */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 942 | skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), |
| 943 | flen); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 944 | } else { |
| 945 | /* append frame payload to the end of the fragment |
| 946 | * cache skb */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 947 | skb_copy_from_linear_data_offset(skb, hdrlen, |
| 948 | skb_put(frag_skb, |
| 949 | flen), flen); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 950 | } |
| 951 | dev_kfree_skb(skb); |
| 952 | skb = NULL; |
| 953 | |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 954 | if (fc & IEEE80211_FCTL_MOREFRAGS) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 955 | /* more fragments expected - leave the skb in fragment |
| 956 | * cache for now; it will be delivered to upper layers |
| 957 | * after all fragments have been received */ |
| 958 | goto rx_exit; |
| 959 | } |
| 960 | |
| 961 | /* this was the last fragment and the frame will be |
| 962 | * delivered, so remove skb from fragment cache */ |
| 963 | skb = frag_skb; |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 964 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 965 | prism2_frag_cache_invalidate(local, hdr); |
| 966 | } |
| 967 | |
| 968 | /* skb: hdr + (possible reassembled) full MSDU payload; possibly still |
| 969 | * encrypted/authenticated */ |
| 970 | |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 971 | if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 972 | hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt)) |
| 973 | goto rx_dropped; |
| 974 | |
James Ketrenos | d041674 | 2005-09-21 12:23:49 -0500 | [diff] [blame] | 975 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 976 | if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 977 | if (local->ieee_802_1x && |
| 978 | hostap_is_eapol_frame(local, skb)) { |
| 979 | /* pass unencrypted EAPOL frames even if encryption is |
| 980 | * configured */ |
| 981 | PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X - passing " |
| 982 | "unencrypted EAPOL frame\n", local->dev->name); |
| 983 | } else { |
| 984 | printk(KERN_DEBUG "%s: encryption configured, but RX " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 985 | "frame not encrypted (SA=%s)\n", |
| 986 | local->dev->name, print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 987 | goto rx_dropped; |
| 988 | } |
| 989 | } |
| 990 | |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 991 | if (local->drop_unencrypted && !(fc & IEEE80211_FCTL_PROTECTED) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 992 | !hostap_is_eapol_frame(local, skb)) { |
| 993 | if (net_ratelimit()) { |
| 994 | printk(KERN_DEBUG "%s: dropped unencrypted RX data " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 995 | "frame from %s" |
| 996 | " (drop_unencrypted=1)\n", |
| 997 | dev->name, print_mac(mac, hdr->addr2)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 998 | } |
| 999 | goto rx_dropped; |
| 1000 | } |
| 1001 | |
| 1002 | /* skb: hdr + (possible reassembled) full plaintext payload */ |
| 1003 | |
| 1004 | payload = skb->data + hdrlen; |
| 1005 | ethertype = (payload[6] << 8) | payload[7]; |
| 1006 | |
| 1007 | /* If IEEE 802.1X is used, check whether the port is authorized to send |
| 1008 | * the received frame. */ |
| 1009 | if (local->ieee_802_1x && local->iw_mode == IW_MODE_MASTER) { |
| 1010 | if (ethertype == ETH_P_PAE) { |
| 1011 | PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X frame\n", |
| 1012 | dev->name); |
| 1013 | if (local->hostapd && local->apdev) { |
| 1014 | /* Send IEEE 802.1X frames to the user |
| 1015 | * space daemon for processing */ |
| 1016 | prism2_rx_80211(local->apdev, skb, rx_stats, |
| 1017 | PRISM2_RX_MGMT); |
| 1018 | local->apdevstats.rx_packets++; |
| 1019 | local->apdevstats.rx_bytes += skb->len; |
| 1020 | goto rx_exit; |
| 1021 | } |
| 1022 | } else if (!frame_authorized) { |
| 1023 | printk(KERN_DEBUG "%s: dropped frame from " |
| 1024 | "unauthorized port (IEEE 802.1X): " |
| 1025 | "ethertype=0x%04x\n", |
| 1026 | dev->name, ethertype); |
| 1027 | goto rx_dropped; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | /* convert hdr + possible LLC headers into Ethernet header */ |
| 1032 | if (skb->len - hdrlen >= 8 && |
| 1033 | ((memcmp(payload, rfc1042_header, 6) == 0 && |
| 1034 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1035 | memcmp(payload, bridge_tunnel_header, 6) == 0)) { |
| 1036 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 1037 | * replace EtherType */ |
| 1038 | skb_pull(skb, hdrlen + 6); |
| 1039 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 1040 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 1041 | } else { |
| 1042 | u16 len; |
| 1043 | /* Leave Ethernet header part of hdr and full payload */ |
| 1044 | skb_pull(skb, hdrlen); |
| 1045 | len = htons(skb->len); |
| 1046 | memcpy(skb_push(skb, 2), &len, 2); |
| 1047 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 1048 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 1049 | } |
| 1050 | |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 1051 | if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 1052 | IEEE80211_FCTL_TODS) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1053 | skb->len >= ETH_HLEN + ETH_ALEN) { |
| 1054 | /* Non-standard frame: get addr4 from its bogus location after |
| 1055 | * the payload */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1056 | skb_copy_from_linear_data_offset(skb, skb->len - ETH_ALEN, |
| 1057 | skb->data + ETH_ALEN, |
| 1058 | ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1059 | skb_trim(skb, skb->len - ETH_ALEN); |
| 1060 | } |
| 1061 | |
| 1062 | stats->rx_packets++; |
| 1063 | stats->rx_bytes += skb->len; |
| 1064 | |
| 1065 | if (local->iw_mode == IW_MODE_MASTER && !wds && |
| 1066 | local->ap->bridge_packets) { |
| 1067 | if (dst[0] & 0x01) { |
| 1068 | /* copy multicast frame both to the higher layers and |
| 1069 | * to the wireless media */ |
| 1070 | local->ap->bridged_multicast++; |
| 1071 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 1072 | if (skb2 == NULL) |
| 1073 | printk(KERN_DEBUG "%s: skb_clone failed for " |
| 1074 | "multicast frame\n", dev->name); |
| 1075 | } else if (hostap_is_sta_authorized(local->ap, dst)) { |
| 1076 | /* send frame directly to the associated STA using |
| 1077 | * wireless media and not passing to higher layers */ |
| 1078 | local->ap->bridged_unicast++; |
| 1079 | skb2 = skb; |
| 1080 | skb = NULL; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | if (skb2 != NULL) { |
| 1085 | /* send to wireless media */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1086 | skb2->dev = dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 1087 | skb2->protocol = __constant_htons(ETH_P_802_3); |
| 1088 | skb_reset_mac_header(skb2); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 1089 | skb_reset_network_header(skb2); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 1090 | /* skb2->network_header += ETH_HLEN; */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1091 | dev_queue_xmit(skb2); |
| 1092 | } |
| 1093 | |
| 1094 | if (skb) { |
| 1095 | skb->protocol = eth_type_trans(skb, dev); |
| 1096 | memset(skb->cb, 0, sizeof(skb->cb)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1097 | netif_rx(skb); |
| 1098 | } |
| 1099 | |
| 1100 | rx_exit: |
| 1101 | if (sta) |
| 1102 | hostap_handle_sta_release(sta); |
| 1103 | return; |
| 1104 | |
| 1105 | rx_dropped: |
| 1106 | dev_kfree_skb(skb); |
| 1107 | |
| 1108 | stats->rx_dropped++; |
| 1109 | goto rx_exit; |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | EXPORT_SYMBOL(hostap_80211_rx); |