Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [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 |
| 6 | * <jkmaline@cc.hut.fi> |
| 7 | * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 8 | * Copyright (c) 2004, Intel Corporation |
| 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 | Few modifications for Realtek's Wi-Fi drivers by |
Andrea Merello | 559a4c3 | 2013-08-26 13:53:30 +0200 | [diff] [blame] | 17 | Andrea Merello <andrea.merello@gmail.com> |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 18 | |
| 19 | A special thanks goes to Realtek for their support ! |
| 20 | |
| 21 | ******************************************************************************/ |
| 22 | |
| 23 | |
| 24 | #include <linux/compiler.h> |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 25 | #include <linux/errno.h> |
| 26 | #include <linux/if_arp.h> |
| 27 | #include <linux/in6.h> |
| 28 | #include <linux/in.h> |
| 29 | #include <linux/ip.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/proc_fs.h> |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/tcp.h> |
| 38 | #include <linux/types.h> |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 39 | #include <linux/wireless.h> |
| 40 | #include <linux/etherdevice.h> |
Dilek Uzulmez | ca67dfe | 2015-03-06 16:08:10 +0200 | [diff] [blame] | 41 | #include <linux/uaccess.h> |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 42 | #include <linux/ctype.h> |
| 43 | |
| 44 | #include "ieee80211.h" |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 45 | #include "dot11d.h" |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 46 | static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, |
| 47 | struct sk_buff *skb, |
| 48 | struct ieee80211_rx_stats *rx_stats) |
| 49 | { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 50 | struct rtl_80211_hdr_4addr *hdr = (struct rtl_80211_hdr_4addr *)skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 51 | u16 fc = le16_to_cpu(hdr->frame_ctl); |
| 52 | |
| 53 | skb->dev = ieee->dev; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 54 | skb_reset_mac_header(skb); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 55 | |
| 56 | skb_pull(skb, ieee80211_get_hdrlen(fc)); |
| 57 | skb->pkt_type = PACKET_OTHERHOST; |
Vaishali Thakkar | 6465144 | 2015-03-06 18:52:28 +0530 | [diff] [blame] | 58 | skb->protocol = htons(ETH_P_80211_RAW); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 59 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 60 | netif_rx(skb); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /* Called only as a tasklet (software IRQ) */ |
| 65 | static struct ieee80211_frag_entry * |
| 66 | ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq, |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 67 | unsigned int frag, u8 tid, u8 *src, u8 *dst) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 68 | { |
| 69 | struct ieee80211_frag_entry *entry; |
| 70 | int i; |
| 71 | |
| 72 | for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) { |
| 73 | entry = &ieee->frag_cache[tid][i]; |
| 74 | if (entry->skb != NULL && |
| 75 | time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
| 76 | IEEE80211_DEBUG_FRAG( |
| 77 | "expiring fragment cache entry " |
| 78 | "seq=%u last_frag=%u\n", |
| 79 | entry->seq, entry->last_frag); |
| 80 | dev_kfree_skb_any(entry->skb); |
| 81 | entry->skb = NULL; |
| 82 | } |
| 83 | |
| 84 | if (entry->skb != NULL && entry->seq == seq && |
| 85 | (entry->last_frag + 1 == frag || frag == -1) && |
| 86 | memcmp(entry->src_addr, src, ETH_ALEN) == 0 && |
| 87 | memcmp(entry->dst_addr, dst, ETH_ALEN) == 0) |
| 88 | return entry; |
| 89 | } |
| 90 | |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | /* Called only as a tasklet (software IRQ) */ |
| 95 | static struct sk_buff * |
| 96 | ieee80211_frag_cache_get(struct ieee80211_device *ieee, |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 97 | struct rtl_80211_hdr_4addr *hdr) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 98 | { |
| 99 | struct sk_buff *skb = NULL; |
| 100 | u16 fc = le16_to_cpu(hdr->frame_ctl); |
| 101 | u16 sc = le16_to_cpu(hdr->seq_ctl); |
| 102 | unsigned int frag = WLAN_GET_SEQ_FRAG(sc); |
| 103 | unsigned int seq = WLAN_GET_SEQ_SEQ(sc); |
| 104 | struct ieee80211_frag_entry *entry; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 105 | struct rtl_80211_hdr_3addrqos *hdr_3addrqos; |
| 106 | struct rtl_80211_hdr_4addrqos *hdr_4addrqos; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 107 | u8 tid; |
| 108 | |
| 109 | if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 110 | hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 111 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 112 | tid = UP2AC(tid); |
| 113 | tid ++; |
| 114 | } else if (IEEE80211_QOS_HAS_SEQ(fc)) { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 115 | hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 116 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 117 | tid = UP2AC(tid); |
| 118 | tid ++; |
| 119 | } else { |
| 120 | tid = 0; |
| 121 | } |
| 122 | |
| 123 | if (frag == 0) { |
| 124 | /* Reserve enough space to fit maximum frame length */ |
| 125 | skb = dev_alloc_skb(ieee->dev->mtu + |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 126 | sizeof(struct rtl_80211_hdr_4addr) + |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 127 | 8 /* LLC */ + |
| 128 | 2 /* alignment */ + |
| 129 | 8 /* WEP */ + |
| 130 | ETH_ALEN /* WDS */ + |
| 131 | (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */); |
| 132 | if (skb == NULL) |
| 133 | return NULL; |
| 134 | |
| 135 | entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]]; |
| 136 | ieee->frag_next_idx[tid]++; |
| 137 | if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN) |
| 138 | ieee->frag_next_idx[tid] = 0; |
| 139 | |
| 140 | if (entry->skb != NULL) |
| 141 | dev_kfree_skb_any(entry->skb); |
| 142 | |
| 143 | entry->first_frag_time = jiffies; |
| 144 | entry->seq = seq; |
| 145 | entry->last_frag = frag; |
| 146 | entry->skb = skb; |
| 147 | memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); |
| 148 | memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); |
| 149 | } else { |
| 150 | /* received a fragment of a frame for which the head fragment |
| 151 | * should have already been received */ |
| 152 | entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2, |
| 153 | hdr->addr1); |
| 154 | if (entry != NULL) { |
| 155 | entry->last_frag = frag; |
| 156 | skb = entry->skb; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return skb; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | /* Called only as a tasklet (software IRQ) */ |
| 165 | static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee, |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 166 | struct rtl_80211_hdr_4addr *hdr) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 167 | { |
| 168 | u16 fc = le16_to_cpu(hdr->frame_ctl); |
| 169 | u16 sc = le16_to_cpu(hdr->seq_ctl); |
| 170 | unsigned int seq = WLAN_GET_SEQ_SEQ(sc); |
| 171 | struct ieee80211_frag_entry *entry; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 172 | struct rtl_80211_hdr_3addrqos *hdr_3addrqos; |
| 173 | struct rtl_80211_hdr_4addrqos *hdr_4addrqos; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 174 | u8 tid; |
| 175 | |
| 176 | if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 177 | hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 178 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 179 | tid = UP2AC(tid); |
| 180 | tid ++; |
| 181 | } else if (IEEE80211_QOS_HAS_SEQ(fc)) { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 182 | hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 183 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 184 | tid = UP2AC(tid); |
| 185 | tid ++; |
| 186 | } else { |
| 187 | tid = 0; |
| 188 | } |
| 189 | |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 190 | entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 191 | hdr->addr1); |
| 192 | |
| 193 | if (entry == NULL) { |
| 194 | IEEE80211_DEBUG_FRAG( |
| 195 | "could not invalidate fragment cache " |
| 196 | "entry (seq=%u)\n", seq); |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | entry->skb = NULL; |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
| 206 | /* ieee80211_rx_frame_mgtmt |
| 207 | * |
| 208 | * Responsible for handling management control frames |
| 209 | * |
| 210 | * Called by ieee80211_rx */ |
| 211 | static inline int |
| 212 | ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, |
| 213 | struct ieee80211_rx_stats *rx_stats, u16 type, |
| 214 | u16 stype) |
| 215 | { |
| 216 | /* On the struct stats definition there is written that |
| 217 | * this is not mandatory.... but seems that the probe |
| 218 | * response parser uses it |
| 219 | */ |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 220 | struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 221 | |
| 222 | rx_stats->len = skb->len; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 223 | ieee80211_rx_mgt(ieee,(struct rtl_80211_hdr_4addr *)skb->data,rx_stats); |
Dilek Uzulmez | 8236589 | 2015-03-06 16:18:31 +0200 | [diff] [blame] | 224 | /* if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) */ |
| 225 | if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))/* use ADDR1 to perform address matching for Management frames */ |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 226 | { |
| 227 | dev_kfree_skb_any(skb); |
| 228 | return 0; |
| 229 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 230 | |
| 231 | ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype); |
| 232 | |
| 233 | dev_kfree_skb_any(skb); |
| 234 | |
| 235 | return 0; |
| 236 | |
| 237 | #ifdef NOT_YET |
| 238 | if (ieee->iw_mode == IW_MODE_MASTER) { |
Masanari Iida | d0bc218 | 2012-01-25 00:35:41 +0900 | [diff] [blame] | 239 | printk(KERN_DEBUG "%s: Master mode not yet supported.\n", |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 240 | ieee->dev->name); |
| 241 | return 0; |
| 242 | /* |
| 243 | hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *) |
| 244 | skb->data);*/ |
| 245 | } |
| 246 | |
| 247 | if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) { |
| 248 | if (stype == WLAN_FC_STYPE_BEACON && |
| 249 | ieee->iw_mode == IW_MODE_MASTER) { |
| 250 | struct sk_buff *skb2; |
| 251 | /* Process beacon frames also in kernel driver to |
| 252 | * update STA(AP) table statistics */ |
| 253 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 254 | if (skb2) |
| 255 | hostap_rx(skb2->dev, skb2, rx_stats); |
| 256 | } |
| 257 | |
| 258 | /* send management frames to the user space daemon for |
| 259 | * processing */ |
| 260 | ieee->apdevstats.rx_packets++; |
| 261 | ieee->apdevstats.rx_bytes += skb->len; |
| 262 | prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT); |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | if (ieee->iw_mode == IW_MODE_MASTER) { |
| 267 | if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) { |
| 268 | printk(KERN_DEBUG "%s: unknown management frame " |
| 269 | "(type=0x%02x, stype=0x%02x) dropped\n", |
| 270 | skb->dev->name, type, stype); |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | hostap_rx(skb->dev, skb, rx_stats); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame " |
| 279 | "received in non-Host AP mode\n", skb->dev->name); |
| 280 | return -1; |
| 281 | #endif |
| 282 | } |
| 283 | |
| 284 | |
| 285 | |
| 286 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 287 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
| 288 | static unsigned char rfc1042_header[] = |
| 289 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 290 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
| 291 | static unsigned char bridge_tunnel_header[] = |
| 292 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 293 | /* No encapsulation header if EtherType < 0x600 (=length) */ |
| 294 | |
| 295 | /* Called by ieee80211_rx_frame_decrypt */ |
| 296 | static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee, |
| 297 | struct sk_buff *skb, size_t hdrlen) |
| 298 | { |
| 299 | struct net_device *dev = ieee->dev; |
| 300 | u16 fc, ethertype; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 301 | struct rtl_80211_hdr_4addr *hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 302 | u8 *pos; |
| 303 | |
| 304 | if (skb->len < 24) |
| 305 | return 0; |
| 306 | |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 307 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 308 | fc = le16_to_cpu(hdr->frame_ctl); |
| 309 | |
| 310 | /* check that the frame is unicast frame to us */ |
| 311 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 312 | IEEE80211_FCTL_TODS && |
| 313 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 && |
| 314 | memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { |
| 315 | /* ToDS frame with own addr BSSID and DA */ |
| 316 | } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == |
| 317 | IEEE80211_FCTL_FROMDS && |
| 318 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { |
| 319 | /* FromDS frame with own addr as DA */ |
| 320 | } else |
| 321 | return 0; |
| 322 | |
| 323 | if (skb->len < 24 + 8) |
| 324 | return 0; |
| 325 | |
| 326 | /* check for port access entity Ethernet type */ |
| 327 | // pos = skb->data + 24; |
| 328 | pos = skb->data + hdrlen; |
| 329 | ethertype = (pos[6] << 8) | pos[7]; |
| 330 | if (ethertype == ETH_P_PAE) |
| 331 | return 1; |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ |
| 337 | static inline int |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 338 | ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 339 | struct ieee80211_crypt_data *crypt) |
| 340 | { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 341 | struct rtl_80211_hdr_4addr *hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 342 | int res, hdrlen; |
| 343 | |
| 344 | if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) |
| 345 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 346 | if (ieee->hwsec_active) |
| 347 | { |
| 348 | cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); |
| 349 | tcb_desc->bHwSec = 1; |
| 350 | } |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 351 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 352 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
| 353 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 354 | if (ieee->tkip_countermeasures && |
| 355 | strcmp(crypt->ops->name, "TKIP") == 0) { |
| 356 | if (net_ratelimit()) { |
| 357 | printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 358 | "received packet from %pM\n", |
| 359 | ieee->dev->name, hdr->addr2); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 360 | } |
| 361 | return -1; |
| 362 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 363 | |
| 364 | atomic_inc(&crypt->refcnt); |
| 365 | res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); |
| 366 | atomic_dec(&crypt->refcnt); |
| 367 | if (res < 0) { |
| 368 | IEEE80211_DEBUG_DROP( |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 369 | "decryption failed (SA=%pM" |
| 370 | ") res=%d\n", hdr->addr2, res); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 371 | if (res == -2) |
| 372 | IEEE80211_DEBUG_DROP("Decryption failed ICV " |
| 373 | "mismatch (key %d)\n", |
| 374 | skb->data[hdrlen + 3] >> 6); |
| 375 | ieee->ieee_stats.rx_discards_undecryptable++; |
| 376 | return -1; |
| 377 | } |
| 378 | |
| 379 | return res; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ |
| 384 | static inline int |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 385 | ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *skb, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 386 | int keyidx, struct ieee80211_crypt_data *crypt) |
| 387 | { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 388 | struct rtl_80211_hdr_4addr *hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 389 | int res, hdrlen; |
| 390 | |
| 391 | if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) |
| 392 | return 0; |
| 393 | if (ieee->hwsec_active) |
| 394 | { |
| 395 | cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); |
| 396 | tcb_desc->bHwSec = 1; |
| 397 | } |
| 398 | |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 399 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 400 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
| 401 | |
| 402 | atomic_inc(&crypt->refcnt); |
| 403 | res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); |
| 404 | atomic_dec(&crypt->refcnt); |
| 405 | if (res < 0) { |
| 406 | printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed" |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 407 | " (SA=%pM keyidx=%d)\n", |
| 408 | ieee->dev->name, hdr->addr2, keyidx); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 409 | return -1; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | /* this function is stolen from ipw2200 driver*/ |
| 417 | #define IEEE_PACKET_RETRY_TIME (5*HZ) |
| 418 | static int is_duplicate_packet(struct ieee80211_device *ieee, |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 419 | struct rtl_80211_hdr_4addr *header) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 420 | { |
| 421 | u16 fc = le16_to_cpu(header->frame_ctl); |
| 422 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 423 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 424 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 425 | u16 *last_seq, *last_frag; |
| 426 | unsigned long *last_time; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 427 | struct rtl_80211_hdr_3addrqos *hdr_3addrqos; |
| 428 | struct rtl_80211_hdr_4addrqos *hdr_4addrqos; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 429 | u8 tid; |
| 430 | |
| 431 | |
| 432 | //TO2DS and QoS |
| 433 | if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 434 | hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 435 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 436 | tid = UP2AC(tid); |
| 437 | tid ++; |
| 438 | } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 439 | hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 440 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; |
| 441 | tid = UP2AC(tid); |
| 442 | tid ++; |
| 443 | } else { // no QoS |
| 444 | tid = 0; |
| 445 | } |
| 446 | |
| 447 | switch (ieee->iw_mode) { |
| 448 | case IW_MODE_ADHOC: |
| 449 | { |
| 450 | struct list_head *p; |
| 451 | struct ieee_ibss_seq *entry = NULL; |
| 452 | u8 *mac = header->addr2; |
| 453 | int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE; |
Dave Jones | 0c29359 | 2013-06-17 22:26:40 -0400 | [diff] [blame] | 454 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 455 | list_for_each(p, &ieee->ibss_mac_hash[index]) { |
| 456 | entry = list_entry(p, struct ieee_ibss_seq, list); |
| 457 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 458 | break; |
| 459 | } |
| 460 | // if (memcmp(entry->mac, mac, ETH_ALEN)){ |
| 461 | if (p == &ieee->ibss_mac_hash[index]) { |
| 462 | entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC); |
Bhumika Goyal | 5a95f07 | 2016-02-24 22:46:00 +0530 | [diff] [blame] | 463 | if (!entry) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 464 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 465 | memcpy(entry->mac, mac, ETH_ALEN); |
| 466 | entry->seq_num[tid] = seq; |
| 467 | entry->frag_num[tid] = frag; |
| 468 | entry->packet_time[tid] = jiffies; |
| 469 | list_add(&entry->list, &ieee->ibss_mac_hash[index]); |
| 470 | return 0; |
| 471 | } |
| 472 | last_seq = &entry->seq_num[tid]; |
| 473 | last_frag = &entry->frag_num[tid]; |
| 474 | last_time = &entry->packet_time[tid]; |
| 475 | break; |
| 476 | } |
| 477 | |
| 478 | case IW_MODE_INFRA: |
| 479 | last_seq = &ieee->last_rxseq_num[tid]; |
| 480 | last_frag = &ieee->last_rxfrag_num[tid]; |
| 481 | last_time = &ieee->last_packet_time[tid]; |
| 482 | |
| 483 | break; |
| 484 | default: |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | // if(tid != 0) { |
| 489 | // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl); |
| 490 | // } |
| 491 | if ((*last_seq == seq) && |
| 492 | time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) { |
Shraddha Barke | 879f307 | 2015-10-11 10:41:23 +0530 | [diff] [blame] | 493 | if (*last_frag == frag) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 494 | goto drop; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 495 | if (*last_frag + 1 != frag) |
| 496 | /* out-of-order fragment */ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 497 | goto drop; |
| 498 | } else |
| 499 | *last_seq = seq; |
| 500 | |
| 501 | *last_frag = frag; |
| 502 | *last_time = jiffies; |
| 503 | return 0; |
| 504 | |
| 505 | drop: |
| 506 | // BUG_ON(!(fc & IEEE80211_FCTL_RETRY)); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 507 | |
| 508 | return 1; |
| 509 | } |
Ana Rey | 4b10d50 | 2014-03-14 12:34:43 +0100 | [diff] [blame] | 510 | |
| 511 | static bool AddReorderEntry(PRX_TS_RECORD pTS, PRX_REORDER_ENTRY pReorderEntry) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 512 | { |
| 513 | struct list_head *pList = &pTS->RxPendingPktList; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 514 | while(pList->next != &pTS->RxPendingPktList) |
| 515 | { |
| 516 | if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) ) |
| 517 | { |
| 518 | pList = pList->next; |
| 519 | } |
| 520 | else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) ) |
| 521 | { |
| 522 | return false; |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | break; |
| 527 | } |
| 528 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 529 | pReorderEntry->List.next = pList->next; |
| 530 | pReorderEntry->List.next->prev = &pReorderEntry->List; |
| 531 | pReorderEntry->List.prev = pList; |
| 532 | pList->next = &pReorderEntry->List; |
| 533 | |
| 534 | return true; |
| 535 | } |
| 536 | |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 537 | void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray,u8 index) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 538 | { |
| 539 | u8 i = 0 , j=0; |
| 540 | u16 ethertype; |
| 541 | // if(index > 1) |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 542 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__func__,index); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 543 | for(j = 0; j<index; j++) |
| 544 | { |
| 545 | //added by amy for reorder |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 546 | struct ieee80211_rxb *prxb = prxbIndicateArray[j]; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 547 | for(i = 0; i<prxb->nr_subframes; i++) { |
| 548 | struct sk_buff *sub_skb = prxb->subframes[i]; |
| 549 | |
| 550 | /* convert hdr + possible LLC headers into Ethernet header */ |
| 551 | ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7]; |
| 552 | if (sub_skb->len >= 8 && |
| 553 | ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 && |
| 554 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 555 | memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) { |
| 556 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 557 | * replace EtherType */ |
| 558 | skb_pull(sub_skb, SNAP_SIZE); |
| 559 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN); |
| 560 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN); |
| 561 | } else { |
| 562 | u16 len; |
| 563 | /* Leave Ethernet header part of hdr and full payload */ |
| 564 | len = htons(sub_skb->len); |
| 565 | memcpy(skb_push(sub_skb, 2), &len, 2); |
| 566 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN); |
| 567 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN); |
| 568 | } |
| 569 | //stats->rx_packets++; |
| 570 | //stats->rx_bytes += sub_skb->len; |
| 571 | |
| 572 | /* Indicat the packets to upper layer */ |
| 573 | if (sub_skb) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 574 | sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev); |
| 575 | memset(sub_skb->cb, 0, sizeof(sub_skb->cb)); |
| 576 | sub_skb->dev = ieee->dev; |
| 577 | sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ |
| 578 | //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */ |
| 579 | ieee->last_rx_ps_time = jiffies; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 580 | netif_rx(sub_skb); |
| 581 | } |
| 582 | } |
| 583 | kfree(prxb); |
| 584 | prxb = NULL; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | |
Ana Rey | 4b10d50 | 2014-03-14 12:34:43 +0100 | [diff] [blame] | 589 | static void RxReorderIndicatePacket(struct ieee80211_device *ieee, |
| 590 | struct ieee80211_rxb *prxb, |
| 591 | PRX_TS_RECORD pTS, u16 SeqNum) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 592 | { |
| 593 | PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 594 | PRX_REORDER_ENTRY pReorderEntry = NULL; |
Okash Khawaja | 79a5ccd | 2015-12-17 20:30:38 +0000 | [diff] [blame] | 595 | struct ieee80211_rxb **prxbIndicateArray; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 596 | u8 WinSize = pHTInfo->RxReorderWinSize; |
| 597 | u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096; |
| 598 | u8 index = 0; |
| 599 | bool bMatchWinStart = false, bPktInBuf = false; |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 600 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize); |
Okash Khawaja | 79a5ccd | 2015-12-17 20:30:38 +0000 | [diff] [blame] | 601 | |
| 602 | prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) * |
| 603 | REORDER_WIN_SIZE, GFP_KERNEL); |
| 604 | if (!prxbIndicateArray) |
| 605 | return; |
| 606 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 607 | /* Rx Reorder initialize condition.*/ |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 608 | if (pTS->RxIndicateSeq == 0xffff) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 609 | pTS->RxIndicateSeq = SeqNum; |
| 610 | } |
| 611 | |
| 612 | /* Drop out the packet which SeqNum is smaller than WinStart */ |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 613 | if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 614 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n", |
| 615 | pTS->RxIndicateSeq, SeqNum); |
| 616 | pHTInfo->RxReorderDropCounter++; |
| 617 | { |
| 618 | int i; |
| 619 | for(i =0; i < prxb->nr_subframes; i++) { |
| 620 | dev_kfree_skb(prxb->subframes[i]); |
| 621 | } |
| 622 | kfree(prxb); |
| 623 | prxb = NULL; |
| 624 | } |
Okash Khawaja | 79a5ccd | 2015-12-17 20:30:38 +0000 | [diff] [blame] | 625 | |
| 626 | kfree(prxbIndicateArray); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Sliding window manipulation. Conditions includes: |
| 632 | * 1. Incoming SeqNum is equal to WinStart =>Window shift 1 |
| 633 | * 2. Incoming SeqNum is larger than the WinEnd => Window shift N |
| 634 | */ |
| 635 | if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) { |
| 636 | pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096; |
| 637 | bMatchWinStart = true; |
| 638 | } else if(SN_LESS(WinEnd, SeqNum)) { |
| 639 | if(SeqNum >= (WinSize - 1)) { |
| 640 | pTS->RxIndicateSeq = SeqNum + 1 -WinSize; |
| 641 | } else { |
| 642 | pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1; |
| 643 | } |
| 644 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * Indication process. |
| 649 | * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets |
| 650 | * with the SeqNum smaller than latest WinStart and buffer other packets. |
| 651 | */ |
| 652 | /* For Rx Reorder condition: |
| 653 | * 1. All packets with SeqNum smaller than WinStart => Indicate |
| 654 | * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. |
| 655 | */ |
| 656 | if(bMatchWinStart) { |
| 657 | /* Current packet is going to be indicated.*/ |
| 658 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\ |
| 659 | pTS->RxIndicateSeq, SeqNum); |
| 660 | prxbIndicateArray[0] = prxb; |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 661 | // printk("========================>%s(): SeqNum is %d\n",__func__,SeqNum); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 662 | index = 1; |
| 663 | } else { |
| 664 | /* Current packet is going to be inserted into pending list.*/ |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 665 | //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 666 | if(!list_empty(&ieee->RxReorder_Unused_List)) { |
| 667 | pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List); |
| 668 | list_del_init(&pReorderEntry->List); |
| 669 | |
| 670 | /* Make a reorder entry and insert into a the packet list.*/ |
| 671 | pReorderEntry->SeqNum = SeqNum; |
| 672 | pReorderEntry->prxb = prxb; |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 673 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 674 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 675 | if(!AddReorderEntry(pTS, pReorderEntry)) { |
| 676 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n", |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 677 | __func__, pTS->RxIndicateSeq, SeqNum); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 678 | list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); |
| 679 | { |
| 680 | int i; |
| 681 | for(i =0; i < prxb->nr_subframes; i++) { |
| 682 | dev_kfree_skb(prxb->subframes[i]); |
| 683 | } |
| 684 | kfree(prxb); |
| 685 | prxb = NULL; |
| 686 | } |
| 687 | } else { |
| 688 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, |
| 689 | "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); |
| 690 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 691 | } |
| 692 | else { |
| 693 | /* |
| 694 | * Packets are dropped if there is not enough reorder entries. |
| 695 | * This part shall be modified!! We can just indicate all the |
| 696 | * packets in buffer and get reorder entries. |
| 697 | */ |
| 698 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n"); |
| 699 | { |
| 700 | int i; |
| 701 | for(i =0; i < prxb->nr_subframes; i++) { |
| 702 | dev_kfree_skb(prxb->subframes[i]); |
| 703 | } |
| 704 | kfree(prxb); |
| 705 | prxb = NULL; |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /* Check if there is any packet need indicate.*/ |
| 711 | while(!list_empty(&pTS->RxPendingPktList)) { |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 712 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 713 | pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List); |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 714 | if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) || |
| 715 | SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 716 | { |
| 717 | /* This protect buffer from overflow. */ |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 718 | if (index >= REORDER_WIN_SIZE) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 719 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n"); |
| 720 | bPktInBuf = true; |
| 721 | break; |
| 722 | } |
| 723 | |
| 724 | list_del_init(&pReorderEntry->List); |
| 725 | |
| 726 | if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) |
| 727 | pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096; |
| 728 | |
| 729 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); |
| 730 | prxbIndicateArray[index] = pReorderEntry->prxb; |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 731 | // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 732 | index++; |
| 733 | |
| 734 | list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); |
| 735 | } else { |
| 736 | bPktInBuf = true; |
| 737 | break; |
| 738 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/ |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 742 | if (index>0) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 743 | // Cancel previous pending timer. |
| 744 | // del_timer_sync(&pTS->RxPktPendingTimer); |
| 745 | pTS->RxTimeoutIndicateSeq = 0xffff; |
| 746 | |
| 747 | // Indicate packets |
| 748 | if(index>REORDER_WIN_SIZE){ |
Nik Nyby | 58493d8 | 2016-03-20 15:46:35 -0400 | [diff] [blame] | 749 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorder buffer full!! \n"); |
Okash Khawaja | 79a5ccd | 2015-12-17 20:30:38 +0000 | [diff] [blame] | 750 | kfree(prxbIndicateArray); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 751 | return; |
| 752 | } |
| 753 | ieee80211_indicate_packets(ieee, prxbIndicateArray, index); |
| 754 | } |
| 755 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 756 | if (bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 757 | // Set new pending timer. |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 758 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 759 | pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq; |
| 760 | if(timer_pending(&pTS->RxPktPendingTimer)) |
| 761 | del_timer_sync(&pTS->RxPktPendingTimer); |
Amitoj Kaur Chawla | b1d9660 | 2016-02-13 10:04:10 +0530 | [diff] [blame] | 762 | pTS->RxPktPendingTimer.expires = jiffies + |
| 763 | msecs_to_jiffies(pHTInfo->RxReorderPendingTime); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 764 | add_timer(&pTS->RxPktPendingTimer); |
| 765 | } |
Okash Khawaja | 79a5ccd | 2015-12-17 20:30:38 +0000 | [diff] [blame] | 766 | |
| 767 | kfree(prxbIndicateArray); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 768 | } |
| 769 | |
Ana Rey | 4b10d50 | 2014-03-14 12:34:43 +0100 | [diff] [blame] | 770 | static u8 parse_subframe(struct sk_buff *skb, |
| 771 | struct ieee80211_rx_stats *rx_stats, |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 772 | struct ieee80211_rxb *rxb, u8 *src, u8 *dst) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 773 | { |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 774 | struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 775 | u16 fc = le16_to_cpu(hdr->frame_ctl); |
| 776 | |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 777 | u16 LLCOffset= sizeof(struct rtl_80211_hdr_3addr); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 778 | u16 ChkLength; |
| 779 | bool bIsAggregateFrame = false; |
| 780 | u16 nSubframe_Length; |
| 781 | u8 nPadding_Length = 0; |
| 782 | u16 SeqNum=0; |
| 783 | |
| 784 | struct sk_buff *sub_skb; |
| 785 | u8 *data_ptr; |
| 786 | /* just for debug purpose */ |
| 787 | SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl)); |
| 788 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 789 | if ((IEEE80211_QOS_HAS_SEQ(fc))&&\ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 790 | (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) { |
| 791 | bIsAggregateFrame = true; |
| 792 | } |
| 793 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 794 | if (IEEE80211_QOS_HAS_SEQ(fc)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 795 | LLCOffset += 2; |
| 796 | } |
| 797 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 798 | if (rx_stats->bContainHTC) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 799 | LLCOffset += sHTCLng; |
| 800 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 801 | // Null packet, don't indicate it to upper layer |
| 802 | ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/ |
| 803 | |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 804 | if (skb->len <= ChkLength) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 805 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 806 | |
| 807 | skb_pull(skb, LLCOffset); |
| 808 | |
| 809 | if(!bIsAggregateFrame) { |
| 810 | rxb->nr_subframes = 1; |
| 811 | #ifdef JOHN_NOCPY |
| 812 | rxb->subframes[0] = skb; |
| 813 | #else |
| 814 | rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC); |
| 815 | #endif |
| 816 | |
| 817 | memcpy(rxb->src,src,ETH_ALEN); |
| 818 | memcpy(rxb->dst,dst,ETH_ALEN); |
| 819 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len); |
| 820 | return 1; |
| 821 | } else { |
| 822 | rxb->nr_subframes = 0; |
| 823 | memcpy(rxb->src,src,ETH_ALEN); |
| 824 | memcpy(rxb->dst,dst,ETH_ALEN); |
| 825 | while(skb->len > ETHERNET_HEADER_SIZE) { |
| 826 | /* Offset 12 denote 2 mac address */ |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 827 | nSubframe_Length = *((u16 *)(skb->data + 12)); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 828 | //==m==>change the length order |
| 829 | nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8); |
| 830 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 831 | if (skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 832 | printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\ |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 833 | __func__, rxb->nr_subframes); |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 834 | printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__func__, nSubframe_Length); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 835 | printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length); |
| 836 | printk("The Packet SeqNum is %d\n",SeqNum); |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | /* move the data point to data content */ |
| 841 | skb_pull(skb, ETHERNET_HEADER_SIZE); |
| 842 | |
| 843 | #ifdef JOHN_NOCPY |
| 844 | sub_skb = skb_clone(skb, GFP_ATOMIC); |
| 845 | sub_skb->len = nSubframe_Length; |
| 846 | sub_skb->tail = sub_skb->data + nSubframe_Length; |
| 847 | #else |
| 848 | /* Allocate new skb for releasing to upper layer */ |
| 849 | sub_skb = dev_alloc_skb(nSubframe_Length + 12); |
Valdis Kletnieks | 79d99c3 | 2014-09-08 18:09:48 -0400 | [diff] [blame] | 850 | if (!sub_skb) |
| 851 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 852 | skb_reserve(sub_skb, 12); |
| 853 | data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length); |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 854 | memcpy(data_ptr, skb->data, nSubframe_Length); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 855 | #endif |
| 856 | rxb->subframes[rxb->nr_subframes++] = sub_skb; |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 857 | if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 858 | IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n"); |
| 859 | break; |
| 860 | } |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 861 | skb_pull(skb, nSubframe_Length); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 862 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 863 | if (skb->len != 0) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 864 | nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4); |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 865 | if (nPadding_Length == 4) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 866 | nPadding_Length = 0; |
| 867 | } |
| 868 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 869 | if (skb->len < nPadding_Length) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 873 | skb_pull(skb, nPadding_Length); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | #ifdef JOHN_NOCPY |
| 877 | dev_kfree_skb(skb); |
| 878 | #endif |
| 879 | //{just for debug added by david |
| 880 | //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes); |
| 881 | //} |
| 882 | return rxb->nr_subframes; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /* All received frames are sent to this function. @skb contains the frame in |
| 887 | * IEEE 802.11 format, i.e., in the format it was sent over air. |
| 888 | * This function is called only as a tasklet (software IRQ). */ |
| 889 | int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, |
| 890 | struct ieee80211_rx_stats *rx_stats) |
| 891 | { |
| 892 | struct net_device *dev = ieee->dev; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 893 | struct rtl_80211_hdr_4addr *hdr; |
| 894 | //struct rtl_80211_hdr_3addrqos *hdr; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 895 | |
| 896 | size_t hdrlen; |
| 897 | u16 fc, type, stype, sc; |
| 898 | struct net_device_stats *stats; |
| 899 | unsigned int frag; |
| 900 | u8 *payload; |
| 901 | u16 ethertype; |
| 902 | //added by amy for reorder |
| 903 | u8 TID = 0; |
| 904 | u16 SeqNum = 0; |
| 905 | PRX_TS_RECORD pTS = NULL; |
| 906 | //bool bIsAggregateFrame = false; |
| 907 | //added by amy for reorder |
| 908 | #ifdef NOT_YET |
| 909 | struct net_device *wds = NULL; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 910 | struct net_device *wds = NULL; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 911 | int from_assoc_ap = 0; |
| 912 | void *sta = NULL; |
| 913 | #endif |
| 914 | // u16 qos_ctl = 0; |
| 915 | u8 dst[ETH_ALEN]; |
| 916 | u8 src[ETH_ALEN]; |
| 917 | u8 bssid[ETH_ALEN]; |
| 918 | struct ieee80211_crypt_data *crypt = NULL; |
| 919 | int keyidx = 0; |
| 920 | |
| 921 | int i; |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 922 | struct ieee80211_rxb *rxb = NULL; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 923 | // cheat the the hdr type |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 924 | hdr = (struct rtl_80211_hdr_4addr *)skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 925 | stats = &ieee->stats; |
| 926 | |
| 927 | if (skb->len < 10) { |
| 928 | printk(KERN_INFO "%s: SKB length < 10\n", |
| 929 | dev->name); |
| 930 | goto rx_dropped; |
| 931 | } |
| 932 | |
| 933 | fc = le16_to_cpu(hdr->frame_ctl); |
| 934 | type = WLAN_FC_GET_TYPE(fc); |
| 935 | stype = WLAN_FC_GET_STYPE(fc); |
| 936 | sc = le16_to_cpu(hdr->seq_ctl); |
| 937 | |
| 938 | frag = WLAN_GET_SEQ_FRAG(sc); |
| 939 | hdrlen = ieee80211_get_hdrlen(fc); |
| 940 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 941 | if (HTCCheck(ieee, skb->data)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 942 | { |
| 943 | if(net_ratelimit()) |
| 944 | printk("find HTCControl\n"); |
| 945 | hdrlen += 4; |
Cristina Opriceana | 19cd229 | 2015-03-04 12:37:28 +0200 | [diff] [blame] | 946 | rx_stats->bContainHTC = true; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); |
| 950 | #ifdef NOT_YET |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 951 | /* Put this code here so that we avoid duplicating it in all |
| 952 | * Rx paths. - Jean II */ |
| 953 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ |
| 954 | /* If spy monitoring on */ |
| 955 | if (iface->spy_data.spy_number > 0) { |
| 956 | struct iw_quality wstats; |
| 957 | wstats.level = rx_stats->rssi; |
| 958 | wstats.noise = rx_stats->noise; |
| 959 | wstats.updated = 6; /* No qual value */ |
| 960 | /* Update spy records */ |
| 961 | wireless_spy_update(dev, hdr->addr2, &wstats); |
| 962 | } |
| 963 | #endif /* IW_WIRELESS_SPY */ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 964 | hostap_update_rx_stats(local->ap, hdr, rx_stats); |
| 965 | #endif |
| 966 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 967 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 968 | ieee80211_monitor_rx(ieee, skb, rx_stats); |
| 969 | stats->rx_packets++; |
| 970 | stats->rx_bytes += skb->len; |
| 971 | return 1; |
| 972 | } |
Joel Pelaez Jorge | e6c1ef6 | 2014-05-23 14:27:43 -0500 | [diff] [blame] | 973 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 974 | if (ieee->host_decrypt) { |
| 975 | int idx = 0; |
| 976 | if (skb->len >= hdrlen + 3) |
| 977 | idx = skb->data[hdrlen + 3] >> 6; |
| 978 | crypt = ieee->crypt[idx]; |
| 979 | #ifdef NOT_YET |
| 980 | sta = NULL; |
| 981 | |
| 982 | /* Use station specific key to override default keys if the |
| 983 | * receiver address is a unicast address ("individual RA"). If |
| 984 | * bcrx_sta_key parameter is set, station specific key is used |
| 985 | * even with broad/multicast targets (this is against IEEE |
| 986 | * 802.11, but makes it easier to use different keys with |
| 987 | * stations that do not support WEP key mapping). */ |
| 988 | |
| 989 | if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) |
| 990 | (void) hostap_handle_sta_crypto(local, hdr, &crypt, |
| 991 | &sta); |
| 992 | #endif |
| 993 | |
| 994 | /* allow NULL decrypt to indicate an station specific override |
| 995 | * for default encryption */ |
| 996 | if (crypt && (crypt->ops == NULL || |
| 997 | crypt->ops->decrypt_mpdu == NULL)) |
| 998 | crypt = NULL; |
| 999 | |
| 1000 | if (!crypt && (fc & IEEE80211_FCTL_WEP)) { |
| 1001 | /* This seems to be triggered by some (multicast?) |
| 1002 | * frames from other than current BSS, so just drop the |
| 1003 | * frames silently instead of filling system log with |
| 1004 | * these reports. */ |
| 1005 | IEEE80211_DEBUG_DROP("Decryption failed (not set)" |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 1006 | " (SA=%pM)\n", |
| 1007 | hdr->addr2); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1008 | ieee->ieee_stats.rx_discards_undecryptable++; |
| 1009 | goto rx_dropped; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if (skb->len < IEEE80211_DATA_HDR3_LEN) |
| 1014 | goto rx_dropped; |
| 1015 | |
| 1016 | // if QoS enabled, should check the sequence for each of the AC |
Luis de Bethencourt | f9bd549 | 2015-07-20 18:35:42 +0200 | [diff] [blame] | 1017 | if ((!ieee->pHTInfo->bCurRxReorderEnable) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1018 | if (is_duplicate_packet(ieee, hdr)) |
| 1019 | goto rx_dropped; |
| 1020 | |
| 1021 | } |
| 1022 | else |
| 1023 | { |
| 1024 | PRX_TS_RECORD pRxTS = NULL; |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 1025 | //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__func__, tid); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1026 | if(GetTs( |
| 1027 | ieee, |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 1028 | (PTS_COMMON_INFO *) &pRxTS, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1029 | hdr->addr2, |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 1030 | (u8)Frame_QoSTID((u8 *)(skb->data)), |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1031 | RX_DIR, |
| 1032 | true)) |
| 1033 | { |
| 1034 | |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 1035 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__func__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc)); |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 1036 | if ((fc & (1<<11)) && |
| 1037 | (frag == pRxTS->RxLastFragNum) && |
| 1038 | (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1039 | goto rx_dropped; |
| 1040 | } |
| 1041 | else |
| 1042 | { |
| 1043 | pRxTS->RxLastFragNum = frag; |
| 1044 | pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc); |
| 1045 | } |
| 1046 | } |
| 1047 | else |
| 1048 | { |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 1049 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1050 | goto rx_dropped; |
| 1051 | } |
| 1052 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1053 | if (type == IEEE80211_FTYPE_MGMT) { |
| 1054 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1055 | |
| 1056 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); |
| 1057 | if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype)) |
| 1058 | goto rx_dropped; |
| 1059 | else |
| 1060 | goto rx_exit; |
| 1061 | } |
| 1062 | |
| 1063 | /* Data frame - extract src/dst addresses */ |
| 1064 | switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { |
| 1065 | case IEEE80211_FCTL_FROMDS: |
| 1066 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1067 | memcpy(src, hdr->addr3, ETH_ALEN); |
| 1068 | memcpy(bssid, hdr->addr2, ETH_ALEN); |
| 1069 | break; |
| 1070 | case IEEE80211_FCTL_TODS: |
| 1071 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1072 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1073 | memcpy(bssid, hdr->addr1, ETH_ALEN); |
| 1074 | break; |
| 1075 | case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: |
| 1076 | if (skb->len < IEEE80211_DATA_HDR4_LEN) |
| 1077 | goto rx_dropped; |
| 1078 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1079 | memcpy(src, hdr->addr4, ETH_ALEN); |
| 1080 | memcpy(bssid, ieee->current_network.bssid, ETH_ALEN); |
| 1081 | break; |
| 1082 | case 0: |
| 1083 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1084 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1085 | memcpy(bssid, hdr->addr3, ETH_ALEN); |
| 1086 | break; |
| 1087 | } |
| 1088 | |
| 1089 | #ifdef NOT_YET |
| 1090 | if (hostap_rx_frame_wds(ieee, hdr, fc, &wds)) |
| 1091 | goto rx_dropped; |
| 1092 | if (wds) { |
| 1093 | skb->dev = dev = wds; |
| 1094 | stats = hostap_get_stats(dev); |
| 1095 | } |
| 1096 | |
| 1097 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && |
| 1098 | (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS && |
| 1099 | ieee->stadev && |
| 1100 | memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) { |
| 1101 | /* Frame from BSSID of the AP for which we are a client */ |
| 1102 | skb->dev = dev = ieee->stadev; |
| 1103 | stats = hostap_get_stats(dev); |
| 1104 | from_assoc_ap = 1; |
| 1105 | } |
| 1106 | #endif |
| 1107 | |
| 1108 | dev->last_rx = jiffies; |
| 1109 | |
| 1110 | #ifdef NOT_YET |
| 1111 | if ((ieee->iw_mode == IW_MODE_MASTER || |
| 1112 | ieee->iw_mode == IW_MODE_REPEAT) && |
| 1113 | !from_assoc_ap) { |
| 1114 | switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats, |
| 1115 | wds != NULL)) { |
| 1116 | case AP_RX_CONTINUE_NOT_AUTHORIZED: |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1117 | case AP_RX_CONTINUE: |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1118 | break; |
| 1119 | case AP_RX_DROP: |
| 1120 | goto rx_dropped; |
| 1121 | case AP_RX_EXIT: |
| 1122 | goto rx_exit; |
| 1123 | } |
| 1124 | } |
| 1125 | #endif |
| 1126 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); |
| 1127 | /* Nullfunc frames may have PS-bit set, so they must be passed to |
| 1128 | * hostap_handle_sta_rx() before being dropped here. */ |
| 1129 | if (stype != IEEE80211_STYPE_DATA && |
| 1130 | stype != IEEE80211_STYPE_DATA_CFACK && |
| 1131 | stype != IEEE80211_STYPE_DATA_CFPOLL && |
| 1132 | stype != IEEE80211_STYPE_DATA_CFACKPOLL&& |
| 1133 | stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4 |
| 1134 | ) { |
| 1135 | if (stype != IEEE80211_STYPE_NULLFUNC) |
| 1136 | IEEE80211_DEBUG_DROP( |
| 1137 | "RX: dropped data frame " |
| 1138 | "with no data (type=0x%02x, " |
| 1139 | "subtype=0x%02x, len=%d)\n", |
| 1140 | type, stype, skb->len); |
| 1141 | goto rx_dropped; |
| 1142 | } |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1143 | if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) |
| 1144 | goto rx_dropped; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1145 | |
| 1146 | /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ |
| 1147 | |
| 1148 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && |
| 1149 | (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) |
| 1150 | { |
| 1151 | printk("decrypt frame error\n"); |
| 1152 | goto rx_dropped; |
| 1153 | } |
| 1154 | |
| 1155 | |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 1156 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1157 | |
| 1158 | /* skb: hdr + (possibly fragmented) plaintext payload */ |
| 1159 | // PR: FIXME: hostap has additional conditions in the "if" below: |
| 1160 | // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && |
| 1161 | if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) { |
| 1162 | int flen; |
| 1163 | struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr); |
| 1164 | IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag); |
| 1165 | |
| 1166 | if (!frag_skb) { |
| 1167 | IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG, |
| 1168 | "Rx cannot get skb from fragment " |
| 1169 | "cache (morefrag=%d seq=%u frag=%u)\n", |
| 1170 | (fc & IEEE80211_FCTL_MOREFRAGS) != 0, |
| 1171 | WLAN_GET_SEQ_SEQ(sc), frag); |
| 1172 | goto rx_dropped; |
| 1173 | } |
| 1174 | flen = skb->len; |
| 1175 | if (frag != 0) |
| 1176 | flen -= hdrlen; |
| 1177 | |
| 1178 | if (frag_skb->tail + flen > frag_skb->end) { |
| 1179 | printk(KERN_WARNING "%s: host decrypted and " |
| 1180 | "reassembled frame did not fit skb\n", |
| 1181 | dev->name); |
| 1182 | ieee80211_frag_cache_invalidate(ieee, hdr); |
| 1183 | goto rx_dropped; |
| 1184 | } |
| 1185 | |
| 1186 | if (frag == 0) { |
| 1187 | /* copy first fragment (including full headers) into |
| 1188 | * beginning of the fragment cache skb */ |
| 1189 | memcpy(skb_put(frag_skb, flen), skb->data, flen); |
| 1190 | } else { |
| 1191 | /* append frame payload to the end of the fragment |
| 1192 | * cache skb */ |
| 1193 | memcpy(skb_put(frag_skb, flen), skb->data + hdrlen, |
| 1194 | flen); |
| 1195 | } |
| 1196 | dev_kfree_skb_any(skb); |
| 1197 | skb = NULL; |
| 1198 | |
| 1199 | if (fc & IEEE80211_FCTL_MOREFRAGS) { |
| 1200 | /* more fragments expected - leave the skb in fragment |
| 1201 | * cache for now; it will be delivered to upper layers |
| 1202 | * after all fragments have been received */ |
| 1203 | goto rx_exit; |
| 1204 | } |
| 1205 | |
| 1206 | /* this was the last fragment and the frame will be |
| 1207 | * delivered, so remove skb from fragment cache */ |
| 1208 | skb = frag_skb; |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 1209 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1210 | ieee80211_frag_cache_invalidate(ieee, hdr); |
| 1211 | } |
| 1212 | |
| 1213 | /* skb: hdr + (possible reassembled) full MSDU payload; possibly still |
| 1214 | * encrypted/authenticated */ |
| 1215 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && |
| 1216 | ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) |
| 1217 | { |
| 1218 | printk("==>decrypt msdu error\n"); |
| 1219 | goto rx_dropped; |
| 1220 | } |
| 1221 | |
| 1222 | //added by amy for AP roaming |
| 1223 | ieee->LinkDetectInfo.NumRecvDataInPeriod++; |
| 1224 | ieee->LinkDetectInfo.NumRxOkInPeriod++; |
| 1225 | |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 1226 | hdr = (struct rtl_80211_hdr_4addr *) skb->data; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1227 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) { |
| 1228 | if (/*ieee->ieee802_1x &&*/ |
| 1229 | ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { |
| 1230 | |
| 1231 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1232 | /* pass unencrypted EAPOL frames even if encryption is |
| 1233 | * configured */ |
| 1234 | struct eapol *eap = (struct eapol *)(skb->data + |
| 1235 | 24); |
| 1236 | IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", |
| 1237 | eap_get_type(eap->type)); |
| 1238 | #endif |
| 1239 | } else { |
| 1240 | IEEE80211_DEBUG_DROP( |
| 1241 | "encryption configured, but RX " |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 1242 | "frame not encrypted (SA=%pM)\n", |
| 1243 | hdr->addr2); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1244 | goto rx_dropped; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1249 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && |
| 1250 | ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { |
| 1251 | struct eapol *eap = (struct eapol *)(skb->data + |
| 1252 | 24); |
| 1253 | IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", |
| 1254 | eap_get_type(eap->type)); |
| 1255 | } |
| 1256 | #endif |
| 1257 | |
| 1258 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep && |
| 1259 | !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { |
| 1260 | IEEE80211_DEBUG_DROP( |
| 1261 | "dropped unencrypted RX data " |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 1262 | "frame from %pM" |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1263 | " (drop_unencrypted=1)\n", |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 1264 | hdr->addr2); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1265 | goto rx_dropped; |
| 1266 | } |
| 1267 | /* |
| 1268 | if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { |
| 1269 | printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n"); |
| 1270 | } |
| 1271 | */ |
| 1272 | //added by amy for reorder |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1273 | if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data) |
Joe Perches | 14fc423 | 2012-05-08 10:11:56 -0700 | [diff] [blame] | 1274 | && !is_multicast_ether_addr(hdr->addr1)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1275 | { |
| 1276 | TID = Frame_QoSTID(skb->data); |
| 1277 | SeqNum = WLAN_GET_SEQ_SEQ(sc); |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 1278 | GetTs(ieee,(PTS_COMMON_INFO *) &pTS,hdr->addr2,TID,RX_DIR,true); |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1279 | if (TID !=0 && TID !=3) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1280 | { |
| 1281 | ieee->bis_any_nonbepkts = true; |
| 1282 | } |
| 1283 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1284 | //added by amy for reorder |
| 1285 | /* skb: hdr + (possible reassembled) full plaintext payload */ |
| 1286 | payload = skb->data + hdrlen; |
| 1287 | //ethertype = (payload[6] << 8) | payload[7]; |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 1288 | rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC); |
Bhumika Goyal | 61645cc | 2016-02-24 15:47:35 +0530 | [diff] [blame] | 1289 | if (!rxb) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1290 | goto rx_dropped; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1291 | /* to parse amsdu packets */ |
| 1292 | /* qos data packets & reserved bit is 1 */ |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 1293 | if (parse_subframe(skb, rx_stats, rxb, src, dst) == 0) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1294 | /* only to free rxb, and not submit the packets to upper layer */ |
| 1295 | for(i =0; i < rxb->nr_subframes; i++) { |
| 1296 | dev_kfree_skb(rxb->subframes[i]); |
| 1297 | } |
| 1298 | kfree(rxb); |
| 1299 | rxb = NULL; |
| 1300 | goto rx_dropped; |
| 1301 | } |
| 1302 | |
| 1303 | //added by amy for reorder |
Luis de Bethencourt | f9bd549 | 2015-07-20 18:35:42 +0200 | [diff] [blame] | 1304 | if (!ieee->pHTInfo->bCurRxReorderEnable || pTS == NULL){ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1305 | //added by amy for reorder |
| 1306 | for(i = 0; i<rxb->nr_subframes; i++) { |
| 1307 | struct sk_buff *sub_skb = rxb->subframes[i]; |
| 1308 | |
| 1309 | if (sub_skb) { |
| 1310 | /* convert hdr + possible LLC headers into Ethernet header */ |
| 1311 | ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7]; |
| 1312 | if (sub_skb->len >= 8 && |
| 1313 | ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 && |
| 1314 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1315 | memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) { |
| 1316 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 1317 | * replace EtherType */ |
| 1318 | skb_pull(sub_skb, SNAP_SIZE); |
| 1319 | memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN); |
| 1320 | memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN); |
| 1321 | } else { |
| 1322 | u16 len; |
| 1323 | /* Leave Ethernet header part of hdr and full payload */ |
| 1324 | len = htons(sub_skb->len); |
| 1325 | memcpy(skb_push(sub_skb, 2), &len, 2); |
| 1326 | memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN); |
| 1327 | memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN); |
| 1328 | } |
| 1329 | |
| 1330 | stats->rx_packets++; |
| 1331 | stats->rx_bytes += sub_skb->len; |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1332 | if (is_multicast_ether_addr(dst)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1333 | stats->multicast++; |
| 1334 | } |
| 1335 | |
| 1336 | /* Indicat the packets to upper layer */ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1337 | sub_skb->protocol = eth_type_trans(sub_skb, dev); |
| 1338 | memset(sub_skb->cb, 0, sizeof(sub_skb->cb)); |
| 1339 | sub_skb->dev = dev; |
| 1340 | sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ |
| 1341 | //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */ |
| 1342 | ieee->last_rx_ps_time = jiffies; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1343 | netif_rx(sub_skb); |
| 1344 | } |
| 1345 | } |
| 1346 | kfree(rxb); |
| 1347 | rxb = NULL; |
| 1348 | |
| 1349 | } |
| 1350 | else |
| 1351 | { |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 1352 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1353 | RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum); |
| 1354 | } |
| 1355 | #ifndef JOHN_NOCPY |
| 1356 | dev_kfree_skb(skb); |
| 1357 | #endif |
| 1358 | |
| 1359 | rx_exit: |
| 1360 | #ifdef NOT_YET |
| 1361 | if (sta) |
| 1362 | hostap_handle_sta_release(sta); |
| 1363 | #endif |
| 1364 | return 1; |
| 1365 | |
| 1366 | rx_dropped: |
Ilia Mirkin | e72714f | 2011-03-13 00:29:07 -0500 | [diff] [blame] | 1367 | kfree(rxb); |
| 1368 | rxb = NULL; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1369 | stats->rx_dropped++; |
| 1370 | |
| 1371 | /* Returning 0 indicates to caller that we have not handled the SKB-- |
| 1372 | * so it is still allocated and can be used again by underlying |
| 1373 | * hardware as a DMA target */ |
| 1374 | return 0; |
| 1375 | } |
Benoit Taine | 539b4f7 | 2014-05-16 14:22:41 +0200 | [diff] [blame] | 1376 | EXPORT_SYMBOL(ieee80211_rx); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1377 | |
| 1378 | #define MGMT_FRAME_FIXED_PART_LENGTH 0x24 |
| 1379 | |
| 1380 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 1381 | |
| 1382 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1383 | * Make the structure we read from the beacon packet to have |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1384 | * the right values |
| 1385 | */ |
| 1386 | static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1387 | *info_element, int sub_type) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1388 | { |
| 1389 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1390 | if (info_element->qui_subtype != sub_type) |
| 1391 | return -1; |
| 1392 | if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) |
| 1393 | return -1; |
| 1394 | if (info_element->qui_type != QOS_OUI_TYPE) |
| 1395 | return -1; |
| 1396 | if (info_element->version != QOS_VERSION_1) |
| 1397 | return -1; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1398 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1399 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | /* |
| 1404 | * Parse a QoS parameter element |
| 1405 | */ |
| 1406 | static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1407 | *element_param, struct ieee80211_info_element |
| 1408 | *info_element) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1409 | { |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1410 | int ret = 0; |
| 1411 | u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1412 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1413 | if ((info_element == NULL) || (element_param == NULL)) |
| 1414 | return -1; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1415 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1416 | if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { |
| 1417 | memcpy(element_param->info_element.qui, info_element->data, |
| 1418 | info_element->len); |
| 1419 | element_param->info_element.elementID = info_element->id; |
| 1420 | element_param->info_element.length = info_element->len; |
| 1421 | } else |
| 1422 | ret = -1; |
| 1423 | if (ret == 0) |
| 1424 | ret = ieee80211_verify_qos_info(&element_param->info_element, |
| 1425 | QOS_OUI_PARAM_SUB_TYPE); |
| 1426 | return ret; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * Parse a QoS information element |
| 1431 | */ |
| 1432 | static int ieee80211_read_qos_info_element(struct |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1433 | ieee80211_qos_information_element |
| 1434 | *element_info, struct ieee80211_info_element |
| 1435 | *info_element) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1436 | { |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1437 | int ret = 0; |
| 1438 | u16 size = sizeof(struct ieee80211_qos_information_element) - 2; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1439 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1440 | if (element_info == NULL) |
| 1441 | return -1; |
| 1442 | if (info_element == NULL) |
| 1443 | return -1; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1444 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1445 | if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { |
| 1446 | memcpy(element_info->qui, info_element->data, |
| 1447 | info_element->len); |
| 1448 | element_info->elementID = info_element->id; |
| 1449 | element_info->length = info_element->len; |
| 1450 | } else |
| 1451 | ret = -1; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1452 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1453 | if (ret == 0) |
| 1454 | ret = ieee80211_verify_qos_info(element_info, |
| 1455 | QOS_OUI_INFO_SUB_TYPE); |
| 1456 | return ret; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | |
| 1460 | /* |
| 1461 | * Write QoS parameters from the ac parameters. |
| 1462 | */ |
| 1463 | static int ieee80211_qos_convert_ac_to_parameters(struct |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1464 | ieee80211_qos_parameter_info |
| 1465 | *param_elm, struct |
| 1466 | ieee80211_qos_parameters |
| 1467 | *qos_param) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1468 | { |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1469 | int i; |
| 1470 | struct ieee80211_qos_ac_parameter *ac_params; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1471 | u8 aci; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1472 | //u8 cw_min; |
| 1473 | //u8 cw_max; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1474 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1475 | for (i = 0; i < QOS_QUEUE_NUM; i++) { |
| 1476 | ac_params = &(param_elm->ac_params_record[i]); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1477 | |
| 1478 | aci = (ac_params->aci_aifsn & 0x60) >> 5; |
| 1479 | |
| 1480 | if(aci >= QOS_QUEUE_NUM) |
| 1481 | continue; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1482 | qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1483 | |
| 1484 | /* WMM spec P.11: The minimum value for AIFSN shall be 2 */ |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1485 | qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1486 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1487 | qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1488 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1489 | qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1490 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1491 | qos_param->flag[aci] = |
| 1492 | (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; |
| 1493 | qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit); |
| 1494 | } |
Peter Senna Tschudin | 4764ca9 | 2014-05-26 16:08:50 +0200 | [diff] [blame] | 1495 | return 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | * we have a generic data element which it may contain QoS information or |
| 1500 | * parameters element. check the information element length to decide |
| 1501 | * which type to read |
| 1502 | */ |
| 1503 | static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1504 | *info_element, |
| 1505 | struct ieee80211_network *network) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1506 | { |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1507 | int rc = 0; |
| 1508 | struct ieee80211_qos_parameters *qos_param = NULL; |
| 1509 | struct ieee80211_qos_information_element qos_info_element; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1510 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1511 | rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1512 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1513 | if (rc == 0) { |
| 1514 | network->qos_data.param_count = qos_info_element.ac_info & 0x0F; |
| 1515 | network->flags |= NETWORK_HAS_QOS_INFORMATION; |
| 1516 | } else { |
| 1517 | struct ieee80211_qos_parameter_info param_element; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1518 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1519 | rc = ieee80211_read_qos_param_element(¶m_element, |
| 1520 | info_element); |
| 1521 | if (rc == 0) { |
| 1522 | qos_param = &(network->qos_data.parameters); |
| 1523 | ieee80211_qos_convert_ac_to_parameters(¶m_element, |
| 1524 | qos_param); |
| 1525 | network->flags |= NETWORK_HAS_QOS_PARAMETERS; |
| 1526 | network->qos_data.param_count = |
| 1527 | param_element.info_element.ac_info & 0x0F; |
| 1528 | } |
| 1529 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1530 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1531 | if (rc == 0) { |
| 1532 | IEEE80211_DEBUG_QOS("QoS is supported\n"); |
| 1533 | network->qos_data.supported = 1; |
| 1534 | } |
| 1535 | return rc; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1539 | #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x |
| 1540 | |
| 1541 | static const char *get_info_element_string(u16 id) |
| 1542 | { |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1543 | switch (id) { |
| 1544 | MFIE_STRING(SSID); |
| 1545 | MFIE_STRING(RATES); |
| 1546 | MFIE_STRING(FH_SET); |
| 1547 | MFIE_STRING(DS_SET); |
| 1548 | MFIE_STRING(CF_SET); |
| 1549 | MFIE_STRING(TIM); |
| 1550 | MFIE_STRING(IBSS_SET); |
| 1551 | MFIE_STRING(COUNTRY); |
| 1552 | MFIE_STRING(HOP_PARAMS); |
| 1553 | MFIE_STRING(HOP_TABLE); |
| 1554 | MFIE_STRING(REQUEST); |
| 1555 | MFIE_STRING(CHALLENGE); |
| 1556 | MFIE_STRING(POWER_CONSTRAINT); |
| 1557 | MFIE_STRING(POWER_CAPABILITY); |
| 1558 | MFIE_STRING(TPC_REQUEST); |
| 1559 | MFIE_STRING(TPC_REPORT); |
| 1560 | MFIE_STRING(SUPP_CHANNELS); |
| 1561 | MFIE_STRING(CSA); |
| 1562 | MFIE_STRING(MEASURE_REQUEST); |
| 1563 | MFIE_STRING(MEASURE_REPORT); |
| 1564 | MFIE_STRING(QUIET); |
| 1565 | MFIE_STRING(IBSS_DFS); |
| 1566 | // MFIE_STRING(ERP_INFO); |
| 1567 | MFIE_STRING(RSN); |
| 1568 | MFIE_STRING(RATES_EX); |
| 1569 | MFIE_STRING(GENERIC); |
| 1570 | MFIE_STRING(QOS_PARAMETER); |
| 1571 | default: |
| 1572 | return "UNKNOWN"; |
| 1573 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1574 | } |
| 1575 | #endif |
| 1576 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1577 | static inline void ieee80211_extract_country_ie( |
| 1578 | struct ieee80211_device *ieee, |
| 1579 | struct ieee80211_info_element *info_element, |
| 1580 | struct ieee80211_network *network, |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 1581 | u8 *addr2 |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1582 | ) |
| 1583 | { |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1584 | if (IS_DOT11D_ENABLE(ieee)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1585 | { |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1586 | if (info_element->len!= 0) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1587 | { |
| 1588 | memcpy(network->CountryIeBuf, info_element->data, info_element->len); |
| 1589 | network->CountryIeLen = info_element->len; |
| 1590 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1591 | if (!IS_COUNTRY_IE_VALID(ieee)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1592 | { |
| 1593 | Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data); |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | // |
| 1598 | // 070305, rcnjko: I update country IE watch dog here because |
| 1599 | // some AP (e.g. Cisco 1242) don't include country IE in their |
| 1600 | // probe response frame. |
| 1601 | // |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1602 | if (IS_EQUAL_CIE_SRC(ieee, addr2) ) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1603 | { |
| 1604 | UPDATE_CIE_WATCHDOG(ieee); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1609 | |
| 1610 | int ieee80211_parse_info_param(struct ieee80211_device *ieee, |
| 1611 | struct ieee80211_info_element *info_element, |
| 1612 | u16 length, |
| 1613 | struct ieee80211_network *network, |
| 1614 | struct ieee80211_rx_stats *stats) |
| 1615 | { |
| 1616 | u8 i; |
| 1617 | short offset; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1618 | u16 tmp_htcap_len=0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1619 | u16 tmp_htinfo_len=0; |
| 1620 | u16 ht_realtek_agg_len=0; |
| 1621 | u8 ht_realtek_agg_buf[MAX_IE_LEN]; |
| 1622 | // u16 broadcom_len = 0; |
| 1623 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1624 | char rates_str[64]; |
| 1625 | char *p; |
| 1626 | #endif |
| 1627 | |
| 1628 | while (length >= sizeof(*info_element)) { |
| 1629 | if (sizeof(*info_element) + info_element->len > length) { |
| 1630 | IEEE80211_DEBUG_MGMT("Info elem: parse failed: " |
| 1631 | "info_element->len + 2 > left : " |
| 1632 | "info_element->len+2=%zd left=%d, id=%d.\n", |
| 1633 | info_element->len + |
| 1634 | sizeof(*info_element), |
| 1635 | length, info_element->id); |
| 1636 | /* We stop processing but don't return an error here |
| 1637 | * because some misbehaviour APs break this rule. ie. |
| 1638 | * Orinoco AP1000. */ |
| 1639 | break; |
| 1640 | } |
| 1641 | |
| 1642 | switch (info_element->id) { |
| 1643 | case MFIE_TYPE_SSID: |
| 1644 | if (ieee80211_is_empty_essid(info_element->data, |
| 1645 | info_element->len)) { |
| 1646 | network->flags |= NETWORK_EMPTY_ESSID; |
| 1647 | break; |
| 1648 | } |
| 1649 | |
| 1650 | network->ssid_len = min(info_element->len, |
| 1651 | (u8) IW_ESSID_MAX_SIZE); |
| 1652 | memcpy(network->ssid, info_element->data, network->ssid_len); |
| 1653 | if (network->ssid_len < IW_ESSID_MAX_SIZE) |
| 1654 | memset(network->ssid + network->ssid_len, 0, |
| 1655 | IW_ESSID_MAX_SIZE - network->ssid_len); |
| 1656 | |
| 1657 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n", |
| 1658 | network->ssid, network->ssid_len); |
| 1659 | break; |
| 1660 | |
| 1661 | case MFIE_TYPE_RATES: |
| 1662 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1663 | p = rates_str; |
| 1664 | #endif |
| 1665 | network->rates_len = min(info_element->len, |
| 1666 | MAX_RATES_LENGTH); |
| 1667 | for (i = 0; i < network->rates_len; i++) { |
| 1668 | network->rates[i] = info_element->data[i]; |
| 1669 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1670 | p += snprintf(p, sizeof(rates_str) - |
| 1671 | (p - rates_str), "%02X ", |
| 1672 | network->rates[i]); |
| 1673 | #endif |
| 1674 | if (ieee80211_is_ofdm_rate |
| 1675 | (info_element->data[i])) { |
| 1676 | network->flags |= NETWORK_HAS_OFDM; |
| 1677 | if (info_element->data[i] & |
| 1678 | IEEE80211_BASIC_RATE_MASK) |
| 1679 | network->flags &= |
| 1680 | ~NETWORK_HAS_CCK; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n", |
| 1685 | rates_str, network->rates_len); |
| 1686 | break; |
| 1687 | |
| 1688 | case MFIE_TYPE_RATES_EX: |
| 1689 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1690 | p = rates_str; |
| 1691 | #endif |
| 1692 | network->rates_ex_len = min(info_element->len, |
| 1693 | MAX_RATES_EX_LENGTH); |
| 1694 | for (i = 0; i < network->rates_ex_len; i++) { |
| 1695 | network->rates_ex[i] = info_element->data[i]; |
| 1696 | #ifdef CONFIG_IEEE80211_DEBUG |
| 1697 | p += snprintf(p, sizeof(rates_str) - |
| 1698 | (p - rates_str), "%02X ", |
Dan Carpenter | c415170 | 2015-03-31 11:58:55 +0300 | [diff] [blame] | 1699 | network->rates_ex[i]); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1700 | #endif |
| 1701 | if (ieee80211_is_ofdm_rate |
| 1702 | (info_element->data[i])) { |
| 1703 | network->flags |= NETWORK_HAS_OFDM; |
| 1704 | if (info_element->data[i] & |
| 1705 | IEEE80211_BASIC_RATE_MASK) |
| 1706 | network->flags &= |
| 1707 | ~NETWORK_HAS_CCK; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n", |
| 1712 | rates_str, network->rates_ex_len); |
| 1713 | break; |
| 1714 | |
| 1715 | case MFIE_TYPE_DS_SET: |
| 1716 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n", |
| 1717 | info_element->data[0]); |
| 1718 | network->channel = info_element->data[0]; |
| 1719 | break; |
| 1720 | |
| 1721 | case MFIE_TYPE_FH_SET: |
| 1722 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n"); |
| 1723 | break; |
| 1724 | |
| 1725 | case MFIE_TYPE_CF_SET: |
| 1726 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n"); |
| 1727 | break; |
| 1728 | |
| 1729 | case MFIE_TYPE_TIM: |
| 1730 | if(info_element->len < 4) |
| 1731 | break; |
| 1732 | |
| 1733 | network->tim.tim_count = info_element->data[0]; |
| 1734 | network->tim.tim_period = info_element->data[1]; |
| 1735 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1736 | network->dtim_period = info_element->data[1]; |
| 1737 | if(ieee->state != IEEE80211_LINKED) |
| 1738 | break; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1739 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1740 | network->last_dtim_sta_time[0] = stats->mac_time[0]; |
| 1741 | network->last_dtim_sta_time[1] = stats->mac_time[1]; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1742 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1743 | network->dtim_data = IEEE80211_DTIM_VALID; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1744 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1745 | if(info_element->data[0] != 0) |
| 1746 | break; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1747 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1748 | if(info_element->data[2] & 1) |
| 1749 | network->dtim_data |= IEEE80211_DTIM_MBCAST; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1750 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1751 | offset = (info_element->data[2] >> 1)*2; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1752 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1753 | if(ieee->assoc_id < 8*offset || |
| 1754 | ieee->assoc_id > 8*(offset + info_element->len -3)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1755 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1756 | break; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1757 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1758 | offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1759 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1760 | if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) |
| 1761 | network->dtim_data |= IEEE80211_DTIM_UCAST; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1762 | |
| 1763 | //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); |
| 1764 | break; |
| 1765 | |
| 1766 | case MFIE_TYPE_ERP: |
| 1767 | network->erp_value = info_element->data[0]; |
| 1768 | network->flags |= NETWORK_HAS_ERP_VALUE; |
| 1769 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n", |
| 1770 | network->erp_value); |
| 1771 | break; |
| 1772 | case MFIE_TYPE_IBSS_SET: |
| 1773 | network->atim_window = info_element->data[0]; |
| 1774 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n", |
| 1775 | network->atim_window); |
| 1776 | break; |
| 1777 | |
| 1778 | case MFIE_TYPE_CHALLENGE: |
| 1779 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n"); |
| 1780 | break; |
| 1781 | |
| 1782 | case MFIE_TYPE_GENERIC: |
| 1783 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n", |
| 1784 | info_element->len); |
| 1785 | if (!ieee80211_parse_qos_info_param_IE(info_element, |
| 1786 | network)) |
| 1787 | break; |
| 1788 | |
| 1789 | if (info_element->len >= 4 && |
| 1790 | info_element->data[0] == 0x00 && |
| 1791 | info_element->data[1] == 0x50 && |
| 1792 | info_element->data[2] == 0xf2 && |
| 1793 | info_element->data[3] == 0x01) { |
| 1794 | network->wpa_ie_len = min(info_element->len + 2, |
| 1795 | MAX_WPA_IE_LEN); |
| 1796 | memcpy(network->wpa_ie, info_element, |
| 1797 | network->wpa_ie_len); |
| 1798 | break; |
| 1799 | } |
| 1800 | |
| 1801 | #ifdef THOMAS_TURBO |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1802 | if (info_element->len == 7 && |
| 1803 | info_element->data[0] == 0x00 && |
| 1804 | info_element->data[1] == 0xe0 && |
| 1805 | info_element->data[2] == 0x4c && |
| 1806 | info_element->data[3] == 0x01 && |
| 1807 | info_element->data[4] == 0x02) { |
| 1808 | network->Turbo_Enable = 1; |
| 1809 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1810 | #endif |
| 1811 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1812 | //for HTcap and HTinfo parameters |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1813 | if(tmp_htcap_len == 0){ |
| 1814 | if(info_element->len >= 4 && |
| 1815 | info_element->data[0] == 0x00 && |
| 1816 | info_element->data[1] == 0x90 && |
| 1817 | info_element->data[2] == 0x4c && |
| 1818 | info_element->data[3] == 0x033){ |
| 1819 | |
| 1820 | tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 1821 | if(tmp_htcap_len != 0){ |
| 1822 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1823 | network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ |
| 1824 | sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; |
| 1825 | memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 1826 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1827 | } |
| 1828 | if(tmp_htcap_len != 0) |
| 1829 | network->bssht.bdSupportHT = true; |
| 1830 | else |
| 1831 | network->bssht.bdSupportHT = false; |
| 1832 | } |
| 1833 | |
| 1834 | |
| 1835 | if(tmp_htinfo_len == 0){ |
| 1836 | if(info_element->len >= 4 && |
| 1837 | info_element->data[0] == 0x00 && |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 1838 | info_element->data[1] == 0x90 && |
| 1839 | info_element->data[2] == 0x4c && |
| 1840 | info_element->data[3] == 0x034){ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1841 | |
| 1842 | tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); |
| 1843 | if(tmp_htinfo_len != 0){ |
| 1844 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; |
| 1845 | if(tmp_htinfo_len){ |
| 1846 | network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ |
| 1847 | sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; |
| 1848 | memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); |
| 1849 | } |
| 1850 | |
| 1851 | } |
| 1852 | |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | if(ieee->aggregation){ |
| 1857 | if(network->bssht.bdSupportHT){ |
| 1858 | if(info_element->len >= 4 && |
| 1859 | info_element->data[0] == 0x00 && |
| 1860 | info_element->data[1] == 0xe0 && |
| 1861 | info_element->data[2] == 0x4c && |
| 1862 | info_element->data[3] == 0x02){ |
| 1863 | |
| 1864 | ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN); |
| 1865 | memcpy(ht_realtek_agg_buf,info_element->data,info_element->len); |
| 1866 | |
| 1867 | } |
| 1868 | if(ht_realtek_agg_len >= 5){ |
| 1869 | network->bssht.bdRT2RTAggregation = true; |
| 1870 | |
| 1871 | if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02)) |
| 1872 | network->bssht.bdRT2RTLongSlotTime = true; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | } |
| 1877 | |
| 1878 | //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0) |
| 1879 | { |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1880 | if ((info_element->len >= 3 && |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1881 | info_element->data[0] == 0x00 && |
| 1882 | info_element->data[1] == 0x05 && |
| 1883 | info_element->data[2] == 0xb5) || |
| 1884 | (info_element->len >= 3 && |
| 1885 | info_element->data[0] == 0x00 && |
| 1886 | info_element->data[1] == 0x0a && |
| 1887 | info_element->data[2] == 0xf7) || |
| 1888 | (info_element->len >= 3 && |
| 1889 | info_element->data[0] == 0x00 && |
| 1890 | info_element->data[1] == 0x10 && |
| 1891 | info_element->data[2] == 0x18)){ |
| 1892 | |
| 1893 | network->broadcom_cap_exist = true; |
| 1894 | |
| 1895 | } |
| 1896 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1897 | if(info_element->len >= 3 && |
| 1898 | info_element->data[0] == 0x00 && |
| 1899 | info_element->data[1] == 0x0c && |
| 1900 | info_element->data[2] == 0x43) |
| 1901 | { |
| 1902 | network->ralink_cap_exist = true; |
| 1903 | } |
| 1904 | else |
| 1905 | network->ralink_cap_exist = false; |
| 1906 | //added by amy for atheros AP |
| 1907 | if((info_element->len >= 3 && |
| 1908 | info_element->data[0] == 0x00 && |
| 1909 | info_element->data[1] == 0x03 && |
| 1910 | info_element->data[2] == 0x7f) || |
| 1911 | (info_element->len >= 3 && |
| 1912 | info_element->data[0] == 0x00 && |
| 1913 | info_element->data[1] == 0x13 && |
| 1914 | info_element->data[2] == 0x74)) |
| 1915 | { |
Joe Perches | f8628a4 | 2014-05-23 22:13:20 -0700 | [diff] [blame] | 1916 | printk("========>%s(): athros AP is exist\n",__func__); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1917 | network->atheros_cap_exist = true; |
| 1918 | } |
| 1919 | else |
| 1920 | network->atheros_cap_exist = false; |
| 1921 | |
| 1922 | if(info_element->len >= 3 && |
| 1923 | info_element->data[0] == 0x00 && |
| 1924 | info_element->data[1] == 0x40 && |
| 1925 | info_element->data[2] == 0x96) |
| 1926 | { |
| 1927 | network->cisco_cap_exist = true; |
| 1928 | } |
| 1929 | else |
| 1930 | network->cisco_cap_exist = false; |
| 1931 | //added by amy for LEAP of cisco |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1932 | if (info_element->len > 4 && |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1933 | info_element->data[0] == 0x00 && |
| 1934 | info_element->data[1] == 0x40 && |
| 1935 | info_element->data[2] == 0x96 && |
| 1936 | info_element->data[3] == 0x01) |
| 1937 | { |
| 1938 | if(info_element->len == 6) |
| 1939 | { |
| 1940 | memcpy(network->CcxRmState, &info_element[4], 2); |
| 1941 | if(network->CcxRmState[0] != 0) |
| 1942 | { |
| 1943 | network->bCcxRmEnable = true; |
| 1944 | } |
| 1945 | else |
| 1946 | network->bCcxRmEnable = false; |
| 1947 | // |
| 1948 | // CCXv4 Table 59-1 MBSSID Masks. |
| 1949 | // |
| 1950 | network->MBssidMask = network->CcxRmState[1] & 0x07; |
| 1951 | if(network->MBssidMask != 0) |
| 1952 | { |
| 1953 | network->bMBssidValid = true; |
| 1954 | network->MBssidMask = 0xff << (network->MBssidMask); |
| 1955 | cpMacAddr(network->MBssid, network->bssid); |
| 1956 | network->MBssid[5] &= network->MBssidMask; |
| 1957 | } |
| 1958 | else |
| 1959 | { |
| 1960 | network->bMBssidValid = false; |
| 1961 | } |
| 1962 | } |
| 1963 | else |
| 1964 | { |
| 1965 | network->bCcxRmEnable = false; |
| 1966 | } |
| 1967 | } |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 1968 | if (info_element->len > 4 && |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1969 | info_element->data[0] == 0x00 && |
| 1970 | info_element->data[1] == 0x40 && |
| 1971 | info_element->data[2] == 0x96 && |
| 1972 | info_element->data[3] == 0x03) |
| 1973 | { |
| 1974 | if(info_element->len == 5) |
| 1975 | { |
| 1976 | network->bWithCcxVerNum = true; |
| 1977 | network->BssCcxVerNumber = info_element->data[4]; |
| 1978 | } |
| 1979 | else |
| 1980 | { |
| 1981 | network->bWithCcxVerNum = false; |
| 1982 | network->BssCcxVerNumber = 0; |
| 1983 | } |
| 1984 | } |
| 1985 | break; |
| 1986 | |
| 1987 | case MFIE_TYPE_RSN: |
| 1988 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n", |
| 1989 | info_element->len); |
| 1990 | network->rsn_ie_len = min(info_element->len + 2, |
| 1991 | MAX_WPA_IE_LEN); |
| 1992 | memcpy(network->rsn_ie, info_element, |
| 1993 | network->rsn_ie_len); |
| 1994 | break; |
| 1995 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 1996 | //HT related element. |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1997 | case MFIE_TYPE_HT_CAP: |
| 1998 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n", |
| 1999 | info_element->len); |
| 2000 | tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); |
| 2001 | if(tmp_htcap_len != 0){ |
| 2002 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; |
| 2003 | network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ |
| 2004 | sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; |
| 2005 | memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); |
| 2006 | |
| 2007 | //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT() |
| 2008 | // windows driver will update WMM parameters each beacon received once connected |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2009 | // Linux driver is a bit different. |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2010 | network->bssht.bdSupportHT = true; |
| 2011 | } |
| 2012 | else |
| 2013 | network->bssht.bdSupportHT = false; |
| 2014 | break; |
| 2015 | |
| 2016 | |
| 2017 | case MFIE_TYPE_HT_INFO: |
| 2018 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n", |
| 2019 | info_element->len); |
| 2020 | tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); |
| 2021 | if(tmp_htinfo_len){ |
| 2022 | network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE; |
| 2023 | network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ |
| 2024 | sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; |
| 2025 | memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); |
| 2026 | } |
| 2027 | break; |
| 2028 | |
| 2029 | case MFIE_TYPE_AIRONET: |
| 2030 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n", |
| 2031 | info_element->len); |
| 2032 | if(info_element->len >IE_CISCO_FLAG_POSITION) |
| 2033 | { |
| 2034 | network->bWithAironetIE = true; |
| 2035 | |
| 2036 | // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23): |
| 2037 | // "A Cisco access point advertises support for CKIP in beacon and probe response packets, |
| 2038 | // by adding an Aironet element and setting one or both of the CKIP negotiation bits." |
| 2039 | if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) || |
| 2040 | (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) ) |
| 2041 | { |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 2042 | network->bCkipSupported = true; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2043 | } |
| 2044 | else |
| 2045 | { |
| 2046 | network->bCkipSupported = false; |
| 2047 | } |
| 2048 | } |
| 2049 | else |
| 2050 | { |
| 2051 | network->bWithAironetIE = false; |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 2052 | network->bCkipSupported = false; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2053 | } |
| 2054 | break; |
| 2055 | case MFIE_TYPE_QOS_PARAMETER: |
| 2056 | printk(KERN_ERR |
| 2057 | "QoS Error need to parse QOS_PARAMETER IE\n"); |
| 2058 | break; |
| 2059 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2060 | case MFIE_TYPE_COUNTRY: |
| 2061 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n", |
| 2062 | info_element->len); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2063 | ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP |
| 2064 | break; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2065 | /* TODO */ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2066 | default: |
| 2067 | IEEE80211_DEBUG_MGMT |
| 2068 | ("Unsupported info element: %s (%d)\n", |
| 2069 | get_info_element_string(info_element->id), |
| 2070 | info_element->id); |
| 2071 | break; |
| 2072 | } |
| 2073 | |
| 2074 | length -= sizeof(*info_element) + info_element->len; |
| 2075 | info_element = |
| 2076 | (struct ieee80211_info_element *)&info_element-> |
| 2077 | data[info_element->len]; |
| 2078 | } |
| 2079 | |
| 2080 | if(!network->atheros_cap_exist && !network->broadcom_cap_exist && |
| 2081 | !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation) |
| 2082 | { |
| 2083 | network->unknown_cap_exist = true; |
| 2084 | } |
| 2085 | else |
| 2086 | { |
| 2087 | network->unknown_cap_exist = false; |
| 2088 | } |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | static inline u8 ieee80211_SignalStrengthTranslate( |
| 2093 | u8 CurrSS |
| 2094 | ) |
| 2095 | { |
| 2096 | u8 RetSS; |
| 2097 | |
| 2098 | // Step 1. Scale mapping. |
| 2099 | if(CurrSS >= 71 && CurrSS <= 100) |
| 2100 | { |
| 2101 | RetSS = 90 + ((CurrSS - 70) / 3); |
| 2102 | } |
| 2103 | else if(CurrSS >= 41 && CurrSS <= 70) |
| 2104 | { |
| 2105 | RetSS = 78 + ((CurrSS - 40) / 3); |
| 2106 | } |
| 2107 | else if(CurrSS >= 31 && CurrSS <= 40) |
| 2108 | { |
| 2109 | RetSS = 66 + (CurrSS - 30); |
| 2110 | } |
| 2111 | else if(CurrSS >= 21 && CurrSS <= 30) |
| 2112 | { |
| 2113 | RetSS = 54 + (CurrSS - 20); |
| 2114 | } |
| 2115 | else if(CurrSS >= 5 && CurrSS <= 20) |
| 2116 | { |
| 2117 | RetSS = 42 + (((CurrSS - 5) * 2) / 3); |
| 2118 | } |
| 2119 | else if(CurrSS == 4) |
| 2120 | { |
| 2121 | RetSS = 36; |
| 2122 | } |
| 2123 | else if(CurrSS == 3) |
| 2124 | { |
| 2125 | RetSS = 27; |
| 2126 | } |
| 2127 | else if(CurrSS == 2) |
| 2128 | { |
| 2129 | RetSS = 18; |
| 2130 | } |
| 2131 | else if(CurrSS == 1) |
| 2132 | { |
| 2133 | RetSS = 9; |
| 2134 | } |
| 2135 | else |
| 2136 | { |
| 2137 | RetSS = CurrSS; |
| 2138 | } |
| 2139 | //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); |
| 2140 | |
| 2141 | // Step 2. Smoothing. |
| 2142 | |
| 2143 | //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); |
| 2144 | |
| 2145 | return RetSS; |
| 2146 | } |
| 2147 | |
Teodora Baluta | 57a8852 | 2013-10-16 01:59:52 +0300 | [diff] [blame] | 2148 | /* 0-100 index */ |
| 2149 | static long ieee80211_translate_todbm(u8 signal_strength_index) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2150 | { |
| 2151 | long signal_power; // in dBm. |
| 2152 | |
| 2153 | // Translate to dBm (x=0.5y-95). |
| 2154 | signal_power = (long)((signal_strength_index + 1) >> 1); |
| 2155 | signal_power -= 95; |
| 2156 | |
| 2157 | return signal_power; |
| 2158 | } |
| 2159 | |
| 2160 | static inline int ieee80211_network_init( |
| 2161 | struct ieee80211_device *ieee, |
| 2162 | struct ieee80211_probe_response *beacon, |
| 2163 | struct ieee80211_network *network, |
| 2164 | struct ieee80211_rx_stats *stats) |
| 2165 | { |
| 2166 | #ifdef CONFIG_IEEE80211_DEBUG |
| 2167 | //char rates_str[64]; |
| 2168 | //char *p; |
| 2169 | #endif |
| 2170 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2171 | network->qos_data.active = 0; |
| 2172 | network->qos_data.supported = 0; |
| 2173 | network->qos_data.param_count = 0; |
| 2174 | network->qos_data.old_param_count = 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2175 | |
| 2176 | /* Pull out fixed field data */ |
| 2177 | memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); |
| 2178 | network->capability = le16_to_cpu(beacon->capability); |
| 2179 | network->last_scanned = jiffies; |
| 2180 | network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]); |
| 2181 | network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]); |
Himangi Saraogi | 1a32444 | 2014-03-05 20:19:07 +0530 | [diff] [blame] | 2182 | network->beacon_interval = le16_to_cpu(beacon->beacon_interval); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2183 | /* Where to pull this? beacon->listen_interval;*/ |
| 2184 | network->listen_interval = 0x0A; |
| 2185 | network->rates_len = network->rates_ex_len = 0; |
| 2186 | network->last_associate = 0; |
| 2187 | network->ssid_len = 0; |
| 2188 | network->flags = 0; |
| 2189 | network->atim_window = 0; |
| 2190 | network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ? |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2191 | 0x3 : 0x0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2192 | network->berp_info_valid = false; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2193 | network->broadcom_cap_exist = false; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2194 | network->ralink_cap_exist = false; |
| 2195 | network->atheros_cap_exist = false; |
| 2196 | network->cisco_cap_exist = false; |
| 2197 | network->unknown_cap_exist = false; |
| 2198 | #ifdef THOMAS_TURBO |
| 2199 | network->Turbo_Enable = 0; |
| 2200 | #endif |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2201 | network->CountryIeLen = 0; |
| 2202 | memset(network->CountryIeBuf, 0, MAX_IE_LEN); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2203 | //Initialize HT parameters |
| 2204 | //ieee80211_ht_initialize(&network->bssht); |
| 2205 | HTInitializeBssDesc(&network->bssht); |
| 2206 | if (stats->freq == IEEE80211_52GHZ_BAND) { |
| 2207 | /* for A band (No DS info) */ |
| 2208 | network->channel = stats->received_channel; |
| 2209 | } else |
| 2210 | network->flags |= NETWORK_HAS_CCK; |
| 2211 | |
Sebastian Hahn | 35997ff | 2012-12-05 21:40:18 +0100 | [diff] [blame] | 2212 | network->wpa_ie_len = 0; |
| 2213 | network->rsn_ie_len = 0; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2214 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2215 | if (ieee80211_parse_info_param |
| 2216 | (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) |
| 2217 | return 1; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2218 | |
| 2219 | network->mode = 0; |
| 2220 | if (stats->freq == IEEE80211_52GHZ_BAND) |
| 2221 | network->mode = IEEE_A; |
| 2222 | else { |
| 2223 | if (network->flags & NETWORK_HAS_OFDM) |
| 2224 | network->mode |= IEEE_G; |
| 2225 | if (network->flags & NETWORK_HAS_CCK) |
| 2226 | network->mode |= IEEE_B; |
| 2227 | } |
| 2228 | |
| 2229 | if (network->mode == 0) { |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2230 | IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' " |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2231 | "network.\n", |
| 2232 | escape_essid(network->ssid, |
| 2233 | network->ssid_len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2234 | network->bssid); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2235 | return 1; |
| 2236 | } |
| 2237 | |
| 2238 | if(network->bssht.bdSupportHT){ |
| 2239 | if(network->mode == IEEE_A) |
| 2240 | network->mode = IEEE_N_5G; |
| 2241 | else if(network->mode & (IEEE_G | IEEE_B)) |
| 2242 | network->mode = IEEE_N_24G; |
| 2243 | } |
| 2244 | if (ieee80211_is_empty_essid(network->ssid, network->ssid_len)) |
| 2245 | network->flags |= NETWORK_EMPTY_ESSID; |
| 2246 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2247 | stats->signal = 30 + (stats->SignalStrength * 70) / 100; |
| 2248 | //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal); |
| 2249 | stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2250 | |
| 2251 | memcpy(&network->stats, stats, sizeof(network->stats)); |
| 2252 | |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
| 2256 | static inline int is_same_network(struct ieee80211_network *src, |
Xenia Ragiadakou | ea77527 | 2013-05-11 21:10:47 +0300 | [diff] [blame] | 2257 | struct ieee80211_network *dst, struct ieee80211_device *ieee) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2258 | { |
| 2259 | /* A network is only a duplicate if the channel, BSSID, ESSID |
| 2260 | * and the capability field (in particular IBSS and BSS) all match. |
| 2261 | * We treat all <hidden> with the same BSSID and channel |
| 2262 | * as one network */ |
| 2263 | return //((src->ssid_len == dst->ssid_len) && |
| 2264 | (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && |
| 2265 | (src->channel == dst->channel) && |
| 2266 | !memcmp(src->bssid, dst->bssid, ETH_ALEN) && |
| 2267 | //!memcmp(src->ssid, dst->ssid, src->ssid_len) && |
| 2268 | (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && |
| 2269 | ((src->capability & WLAN_CAPABILITY_IBSS) == |
| 2270 | (dst->capability & WLAN_CAPABILITY_IBSS)) && |
| 2271 | ((src->capability & WLAN_CAPABILITY_BSS) == |
| 2272 | (dst->capability & WLAN_CAPABILITY_BSS))); |
| 2273 | } |
| 2274 | |
| 2275 | static inline void update_network(struct ieee80211_network *dst, |
| 2276 | struct ieee80211_network *src) |
| 2277 | { |
| 2278 | int qos_active; |
| 2279 | u8 old_param; |
| 2280 | |
| 2281 | memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats)); |
| 2282 | dst->capability = src->capability; |
| 2283 | memcpy(dst->rates, src->rates, src->rates_len); |
| 2284 | dst->rates_len = src->rates_len; |
| 2285 | memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); |
| 2286 | dst->rates_ex_len = src->rates_ex_len; |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2287 | if (src->ssid_len > 0) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2288 | { |
| 2289 | memset(dst->ssid, 0, dst->ssid_len); |
| 2290 | dst->ssid_len = src->ssid_len; |
| 2291 | memcpy(dst->ssid, src->ssid, src->ssid_len); |
| 2292 | } |
| 2293 | dst->mode = src->mode; |
| 2294 | dst->flags = src->flags; |
| 2295 | dst->time_stamp[0] = src->time_stamp[0]; |
| 2296 | dst->time_stamp[1] = src->time_stamp[1]; |
| 2297 | if (src->flags & NETWORK_HAS_ERP_VALUE) |
| 2298 | { |
| 2299 | dst->erp_value = src->erp_value; |
| 2300 | dst->berp_info_valid = src->berp_info_valid = true; |
| 2301 | } |
| 2302 | dst->beacon_interval = src->beacon_interval; |
| 2303 | dst->listen_interval = src->listen_interval; |
| 2304 | dst->atim_window = src->atim_window; |
| 2305 | dst->dtim_period = src->dtim_period; |
| 2306 | dst->dtim_data = src->dtim_data; |
| 2307 | dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0]; |
| 2308 | dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1]; |
| 2309 | memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters)); |
| 2310 | |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 2311 | dst->bssht.bdSupportHT = src->bssht.bdSupportHT; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2312 | dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation; |
| 2313 | dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen; |
| 2314 | memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen); |
| 2315 | dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen; |
| 2316 | memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen); |
| 2317 | dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer; |
| 2318 | dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime; |
| 2319 | dst->broadcom_cap_exist = src->broadcom_cap_exist; |
| 2320 | dst->ralink_cap_exist = src->ralink_cap_exist; |
| 2321 | dst->atheros_cap_exist = src->atheros_cap_exist; |
| 2322 | dst->cisco_cap_exist = src->cisco_cap_exist; |
| 2323 | dst->unknown_cap_exist = src->unknown_cap_exist; |
| 2324 | memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len); |
| 2325 | dst->wpa_ie_len = src->wpa_ie_len; |
| 2326 | memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len); |
| 2327 | dst->rsn_ie_len = src->rsn_ie_len; |
| 2328 | |
| 2329 | dst->last_scanned = jiffies; |
| 2330 | /* qos related parameters */ |
| 2331 | //qos_active = src->qos_data.active; |
| 2332 | qos_active = dst->qos_data.active; |
| 2333 | //old_param = dst->qos_data.old_param_count; |
| 2334 | old_param = dst->qos_data.param_count; |
| 2335 | if(dst->flags & NETWORK_HAS_QOS_MASK) |
| 2336 | memcpy(&dst->qos_data, &src->qos_data, |
| 2337 | sizeof(struct ieee80211_qos_data)); |
| 2338 | else { |
| 2339 | dst->qos_data.supported = src->qos_data.supported; |
| 2340 | dst->qos_data.param_count = src->qos_data.param_count; |
| 2341 | } |
| 2342 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2343 | if (dst->qos_data.supported == 1) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2344 | dst->QoS_Enable = 1; |
| 2345 | if(dst->ssid_len) |
| 2346 | IEEE80211_DEBUG_QOS |
| 2347 | ("QoS the network %s is QoS supported\n", |
| 2348 | dst->ssid); |
| 2349 | else |
| 2350 | IEEE80211_DEBUG_QOS |
| 2351 | ("QoS the network is QoS supported\n"); |
| 2352 | } |
| 2353 | dst->qos_data.active = qos_active; |
| 2354 | dst->qos_data.old_param_count = old_param; |
| 2355 | |
| 2356 | /* dst->last_associate is not overwritten */ |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2357 | dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame. |
Paul Gortmaker | 7c6e3f2 | 2015-04-27 01:25:38 -0400 | [diff] [blame] | 2358 | if (src->wmm_param[0].aci_aifsn|| \ |
| 2359 | src->wmm_param[1].aci_aifsn|| \ |
| 2360 | src->wmm_param[2].aci_aifsn|| \ |
| 2361 | src->wmm_param[3].aci_aifsn) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2362 | memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN); |
| 2363 | } |
| 2364 | //dst->QoS_Enable = src->QoS_Enable; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2365 | #ifdef THOMAS_TURBO |
| 2366 | dst->Turbo_Enable = src->Turbo_Enable; |
| 2367 | #endif |
| 2368 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2369 | dst->CountryIeLen = src->CountryIeLen; |
| 2370 | memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2371 | |
| 2372 | //added by amy for LEAP |
| 2373 | dst->bWithAironetIE = src->bWithAironetIE; |
| 2374 | dst->bCkipSupported = src->bCkipSupported; |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 2375 | memcpy(dst->CcxRmState, src->CcxRmState, 2); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2376 | dst->bCcxRmEnable = src->bCcxRmEnable; |
| 2377 | dst->MBssidMask = src->MBssidMask; |
| 2378 | dst->bMBssidValid = src->bMBssidValid; |
Greg Donald | 0b4ef0a | 2014-08-24 04:57:36 -0500 | [diff] [blame] | 2379 | memcpy(dst->MBssid, src->MBssid, 6); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2380 | dst->bWithCcxVerNum = src->bWithCcxVerNum; |
| 2381 | dst->BssCcxVerNumber = src->BssCcxVerNumber; |
| 2382 | |
| 2383 | } |
| 2384 | |
| 2385 | static inline int is_beacon(__le16 fc) |
| 2386 | { |
| 2387 | return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON); |
| 2388 | } |
| 2389 | |
| 2390 | static inline void ieee80211_process_probe_response( |
| 2391 | struct ieee80211_device *ieee, |
| 2392 | struct ieee80211_probe_response *beacon, |
| 2393 | struct ieee80211_rx_stats *stats) |
| 2394 | { |
| 2395 | struct ieee80211_network network; |
| 2396 | struct ieee80211_network *target; |
| 2397 | struct ieee80211_network *oldest = NULL; |
| 2398 | #ifdef CONFIG_IEEE80211_DEBUG |
| 2399 | struct ieee80211_info_element *info_element = &beacon->info_element[0]; |
| 2400 | #endif |
| 2401 | unsigned long flags; |
| 2402 | short renew; |
| 2403 | //u8 wmm_info; |
| 2404 | |
| 2405 | memset(&network, 0, sizeof(struct ieee80211_network)); |
| 2406 | IEEE80211_DEBUG_SCAN( |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2407 | "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2408 | escape_essid(info_element->data, info_element->len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2409 | beacon->header.addr3, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2410 | (beacon->capability & (1<<0xf)) ? '1' : '0', |
| 2411 | (beacon->capability & (1<<0xe)) ? '1' : '0', |
| 2412 | (beacon->capability & (1<<0xd)) ? '1' : '0', |
| 2413 | (beacon->capability & (1<<0xc)) ? '1' : '0', |
| 2414 | (beacon->capability & (1<<0xb)) ? '1' : '0', |
| 2415 | (beacon->capability & (1<<0xa)) ? '1' : '0', |
| 2416 | (beacon->capability & (1<<0x9)) ? '1' : '0', |
| 2417 | (beacon->capability & (1<<0x8)) ? '1' : '0', |
| 2418 | (beacon->capability & (1<<0x7)) ? '1' : '0', |
| 2419 | (beacon->capability & (1<<0x6)) ? '1' : '0', |
| 2420 | (beacon->capability & (1<<0x5)) ? '1' : '0', |
| 2421 | (beacon->capability & (1<<0x4)) ? '1' : '0', |
| 2422 | (beacon->capability & (1<<0x3)) ? '1' : '0', |
| 2423 | (beacon->capability & (1<<0x2)) ? '1' : '0', |
| 2424 | (beacon->capability & (1<<0x1)) ? '1' : '0', |
| 2425 | (beacon->capability & (1<<0x0)) ? '1' : '0'); |
| 2426 | |
| 2427 | if (ieee80211_network_init(ieee, beacon, &network, stats)) { |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2428 | IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n", |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2429 | escape_essid(info_element->data, |
| 2430 | info_element->len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2431 | beacon->header.addr3, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2432 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
| 2433 | IEEE80211_STYPE_PROBE_RESP ? |
| 2434 | "PROBE RESPONSE" : "BEACON"); |
| 2435 | return; |
| 2436 | } |
| 2437 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2438 | // For Asus EeePc request, |
| 2439 | // (1) if wireless adapter receive get any 802.11d country code in AP beacon, |
| 2440 | // wireless adapter should follow the country code. |
| 2441 | // (2) If there is no any country code in beacon, |
| 2442 | // then wireless adapter should do active scan from ch1~11 and |
| 2443 | // passive scan from ch12~14 |
| 2444 | |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 2445 | if (!IsLegalChannel(ieee, network.channel)) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2446 | return; |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2447 | if (ieee->bGlobalDomain) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2448 | { |
| 2449 | if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP) |
| 2450 | { |
| 2451 | // Case 1: Country code |
| 2452 | if(IS_COUNTRY_IE_VALID(ieee) ) |
| 2453 | { |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 2454 | if (!IsLegalChannel(ieee, network.channel)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2455 | printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel); |
| 2456 | return; |
| 2457 | } |
| 2458 | } |
| 2459 | // Case 2: No any country code. |
| 2460 | else |
| 2461 | { |
| 2462 | // Filter over channel ch12~14 |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2463 | if (network.channel > 11) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2464 | { |
| 2465 | printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel); |
| 2466 | return; |
| 2467 | } |
| 2468 | } |
| 2469 | } |
| 2470 | else |
| 2471 | { |
| 2472 | // Case 1: Country code |
| 2473 | if(IS_COUNTRY_IE_VALID(ieee) ) |
| 2474 | { |
Greg Donald | d59d6f5 | 2014-10-26 15:19:22 -0500 | [diff] [blame] | 2475 | if (!IsLegalChannel(ieee, network.channel)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2476 | printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel); |
| 2477 | return; |
| 2478 | } |
| 2479 | } |
| 2480 | // Case 2: No any country code. |
| 2481 | else |
| 2482 | { |
| 2483 | // Filter over channel ch12~14 |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2484 | if (network.channel > 14) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2485 | { |
| 2486 | printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel); |
| 2487 | return; |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2492 | |
| 2493 | /* The network parsed correctly -- so now we scan our known networks |
| 2494 | * to see if we can find it in our list. |
| 2495 | * |
| 2496 | * NOTE: This search is definitely not optimized. Once its doing |
| 2497 | * the "right thing" we'll optimize it for efficiency if |
| 2498 | * necessary */ |
| 2499 | |
| 2500 | /* Search for this entry in the list and update it if it is |
| 2501 | * already there. */ |
| 2502 | |
| 2503 | spin_lock_irqsave(&ieee->lock, flags); |
| 2504 | |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2505 | if (is_same_network(&ieee->current_network, &network, ieee)) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2506 | update_network(&ieee->current_network, &network); |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2507 | if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2508 | && ieee->current_network.berp_info_valid){ |
| 2509 | if(ieee->current_network.erp_value& ERP_UseProtection) |
| 2510 | ieee->current_network.buseprotection = true; |
| 2511 | else |
| 2512 | ieee->current_network.buseprotection = false; |
| 2513 | } |
| 2514 | if(is_beacon(beacon->header.frame_ctl)) |
| 2515 | { |
| 2516 | if(ieee->state == IEEE80211_LINKED) |
| 2517 | ieee->LinkDetectInfo.NumRecvBcnInPeriod++; |
| 2518 | } |
| 2519 | else //hidden AP |
| 2520 | network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags); |
| 2521 | } |
| 2522 | |
| 2523 | list_for_each_entry(target, &ieee->network_list, list) { |
| 2524 | if (is_same_network(target, &network, ieee)) |
| 2525 | break; |
| 2526 | if ((oldest == NULL) || |
| 2527 | (target->last_scanned < oldest->last_scanned)) |
| 2528 | oldest = target; |
| 2529 | } |
| 2530 | |
| 2531 | /* If we didn't find a match, then get a new network slot to initialize |
| 2532 | * with this beacon's information */ |
| 2533 | if (&target->list == &ieee->network_list) { |
| 2534 | if (list_empty(&ieee->network_free_list)) { |
| 2535 | /* If there are no more slots, expire the oldest */ |
| 2536 | list_del(&oldest->list); |
| 2537 | target = oldest; |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2538 | IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from " |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2539 | "network list.\n", |
| 2540 | escape_essid(target->ssid, |
| 2541 | target->ssid_len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2542 | target->bssid); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2543 | } else { |
| 2544 | /* Otherwise just pull from the free list */ |
| 2545 | target = list_entry(ieee->network_free_list.next, |
| 2546 | struct ieee80211_network, list); |
| 2547 | list_del(ieee->network_free_list.next); |
| 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | #ifdef CONFIG_IEEE80211_DEBUG |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2552 | IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n", |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2553 | escape_essid(network.ssid, |
| 2554 | network.ssid_len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2555 | network.bssid, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2556 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
| 2557 | IEEE80211_STYPE_PROBE_RESP ? |
| 2558 | "PROBE RESPONSE" : "BEACON"); |
| 2559 | #endif |
| 2560 | memcpy(target, &network, sizeof(*target)); |
| 2561 | list_add_tail(&target->list, &ieee->network_list); |
| 2562 | if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) |
| 2563 | ieee80211_softmac_new_net(ieee,&network); |
| 2564 | } else { |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2565 | IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n", |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2566 | escape_essid(target->ssid, |
| 2567 | target->ssid_len), |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 2568 | target->bssid, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2569 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
| 2570 | IEEE80211_STYPE_PROBE_RESP ? |
| 2571 | "PROBE RESPONSE" : "BEACON"); |
| 2572 | |
| 2573 | /* we have an entry and we are going to update it. But this entry may |
| 2574 | * be already expired. In this case we do the same as we found a new |
| 2575 | * net and call the new_net handler |
| 2576 | */ |
| 2577 | renew = !time_after(target->last_scanned + ieee->scan_age, jiffies); |
| 2578 | //YJ,add,080819,for hidden ap |
| 2579 | if(is_beacon(beacon->header.frame_ctl) == 0) |
| 2580 | network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags); |
| 2581 | //if(strncmp(network.ssid, "linksys-c",9) == 0) |
| 2582 | // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags); |
| 2583 | if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \ |
| 2584 | && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\ |
| 2585 | ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK)))) |
| 2586 | renew = 1; |
| 2587 | //YJ,add,080819,for hidden ap,end |
| 2588 | |
| 2589 | update_network(target, &network); |
| 2590 | if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)) |
| 2591 | ieee80211_softmac_new_net(ieee,&network); |
| 2592 | } |
| 2593 | |
| 2594 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 2595 | if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\ |
| 2596 | (ieee->state == IEEE80211_LINKED)) { |
Haneen Mohammed | dde48b9 | 2015-03-25 08:07:06 +0300 | [diff] [blame] | 2597 | if (ieee->handle_beacon != NULL) { |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2598 | ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network); |
| 2599 | } |
| 2600 | } |
| 2601 | } |
| 2602 | |
| 2603 | void ieee80211_rx_mgt(struct ieee80211_device *ieee, |
Paul Gortmaker | 5c2918a | 2015-04-27 01:25:36 -0400 | [diff] [blame] | 2604 | struct rtl_80211_hdr_4addr *header, |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2605 | struct ieee80211_rx_stats *stats) |
| 2606 | { |
| 2607 | switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { |
| 2608 | |
| 2609 | case IEEE80211_STYPE_BEACON: |
| 2610 | IEEE80211_DEBUG_MGMT("received BEACON (%d)\n", |
| 2611 | WLAN_FC_GET_STYPE(header->frame_ctl)); |
| 2612 | IEEE80211_DEBUG_SCAN("Beacon\n"); |
| 2613 | ieee80211_process_probe_response( |
| 2614 | ieee, (struct ieee80211_probe_response *)header, stats); |
| 2615 | break; |
| 2616 | |
| 2617 | case IEEE80211_STYPE_PROBE_RESP: |
| 2618 | IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n", |
| 2619 | WLAN_FC_GET_STYPE(header->frame_ctl)); |
| 2620 | IEEE80211_DEBUG_SCAN("Probe response\n"); |
| 2621 | ieee80211_process_probe_response( |
| 2622 | ieee, (struct ieee80211_probe_response *)header, stats); |
| 2623 | break; |
| 2624 | |
| 2625 | } |
| 2626 | } |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 2627 | EXPORT_SYMBOL(ieee80211_rx_mgt); |