Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Original code based Host AP (software wireless LAN access point) driver |
| 3 | * for Intersil Prism2/2.5/3 - hostap.o module, common routines |
| 4 | * |
| 5 | * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen |
Jouni Malinen | 85d32e7 | 2007-03-24 17:15:30 -0700 | [diff] [blame] | 6 | * <j@w1.fi> |
| 7 | * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi> |
James Ketrenos | ebeaddc | 2005-09-21 11:58:43 -0500 | [diff] [blame] | 8 | * Copyright (c) 2004-2005, Intel Corporation |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. See README and COPYING for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/compiler.h> |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | #include <linux/if_arp.h> |
| 19 | #include <linux/in6.h> |
| 20 | #include <linux/in.h> |
| 21 | #include <linux/ip.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/netdevice.h> |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 25 | #include <linux/proc_fs.h> |
| 26 | #include <linux/skbuff.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/tcp.h> |
| 29 | #include <linux/types.h> |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 30 | #include <linux/wireless.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <asm/uaccess.h> |
| 33 | #include <linux/ctype.h> |
| 34 | |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 35 | #include <net/lib80211.h> |
Dan Williams | f3734ee | 2009-02-12 12:32:55 -0500 | [diff] [blame^] | 36 | |
| 37 | #include "ieee80211.h" |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 38 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 39 | static void ieee80211_monitor_rx(struct ieee80211_device *ieee, |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 40 | struct sk_buff *skb, |
| 41 | struct ieee80211_rx_stats *rx_stats) |
| 42 | { |
| 43 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 44 | u16 fc = le16_to_cpu(hdr->frame_control); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 45 | |
| 46 | skb->dev = ieee->dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 47 | skb_reset_mac_header(skb); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 48 | skb_pull(skb, ieee80211_get_hdrlen(fc)); |
| 49 | skb->pkt_type = PACKET_OTHERHOST; |
YOSHIFUJI Hideaki | 4e39430 | 2007-12-12 03:52:26 +0900 | [diff] [blame] | 50 | skb->protocol = htons(ETH_P_80211_RAW); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 51 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 52 | netif_rx(skb); |
| 53 | } |
| 54 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 55 | /* Called only as a tasklet (software IRQ) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 56 | static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct |
| 57 | ieee80211_device |
| 58 | *ieee, |
| 59 | unsigned int seq, |
| 60 | unsigned int frag, |
| 61 | u8 * src, |
| 62 | u8 * dst) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 63 | { |
| 64 | struct ieee80211_frag_entry *entry; |
| 65 | int i; |
| 66 | |
| 67 | for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) { |
| 68 | entry = &ieee->frag_cache[i]; |
| 69 | if (entry->skb != NULL && |
| 70 | time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 71 | IEEE80211_DEBUG_FRAG("expiring fragment cache entry " |
| 72 | "seq=%u last_frag=%u\n", |
| 73 | entry->seq, entry->last_frag); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 74 | dev_kfree_skb_any(entry->skb); |
| 75 | entry->skb = NULL; |
| 76 | } |
| 77 | |
| 78 | if (entry->skb != NULL && entry->seq == seq && |
| 79 | (entry->last_frag + 1 == frag || frag == -1) && |
Kris Katterjohn | d3f4a68 | 2006-01-09 16:01:43 -0800 | [diff] [blame] | 80 | !compare_ether_addr(entry->src_addr, src) && |
| 81 | !compare_ether_addr(entry->dst_addr, dst)) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 82 | return entry; |
| 83 | } |
| 84 | |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | /* Called only as a tasklet (software IRQ) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 89 | static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee, |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 90 | struct ieee80211_hdr_4addr *hdr) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 91 | { |
| 92 | struct sk_buff *skb = NULL; |
| 93 | u16 sc; |
| 94 | unsigned int frag, seq; |
| 95 | struct ieee80211_frag_entry *entry; |
| 96 | |
| 97 | sc = le16_to_cpu(hdr->seq_ctl); |
| 98 | frag = WLAN_GET_SEQ_FRAG(sc); |
| 99 | seq = WLAN_GET_SEQ_SEQ(sc); |
| 100 | |
| 101 | if (frag == 0) { |
| 102 | /* Reserve enough space to fit maximum frame length */ |
| 103 | skb = dev_alloc_skb(ieee->dev->mtu + |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 104 | sizeof(struct ieee80211_hdr_4addr) + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 105 | 8 /* LLC */ + |
| 106 | 2 /* alignment */ + |
| 107 | 8 /* WEP */ + ETH_ALEN /* WDS */ ); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 108 | if (skb == NULL) |
| 109 | return NULL; |
| 110 | |
| 111 | entry = &ieee->frag_cache[ieee->frag_next_idx]; |
| 112 | ieee->frag_next_idx++; |
| 113 | if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN) |
| 114 | ieee->frag_next_idx = 0; |
| 115 | |
| 116 | if (entry->skb != NULL) |
| 117 | dev_kfree_skb_any(entry->skb); |
| 118 | |
| 119 | entry->first_frag_time = jiffies; |
| 120 | entry->seq = seq; |
| 121 | entry->last_frag = frag; |
| 122 | entry->skb = skb; |
| 123 | memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); |
| 124 | memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); |
| 125 | } else { |
| 126 | /* received a fragment of a frame for which the head fragment |
| 127 | * should have already been received */ |
| 128 | entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2, |
| 129 | hdr->addr1); |
| 130 | if (entry != NULL) { |
| 131 | entry->last_frag = frag; |
| 132 | skb = entry->skb; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return skb; |
| 137 | } |
| 138 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 139 | /* Called only as a tasklet (software IRQ) */ |
| 140 | static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee, |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 141 | struct ieee80211_hdr_4addr *hdr) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 142 | { |
| 143 | u16 sc; |
| 144 | unsigned int seq; |
| 145 | struct ieee80211_frag_entry *entry; |
| 146 | |
| 147 | sc = le16_to_cpu(hdr->seq_ctl); |
| 148 | seq = WLAN_GET_SEQ_SEQ(sc); |
| 149 | |
| 150 | entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2, |
| 151 | hdr->addr1); |
| 152 | |
| 153 | if (entry == NULL) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 154 | IEEE80211_DEBUG_FRAG("could not invalidate fragment cache " |
| 155 | "entry (seq=%u)\n", seq); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | entry->skb = NULL; |
| 160 | return 0; |
| 161 | } |
| 162 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 163 | #ifdef NOT_YET |
| 164 | /* ieee80211_rx_frame_mgtmt |
| 165 | * |
| 166 | * Responsible for handling management control frames |
| 167 | * |
| 168 | * Called by ieee80211_rx */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 169 | static int |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 170 | ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, |
| 171 | struct ieee80211_rx_stats *rx_stats, u16 type, |
| 172 | u16 stype) |
| 173 | { |
| 174 | if (ieee->iw_mode == IW_MODE_MASTER) { |
| 175 | printk(KERN_DEBUG "%s: Master mode not yet suppported.\n", |
| 176 | ieee->dev->name); |
| 177 | return 0; |
| 178 | /* |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 179 | hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 180 | skb->data);*/ |
| 181 | } |
| 182 | |
| 183 | if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) { |
| 184 | if (stype == WLAN_FC_STYPE_BEACON && |
| 185 | ieee->iw_mode == IW_MODE_MASTER) { |
| 186 | struct sk_buff *skb2; |
| 187 | /* Process beacon frames also in kernel driver to |
| 188 | * update STA(AP) table statistics */ |
| 189 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 190 | if (skb2) |
| 191 | hostap_rx(skb2->dev, skb2, rx_stats); |
| 192 | } |
| 193 | |
| 194 | /* send management frames to the user space daemon for |
| 195 | * processing */ |
| 196 | ieee->apdevstats.rx_packets++; |
| 197 | ieee->apdevstats.rx_bytes += skb->len; |
| 198 | prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT); |
| 199 | return 0; |
| 200 | } |
| 201 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 202 | if (ieee->iw_mode == IW_MODE_MASTER) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 203 | if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) { |
| 204 | printk(KERN_DEBUG "%s: unknown management frame " |
| 205 | "(type=0x%02x, stype=0x%02x) dropped\n", |
| 206 | skb->dev->name, type, stype); |
| 207 | return -1; |
| 208 | } |
| 209 | |
| 210 | hostap_rx(skb->dev, skb, rx_stats); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame " |
| 215 | "received in non-Host AP mode\n", skb->dev->name); |
| 216 | return -1; |
| 217 | } |
| 218 | #endif |
| 219 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 220 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 221 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 222 | static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 223 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 224 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
| 225 | static unsigned char bridge_tunnel_header[] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 226 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 227 | /* No encapsulation header if EtherType < 0x600 (=length) */ |
| 228 | |
| 229 | /* Called by ieee80211_rx_frame_decrypt */ |
| 230 | static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee, |
| 231 | struct sk_buff *skb) |
| 232 | { |
| 233 | struct net_device *dev = ieee->dev; |
| 234 | u16 fc, ethertype; |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 235 | struct ieee80211_hdr_3addr *hdr; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 236 | u8 *pos; |
| 237 | |
| 238 | if (skb->len < 24) |
| 239 | return 0; |
| 240 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 241 | hdr = (struct ieee80211_hdr_3addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 242 | fc = le16_to_cpu(hdr->frame_ctl); |
| 243 | |
| 244 | /* check that the frame is unicast frame to us */ |
| 245 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 246 | IEEE80211_FCTL_TODS && |
Kris Katterjohn | d3f4a68 | 2006-01-09 16:01:43 -0800 | [diff] [blame] | 247 | !compare_ether_addr(hdr->addr1, dev->dev_addr) && |
| 248 | !compare_ether_addr(hdr->addr3, dev->dev_addr)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 249 | /* ToDS frame with own addr BSSID and DA */ |
| 250 | } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 251 | IEEE80211_FCTL_FROMDS && |
Kris Katterjohn | d3f4a68 | 2006-01-09 16:01:43 -0800 | [diff] [blame] | 252 | !compare_ether_addr(hdr->addr1, dev->dev_addr)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 253 | /* FromDS frame with own addr as DA */ |
| 254 | } else |
| 255 | return 0; |
| 256 | |
| 257 | if (skb->len < 24 + 8) |
| 258 | return 0; |
| 259 | |
| 260 | /* check for port access entity Ethernet type */ |
| 261 | pos = skb->data + 24; |
| 262 | ethertype = (pos[6] << 8) | pos[7]; |
| 263 | if (ethertype == ETH_P_PAE) |
| 264 | return 1; |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 270 | static int |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 271 | ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb, |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 272 | struct lib80211_crypt_data *crypt) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 273 | { |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 274 | struct ieee80211_hdr_3addr *hdr; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 275 | int res, hdrlen; |
| 276 | |
| 277 | if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) |
| 278 | return 0; |
| 279 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 280 | hdr = (struct ieee80211_hdr_3addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 281 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
| 282 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 283 | atomic_inc(&crypt->refcnt); |
| 284 | res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); |
| 285 | atomic_dec(&crypt->refcnt); |
| 286 | if (res < 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 287 | IEEE80211_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n", |
| 288 | hdr->addr2, res); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 289 | if (res == -2) |
| 290 | IEEE80211_DEBUG_DROP("Decryption failed ICV " |
| 291 | "mismatch (key %d)\n", |
| 292 | skb->data[hdrlen + 3] >> 6); |
| 293 | ieee->ieee_stats.rx_discards_undecryptable++; |
| 294 | return -1; |
| 295 | } |
| 296 | |
| 297 | return res; |
| 298 | } |
| 299 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 300 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 301 | static int |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 302 | ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, |
| 303 | struct sk_buff *skb, int keyidx, |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 304 | struct lib80211_crypt_data *crypt) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 305 | { |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 306 | struct ieee80211_hdr_3addr *hdr; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 307 | int res, hdrlen; |
| 308 | |
| 309 | if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) |
| 310 | return 0; |
| 311 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 312 | hdr = (struct ieee80211_hdr_3addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 313 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
| 314 | |
| 315 | atomic_inc(&crypt->refcnt); |
| 316 | res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); |
| 317 | atomic_dec(&crypt->refcnt); |
| 318 | if (res < 0) { |
| 319 | printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 320 | " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2, |
David S. Miller | 21f644f | 2008-04-08 16:50:44 -0700 | [diff] [blame] | 321 | keyidx); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 322 | return -1; |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 328 | /* All received frames are sent to this function. @skb contains the frame in |
| 329 | * IEEE 802.11 format, i.e., in the format it was sent over air. |
| 330 | * This function is called only as a tasklet (software IRQ). */ |
| 331 | int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, |
| 332 | struct ieee80211_rx_stats *rx_stats) |
| 333 | { |
| 334 | struct net_device *dev = ieee->dev; |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 335 | struct ieee80211_hdr_4addr *hdr; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 336 | size_t hdrlen; |
| 337 | u16 fc, type, stype, sc; |
| 338 | struct net_device_stats *stats; |
| 339 | unsigned int frag; |
| 340 | u8 *payload; |
| 341 | u16 ethertype; |
| 342 | #ifdef NOT_YET |
| 343 | struct net_device *wds = NULL; |
| 344 | struct sk_buff *skb2 = NULL; |
| 345 | struct net_device *wds = NULL; |
| 346 | int frame_authorized = 0; |
| 347 | int from_assoc_ap = 0; |
| 348 | void *sta = NULL; |
| 349 | #endif |
| 350 | u8 dst[ETH_ALEN]; |
| 351 | u8 src[ETH_ALEN]; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 352 | struct lib80211_crypt_data *crypt = NULL; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 353 | int keyidx = 0; |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 354 | int can_be_decrypted = 0; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 355 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 356 | hdr = (struct ieee80211_hdr_4addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 357 | stats = &ieee->stats; |
| 358 | |
| 359 | if (skb->len < 10) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 360 | printk(KERN_INFO "%s: SKB length < 10\n", dev->name); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 361 | goto rx_dropped; |
| 362 | } |
| 363 | |
| 364 | fc = le16_to_cpu(hdr->frame_ctl); |
| 365 | type = WLAN_FC_GET_TYPE(fc); |
| 366 | stype = WLAN_FC_GET_STYPE(fc); |
| 367 | sc = le16_to_cpu(hdr->seq_ctl); |
| 368 | frag = WLAN_GET_SEQ_FRAG(sc); |
| 369 | hdrlen = ieee80211_get_hdrlen(fc); |
| 370 | |
John W. Linville | 04045f9 | 2007-10-01 21:03:54 -0700 | [diff] [blame] | 371 | if (skb->len < hdrlen) { |
| 372 | printk(KERN_INFO "%s: invalid SKB length %d\n", |
| 373 | dev->name, skb->len); |
| 374 | goto rx_dropped; |
| 375 | } |
| 376 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 377 | /* Put this code here so that we avoid duplicating it in all |
| 378 | * Rx paths. - Jean II */ |
Horms | 8f7eb407 | 2006-06-26 17:44:38 +0900 | [diff] [blame] | 379 | #ifdef CONFIG_WIRELESS_EXT |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 380 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ |
| 381 | /* If spy monitoring on */ |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 382 | if (ieee->spy_data.spy_number > 0) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 383 | struct iw_quality wstats; |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 384 | |
| 385 | wstats.updated = 0; |
| 386 | if (rx_stats->mask & IEEE80211_STATMASK_RSSI) { |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 387 | wstats.level = rx_stats->signal; |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 388 | wstats.updated |= IW_QUAL_LEVEL_UPDATED; |
| 389 | } else |
| 390 | wstats.updated |= IW_QUAL_LEVEL_INVALID; |
| 391 | |
| 392 | if (rx_stats->mask & IEEE80211_STATMASK_NOISE) { |
| 393 | wstats.noise = rx_stats->noise; |
| 394 | wstats.updated |= IW_QUAL_NOISE_UPDATED; |
| 395 | } else |
| 396 | wstats.updated |= IW_QUAL_NOISE_INVALID; |
| 397 | |
| 398 | if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) { |
| 399 | wstats.qual = rx_stats->signal; |
| 400 | wstats.updated |= IW_QUAL_QUAL_UPDATED; |
| 401 | } else |
| 402 | wstats.updated |= IW_QUAL_QUAL_INVALID; |
| 403 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 404 | /* Update spy records */ |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 405 | wireless_spy_update(ieee->dev, hdr->addr2, &wstats); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 406 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 407 | #endif /* IW_WIRELESS_SPY */ |
Horms | 8f7eb407 | 2006-06-26 17:44:38 +0900 | [diff] [blame] | 408 | #endif /* CONFIG_WIRELESS_EXT */ |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 409 | |
| 410 | #ifdef NOT_YET |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 411 | hostap_update_rx_stats(local->ap, hdr, rx_stats); |
| 412 | #endif |
| 413 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 414 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 415 | stats->rx_packets++; |
| 416 | stats->rx_bytes += skb->len; |
Eric Sesterhenn | 60d48f1 | 2006-06-21 21:05:58 +0200 | [diff] [blame] | 417 | ieee80211_monitor_rx(ieee, skb, rx_stats); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 418 | return 1; |
| 419 | } |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 420 | |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 421 | can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) || |
| 422 | is_broadcast_ether_addr(hdr->addr2)) ? |
| 423 | ieee->host_mc_decrypt : ieee->host_decrypt; |
| 424 | |
| 425 | if (can_be_decrypted) { |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 426 | if (skb->len >= hdrlen + 3) { |
| 427 | /* Top two-bits of byte 3 are the key index */ |
Daniel Drake | c9308b0 | 2006-09-27 03:50:31 +0100 | [diff] [blame] | 428 | keyidx = skb->data[hdrlen + 3] >> 6; |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 429 | } |
| 430 | |
Daniel Drake | c9308b0 | 2006-09-27 03:50:31 +0100 | [diff] [blame] | 431 | /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx |
| 432 | * is only allowed 2-bits of storage, no value of keyidx can |
| 433 | * be provided via above code that would result in keyidx |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 434 | * being out of range */ |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 435 | crypt = ieee->crypt_info.crypt[keyidx]; |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 436 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 437 | #ifdef NOT_YET |
| 438 | sta = NULL; |
| 439 | |
| 440 | /* Use station specific key to override default keys if the |
| 441 | * receiver address is a unicast address ("individual RA"). If |
| 442 | * bcrx_sta_key parameter is set, station specific key is used |
| 443 | * even with broad/multicast targets (this is against IEEE |
| 444 | * 802.11, but makes it easier to use different keys with |
| 445 | * stations that do not support WEP key mapping). */ |
| 446 | |
| 447 | if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 448 | (void)hostap_handle_sta_crypto(local, hdr, &crypt, |
| 449 | &sta); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 450 | #endif |
| 451 | |
| 452 | /* allow NULL decrypt to indicate an station specific override |
| 453 | * for default encryption */ |
| 454 | if (crypt && (crypt->ops == NULL || |
| 455 | crypt->ops->decrypt_mpdu == NULL)) |
| 456 | crypt = NULL; |
| 457 | |
Jiri Benc | f13baae | 2005-08-25 20:11:46 -0400 | [diff] [blame] | 458 | if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 459 | /* This seems to be triggered by some (multicast?) |
| 460 | * frames from other than current BSS, so just drop the |
| 461 | * frames silently instead of filling system log with |
| 462 | * these reports. */ |
| 463 | IEEE80211_DEBUG_DROP("Decryption failed (not set)" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 464 | " (SA=%pM)\n", hdr->addr2); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 465 | ieee->ieee_stats.rx_discards_undecryptable++; |
| 466 | goto rx_dropped; |
| 467 | } |
| 468 | } |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 469 | #ifdef NOT_YET |
| 470 | if (type != WLAN_FC_TYPE_DATA) { |
| 471 | if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH && |
Jiri Benc | f13baae | 2005-08-25 20:11:46 -0400 | [diff] [blame] | 472 | fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 473 | (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 474 | printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 475 | "from %pM\n", dev->name, hdr->addr2); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 476 | /* TODO: could inform hostapd about this so that it |
| 477 | * could send auth failure report */ |
| 478 | goto rx_dropped; |
| 479 | } |
| 480 | |
| 481 | if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype)) |
| 482 | goto rx_dropped; |
| 483 | else |
| 484 | goto rx_exit; |
| 485 | } |
| 486 | #endif |
Larry Finger | 837925d | 2006-10-03 18:49:32 -0500 | [diff] [blame] | 487 | /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */ |
| 488 | if (sc == ieee->prev_seq_ctl) |
| 489 | goto rx_dropped; |
| 490 | else |
| 491 | ieee->prev_seq_ctl = sc; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 492 | |
| 493 | /* Data frame - extract src/dst addresses */ |
Jiri Benc | 286d974 | 2005-05-24 15:10:18 +0200 | [diff] [blame] | 494 | if (skb->len < IEEE80211_3ADDR_LEN) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 495 | goto rx_dropped; |
| 496 | |
| 497 | switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { |
| 498 | case IEEE80211_FCTL_FROMDS: |
| 499 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 500 | memcpy(src, hdr->addr3, ETH_ALEN); |
| 501 | break; |
| 502 | case IEEE80211_FCTL_TODS: |
| 503 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 504 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 505 | break; |
| 506 | case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: |
Jiri Benc | 286d974 | 2005-05-24 15:10:18 +0200 | [diff] [blame] | 507 | if (skb->len < IEEE80211_4ADDR_LEN) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 508 | goto rx_dropped; |
| 509 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 510 | memcpy(src, hdr->addr4, ETH_ALEN); |
| 511 | break; |
| 512 | case 0: |
| 513 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 514 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 515 | break; |
| 516 | } |
| 517 | |
| 518 | #ifdef NOT_YET |
| 519 | if (hostap_rx_frame_wds(ieee, hdr, fc, &wds)) |
| 520 | goto rx_dropped; |
| 521 | if (wds) { |
| 522 | skb->dev = dev = wds; |
| 523 | stats = hostap_get_stats(dev); |
| 524 | } |
| 525 | |
| 526 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 527 | (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 528 | IEEE80211_FCTL_FROMDS && ieee->stadev |
Kris Katterjohn | d3f4a68 | 2006-01-09 16:01:43 -0800 | [diff] [blame] | 529 | && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 530 | /* Frame from BSSID of the AP for which we are a client */ |
| 531 | skb->dev = dev = ieee->stadev; |
| 532 | stats = hostap_get_stats(dev); |
| 533 | from_assoc_ap = 1; |
| 534 | } |
| 535 | #endif |
| 536 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 537 | #ifdef NOT_YET |
| 538 | if ((ieee->iw_mode == IW_MODE_MASTER || |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 539 | ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 540 | switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats, |
| 541 | wds != NULL)) { |
| 542 | case AP_RX_CONTINUE_NOT_AUTHORIZED: |
| 543 | frame_authorized = 0; |
| 544 | break; |
| 545 | case AP_RX_CONTINUE: |
| 546 | frame_authorized = 1; |
| 547 | break; |
| 548 | case AP_RX_DROP: |
| 549 | goto rx_dropped; |
| 550 | case AP_RX_EXIT: |
| 551 | goto rx_exit; |
| 552 | } |
| 553 | } |
| 554 | #endif |
| 555 | |
| 556 | /* Nullfunc frames may have PS-bit set, so they must be passed to |
| 557 | * hostap_handle_sta_rx() before being dropped here. */ |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 558 | |
| 559 | stype &= ~IEEE80211_STYPE_QOS_DATA; |
| 560 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 561 | if (stype != IEEE80211_STYPE_DATA && |
| 562 | stype != IEEE80211_STYPE_DATA_CFACK && |
| 563 | stype != IEEE80211_STYPE_DATA_CFPOLL && |
| 564 | stype != IEEE80211_STYPE_DATA_CFACKPOLL) { |
| 565 | if (stype != IEEE80211_STYPE_NULLFUNC) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 566 | IEEE80211_DEBUG_DROP("RX: dropped data frame " |
| 567 | "with no data (type=0x%02x, " |
| 568 | "subtype=0x%02x, len=%d)\n", |
| 569 | type, stype, skb->len); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 570 | goto rx_dropped; |
| 571 | } |
| 572 | |
| 573 | /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ |
| 574 | |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 575 | if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted && |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 576 | (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) |
| 577 | goto rx_dropped; |
| 578 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 579 | hdr = (struct ieee80211_hdr_4addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 580 | |
| 581 | /* skb: hdr + (possibly fragmented) plaintext payload */ |
| 582 | // PR: FIXME: hostap has additional conditions in the "if" below: |
Jiri Benc | f13baae | 2005-08-25 20:11:46 -0400 | [diff] [blame] | 583 | // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
Denis Vlasenko | 9eafe76 | 2006-01-22 13:57:10 +0200 | [diff] [blame] | 584 | if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 585 | int flen; |
| 586 | struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr); |
| 587 | IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag); |
| 588 | |
| 589 | if (!frag_skb) { |
| 590 | IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG, |
| 591 | "Rx cannot get skb from fragment " |
| 592 | "cache (morefrag=%d seq=%u frag=%u)\n", |
| 593 | (fc & IEEE80211_FCTL_MOREFRAGS) != 0, |
| 594 | WLAN_GET_SEQ_SEQ(sc), frag); |
| 595 | goto rx_dropped; |
| 596 | } |
| 597 | |
| 598 | flen = skb->len; |
| 599 | if (frag != 0) |
| 600 | flen -= hdrlen; |
| 601 | |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 602 | if (frag_skb->tail + flen > frag_skb->end) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 603 | printk(KERN_WARNING "%s: host decrypted and " |
| 604 | "reassembled frame did not fit skb\n", |
| 605 | dev->name); |
| 606 | ieee80211_frag_cache_invalidate(ieee, hdr); |
| 607 | goto rx_dropped; |
| 608 | } |
| 609 | |
| 610 | if (frag == 0) { |
| 611 | /* copy first fragment (including full headers) into |
| 612 | * beginning of the fragment cache skb */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 613 | skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 614 | } else { |
| 615 | /* append frame payload to the end of the fragment |
| 616 | * cache skb */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 617 | skb_copy_from_linear_data_offset(skb, hdrlen, |
| 618 | skb_put(frag_skb, flen), flen); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 619 | } |
| 620 | dev_kfree_skb_any(skb); |
| 621 | skb = NULL; |
| 622 | |
| 623 | if (fc & IEEE80211_FCTL_MOREFRAGS) { |
| 624 | /* more fragments expected - leave the skb in fragment |
| 625 | * cache for now; it will be delivered to upper layers |
| 626 | * after all fragments have been received */ |
| 627 | goto rx_exit; |
| 628 | } |
| 629 | |
| 630 | /* this was the last fragment and the frame will be |
| 631 | * delivered, so remove skb from fragment cache */ |
| 632 | skb = frag_skb; |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 633 | hdr = (struct ieee80211_hdr_4addr *)skb->data; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 634 | ieee80211_frag_cache_invalidate(ieee, hdr); |
| 635 | } |
| 636 | |
| 637 | /* skb: hdr + (possible reassembled) full MSDU payload; possibly still |
| 638 | * encrypted/authenticated */ |
Zhu Yi | b6daa25 | 2006-01-19 16:20:42 +0800 | [diff] [blame] | 639 | if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted && |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 640 | ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) |
| 641 | goto rx_dropped; |
| 642 | |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 643 | hdr = (struct ieee80211_hdr_4addr *)skb->data; |
Jiri Benc | f13baae | 2005-08-25 20:11:46 -0400 | [diff] [blame] | 644 | if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 645 | if ( /*ieee->ieee802_1x && */ |
| 646 | ieee80211_is_eapol_frame(ieee, skb)) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 647 | /* pass unencrypted EAPOL frames even if encryption is |
| 648 | * configured */ |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 649 | } else { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 650 | IEEE80211_DEBUG_DROP("encryption configured, but RX " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 651 | "frame not encrypted (SA=%pM)\n", |
| 652 | hdr->addr2); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 653 | goto rx_dropped; |
| 654 | } |
| 655 | } |
| 656 | |
Jiri Benc | f13baae | 2005-08-25 20:11:46 -0400 | [diff] [blame] | 657 | if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep && |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 658 | !ieee80211_is_eapol_frame(ieee, skb)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 659 | IEEE80211_DEBUG_DROP("dropped unencrypted RX data " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 660 | "frame from %pM (drop_unencrypted=1)\n", |
| 661 | hdr->addr2); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 662 | goto rx_dropped; |
| 663 | } |
| 664 | |
Daniel Drake | c9308b0 | 2006-09-27 03:50:31 +0100 | [diff] [blame] | 665 | /* If the frame was decrypted in hardware, we may need to strip off |
| 666 | * any security data (IV, ICV, etc) that was left behind */ |
| 667 | if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) && |
| 668 | ieee->host_strip_iv_icv) { |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 669 | int trimlen = 0; |
Daniel Drake | c9308b0 | 2006-09-27 03:50:31 +0100 | [diff] [blame] | 670 | |
| 671 | /* Top two-bits of byte 3 are the key index */ |
| 672 | if (skb->len >= hdrlen + 3) |
| 673 | keyidx = skb->data[hdrlen + 3] >> 6; |
| 674 | |
| 675 | /* To strip off any security data which appears before the |
| 676 | * payload, we simply increase hdrlen (as the header gets |
| 677 | * chopped off immediately below). For the security data which |
| 678 | * appears after the payload, we use skb_trim. */ |
| 679 | |
| 680 | switch (ieee->sec.encode_alg[keyidx]) { |
| 681 | case SEC_ALG_WEP: |
| 682 | /* 4 byte IV */ |
| 683 | hdrlen += 4; |
| 684 | /* 4 byte ICV */ |
| 685 | trimlen = 4; |
| 686 | break; |
| 687 | case SEC_ALG_TKIP: |
| 688 | /* 4 byte IV, 4 byte ExtIV */ |
| 689 | hdrlen += 8; |
| 690 | /* 8 byte MIC, 4 byte ICV */ |
| 691 | trimlen = 12; |
| 692 | break; |
| 693 | case SEC_ALG_CCMP: |
| 694 | /* 8 byte CCMP header */ |
| 695 | hdrlen += 8; |
| 696 | /* 8 byte MIC */ |
| 697 | trimlen = 8; |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | if (skb->len < trimlen) |
| 702 | goto rx_dropped; |
| 703 | |
| 704 | __skb_trim(skb, skb->len - trimlen); |
| 705 | |
| 706 | if (skb->len < hdrlen) |
| 707 | goto rx_dropped; |
| 708 | } |
| 709 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 710 | /* skb: hdr + (possible reassembled) full plaintext payload */ |
| 711 | |
| 712 | payload = skb->data + hdrlen; |
| 713 | ethertype = (payload[6] << 8) | payload[7]; |
| 714 | |
| 715 | #ifdef NOT_YET |
| 716 | /* If IEEE 802.1X is used, check whether the port is authorized to send |
| 717 | * the received frame. */ |
| 718 | if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) { |
| 719 | if (ethertype == ETH_P_PAE) { |
| 720 | printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n", |
| 721 | dev->name); |
| 722 | if (ieee->hostapd && ieee->apdev) { |
| 723 | /* Send IEEE 802.1X frames to the user |
| 724 | * space daemon for processing */ |
| 725 | prism2_rx_80211(ieee->apdev, skb, rx_stats, |
| 726 | PRISM2_RX_MGMT); |
| 727 | ieee->apdevstats.rx_packets++; |
| 728 | ieee->apdevstats.rx_bytes += skb->len; |
| 729 | goto rx_exit; |
| 730 | } |
| 731 | } else if (!frame_authorized) { |
| 732 | printk(KERN_DEBUG "%s: dropped frame from " |
| 733 | "unauthorized port (IEEE 802.1X): " |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 734 | "ethertype=0x%04x\n", dev->name, ethertype); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 735 | goto rx_dropped; |
| 736 | } |
| 737 | } |
| 738 | #endif |
| 739 | |
| 740 | /* convert hdr + possible LLC headers into Ethernet header */ |
| 741 | if (skb->len - hdrlen >= 8 && |
| 742 | ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 && |
| 743 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 744 | memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) { |
| 745 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 746 | * replace EtherType */ |
| 747 | skb_pull(skb, hdrlen + SNAP_SIZE); |
| 748 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 749 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 750 | } else { |
Al Viro | d9e94d5 | 2007-12-29 05:01:07 -0500 | [diff] [blame] | 751 | __be16 len; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 752 | /* Leave Ethernet header part of hdr and full payload */ |
| 753 | skb_pull(skb, hdrlen); |
| 754 | len = htons(skb->len); |
| 755 | memcpy(skb_push(skb, 2), &len, 2); |
| 756 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 757 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 758 | } |
| 759 | |
| 760 | #ifdef NOT_YET |
| 761 | if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 762 | IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 763 | /* Non-standard frame: get addr4 from its bogus location after |
| 764 | * the payload */ |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 765 | skb_copy_to_linear_data_offset(skb, ETH_ALEN, |
| 766 | skb->data + skb->len - ETH_ALEN, |
| 767 | ETH_ALEN); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 768 | skb_trim(skb, skb->len - ETH_ALEN); |
| 769 | } |
| 770 | #endif |
| 771 | |
| 772 | stats->rx_packets++; |
| 773 | stats->rx_bytes += skb->len; |
| 774 | |
| 775 | #ifdef NOT_YET |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 776 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 777 | if (dst[0] & 0x01) { |
| 778 | /* copy multicast frame both to the higher layers and |
| 779 | * to the wireless media */ |
| 780 | ieee->ap->bridged_multicast++; |
| 781 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 782 | if (skb2 == NULL) |
| 783 | printk(KERN_DEBUG "%s: skb_clone failed for " |
| 784 | "multicast frame\n", dev->name); |
| 785 | } else if (hostap_is_sta_assoc(ieee->ap, dst)) { |
| 786 | /* send frame directly to the associated STA using |
| 787 | * wireless media and not passing to higher layers */ |
| 788 | ieee->ap->bridged_unicast++; |
| 789 | skb2 = skb; |
| 790 | skb = NULL; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | if (skb2 != NULL) { |
| 795 | /* send to wireless media */ |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 796 | skb2->dev = dev; |
YOSHIFUJI Hideaki | 4e39430 | 2007-12-12 03:52:26 +0900 | [diff] [blame] | 797 | skb2->protocol = htons(ETH_P_802_3); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 798 | skb_reset_mac_header(skb2); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 799 | skb_reset_network_header(skb2); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 800 | /* skb2->network_header += ETH_HLEN; */ |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 801 | dev_queue_xmit(skb2); |
| 802 | } |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 803 | #endif |
| 804 | |
| 805 | if (skb) { |
| 806 | skb->protocol = eth_type_trans(skb, dev); |
| 807 | memset(skb->cb, 0, sizeof(skb->cb)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 808 | skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ |
Zhu Yi | d652923 | 2006-01-19 16:20:49 +0800 | [diff] [blame] | 809 | if (netif_rx(skb) == NET_RX_DROP) { |
| 810 | /* netif_rx always succeeds, but it might drop |
| 811 | * the packet. If it drops the packet, we log that |
| 812 | * in our stats. */ |
| 813 | IEEE80211_DEBUG_DROP |
| 814 | ("RX: netif_rx dropped the packet\n"); |
| 815 | stats->rx_dropped++; |
| 816 | } |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 819 | rx_exit: |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 820 | #ifdef NOT_YET |
| 821 | if (sta) |
| 822 | hostap_handle_sta_release(sta); |
| 823 | #endif |
| 824 | return 1; |
| 825 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 826 | rx_dropped: |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 827 | stats->rx_dropped++; |
| 828 | |
| 829 | /* Returning 0 indicates to caller that we have not handled the SKB-- |
| 830 | * so it is still allocated and can be used again by underlying |
| 831 | * hardware as a DMA target */ |
| 832 | return 0; |
| 833 | } |
| 834 | |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 835 | /* Filter out unrelated packets, call ieee80211_rx[_mgt] |
| 836 | * This function takes over the skb, it should not be used again after calling |
| 837 | * this function. */ |
| 838 | void ieee80211_rx_any(struct ieee80211_device *ieee, |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 839 | struct sk_buff *skb, struct ieee80211_rx_stats *stats) |
| 840 | { |
| 841 | struct ieee80211_hdr_4addr *hdr; |
| 842 | int is_packet_for_us; |
| 843 | u16 fc; |
| 844 | |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 845 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 846 | if (!ieee80211_rx(ieee, skb, stats)) |
| 847 | dev_kfree_skb_irq(skb); |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | if (skb->len < sizeof(struct ieee80211_hdr)) |
| 852 | goto drop_free; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 853 | |
| 854 | hdr = (struct ieee80211_hdr_4addr *)skb->data; |
| 855 | fc = le16_to_cpu(hdr->frame_ctl); |
| 856 | |
| 857 | if ((fc & IEEE80211_FCTL_VERS) != 0) |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 858 | goto drop_free; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 859 | |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 860 | switch (fc & IEEE80211_FCTL_FTYPE) { |
| 861 | case IEEE80211_FTYPE_MGMT: |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 862 | if (skb->len < sizeof(struct ieee80211_hdr_3addr)) |
| 863 | goto drop_free; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 864 | ieee80211_rx_mgt(ieee, hdr, stats); |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 865 | dev_kfree_skb_irq(skb); |
| 866 | return; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 867 | case IEEE80211_FTYPE_DATA: |
| 868 | break; |
| 869 | case IEEE80211_FTYPE_CTL: |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 870 | return; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 871 | default: |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 872 | return; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | is_packet_for_us = 0; |
| 876 | switch (ieee->iw_mode) { |
| 877 | case IW_MODE_ADHOC: |
| 878 | /* our BSS and not from/to DS */ |
| 879 | if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0) |
| 880 | if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) { |
| 881 | /* promisc: get all */ |
| 882 | if (ieee->dev->flags & IFF_PROMISC) |
| 883 | is_packet_for_us = 1; |
| 884 | /* to us */ |
| 885 | else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0) |
| 886 | is_packet_for_us = 1; |
| 887 | /* mcast */ |
| 888 | else if (is_multicast_ether_addr(hdr->addr1)) |
| 889 | is_packet_for_us = 1; |
| 890 | } |
| 891 | break; |
| 892 | case IW_MODE_INFRA: |
| 893 | /* our BSS (== from our AP) and from DS */ |
| 894 | if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0) |
| 895 | if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) { |
| 896 | /* promisc: get all */ |
| 897 | if (ieee->dev->flags & IFF_PROMISC) |
| 898 | is_packet_for_us = 1; |
| 899 | /* to us */ |
| 900 | else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0) |
| 901 | is_packet_for_us = 1; |
| 902 | /* mcast */ |
| 903 | else if (is_multicast_ether_addr(hdr->addr1)) { |
| 904 | /* not our own packet bcasted from AP */ |
| 905 | if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN)) |
| 906 | is_packet_for_us = 1; |
| 907 | } |
| 908 | } |
| 909 | break; |
| 910 | default: |
| 911 | /* ? */ |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | if (is_packet_for_us) |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 916 | if (!ieee80211_rx(ieee, skb, stats)) |
| 917 | dev_kfree_skb_irq(skb); |
| 918 | return; |
| 919 | |
| 920 | drop_free: |
| 921 | dev_kfree_skb_irq(skb); |
| 922 | ieee->stats.rx_dropped++; |
| 923 | return; |
Denis Vlasenko | 1a995b45 | 2006-01-24 16:57:11 +0200 | [diff] [blame] | 924 | } |
| 925 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 926 | #define MGMT_FRAME_FIXED_PART_LENGTH 0x24 |
| 927 | |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 928 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 929 | |
| 930 | /* |
| 931 | * Make ther structure we read from the beacon packet has |
| 932 | * the right values |
| 933 | */ |
| 934 | static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element |
| 935 | *info_element, int sub_type) |
| 936 | { |
| 937 | |
| 938 | if (info_element->qui_subtype != sub_type) |
| 939 | return -1; |
| 940 | if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) |
| 941 | return -1; |
| 942 | if (info_element->qui_type != QOS_OUI_TYPE) |
| 943 | return -1; |
| 944 | if (info_element->version != QOS_VERSION_1) |
| 945 | return -1; |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | /* |
| 951 | * Parse a QoS parameter element |
| 952 | */ |
| 953 | static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info |
| 954 | *element_param, struct ieee80211_info_element |
| 955 | *info_element) |
| 956 | { |
| 957 | int ret = 0; |
| 958 | u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; |
| 959 | |
| 960 | if ((info_element == NULL) || (element_param == NULL)) |
| 961 | return -1; |
| 962 | |
| 963 | if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { |
| 964 | memcpy(element_param->info_element.qui, info_element->data, |
| 965 | info_element->len); |
| 966 | element_param->info_element.elementID = info_element->id; |
| 967 | element_param->info_element.length = info_element->len; |
| 968 | } else |
| 969 | ret = -1; |
| 970 | if (ret == 0) |
| 971 | ret = ieee80211_verify_qos_info(&element_param->info_element, |
| 972 | QOS_OUI_PARAM_SUB_TYPE); |
| 973 | return ret; |
| 974 | } |
| 975 | |
| 976 | /* |
| 977 | * Parse a QoS information element |
| 978 | */ |
| 979 | static int ieee80211_read_qos_info_element(struct |
| 980 | ieee80211_qos_information_element |
| 981 | *element_info, struct ieee80211_info_element |
| 982 | *info_element) |
| 983 | { |
| 984 | int ret = 0; |
| 985 | u16 size = sizeof(struct ieee80211_qos_information_element) - 2; |
| 986 | |
| 987 | if (element_info == NULL) |
| 988 | return -1; |
| 989 | if (info_element == NULL) |
| 990 | return -1; |
| 991 | |
| 992 | if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { |
| 993 | memcpy(element_info->qui, info_element->data, |
| 994 | info_element->len); |
| 995 | element_info->elementID = info_element->id; |
| 996 | element_info->length = info_element->len; |
| 997 | } else |
| 998 | ret = -1; |
| 999 | |
| 1000 | if (ret == 0) |
| 1001 | ret = ieee80211_verify_qos_info(element_info, |
| 1002 | QOS_OUI_INFO_SUB_TYPE); |
| 1003 | return ret; |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * Write QoS parameters from the ac parameters. |
| 1008 | */ |
| 1009 | static int ieee80211_qos_convert_ac_to_parameters(struct |
| 1010 | ieee80211_qos_parameter_info |
| 1011 | *param_elm, struct |
| 1012 | ieee80211_qos_parameters |
| 1013 | *qos_param) |
| 1014 | { |
| 1015 | int rc = 0; |
| 1016 | int i; |
| 1017 | struct ieee80211_qos_ac_parameter *ac_params; |
| 1018 | u32 txop; |
| 1019 | u8 cw_min; |
| 1020 | u8 cw_max; |
| 1021 | |
| 1022 | for (i = 0; i < QOS_QUEUE_NUM; i++) { |
| 1023 | ac_params = &(param_elm->ac_params_record[i]); |
| 1024 | |
| 1025 | qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F; |
| 1026 | qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2; |
| 1027 | |
| 1028 | cw_min = ac_params->ecw_min_max & 0x0F; |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 1029 | qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1030 | |
| 1031 | cw_max = (ac_params->ecw_min_max & 0xF0) >> 4; |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 1032 | qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1033 | |
| 1034 | qos_param->flag[i] = |
| 1035 | (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; |
| 1036 | |
| 1037 | txop = le16_to_cpu(ac_params->tx_op_limit) * 32; |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 1038 | qos_param->tx_op_limit[i] = cpu_to_le16(txop); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1039 | } |
| 1040 | return rc; |
| 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * we have a generic data element which it may contain QoS information or |
| 1045 | * parameters element. check the information element length to decide |
| 1046 | * which type to read |
| 1047 | */ |
| 1048 | static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element |
| 1049 | *info_element, |
| 1050 | struct ieee80211_network *network) |
| 1051 | { |
| 1052 | int rc = 0; |
| 1053 | struct ieee80211_qos_parameters *qos_param = NULL; |
| 1054 | struct ieee80211_qos_information_element qos_info_element; |
| 1055 | |
| 1056 | rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); |
| 1057 | |
| 1058 | if (rc == 0) { |
| 1059 | network->qos_data.param_count = qos_info_element.ac_info & 0x0F; |
| 1060 | network->flags |= NETWORK_HAS_QOS_INFORMATION; |
| 1061 | } else { |
| 1062 | struct ieee80211_qos_parameter_info param_element; |
| 1063 | |
| 1064 | rc = ieee80211_read_qos_param_element(¶m_element, |
| 1065 | info_element); |
| 1066 | if (rc == 0) { |
| 1067 | qos_param = &(network->qos_data.parameters); |
| 1068 | ieee80211_qos_convert_ac_to_parameters(¶m_element, |
| 1069 | qos_param); |
| 1070 | network->flags |= NETWORK_HAS_QOS_PARAMETERS; |
| 1071 | network->qos_data.param_count = |
| 1072 | param_element.info_element.ac_info & 0x0F; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | if (rc == 0) { |
| 1077 | IEEE80211_DEBUG_QOS("QoS is supported\n"); |
| 1078 | network->qos_data.supported = 1; |
| 1079 | } |
| 1080 | return rc; |
| 1081 | } |
| 1082 | |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1083 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1084 | #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x |
| 1085 | |
| 1086 | static const char *get_info_element_string(u16 id) |
| 1087 | { |
| 1088 | switch (id) { |
| 1089 | MFIE_STRING(SSID); |
| 1090 | MFIE_STRING(RATES); |
| 1091 | MFIE_STRING(FH_SET); |
| 1092 | MFIE_STRING(DS_SET); |
| 1093 | MFIE_STRING(CF_SET); |
| 1094 | MFIE_STRING(TIM); |
| 1095 | MFIE_STRING(IBSS_SET); |
| 1096 | MFIE_STRING(COUNTRY); |
| 1097 | MFIE_STRING(HOP_PARAMS); |
| 1098 | MFIE_STRING(HOP_TABLE); |
| 1099 | MFIE_STRING(REQUEST); |
| 1100 | MFIE_STRING(CHALLENGE); |
| 1101 | MFIE_STRING(POWER_CONSTRAINT); |
| 1102 | MFIE_STRING(POWER_CAPABILITY); |
| 1103 | MFIE_STRING(TPC_REQUEST); |
| 1104 | MFIE_STRING(TPC_REPORT); |
| 1105 | MFIE_STRING(SUPP_CHANNELS); |
| 1106 | MFIE_STRING(CSA); |
| 1107 | MFIE_STRING(MEASURE_REQUEST); |
| 1108 | MFIE_STRING(MEASURE_REPORT); |
| 1109 | MFIE_STRING(QUIET); |
| 1110 | MFIE_STRING(IBSS_DFS); |
| 1111 | MFIE_STRING(ERP_INFO); |
| 1112 | MFIE_STRING(RSN); |
| 1113 | MFIE_STRING(RATES_EX); |
| 1114 | MFIE_STRING(GENERIC); |
| 1115 | MFIE_STRING(QOS_PARAMETER); |
| 1116 | default: |
| 1117 | return "UNKNOWN"; |
| 1118 | } |
| 1119 | } |
| 1120 | #endif |
| 1121 | |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1122 | static int ieee80211_parse_info_param(struct ieee80211_info_element |
| 1123 | *info_element, u16 length, |
| 1124 | struct ieee80211_network *network) |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1125 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1126 | DECLARE_SSID_BUF(ssid); |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1127 | u8 i; |
| 1128 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1129 | char rates_str[64]; |
| 1130 | char *p; |
| 1131 | #endif |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1132 | |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1133 | while (length >= sizeof(*info_element)) { |
| 1134 | if (sizeof(*info_element) + info_element->len > length) { |
Jiri Benc | aec41a0 | 2006-10-18 19:34:40 +0200 | [diff] [blame] | 1135 | IEEE80211_DEBUG_MGMT("Info elem: parse failed: " |
| 1136 | "info_element->len + 2 > left : " |
| 1137 | "info_element->len+2=%zd left=%d, id=%d.\n", |
| 1138 | info_element->len + |
| 1139 | sizeof(*info_element), |
| 1140 | length, info_element->id); |
Zhu Yi | f09fc44 | 2006-08-21 11:34:19 +0800 | [diff] [blame] | 1141 | /* We stop processing but don't return an error here |
| 1142 | * because some misbehaviour APs break this rule. ie. |
| 1143 | * Orinoco AP1000. */ |
| 1144 | break; |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | switch (info_element->id) { |
| 1148 | case MFIE_TYPE_SSID: |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1149 | network->ssid_len = min(info_element->len, |
| 1150 | (u8) IW_ESSID_MAX_SIZE); |
| 1151 | memcpy(network->ssid, info_element->data, |
| 1152 | network->ssid_len); |
| 1153 | if (network->ssid_len < IW_ESSID_MAX_SIZE) |
| 1154 | memset(network->ssid + network->ssid_len, 0, |
| 1155 | IW_ESSID_MAX_SIZE - network->ssid_len); |
| 1156 | |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1157 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1158 | print_ssid(ssid, network->ssid, |
| 1159 | network->ssid_len), |
John W. Linville | c5d3dce | 2008-09-30 17:17:26 -0400 | [diff] [blame] | 1160 | network->ssid_len); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1161 | break; |
| 1162 | |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1163 | case MFIE_TYPE_RATES: |
| 1164 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1165 | p = rates_str; |
| 1166 | #endif |
| 1167 | network->rates_len = min(info_element->len, |
| 1168 | MAX_RATES_LENGTH); |
| 1169 | for (i = 0; i < network->rates_len; i++) { |
| 1170 | network->rates[i] = info_element->data[i]; |
| 1171 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1172 | p += snprintf(p, sizeof(rates_str) - |
| 1173 | (p - rates_str), "%02X ", |
| 1174 | network->rates[i]); |
| 1175 | #endif |
| 1176 | if (ieee80211_is_ofdm_rate |
| 1177 | (info_element->data[i])) { |
| 1178 | network->flags |= NETWORK_HAS_OFDM; |
| 1179 | if (info_element->data[i] & |
| 1180 | IEEE80211_BASIC_RATE_MASK) |
| 1181 | network->flags &= |
| 1182 | ~NETWORK_HAS_CCK; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n", |
| 1187 | rates_str, network->rates_len); |
| 1188 | break; |
| 1189 | |
| 1190 | case MFIE_TYPE_RATES_EX: |
| 1191 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1192 | p = rates_str; |
| 1193 | #endif |
| 1194 | network->rates_ex_len = min(info_element->len, |
| 1195 | MAX_RATES_EX_LENGTH); |
| 1196 | for (i = 0; i < network->rates_ex_len; i++) { |
| 1197 | network->rates_ex[i] = info_element->data[i]; |
| 1198 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1199 | p += snprintf(p, sizeof(rates_str) - |
| 1200 | (p - rates_str), "%02X ", |
| 1201 | network->rates[i]); |
| 1202 | #endif |
| 1203 | if (ieee80211_is_ofdm_rate |
| 1204 | (info_element->data[i])) { |
| 1205 | network->flags |= NETWORK_HAS_OFDM; |
| 1206 | if (info_element->data[i] & |
| 1207 | IEEE80211_BASIC_RATE_MASK) |
| 1208 | network->flags &= |
| 1209 | ~NETWORK_HAS_CCK; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n", |
| 1214 | rates_str, network->rates_ex_len); |
| 1215 | break; |
| 1216 | |
| 1217 | case MFIE_TYPE_DS_SET: |
| 1218 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n", |
| 1219 | info_element->data[0]); |
| 1220 | network->channel = info_element->data[0]; |
| 1221 | break; |
| 1222 | |
| 1223 | case MFIE_TYPE_FH_SET: |
| 1224 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n"); |
| 1225 | break; |
| 1226 | |
| 1227 | case MFIE_TYPE_CF_SET: |
| 1228 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n"); |
| 1229 | break; |
| 1230 | |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1231 | case MFIE_TYPE_TIM: |
Zhu Yi | 41a25c6 | 2006-01-19 16:22:23 +0800 | [diff] [blame] | 1232 | network->tim.tim_count = info_element->data[0]; |
| 1233 | network->tim.tim_period = info_element->data[1]; |
| 1234 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1235 | break; |
| 1236 | |
| 1237 | case MFIE_TYPE_ERP_INFO: |
| 1238 | network->erp_value = info_element->data[0]; |
Daniel Drake | d8e2be9 | 2006-07-18 21:30:34 +0100 | [diff] [blame] | 1239 | network->flags |= NETWORK_HAS_ERP_VALUE; |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1240 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n", |
| 1241 | network->erp_value); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1242 | break; |
| 1243 | |
| 1244 | case MFIE_TYPE_IBSS_SET: |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1245 | network->atim_window = info_element->data[0]; |
| 1246 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n", |
| 1247 | network->atim_window); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1248 | break; |
| 1249 | |
| 1250 | case MFIE_TYPE_CHALLENGE: |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1251 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n"); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1252 | break; |
| 1253 | |
| 1254 | case MFIE_TYPE_GENERIC: |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1255 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n", |
| 1256 | info_element->len); |
| 1257 | if (!ieee80211_parse_qos_info_param_IE(info_element, |
| 1258 | network)) |
| 1259 | break; |
| 1260 | |
| 1261 | if (info_element->len >= 4 && |
| 1262 | info_element->data[0] == 0x00 && |
| 1263 | info_element->data[1] == 0x50 && |
| 1264 | info_element->data[2] == 0xf2 && |
| 1265 | info_element->data[3] == 0x01) { |
| 1266 | network->wpa_ie_len = min(info_element->len + 2, |
| 1267 | MAX_WPA_IE_LEN); |
| 1268 | memcpy(network->wpa_ie, info_element, |
| 1269 | network->wpa_ie_len); |
| 1270 | } |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1271 | break; |
| 1272 | |
| 1273 | case MFIE_TYPE_RSN: |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1274 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n", |
| 1275 | info_element->len); |
| 1276 | network->rsn_ie_len = min(info_element->len + 2, |
| 1277 | MAX_WPA_IE_LEN); |
| 1278 | memcpy(network->rsn_ie, info_element, |
| 1279 | network->rsn_ie_len); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1280 | break; |
| 1281 | |
| 1282 | case MFIE_TYPE_QOS_PARAMETER: |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1283 | printk(KERN_ERR |
| 1284 | "QoS Error need to parse QOS_PARAMETER IE\n"); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1285 | break; |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1286 | /* 802.11h */ |
| 1287 | case MFIE_TYPE_POWER_CONSTRAINT: |
| 1288 | network->power_constraint = info_element->data[0]; |
| 1289 | network->flags |= NETWORK_HAS_POWER_CONSTRAINT; |
| 1290 | break; |
| 1291 | |
| 1292 | case MFIE_TYPE_CSA: |
| 1293 | network->power_constraint = info_element->data[0]; |
| 1294 | network->flags |= NETWORK_HAS_CSA; |
| 1295 | break; |
| 1296 | |
| 1297 | case MFIE_TYPE_QUIET: |
| 1298 | network->quiet.count = info_element->data[0]; |
| 1299 | network->quiet.period = info_element->data[1]; |
| 1300 | network->quiet.duration = info_element->data[2]; |
| 1301 | network->quiet.offset = info_element->data[3]; |
| 1302 | network->flags |= NETWORK_HAS_QUIET; |
| 1303 | break; |
| 1304 | |
| 1305 | case MFIE_TYPE_IBSS_DFS: |
| 1306 | if (network->ibss_dfs) |
| 1307 | break; |
Arnaldo Carvalho de Melo | 571d6ee | 2006-11-21 01:26:49 -0200 | [diff] [blame] | 1308 | network->ibss_dfs = kmemdup(info_element->data, |
| 1309 | info_element->len, |
| 1310 | GFP_ATOMIC); |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1311 | if (!network->ibss_dfs) |
| 1312 | return 1; |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1313 | network->flags |= NETWORK_HAS_IBSS_DFS; |
| 1314 | break; |
| 1315 | |
| 1316 | case MFIE_TYPE_TPC_REPORT: |
| 1317 | network->tpc_report.transmit_power = |
| 1318 | info_element->data[0]; |
| 1319 | network->tpc_report.link_margin = info_element->data[1]; |
| 1320 | network->flags |= NETWORK_HAS_TPC_REPORT; |
| 1321 | break; |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1322 | |
| 1323 | default: |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1324 | IEEE80211_DEBUG_MGMT |
| 1325 | ("Unsupported info element: %s (%d)\n", |
| 1326 | get_info_element_string(info_element->id), |
| 1327 | info_element->id); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1328 | break; |
| 1329 | } |
| 1330 | |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1331 | length -= sizeof(*info_element) + info_element->len; |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1332 | info_element = |
| 1333 | (struct ieee80211_info_element *)&info_element-> |
| 1334 | data[info_element->len]; |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1335 | } |
| 1336 | |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response |
| 1341 | *frame, struct ieee80211_rx_stats *stats) |
| 1342 | { |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1343 | struct ieee80211_network network_resp = { |
| 1344 | .ibss_dfs = NULL, |
| 1345 | }; |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1346 | struct ieee80211_network *network = &network_resp; |
| 1347 | struct net_device *dev = ieee->dev; |
| 1348 | |
| 1349 | network->flags = 0; |
| 1350 | network->qos_data.active = 0; |
| 1351 | network->qos_data.supported = 0; |
| 1352 | network->qos_data.param_count = 0; |
| 1353 | network->qos_data.old_param_count = 0; |
| 1354 | |
| 1355 | //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF); |
| 1356 | network->atim_window = le16_to_cpu(frame->aid); |
| 1357 | network->listen_interval = le16_to_cpu(frame->status); |
Ivo van Doorn | c1bda44 | 2005-10-03 10:20:47 -0500 | [diff] [blame] | 1358 | memcpy(network->bssid, frame->header.addr3, ETH_ALEN); |
| 1359 | network->capability = le16_to_cpu(frame->capability); |
| 1360 | network->last_scanned = jiffies; |
| 1361 | network->rates_len = network->rates_ex_len = 0; |
| 1362 | network->last_associate = 0; |
| 1363 | network->ssid_len = 0; |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1364 | network->erp_value = |
| 1365 | (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0; |
Ivo van Doorn | c1bda44 | 2005-10-03 10:20:47 -0500 | [diff] [blame] | 1366 | |
| 1367 | if (stats->freq == IEEE80211_52GHZ_BAND) { |
| 1368 | /* for A band (No DS info) */ |
| 1369 | network->channel = stats->received_channel; |
| 1370 | } else |
| 1371 | network->flags |= NETWORK_HAS_CCK; |
| 1372 | |
| 1373 | network->wpa_ie_len = 0; |
| 1374 | network->rsn_ie_len = 0; |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1375 | |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1376 | if (ieee80211_parse_info_param |
| 1377 | (frame->info_element, stats->len - sizeof(*frame), network)) |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1378 | return 1; |
| 1379 | |
Ivo van Doorn | c1bda44 | 2005-10-03 10:20:47 -0500 | [diff] [blame] | 1380 | network->mode = 0; |
| 1381 | if (stats->freq == IEEE80211_52GHZ_BAND) |
| 1382 | network->mode = IEEE_A; |
| 1383 | else { |
| 1384 | if (network->flags & NETWORK_HAS_OFDM) |
| 1385 | network->mode |= IEEE_G; |
| 1386 | if (network->flags & NETWORK_HAS_CCK) |
| 1387 | network->mode |= IEEE_B; |
| 1388 | } |
| 1389 | |
Ivo van Doorn | c1bda44 | 2005-10-03 10:20:47 -0500 | [diff] [blame] | 1390 | memcpy(&network->stats, stats, sizeof(network->stats)); |
| 1391 | |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1392 | if (ieee->handle_assoc_response != NULL) |
| 1393 | ieee->handle_assoc_response(dev, frame, network); |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | /***************************************************/ |
| 1399 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1400 | static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1401 | *beacon, |
| 1402 | struct ieee80211_network *network, |
| 1403 | struct ieee80211_rx_stats *stats) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1404 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1405 | DECLARE_SSID_BUF(ssid); |
| 1406 | |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1407 | network->qos_data.active = 0; |
| 1408 | network->qos_data.supported = 0; |
| 1409 | network->qos_data.param_count = 0; |
Ivo van Doorn | c1bda44 | 2005-10-03 10:20:47 -0500 | [diff] [blame] | 1410 | network->qos_data.old_param_count = 0; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1411 | |
| 1412 | /* Pull out fixed field data */ |
| 1413 | memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1414 | network->capability = le16_to_cpu(beacon->capability); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1415 | network->last_scanned = jiffies; |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1416 | network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]); |
| 1417 | network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]); |
| 1418 | network->beacon_interval = le16_to_cpu(beacon->beacon_interval); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1419 | /* Where to pull this? beacon->listen_interval; */ |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1420 | network->listen_interval = 0x0A; |
| 1421 | network->rates_len = network->rates_ex_len = 0; |
| 1422 | network->last_associate = 0; |
| 1423 | network->ssid_len = 0; |
| 1424 | network->flags = 0; |
| 1425 | network->atim_window = 0; |
James Ketrenos | 42c94e4 | 2005-09-21 11:58:29 -0500 | [diff] [blame] | 1426 | network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ? |
James Ketrenos | ccd0fda | 2005-09-21 11:58:32 -0500 | [diff] [blame] | 1427 | 0x3 : 0x0; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1428 | |
| 1429 | if (stats->freq == IEEE80211_52GHZ_BAND) { |
| 1430 | /* for A band (No DS info) */ |
| 1431 | network->channel = stats->received_channel; |
| 1432 | } else |
| 1433 | network->flags |= NETWORK_HAS_CCK; |
| 1434 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1435 | network->wpa_ie_len = 0; |
| 1436 | network->rsn_ie_len = 0; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1437 | |
James Ketrenos | ff0037b | 2005-10-03 10:23:42 -0500 | [diff] [blame] | 1438 | if (ieee80211_parse_info_param |
| 1439 | (beacon->info_element, stats->len - sizeof(*beacon), network)) |
Ivo van Doorn | ff9e00f | 2005-10-03 10:19:25 -0500 | [diff] [blame] | 1440 | return 1; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1441 | |
| 1442 | network->mode = 0; |
| 1443 | if (stats->freq == IEEE80211_52GHZ_BAND) |
| 1444 | network->mode = IEEE_A; |
| 1445 | else { |
| 1446 | if (network->flags & NETWORK_HAS_OFDM) |
| 1447 | network->mode |= IEEE_G; |
| 1448 | if (network->flags & NETWORK_HAS_CCK) |
| 1449 | network->mode |= IEEE_B; |
| 1450 | } |
| 1451 | |
| 1452 | if (network->mode == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1453 | IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' " |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1454 | "network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1455 | print_ssid(ssid, network->ssid, |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 1456 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1457 | network->bssid); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1458 | return 1; |
| 1459 | } |
| 1460 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1461 | memcpy(&network->stats, stats, sizeof(network->stats)); |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | static inline int is_same_network(struct ieee80211_network *src, |
| 1467 | struct ieee80211_network *dst) |
| 1468 | { |
| 1469 | /* A network is only a duplicate if the channel, BSSID, and ESSID |
| 1470 | * all match. We treat all <hidden> with the same BSSID and channel |
| 1471 | * as one network */ |
| 1472 | return ((src->ssid_len == dst->ssid_len) && |
| 1473 | (src->channel == dst->channel) && |
Kris Katterjohn | d3f4a68 | 2006-01-09 16:01:43 -0800 | [diff] [blame] | 1474 | !compare_ether_addr(src->bssid, dst->bssid) && |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1475 | !memcmp(src->ssid, dst->ssid, src->ssid_len)); |
| 1476 | } |
| 1477 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1478 | static void update_network(struct ieee80211_network *dst, |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1479 | struct ieee80211_network *src) |
| 1480 | { |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1481 | int qos_active; |
| 1482 | u8 old_param; |
| 1483 | |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1484 | ieee80211_network_reset(dst); |
| 1485 | dst->ibss_dfs = src->ibss_dfs; |
| 1486 | |
James Ketrenos | f44349f | 2006-03-08 13:14:45 -0600 | [diff] [blame] | 1487 | /* We only update the statistics if they were created by receiving |
| 1488 | * the network information on the actual channel the network is on. |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 1489 | * |
James Ketrenos | f44349f | 2006-03-08 13:14:45 -0600 | [diff] [blame] | 1490 | * This keeps beacons received on neighbor channels from bringing |
| 1491 | * down the signal level of an AP. */ |
| 1492 | if (dst->channel == src->stats.received_channel) |
| 1493 | memcpy(&dst->stats, &src->stats, |
| 1494 | sizeof(struct ieee80211_rx_stats)); |
| 1495 | else |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1496 | IEEE80211_DEBUG_SCAN("Network %pM info received " |
| 1497 | "off channel (%d vs. %d)\n", src->bssid, |
James Ketrenos | f44349f | 2006-03-08 13:14:45 -0600 | [diff] [blame] | 1498 | dst->channel, src->stats.received_channel); |
| 1499 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1500 | dst->capability = src->capability; |
| 1501 | memcpy(dst->rates, src->rates, src->rates_len); |
| 1502 | dst->rates_len = src->rates_len; |
| 1503 | memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); |
| 1504 | dst->rates_ex_len = src->rates_ex_len; |
| 1505 | |
| 1506 | dst->mode = src->mode; |
| 1507 | dst->flags = src->flags; |
| 1508 | dst->time_stamp[0] = src->time_stamp[0]; |
| 1509 | dst->time_stamp[1] = src->time_stamp[1]; |
| 1510 | |
| 1511 | dst->beacon_interval = src->beacon_interval; |
| 1512 | dst->listen_interval = src->listen_interval; |
| 1513 | dst->atim_window = src->atim_window; |
James Ketrenos | 42c94e4 | 2005-09-21 11:58:29 -0500 | [diff] [blame] | 1514 | dst->erp_value = src->erp_value; |
Zhu Yi | 41a25c6 | 2006-01-19 16:22:23 +0800 | [diff] [blame] | 1515 | dst->tim = src->tim; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1516 | |
| 1517 | memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len); |
| 1518 | dst->wpa_ie_len = src->wpa_ie_len; |
| 1519 | memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len); |
| 1520 | dst->rsn_ie_len = src->rsn_ie_len; |
| 1521 | |
| 1522 | dst->last_scanned = jiffies; |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1523 | qos_active = src->qos_data.active; |
| 1524 | old_param = dst->qos_data.old_param_count; |
| 1525 | if (dst->flags & NETWORK_HAS_QOS_MASK) |
| 1526 | memcpy(&dst->qos_data, &src->qos_data, |
| 1527 | sizeof(struct ieee80211_qos_data)); |
| 1528 | else { |
| 1529 | dst->qos_data.supported = src->qos_data.supported; |
| 1530 | dst->qos_data.param_count = src->qos_data.param_count; |
| 1531 | } |
| 1532 | |
| 1533 | if (dst->qos_data.supported == 1) { |
| 1534 | if (dst->ssid_len) |
| 1535 | IEEE80211_DEBUG_QOS |
| 1536 | ("QoS the network %s is QoS supported\n", |
| 1537 | dst->ssid); |
| 1538 | else |
| 1539 | IEEE80211_DEBUG_QOS |
| 1540 | ("QoS the network is QoS supported\n"); |
| 1541 | } |
| 1542 | dst->qos_data.active = qos_active; |
| 1543 | dst->qos_data.old_param_count = old_param; |
| 1544 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1545 | /* dst->last_associate is not overwritten */ |
| 1546 | } |
| 1547 | |
Pete Zaitcev | 4832843 | 2006-02-26 23:43:20 -0800 | [diff] [blame] | 1548 | static inline int is_beacon(__le16 fc) |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1549 | { |
| 1550 | return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON); |
| 1551 | } |
| 1552 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1553 | static void ieee80211_process_probe_response(struct ieee80211_device |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 1554 | *ieee, struct |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1555 | ieee80211_probe_response |
James Ketrenos | 74079fd | 2005-09-13 17:35:21 -0500 | [diff] [blame] | 1556 | *beacon, struct ieee80211_rx_stats |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1557 | *stats) |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1558 | { |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1559 | struct net_device *dev = ieee->dev; |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1560 | struct ieee80211_network network = { |
| 1561 | .ibss_dfs = NULL, |
| 1562 | }; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1563 | struct ieee80211_network *target; |
| 1564 | struct ieee80211_network *oldest = NULL; |
| 1565 | #ifdef CONFIG_IEEE80211_DEBUG |
James Ketrenos | 68e4e03 | 2005-09-13 17:37:22 -0500 | [diff] [blame] | 1566 | struct ieee80211_info_element *info_element = beacon->info_element; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1567 | #endif |
| 1568 | unsigned long flags; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1569 | DECLARE_SSID_BUF(ssid); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1570 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1571 | IEEE80211_DEBUG_SCAN("'%s' (%pM" |
Al Viro | 8524f59 | 2007-12-29 05:03:35 -0500 | [diff] [blame] | 1572 | "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1573 | print_ssid(ssid, info_element->data, info_element->len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1574 | beacon->header.addr3, |
Al Viro | 8524f59 | 2007-12-29 05:03:35 -0500 | [diff] [blame] | 1575 | (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0', |
| 1576 | (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0', |
| 1577 | (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0', |
| 1578 | (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0', |
| 1579 | (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0', |
| 1580 | (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0', |
| 1581 | (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0', |
| 1582 | (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0', |
| 1583 | (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0', |
| 1584 | (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0', |
| 1585 | (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0', |
| 1586 | (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0', |
| 1587 | (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0', |
| 1588 | (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0', |
| 1589 | (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0', |
| 1590 | (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0'); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1591 | |
| 1592 | if (ieee80211_network_init(ieee, beacon, &network, stats)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1593 | IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1594 | print_ssid(ssid, info_element->data, |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 1595 | info_element->len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1596 | beacon->header.addr3, |
Pete Zaitcev | 4832843 | 2006-02-26 23:43:20 -0800 | [diff] [blame] | 1597 | is_beacon(beacon->header.frame_ctl) ? |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1598 | "BEACON" : "PROBE RESPONSE"); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1599 | return; |
| 1600 | } |
| 1601 | |
| 1602 | /* The network parsed correctly -- so now we scan our known networks |
| 1603 | * to see if we can find it in our list. |
| 1604 | * |
| 1605 | * NOTE: This search is definitely not optimized. Once its doing |
| 1606 | * the "right thing" we'll optimize it for efficiency if |
| 1607 | * necessary */ |
| 1608 | |
| 1609 | /* Search for this entry in the list and update it if it is |
| 1610 | * already there. */ |
| 1611 | |
| 1612 | spin_lock_irqsave(&ieee->lock, flags); |
| 1613 | |
| 1614 | list_for_each_entry(target, &ieee->network_list, list) { |
| 1615 | if (is_same_network(target, &network)) |
| 1616 | break; |
| 1617 | |
| 1618 | if ((oldest == NULL) || |
| 1619 | (target->last_scanned < oldest->last_scanned)) |
| 1620 | oldest = target; |
| 1621 | } |
| 1622 | |
| 1623 | /* If we didn't find a match, then get a new network slot to initialize |
| 1624 | * with this beacon's information */ |
| 1625 | if (&target->list == &ieee->network_list) { |
| 1626 | if (list_empty(&ieee->network_free_list)) { |
| 1627 | /* If there are no more slots, expire the oldest */ |
| 1628 | list_del(&oldest->list); |
| 1629 | target = oldest; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1630 | IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from " |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1631 | "network list.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1632 | print_ssid(ssid, target->ssid, |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 1633 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1634 | target->bssid); |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1635 | ieee80211_network_reset(target); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1636 | } else { |
| 1637 | /* Otherwise just pull from the free list */ |
| 1638 | target = list_entry(ieee->network_free_list.next, |
| 1639 | struct ieee80211_network, list); |
| 1640 | list_del(ieee->network_free_list.next); |
| 1641 | } |
| 1642 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1643 | #ifdef CONFIG_IEEE80211_DEBUG |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1644 | IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1645 | print_ssid(ssid, network.ssid, |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 1646 | network.ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1647 | network.bssid, |
Pete Zaitcev | 4832843 | 2006-02-26 23:43:20 -0800 | [diff] [blame] | 1648 | is_beacon(beacon->header.frame_ctl) ? |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1649 | "BEACON" : "PROBE RESPONSE"); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1650 | #endif |
| 1651 | memcpy(target, &network, sizeof(*target)); |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1652 | network.ibss_dfs = NULL; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1653 | list_add_tail(&target->list, &ieee->network_list); |
| 1654 | } else { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1655 | IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1656 | print_ssid(ssid, target->ssid, |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 1657 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1658 | target->bssid, |
Pete Zaitcev | 4832843 | 2006-02-26 23:43:20 -0800 | [diff] [blame] | 1659 | is_beacon(beacon->header.frame_ctl) ? |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1660 | "BEACON" : "PROBE RESPONSE"); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1661 | update_network(target, &network); |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1662 | network.ibss_dfs = NULL; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | spin_unlock_irqrestore(&ieee->lock, flags); |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1666 | |
Pete Zaitcev | 4832843 | 2006-02-26 23:43:20 -0800 | [diff] [blame] | 1667 | if (is_beacon(beacon->header.frame_ctl)) { |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1668 | if (ieee->handle_beacon != NULL) |
Hong Liu | 72df16f | 2006-03-08 10:50:20 +0800 | [diff] [blame] | 1669 | ieee->handle_beacon(dev, beacon, target); |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1670 | } else { |
| 1671 | if (ieee->handle_probe_response != NULL) |
Hong Liu | 72df16f | 2006-03-08 10:50:20 +0800 | [diff] [blame] | 1672 | ieee->handle_probe_response(dev, beacon, target); |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1673 | } |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | void ieee80211_rx_mgt(struct ieee80211_device *ieee, |
James Ketrenos | ee34af3 | 2005-09-21 11:54:36 -0500 | [diff] [blame] | 1677 | struct ieee80211_hdr_4addr *header, |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1678 | struct ieee80211_rx_stats *stats) |
| 1679 | { |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1680 | switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) { |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1681 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1682 | IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n", |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1683 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1684 | (header->frame_ctl))); |
James Ketrenos | 9e8571a | 2005-09-21 11:56:33 -0500 | [diff] [blame] | 1685 | ieee80211_handle_assoc_resp(ieee, |
| 1686 | (struct ieee80211_assoc_response *) |
| 1687 | header, stats); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1688 | break; |
| 1689 | |
| 1690 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1691 | IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n", |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1692 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1693 | (header->frame_ctl))); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1694 | break; |
| 1695 | |
James Ketrenos | 42c94e4 | 2005-09-21 11:58:29 -0500 | [diff] [blame] | 1696 | case IEEE80211_STYPE_PROBE_REQ: |
Larry Finger | 1a1fedf | 2006-01-30 09:42:24 -0600 | [diff] [blame] | 1697 | IEEE80211_DEBUG_MGMT("received auth (%d)\n", |
James Ketrenos | 42c94e4 | 2005-09-21 11:58:29 -0500 | [diff] [blame] | 1698 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1699 | (header->frame_ctl))); |
| 1700 | |
| 1701 | if (ieee->handle_probe_request != NULL) |
| 1702 | ieee->handle_probe_request(ieee->dev, |
| 1703 | (struct |
| 1704 | ieee80211_probe_request *) |
| 1705 | header, stats); |
| 1706 | break; |
| 1707 | |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1708 | case IEEE80211_STYPE_PROBE_RESP: |
| 1709 | IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n", |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1710 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1711 | (header->frame_ctl))); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1712 | IEEE80211_DEBUG_SCAN("Probe response\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1713 | ieee80211_process_probe_response(ieee, |
| 1714 | (struct |
| 1715 | ieee80211_probe_response *) |
| 1716 | header, stats); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1717 | break; |
| 1718 | |
| 1719 | case IEEE80211_STYPE_BEACON: |
| 1720 | IEEE80211_DEBUG_MGMT("received BEACON (%d)\n", |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1721 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1722 | (header->frame_ctl))); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1723 | IEEE80211_DEBUG_SCAN("Beacon\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1724 | ieee80211_process_probe_response(ieee, |
| 1725 | (struct |
| 1726 | ieee80211_probe_response *) |
| 1727 | header, stats); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1728 | break; |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1729 | case IEEE80211_STYPE_AUTH: |
| 1730 | |
Larry Finger | 1a1fedf | 2006-01-30 09:42:24 -0600 | [diff] [blame] | 1731 | IEEE80211_DEBUG_MGMT("received auth (%d)\n", |
James Ketrenos | 3f552bb | 2005-09-21 11:54:47 -0500 | [diff] [blame] | 1732 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1733 | (header->frame_ctl))); |
| 1734 | |
| 1735 | if (ieee->handle_auth != NULL) |
| 1736 | ieee->handle_auth(ieee->dev, |
| 1737 | (struct ieee80211_auth *)header); |
| 1738 | break; |
| 1739 | |
| 1740 | case IEEE80211_STYPE_DISASSOC: |
| 1741 | if (ieee->handle_disassoc != NULL) |
| 1742 | ieee->handle_disassoc(ieee->dev, |
| 1743 | (struct ieee80211_disassoc *) |
| 1744 | header); |
| 1745 | break; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1746 | |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1747 | case IEEE80211_STYPE_ACTION: |
| 1748 | IEEE80211_DEBUG_MGMT("ACTION\n"); |
| 1749 | if (ieee->handle_action) |
| 1750 | ieee->handle_action(ieee->dev, |
| 1751 | (struct ieee80211_action *) |
| 1752 | header, stats); |
| 1753 | break; |
| 1754 | |
Larry Finger | 2f633db | 2006-01-30 23:25:10 -0600 | [diff] [blame] | 1755 | case IEEE80211_STYPE_REASSOC_REQ: |
| 1756 | IEEE80211_DEBUG_MGMT("received reassoc (%d)\n", |
| 1757 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1758 | (header->frame_ctl))); |
| 1759 | |
Zhu Yi | 7736b5b | 2006-04-13 17:17:47 +0800 | [diff] [blame] | 1760 | IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n", |
| 1761 | ieee->dev->name); |
Larry Finger | 2f633db | 2006-01-30 23:25:10 -0600 | [diff] [blame] | 1762 | if (ieee->handle_reassoc_request != NULL) |
| 1763 | ieee->handle_reassoc_request(ieee->dev, |
| 1764 | (struct ieee80211_reassoc_request *) |
| 1765 | header); |
| 1766 | break; |
| 1767 | |
| 1768 | case IEEE80211_STYPE_ASSOC_REQ: |
| 1769 | IEEE80211_DEBUG_MGMT("received assoc (%d)\n", |
| 1770 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1771 | (header->frame_ctl))); |
| 1772 | |
Zhu Yi | 7736b5b | 2006-04-13 17:17:47 +0800 | [diff] [blame] | 1773 | IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n", |
| 1774 | ieee->dev->name); |
Larry Finger | 2f633db | 2006-01-30 23:25:10 -0600 | [diff] [blame] | 1775 | if (ieee->handle_assoc_request != NULL) |
| 1776 | ieee->handle_assoc_request(ieee->dev); |
| 1777 | break; |
| 1778 | |
James Ketrenos | 31b59ea | 2005-09-21 11:58:49 -0500 | [diff] [blame] | 1779 | case IEEE80211_STYPE_DEAUTH: |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1780 | IEEE80211_DEBUG_MGMT("DEAUTH\n"); |
James Ketrenos | 31b59ea | 2005-09-21 11:58:49 -0500 | [diff] [blame] | 1781 | if (ieee->handle_deauth != NULL) |
Zhu Yi | d1b46b0 | 2006-01-19 16:22:15 +0800 | [diff] [blame] | 1782 | ieee->handle_deauth(ieee->dev, |
| 1783 | (struct ieee80211_deauth *) |
James Ketrenos | 31b59ea | 2005-09-21 11:58:49 -0500 | [diff] [blame] | 1784 | header); |
| 1785 | break; |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1786 | default: |
| 1787 | IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n", |
James Ketrenos | fd27817 | 2005-09-13 17:25:51 -0500 | [diff] [blame] | 1788 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1789 | (header->frame_ctl))); |
Zhu Yi | 7736b5b | 2006-04-13 17:17:47 +0800 | [diff] [blame] | 1790 | IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n", |
| 1791 | ieee->dev->name, |
| 1792 | WLAN_FC_GET_STYPE(le16_to_cpu |
| 1793 | (header->frame_ctl))); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1794 | break; |
| 1795 | } |
| 1796 | } |
| 1797 | |
Daniel Drake | f2060f03 | 2006-07-18 21:38:05 +0100 | [diff] [blame] | 1798 | EXPORT_SYMBOL_GPL(ieee80211_rx_any); |
Jeff Garzik | b453872 | 2005-05-12 22:48:20 -0400 | [diff] [blame] | 1799 | EXPORT_SYMBOL(ieee80211_rx_mgt); |
| 1800 | EXPORT_SYMBOL(ieee80211_rx); |