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