Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
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 | ||
587b36d3 AP |
20 | #include <uapi/linux/ipv6.h> |
21 | #include <net/ndisc.h> | |
5e6e3a92 BZ |
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 | ||
587b36d3 AP |
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; | |
39 | struct ethhdr *eth_hdr; | |
40 | struct ipv6hdr *ipv6; | |
41 | struct icmp6hdr *icmpv6; | |
42 | ||
43 | eth_hdr = (struct ethhdr *)skb->data; | |
44 | switch (ntohs(eth_hdr->h_proto)) { | |
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 | ||
5e6e3a92 BZ |
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 | */ | |
f3b369e4 | 83 | int mwifiex_process_rx_packet(struct mwifiex_private *priv, |
5e6e3a92 BZ |
84 | struct sk_buff *skb) |
85 | { | |
270e58e8 | 86 | int ret; |
5e6e3a92 BZ |
87 | struct rx_packet_hdr *rx_pkt_hdr; |
88 | struct rxpd *local_rx_pd; | |
89 | int hdr_chop; | |
90 | struct ethhdr *eth_hdr; | |
91 | u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
92 | ||
93 | local_rx_pd = (struct rxpd *) (skb->data); | |
94 | ||
ed1ea6f4 AK |
95 | rx_pkt_hdr = (void *)local_rx_pd + |
96 | le16_to_cpu(local_rx_pd->rx_pkt_offset); | |
5e6e3a92 BZ |
97 | |
98 | if (!memcmp(&rx_pkt_hdr->rfc1042_hdr, | |
99 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) { | |
100 | /* | |
101 | * Replace the 803 header and rfc1042 header (llc/snap) with an | |
102 | * EthernetII header, keep the src/dst and snap_type | |
103 | * (ethertype). | |
104 | * The firmware only passes up SNAP frames converting | |
105 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. | |
106 | * To create the Ethernet II, just move the src, dst address | |
107 | * right before the snap_type. | |
108 | */ | |
109 | eth_hdr = (struct ethhdr *) | |
110 | ((u8 *) &rx_pkt_hdr->eth803_hdr | |
111 | + sizeof(rx_pkt_hdr->eth803_hdr) + | |
112 | sizeof(rx_pkt_hdr->rfc1042_hdr) | |
113 | - sizeof(rx_pkt_hdr->eth803_hdr.h_dest) | |
114 | - sizeof(rx_pkt_hdr->eth803_hdr.h_source) | |
115 | - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type)); | |
116 | ||
117 | memcpy(eth_hdr->h_source, rx_pkt_hdr->eth803_hdr.h_source, | |
118 | sizeof(eth_hdr->h_source)); | |
119 | memcpy(eth_hdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest, | |
120 | sizeof(eth_hdr->h_dest)); | |
121 | ||
122 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap | |
123 | header that was removed. */ | |
124 | hdr_chop = (u8 *) eth_hdr - (u8 *) local_rx_pd; | |
125 | } else { | |
126 | /* Chop off the rxpd */ | |
127 | hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr - | |
128 | (u8 *) local_rx_pd; | |
129 | } | |
130 | ||
131 | /* Chop off the leading header bytes so the it points to the start of | |
132 | either the reconstructed EthII frame or the 802.2/llc/snap frame */ | |
133 | skb_pull(skb, hdr_chop); | |
134 | ||
587b36d3 AP |
135 | if (priv->hs2_enabled && |
136 | mwifiex_discard_gratuitous_arp(priv, skb)) { | |
137 | dev_dbg(priv->adapter->dev, "Bypassed Gratuitous ARP\n"); | |
138 | dev_kfree_skb_any(skb); | |
139 | return 0; | |
140 | } | |
141 | ||
5e6e3a92 BZ |
142 | priv->rxpd_rate = local_rx_pd->rx_rate; |
143 | ||
144 | priv->rxpd_htinfo = local_rx_pd->ht_info; | |
145 | ||
f3b369e4 | 146 | ret = mwifiex_recv_packet(priv, skb); |
5e6e3a92 | 147 | if (ret == -1) |
f3b369e4 | 148 | dev_err(priv->adapter->dev, "recv packet failed\n"); |
5e6e3a92 BZ |
149 | |
150 | return ret; | |
151 | } | |
152 | ||
153 | /* | |
154 | * This function processes the received buffer. | |
155 | * | |
156 | * The function looks into the RxPD and performs sanity tests on the | |
157 | * received buffer to ensure its a valid packet, before processing it | |
158 | * further. If the packet is determined to be aggregated, it is | |
159 | * de-aggregated accordingly. Non-unicast packets are sent directly to | |
160 | * the kernel/upper layers. Unicast packets are handed over to the | |
161 | * Rx reordering routine if 11n is enabled. | |
162 | * | |
163 | * The completion callback is called after processing in complete. | |
164 | */ | |
f3b369e4 | 165 | int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv, |
5e6e3a92 BZ |
166 | struct sk_buff *skb) |
167 | { | |
f3b369e4 | 168 | struct mwifiex_adapter *adapter = priv->adapter; |
5e6e3a92 BZ |
169 | int ret = 0; |
170 | struct rxpd *local_rx_pd; | |
5e6e3a92 BZ |
171 | struct rx_packet_hdr *rx_pkt_hdr; |
172 | u8 ta[ETH_ALEN]; | |
ed1ea6f4 | 173 | u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num; |
8ed13033 | 174 | |
5e6e3a92 | 175 | local_rx_pd = (struct rxpd *) (skb->data); |
ed1ea6f4 AK |
176 | rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type); |
177 | rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset); | |
178 | rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length); | |
179 | seq_num = le16_to_cpu(local_rx_pd->seq_num); | |
5e6e3a92 | 180 | |
ed1ea6f4 | 181 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset; |
5e6e3a92 | 182 | |
ed1ea6f4 AK |
183 | if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) { |
184 | dev_err(adapter->dev, | |
185 | "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n", | |
186 | skb->len, rx_pkt_offset, rx_pkt_length); | |
5e6e3a92 | 187 | priv->stats.rx_dropped++; |
4daffe35 AK |
188 | |
189 | if (adapter->if_ops.data_complete) | |
190 | adapter->if_ops.data_complete(adapter, skb); | |
191 | else | |
192 | dev_kfree_skb_any(skb); | |
193 | ||
5e6e3a92 BZ |
194 | return ret; |
195 | } | |
3b8ab88a | 196 | |
ed1ea6f4 | 197 | if (rx_pkt_type == PKT_TYPE_AMSDU) { |
3b8ab88a YAP |
198 | struct sk_buff_head list; |
199 | struct sk_buff *rx_skb; | |
200 | ||
201 | __skb_queue_head_init(&list); | |
202 | ||
ed1ea6f4 AK |
203 | skb_pull(skb, rx_pkt_offset); |
204 | skb_trim(skb, rx_pkt_length); | |
3b8ab88a YAP |
205 | |
206 | ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr, | |
c65a30f3 | 207 | priv->wdev->iftype, 0, false); |
3b8ab88a YAP |
208 | |
209 | while (!skb_queue_empty(&list)) { | |
210 | rx_skb = __skb_dequeue(&list); | |
f3b369e4 | 211 | ret = mwifiex_recv_packet(priv, rx_skb); |
3b8ab88a YAP |
212 | if (ret == -1) |
213 | dev_err(adapter->dev, "Rx of A-MSDU failed"); | |
214 | } | |
215 | return 0; | |
2dbaf751 | 216 | } else if (rx_pkt_type == PKT_TYPE_MGMT) { |
f3b369e4 | 217 | ret = mwifiex_process_mgmt_packet(priv, skb); |
2dbaf751 SP |
218 | if (ret) |
219 | dev_err(adapter->dev, "Rx of mgmt packet failed"); | |
220 | dev_kfree_skb_any(skb); | |
221 | return ret; | |
5e6e3a92 | 222 | } |
3b8ab88a | 223 | |
5e6e3a92 BZ |
224 | /* |
225 | * If the packet is not an unicast packet then send the packet | |
226 | * directly to os. Don't pass thru rx reordering | |
227 | */ | |
228 | if (!IS_11N_ENABLED(priv) || | |
229 | memcmp(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN)) { | |
f3b369e4 | 230 | mwifiex_process_rx_packet(priv, skb); |
5e6e3a92 BZ |
231 | return ret; |
232 | } | |
233 | ||
234 | if (mwifiex_queuing_ra_based(priv)) { | |
235 | memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN); | |
236 | } else { | |
237 | if (rx_pkt_type != PKT_TYPE_BAR) | |
ed1ea6f4 | 238 | priv->rx_seq[local_rx_pd->priority] = seq_num; |
5e6e3a92 BZ |
239 | memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address, |
240 | ETH_ALEN); | |
241 | } | |
242 | ||
243 | /* Reorder and send to OS */ | |
ed1ea6f4 AK |
244 | ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority, |
245 | ta, (u8) rx_pkt_type, skb); | |
5e6e3a92 | 246 | |
4daffe35 AK |
247 | if (ret || (rx_pkt_type == PKT_TYPE_BAR)) { |
248 | if (adapter->if_ops.data_complete) | |
249 | adapter->if_ops.data_complete(adapter, skb); | |
250 | else | |
251 | dev_kfree_skb_any(skb); | |
252 | } | |
8ed13033 YAP |
253 | |
254 | if (ret) | |
255 | priv->stats.rx_dropped++; | |
5e6e3a92 BZ |
256 | |
257 | return ret; | |
258 | } |