Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: station RX data handling |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 20 | #include <uapi/linux/ipv6.h> |
| 21 | #include <net/ndisc.h> |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 22 | #include "decl.h" |
| 23 | #include "ioctl.h" |
| 24 | #include "util.h" |
| 25 | #include "fw.h" |
| 26 | #include "main.h" |
| 27 | #include "11n_aggr.h" |
| 28 | #include "11n_rxreorder.h" |
| 29 | |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 30 | /* This function checks if a frame is IPv4 ARP or IPv6 Neighbour advertisement |
| 31 | * frame. If frame has both source and destination mac address as same, this |
| 32 | * function drops such gratuitous frames. |
| 33 | */ |
| 34 | static bool |
| 35 | mwifiex_discard_gratuitous_arp(struct mwifiex_private *priv, |
| 36 | struct sk_buff *skb) |
| 37 | { |
| 38 | const struct mwifiex_arp_eth_header *arp; |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 39 | struct ethhdr *eth; |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 40 | struct ipv6hdr *ipv6; |
| 41 | struct icmp6hdr *icmpv6; |
| 42 | |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 43 | eth = (struct ethhdr *)skb->data; |
| 44 | switch (ntohs(eth->h_proto)) { |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 45 | case ETH_P_ARP: |
| 46 | arp = (void *)(skb->data + sizeof(struct ethhdr)); |
| 47 | if (arp->hdr.ar_op == htons(ARPOP_REPLY) || |
| 48 | arp->hdr.ar_op == htons(ARPOP_REQUEST)) { |
| 49 | if (!memcmp(arp->ar_sip, arp->ar_tip, 4)) |
| 50 | return true; |
| 51 | } |
| 52 | break; |
| 53 | case ETH_P_IPV6: |
| 54 | ipv6 = (void *)(skb->data + sizeof(struct ethhdr)); |
| 55 | icmpv6 = (void *)(skb->data + sizeof(struct ethhdr) + |
| 56 | sizeof(struct ipv6hdr)); |
| 57 | if (NDISC_NEIGHBOUR_ADVERTISEMENT == icmpv6->icmp6_type) { |
| 58 | if (!memcmp(&ipv6->saddr, &ipv6->daddr, |
| 59 | sizeof(struct in6_addr))) |
| 60 | return true; |
| 61 | } |
| 62 | break; |
| 63 | default: |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 70 | /* |
| 71 | * This function processes the received packet and forwards it |
| 72 | * to kernel/upper layer. |
| 73 | * |
| 74 | * This function parses through the received packet and determines |
| 75 | * if it is a debug packet or normal packet. |
| 76 | * |
| 77 | * For non-debug packets, the function chops off unnecessary leading |
| 78 | * header bytes, reconstructs the packet as an ethernet frame or |
| 79 | * 802.2/llc/snap frame as required, and sends it to kernel/upper layer. |
| 80 | * |
| 81 | * The completion callback is called after processing in complete. |
| 82 | */ |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 83 | int mwifiex_process_rx_packet(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 84 | struct sk_buff *skb) |
| 85 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 86 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 87 | struct rx_packet_hdr *rx_pkt_hdr; |
| 88 | struct rxpd *local_rx_pd; |
| 89 | int hdr_chop; |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 90 | struct ethhdr *eth; |
Avinash Patil | 5f2caaf | 2014-02-07 16:27:33 -0800 | [diff] [blame] | 91 | u16 rx_pkt_off, rx_pkt_len; |
| 92 | u8 *offset; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 93 | |
| 94 | local_rx_pd = (struct rxpd *) (skb->data); |
| 95 | |
Avinash Patil | 5f2caaf | 2014-02-07 16:27:33 -0800 | [diff] [blame] | 96 | rx_pkt_off = le16_to_cpu(local_rx_pd->rx_pkt_offset); |
| 97 | rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length); |
| 98 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 99 | |
Amitkumar Karwar | c613d16 | 2013-12-02 23:17:51 -0800 | [diff] [blame] | 100 | if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header, |
| 101 | sizeof(bridge_tunnel_header))) || |
| 102 | (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header, |
| 103 | sizeof(rfc1042_header)) && |
| 104 | ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP && |
| 105 | ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 106 | /* |
| 107 | * Replace the 803 header and rfc1042 header (llc/snap) with an |
| 108 | * EthernetII header, keep the src/dst and snap_type |
| 109 | * (ethertype). |
| 110 | * The firmware only passes up SNAP frames converting |
| 111 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. |
| 112 | * To create the Ethernet II, just move the src, dst address |
| 113 | * right before the snap_type. |
| 114 | */ |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 115 | eth = (struct ethhdr *) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 116 | ((u8 *) &rx_pkt_hdr->eth803_hdr |
| 117 | + sizeof(rx_pkt_hdr->eth803_hdr) + |
| 118 | sizeof(rx_pkt_hdr->rfc1042_hdr) |
| 119 | - sizeof(rx_pkt_hdr->eth803_hdr.h_dest) |
| 120 | - sizeof(rx_pkt_hdr->eth803_hdr.h_source) |
| 121 | - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type)); |
| 122 | |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 123 | memcpy(eth->h_source, rx_pkt_hdr->eth803_hdr.h_source, |
| 124 | sizeof(eth->h_source)); |
| 125 | memcpy(eth->h_dest, rx_pkt_hdr->eth803_hdr.h_dest, |
| 126 | sizeof(eth->h_dest)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 127 | |
| 128 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap |
| 129 | header that was removed. */ |
Bing Zhao | f8eb5ee | 2013-12-02 23:17:52 -0800 | [diff] [blame] | 130 | hdr_chop = (u8 *) eth - (u8 *) local_rx_pd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 131 | } else { |
| 132 | /* Chop off the rxpd */ |
| 133 | hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr - |
| 134 | (u8 *) local_rx_pd; |
| 135 | } |
| 136 | |
| 137 | /* Chop off the leading header bytes so the it points to the start of |
| 138 | either the reconstructed EthII frame or the 802.2/llc/snap frame */ |
| 139 | skb_pull(skb, hdr_chop); |
| 140 | |
Avinash Patil | 587b36d | 2013-08-23 16:48:23 -0700 | [diff] [blame] | 141 | if (priv->hs2_enabled && |
| 142 | mwifiex_discard_gratuitous_arp(priv, skb)) { |
| 143 | dev_dbg(priv->adapter->dev, "Bypassed Gratuitous ARP\n"); |
| 144 | dev_kfree_skb_any(skb); |
| 145 | return 0; |
| 146 | } |
| 147 | |
Avinash Patil | 5f2caaf | 2014-02-07 16:27:33 -0800 | [diff] [blame] | 148 | if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
| 149 | ntohs(rx_pkt_hdr->eth803_hdr.h_proto) == ETH_P_TDLS) { |
| 150 | offset = (u8 *)local_rx_pd + rx_pkt_off; |
| 151 | mwifiex_process_tdls_action_frame(priv, offset, rx_pkt_len); |
| 152 | } |
| 153 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 154 | priv->rxpd_rate = local_rx_pd->rx_rate; |
| 155 | |
| 156 | priv->rxpd_htinfo = local_rx_pd->ht_info; |
| 157 | |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 158 | ret = mwifiex_recv_packet(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 159 | if (ret == -1) |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 160 | dev_err(priv->adapter->dev, "recv packet failed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 161 | |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * This function processes the received buffer. |
| 167 | * |
| 168 | * The function looks into the RxPD and performs sanity tests on the |
| 169 | * received buffer to ensure its a valid packet, before processing it |
| 170 | * further. If the packet is determined to be aggregated, it is |
| 171 | * de-aggregated accordingly. Non-unicast packets are sent directly to |
| 172 | * the kernel/upper layers. Unicast packets are handed over to the |
| 173 | * Rx reordering routine if 11n is enabled. |
| 174 | * |
| 175 | * The completion callback is called after processing in complete. |
| 176 | */ |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 177 | int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 178 | struct sk_buff *skb) |
| 179 | { |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 180 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 181 | int ret = 0; |
| 182 | struct rxpd *local_rx_pd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 183 | struct rx_packet_hdr *rx_pkt_hdr; |
| 184 | u8 ta[ETH_ALEN]; |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 185 | u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num; |
Yogesh Ashok Powar | 8ed1303 | 2011-11-07 21:41:10 -0800 | [diff] [blame] | 186 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 187 | local_rx_pd = (struct rxpd *) (skb->data); |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 188 | rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type); |
| 189 | rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset); |
| 190 | rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length); |
| 191 | seq_num = le16_to_cpu(local_rx_pd->seq_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 192 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 193 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 194 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 195 | if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) { |
| 196 | dev_err(adapter->dev, |
| 197 | "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n", |
| 198 | skb->len, rx_pkt_offset, rx_pkt_length); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 199 | priv->stats.rx_dropped++; |
Ujjal Roy | ca8d6df | 2013-12-02 23:17:53 -0800 | [diff] [blame] | 200 | dev_kfree_skb_any(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 201 | return ret; |
| 202 | } |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 203 | |
Amitkumar Karwar | 4c9f9fb | 2014-03-07 19:41:31 -0800 | [diff] [blame] | 204 | if (rx_pkt_type == PKT_TYPE_MGMT) { |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 205 | ret = mwifiex_process_mgmt_packet(priv, skb); |
Stone Piao | 2dbaf75 | 2012-09-25 20:23:35 -0700 | [diff] [blame] | 206 | if (ret) |
| 207 | dev_err(adapter->dev, "Rx of mgmt packet failed"); |
| 208 | dev_kfree_skb_any(skb); |
| 209 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 210 | } |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 211 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 212 | /* |
| 213 | * If the packet is not an unicast packet then send the packet |
| 214 | * directly to os. Don't pass thru rx reordering |
| 215 | */ |
| 216 | if (!IS_11N_ENABLED(priv) || |
dingtianhong | fcad766 | 2013-12-26 19:41:27 +0800 | [diff] [blame] | 217 | !ether_addr_equal_unaligned(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest)) { |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 218 | mwifiex_process_rx_packet(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | if (mwifiex_queuing_ra_based(priv)) { |
| 223 | memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN); |
| 224 | } else { |
| 225 | if (rx_pkt_type != PKT_TYPE_BAR) |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 226 | priv->rx_seq[local_rx_pd->priority] = seq_num; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 227 | memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address, |
| 228 | ETH_ALEN); |
| 229 | } |
| 230 | |
| 231 | /* Reorder and send to OS */ |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame] | 232 | ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority, |
| 233 | ta, (u8) rx_pkt_type, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 234 | |
Ujjal Roy | ca8d6df | 2013-12-02 23:17:53 -0800 | [diff] [blame] | 235 | if (ret || (rx_pkt_type == PKT_TYPE_BAR)) |
| 236 | dev_kfree_skb_any(skb); |
Yogesh Ashok Powar | 8ed1303 | 2011-11-07 21:41:10 -0800 | [diff] [blame] | 237 | |
| 238 | if (ret) |
| 239 | priv->stats.rx_dropped++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 240 | |
| 241 | return ret; |
| 242 | } |