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