Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: station RX data handling | |
3 | * | |
65da33f5 | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
5e6e3a92 BZ |
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; | |
f8eb5ee5 | 39 | struct ethhdr *eth; |
587b36d3 AP |
40 | struct ipv6hdr *ipv6; |
41 | struct icmp6hdr *icmpv6; | |
42 | ||
f8eb5ee5 BZ |
43 | eth = (struct ethhdr *)skb->data; |
44 | switch (ntohs(eth->h_proto)) { | |
587b36d3 AP |
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; | |
f8eb5ee5 | 90 | struct ethhdr *eth; |
5f2caaf3 AP |
91 | u16 rx_pkt_off, rx_pkt_len; |
92 | u8 *offset; | |
cbf6e055 | 93 | u8 adj_rx_rate = 0; |
5e6e3a92 BZ |
94 | |
95 | local_rx_pd = (struct rxpd *) (skb->data); | |
96 | ||
5f2caaf3 AP |
97 | rx_pkt_off = le16_to_cpu(local_rx_pd->rx_pkt_offset); |
98 | rx_pkt_len = le16_to_cpu(local_rx_pd->rx_pkt_length); | |
99 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_off; | |
5e6e3a92 | 100 | |
c613d16f AK |
101 | if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header, |
102 | sizeof(bridge_tunnel_header))) || | |
103 | (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header, | |
104 | sizeof(rfc1042_header)) && | |
105 | ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP && | |
106 | ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) { | |
5e6e3a92 BZ |
107 | /* |
108 | * Replace the 803 header and rfc1042 header (llc/snap) with an | |
109 | * EthernetII header, keep the src/dst and snap_type | |
110 | * (ethertype). | |
111 | * The firmware only passes up SNAP frames converting | |
112 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. | |
113 | * To create the Ethernet II, just move the src, dst address | |
114 | * right before the snap_type. | |
115 | */ | |
f8eb5ee5 | 116 | eth = (struct ethhdr *) |
5e6e3a92 BZ |
117 | ((u8 *) &rx_pkt_hdr->eth803_hdr |
118 | + sizeof(rx_pkt_hdr->eth803_hdr) + | |
119 | sizeof(rx_pkt_hdr->rfc1042_hdr) | |
120 | - sizeof(rx_pkt_hdr->eth803_hdr.h_dest) | |
121 | - sizeof(rx_pkt_hdr->eth803_hdr.h_source) | |
122 | - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type)); | |
123 | ||
f8eb5ee5 BZ |
124 | memcpy(eth->h_source, rx_pkt_hdr->eth803_hdr.h_source, |
125 | sizeof(eth->h_source)); | |
126 | memcpy(eth->h_dest, rx_pkt_hdr->eth803_hdr.h_dest, | |
127 | sizeof(eth->h_dest)); | |
5e6e3a92 BZ |
128 | |
129 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap | |
130 | header that was removed. */ | |
f8eb5ee5 | 131 | hdr_chop = (u8 *) eth - (u8 *) local_rx_pd; |
5e6e3a92 BZ |
132 | } else { |
133 | /* Chop off the rxpd */ | |
134 | hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr - | |
135 | (u8 *) local_rx_pd; | |
136 | } | |
137 | ||
138 | /* Chop off the leading header bytes so the it points to the start of | |
139 | either the reconstructed EthII frame or the 802.2/llc/snap frame */ | |
140 | skb_pull(skb, hdr_chop); | |
141 | ||
587b36d3 AP |
142 | if (priv->hs2_enabled && |
143 | mwifiex_discard_gratuitous_arp(priv, skb)) { | |
acebe8c1 | 144 | mwifiex_dbg(priv->adapter, INFO, "Bypassed Gratuitous ARP\n"); |
587b36d3 AP |
145 | dev_kfree_skb_any(skb); |
146 | return 0; | |
147 | } | |
148 | ||
5f2caaf3 AP |
149 | if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
150 | ntohs(rx_pkt_hdr->eth803_hdr.h_proto) == ETH_P_TDLS) { | |
151 | offset = (u8 *)local_rx_pd + rx_pkt_off; | |
152 | mwifiex_process_tdls_action_frame(priv, offset, rx_pkt_len); | |
153 | } | |
154 | ||
5e6e3a92 BZ |
155 | priv->rxpd_rate = local_rx_pd->rx_rate; |
156 | ||
157 | priv->rxpd_htinfo = local_rx_pd->ht_info; | |
158 | ||
cbf6e055 XH |
159 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || |
160 | GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { | |
161 | adj_rx_rate = mwifiex_adjust_data_rate(priv, priv->rxpd_rate, | |
162 | priv->rxpd_htinfo); | |
163 | mwifiex_hist_data_add(priv, adj_rx_rate, local_rx_pd->snr, | |
164 | local_rx_pd->nf); | |
165 | } | |
166 | ||
f3b369e4 | 167 | ret = mwifiex_recv_packet(priv, skb); |
5e6e3a92 | 168 | if (ret == -1) |
acebe8c1 ZL |
169 | mwifiex_dbg(priv->adapter, ERROR, |
170 | "recv packet failed\n"); | |
5e6e3a92 BZ |
171 | |
172 | return ret; | |
173 | } | |
174 | ||
175 | /* | |
176 | * This function processes the received buffer. | |
177 | * | |
178 | * The function looks into the RxPD and performs sanity tests on the | |
179 | * received buffer to ensure its a valid packet, before processing it | |
180 | * further. If the packet is determined to be aggregated, it is | |
181 | * de-aggregated accordingly. Non-unicast packets are sent directly to | |
182 | * the kernel/upper layers. Unicast packets are handed over to the | |
183 | * Rx reordering routine if 11n is enabled. | |
184 | * | |
185 | * The completion callback is called after processing in complete. | |
186 | */ | |
f3b369e4 | 187 | int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv, |
5e6e3a92 BZ |
188 | struct sk_buff *skb) |
189 | { | |
f3b369e4 | 190 | struct mwifiex_adapter *adapter = priv->adapter; |
5e6e3a92 BZ |
191 | int ret = 0; |
192 | struct rxpd *local_rx_pd; | |
5e6e3a92 BZ |
193 | struct rx_packet_hdr *rx_pkt_hdr; |
194 | u8 ta[ETH_ALEN]; | |
ed1ea6f4 | 195 | u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num; |
09869495 | 196 | struct mwifiex_sta_node *sta_ptr; |
8ed13033 | 197 | |
5e6e3a92 | 198 | local_rx_pd = (struct rxpd *) (skb->data); |
ed1ea6f4 AK |
199 | rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type); |
200 | rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset); | |
201 | rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length); | |
202 | seq_num = le16_to_cpu(local_rx_pd->seq_num); | |
5e6e3a92 | 203 | |
ed1ea6f4 | 204 | rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset; |
5e6e3a92 | 205 | |
ed1ea6f4 | 206 | if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) { |
acebe8c1 ZL |
207 | mwifiex_dbg(adapter, ERROR, |
208 | "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n", | |
209 | skb->len, rx_pkt_offset, rx_pkt_length); | |
5e6e3a92 | 210 | priv->stats.rx_dropped++; |
ca8d6dfc | 211 | dev_kfree_skb_any(skb); |
5e6e3a92 BZ |
212 | return ret; |
213 | } | |
3b8ab88a | 214 | |
4c9f9fb2 | 215 | if (rx_pkt_type == PKT_TYPE_MGMT) { |
f3b369e4 | 216 | ret = mwifiex_process_mgmt_packet(priv, skb); |
2dbaf751 | 217 | if (ret) |
bd642acf | 218 | mwifiex_dbg(adapter, DATA, "Rx of mgmt packet failed"); |
2dbaf751 SP |
219 | dev_kfree_skb_any(skb); |
220 | return ret; | |
5e6e3a92 | 221 | } |
3b8ab88a | 222 | |
5e6e3a92 BZ |
223 | /* |
224 | * If the packet is not an unicast packet then send the packet | |
225 | * directly to os. Don't pass thru rx reordering | |
226 | */ | |
09869495 AP |
227 | if ((!IS_11N_ENABLED(priv) && |
228 | !(ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && | |
229 | !(local_rx_pd->flags & MWIFIEX_RXPD_FLAGS_TDLS_PACKET))) || | |
fcad7668 | 230 | !ether_addr_equal_unaligned(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest)) { |
f3b369e4 | 231 | mwifiex_process_rx_packet(priv, skb); |
5e6e3a92 BZ |
232 | return ret; |
233 | } | |
234 | ||
09869495 AP |
235 | if (mwifiex_queuing_ra_based(priv) || |
236 | (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && | |
237 | local_rx_pd->flags & MWIFIEX_RXPD_FLAGS_TDLS_PACKET)) { | |
5e6e3a92 | 238 | memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN); |
09869495 AP |
239 | if (local_rx_pd->flags & MWIFIEX_RXPD_FLAGS_TDLS_PACKET && |
240 | local_rx_pd->priority < MAX_NUM_TID) { | |
241 | sta_ptr = mwifiex_get_sta_entry(priv, ta); | |
242 | if (sta_ptr) | |
243 | sta_ptr->rx_seq[local_rx_pd->priority] = | |
244 | le16_to_cpu(local_rx_pd->seq_num); | |
9927baa3 AP |
245 | mwifiex_auto_tdls_update_peer_signal(priv, ta, |
246 | local_rx_pd->snr, | |
247 | local_rx_pd->nf); | |
09869495 | 248 | } |
5e6e3a92 BZ |
249 | } else { |
250 | if (rx_pkt_type != PKT_TYPE_BAR) | |
ed1ea6f4 | 251 | priv->rx_seq[local_rx_pd->priority] = seq_num; |
5e6e3a92 BZ |
252 | memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address, |
253 | ETH_ALEN); | |
254 | } | |
255 | ||
256 | /* Reorder and send to OS */ | |
ed1ea6f4 AK |
257 | ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority, |
258 | ta, (u8) rx_pkt_type, skb); | |
5e6e3a92 | 259 | |
ca8d6dfc UR |
260 | if (ret || (rx_pkt_type == PKT_TYPE_BAR)) |
261 | dev_kfree_skb_any(skb); | |
8ed13033 YAP |
262 | |
263 | if (ret) | |
264 | priv->stats.rx_dropped++; | |
5e6e3a92 BZ |
265 | |
266 | return ret; | |
267 | } |