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 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "11n_aggr.h" |
| 26 | #include "11n_rxreorder.h" |
| 27 | |
| 28 | /* |
| 29 | * This function processes the received packet and forwards it |
| 30 | * to kernel/upper layer. |
| 31 | * |
| 32 | * This function parses through the received packet and determines |
| 33 | * if it is a debug packet or normal packet. |
| 34 | * |
| 35 | * For non-debug packets, the function chops off unnecessary leading |
| 36 | * header bytes, reconstructs the packet as an ethernet frame or |
| 37 | * 802.2/llc/snap frame as required, and sends it to kernel/upper layer. |
| 38 | * |
| 39 | * The completion callback is called after processing in complete. |
| 40 | */ |
| 41 | int mwifiex_process_rx_packet(struct mwifiex_adapter *adapter, |
| 42 | struct sk_buff *skb) |
| 43 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 44 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 45 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 46 | struct mwifiex_private *priv = |
| 47 | mwifiex_get_priv_by_id(adapter, rx_info->bss_num, |
| 48 | rx_info->bss_type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 49 | struct rx_packet_hdr *rx_pkt_hdr; |
| 50 | struct rxpd *local_rx_pd; |
| 51 | int hdr_chop; |
| 52 | struct ethhdr *eth_hdr; |
| 53 | u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 54 | |
| 55 | local_rx_pd = (struct rxpd *) (skb->data); |
| 56 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 57 | rx_pkt_hdr = (void *)local_rx_pd + |
| 58 | le16_to_cpu(local_rx_pd->rx_pkt_offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 59 | |
| 60 | if (!memcmp(&rx_pkt_hdr->rfc1042_hdr, |
| 61 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) { |
| 62 | /* |
| 63 | * Replace the 803 header and rfc1042 header (llc/snap) with an |
| 64 | * EthernetII header, keep the src/dst and snap_type |
| 65 | * (ethertype). |
| 66 | * The firmware only passes up SNAP frames converting |
| 67 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. |
| 68 | * To create the Ethernet II, just move the src, dst address |
| 69 | * right before the snap_type. |
| 70 | */ |
| 71 | eth_hdr = (struct ethhdr *) |
| 72 | ((u8 *) &rx_pkt_hdr->eth803_hdr |
| 73 | + sizeof(rx_pkt_hdr->eth803_hdr) + |
| 74 | sizeof(rx_pkt_hdr->rfc1042_hdr) |
| 75 | - sizeof(rx_pkt_hdr->eth803_hdr.h_dest) |
| 76 | - sizeof(rx_pkt_hdr->eth803_hdr.h_source) |
| 77 | - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type)); |
| 78 | |
| 79 | memcpy(eth_hdr->h_source, rx_pkt_hdr->eth803_hdr.h_source, |
| 80 | sizeof(eth_hdr->h_source)); |
| 81 | memcpy(eth_hdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest, |
| 82 | sizeof(eth_hdr->h_dest)); |
| 83 | |
| 84 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap |
| 85 | header that was removed. */ |
| 86 | hdr_chop = (u8 *) eth_hdr - (u8 *) local_rx_pd; |
| 87 | } else { |
| 88 | /* Chop off the rxpd */ |
| 89 | hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr - |
| 90 | (u8 *) local_rx_pd; |
| 91 | } |
| 92 | |
| 93 | /* Chop off the leading header bytes so the it points to the start of |
| 94 | either the reconstructed EthII frame or the 802.2/llc/snap frame */ |
| 95 | skb_pull(skb, hdr_chop); |
| 96 | |
| 97 | priv->rxpd_rate = local_rx_pd->rx_rate; |
| 98 | |
| 99 | priv->rxpd_htinfo = local_rx_pd->ht_info; |
| 100 | |
| 101 | ret = mwifiex_recv_packet(adapter, skb); |
| 102 | if (ret == -1) |
| 103 | dev_err(adapter->dev, "recv packet failed\n"); |
| 104 | |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * This function processes the received buffer. |
| 110 | * |
| 111 | * The function looks into the RxPD and performs sanity tests on the |
| 112 | * received buffer to ensure its a valid packet, before processing it |
| 113 | * further. If the packet is determined to be aggregated, it is |
| 114 | * de-aggregated accordingly. Non-unicast packets are sent directly to |
| 115 | * the kernel/upper layers. Unicast packets are handed over to the |
| 116 | * Rx reordering routine if 11n is enabled. |
| 117 | * |
| 118 | * The completion callback is called after processing in complete. |
| 119 | */ |
| 120 | int mwifiex_process_sta_rx_packet(struct mwifiex_adapter *adapter, |
| 121 | struct sk_buff *skb) |
| 122 | { |
| 123 | int ret = 0; |
| 124 | struct rxpd *local_rx_pd; |
| 125 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); |
| 126 | struct rx_packet_hdr *rx_pkt_hdr; |
| 127 | u8 ta[ETH_ALEN]; |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 128 | u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num; |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 129 | struct mwifiex_private *priv = |
| 130 | mwifiex_get_priv_by_id(adapter, rx_info->bss_num, |
| 131 | rx_info->bss_type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 132 | |
Yogesh Ashok Powar | 8ed1303 | 2011-11-07 21:41:10 -0800 | [diff] [blame] | 133 | if (!priv) |
| 134 | return -1; |
| 135 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 136 | local_rx_pd = (struct rxpd *) (skb->data); |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 137 | rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type); |
| 138 | rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset); |
| 139 | rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length); |
| 140 | seq_num = le16_to_cpu(local_rx_pd->seq_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 141 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 142 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 143 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 144 | if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) { |
| 145 | dev_err(adapter->dev, |
| 146 | "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n", |
| 147 | skb->len, rx_pkt_offset, rx_pkt_length); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 148 | priv->stats.rx_dropped++; |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 149 | |
| 150 | if (adapter->if_ops.data_complete) |
| 151 | adapter->if_ops.data_complete(adapter, skb); |
| 152 | else |
| 153 | dev_kfree_skb_any(skb); |
| 154 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 155 | return ret; |
| 156 | } |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 157 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 158 | if (rx_pkt_type == PKT_TYPE_AMSDU) { |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 159 | struct sk_buff_head list; |
| 160 | struct sk_buff *rx_skb; |
| 161 | |
| 162 | __skb_queue_head_init(&list); |
| 163 | |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 164 | skb_pull(skb, rx_pkt_offset); |
| 165 | skb_trim(skb, rx_pkt_length); |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 166 | |
| 167 | ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr, |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 168 | priv->wdev->iftype, 0, false); |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 169 | |
| 170 | while (!skb_queue_empty(&list)) { |
| 171 | rx_skb = __skb_dequeue(&list); |
| 172 | ret = mwifiex_recv_packet(adapter, rx_skb); |
| 173 | if (ret == -1) |
| 174 | dev_err(adapter->dev, "Rx of A-MSDU failed"); |
| 175 | } |
| 176 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 177 | } |
Yogesh Ashok Powar | 3b8ab88 | 2011-05-13 11:22:32 -0700 | [diff] [blame] | 178 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 179 | /* |
| 180 | * If the packet is not an unicast packet then send the packet |
| 181 | * directly to os. Don't pass thru rx reordering |
| 182 | */ |
| 183 | if (!IS_11N_ENABLED(priv) || |
| 184 | memcmp(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN)) { |
| 185 | mwifiex_process_rx_packet(adapter, skb); |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | if (mwifiex_queuing_ra_based(priv)) { |
| 190 | memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN); |
| 191 | } else { |
| 192 | if (rx_pkt_type != PKT_TYPE_BAR) |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 193 | priv->rx_seq[local_rx_pd->priority] = seq_num; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 194 | memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address, |
| 195 | ETH_ALEN); |
| 196 | } |
| 197 | |
| 198 | /* Reorder and send to OS */ |
Amitkumar Karwar | ed1ea6f | 2012-08-03 18:06:02 -0700 | [diff] [blame^] | 199 | ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority, |
| 200 | ta, (u8) rx_pkt_type, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 201 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 202 | if (ret || (rx_pkt_type == PKT_TYPE_BAR)) { |
| 203 | if (adapter->if_ops.data_complete) |
| 204 | adapter->if_ops.data_complete(adapter, skb); |
| 205 | else |
| 206 | dev_kfree_skb_any(skb); |
| 207 | } |
Yogesh Ashok Powar | 8ed1303 | 2011-11-07 21:41:10 -0800 | [diff] [blame] | 208 | |
| 209 | if (ret) |
| 210 | priv->stats.rx_dropped++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 211 | |
| 212 | return ret; |
| 213 | } |