sta_rx.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include <uapi/linux/ipv6.h>
  20. #include <net/ndisc.h>
  21. #include "decl.h"
  22. #include "ioctl.h"
  23. #include "util.h"
  24. #include "fw.h"
  25. #include "main.h"
  26. #include "11n_aggr.h"
  27. #include "11n_rxreorder.h"
  28. /* This function checks if a frame is IPv4 ARP or IPv6 Neighbour advertisement
  29. * frame. If frame has both source and destination mac address as same, this
  30. * function drops such gratuitous frames.
  31. */
  32. static bool
  33. mwifiex_discard_gratuitous_arp(struct mwifiex_private *priv,
  34. struct sk_buff *skb)
  35. {
  36. const struct mwifiex_arp_eth_header *arp;
  37. struct ethhdr *eth;
  38. struct ipv6hdr *ipv6;
  39. struct icmp6hdr *icmpv6;
  40. eth = (struct ethhdr *)skb->data;
  41. switch (ntohs(eth->h_proto)) {
  42. case ETH_P_ARP:
  43. arp = (void *)(skb->data + sizeof(struct ethhdr));
  44. if (arp->hdr.ar_op == htons(ARPOP_REPLY) ||
  45. arp->hdr.ar_op == htons(ARPOP_REQUEST)) {
  46. if (!memcmp(arp->ar_sip, arp->ar_tip, 4))
  47. return true;
  48. }
  49. break;
  50. case ETH_P_IPV6:
  51. ipv6 = (void *)(skb->data + sizeof(struct ethhdr));
  52. icmpv6 = (void *)(skb->data + sizeof(struct ethhdr) +
  53. sizeof(struct ipv6hdr));
  54. if (NDISC_NEIGHBOUR_ADVERTISEMENT == icmpv6->icmp6_type) {
  55. if (!memcmp(&ipv6->saddr, &ipv6->daddr,
  56. sizeof(struct in6_addr)))
  57. return true;
  58. }
  59. break;
  60. default:
  61. break;
  62. }
  63. return false;
  64. }
  65. /*
  66. * This function processes the received packet and forwards it
  67. * to kernel/upper layer.
  68. *
  69. * This function parses through the received packet and determines
  70. * if it is a debug packet or normal packet.
  71. *
  72. * For non-debug packets, the function chops off unnecessary leading
  73. * header bytes, reconstructs the packet as an ethernet frame or
  74. * 802.2/llc/snap frame as required, and sends it to kernel/upper layer.
  75. *
  76. * The completion callback is called after processing in complete.
  77. */
  78. int mwifiex_process_rx_packet(struct mwifiex_private *priv,
  79. struct sk_buff *skb)
  80. {
  81. int ret;
  82. struct rx_packet_hdr *rx_pkt_hdr;
  83. struct rxpd *local_rx_pd;
  84. int hdr_chop;
  85. struct ethhdr *eth;
  86. local_rx_pd = (struct rxpd *) (skb->data);
  87. rx_pkt_hdr = (void *)local_rx_pd +
  88. le16_to_cpu(local_rx_pd->rx_pkt_offset);
  89. if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
  90. sizeof(bridge_tunnel_header))) ||
  91. (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
  92. sizeof(rfc1042_header)) &&
  93. ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_AARP &&
  94. ntohs(rx_pkt_hdr->rfc1042_hdr.snap_type) != ETH_P_IPX)) {
  95. /*
  96. * Replace the 803 header and rfc1042 header (llc/snap) with an
  97. * EthernetII header, keep the src/dst and snap_type
  98. * (ethertype).
  99. * The firmware only passes up SNAP frames converting
  100. * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
  101. * To create the Ethernet II, just move the src, dst address
  102. * right before the snap_type.
  103. */
  104. eth = (struct ethhdr *)
  105. ((u8 *) &rx_pkt_hdr->eth803_hdr
  106. + sizeof(rx_pkt_hdr->eth803_hdr) +
  107. sizeof(rx_pkt_hdr->rfc1042_hdr)
  108. - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
  109. - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
  110. - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
  111. memcpy(eth->h_source, rx_pkt_hdr->eth803_hdr.h_source,
  112. sizeof(eth->h_source));
  113. memcpy(eth->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
  114. sizeof(eth->h_dest));
  115. /* Chop off the rxpd + the excess memory from the 802.2/llc/snap
  116. header that was removed. */
  117. hdr_chop = (u8 *) eth - (u8 *) local_rx_pd;
  118. } else {
  119. /* Chop off the rxpd */
  120. hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr -
  121. (u8 *) local_rx_pd;
  122. }
  123. /* Chop off the leading header bytes so the it points to the start of
  124. either the reconstructed EthII frame or the 802.2/llc/snap frame */
  125. skb_pull(skb, hdr_chop);
  126. if (priv->hs2_enabled &&
  127. mwifiex_discard_gratuitous_arp(priv, skb)) {
  128. dev_dbg(priv->adapter->dev, "Bypassed Gratuitous ARP\n");
  129. dev_kfree_skb_any(skb);
  130. return 0;
  131. }
  132. priv->rxpd_rate = local_rx_pd->rx_rate;
  133. priv->rxpd_htinfo = local_rx_pd->ht_info;
  134. ret = mwifiex_recv_packet(priv, skb);
  135. if (ret == -1)
  136. dev_err(priv->adapter->dev, "recv packet failed\n");
  137. return ret;
  138. }
  139. /*
  140. * This function processes the received buffer.
  141. *
  142. * The function looks into the RxPD and performs sanity tests on the
  143. * received buffer to ensure its a valid packet, before processing it
  144. * further. If the packet is determined to be aggregated, it is
  145. * de-aggregated accordingly. Non-unicast packets are sent directly to
  146. * the kernel/upper layers. Unicast packets are handed over to the
  147. * Rx reordering routine if 11n is enabled.
  148. *
  149. * The completion callback is called after processing in complete.
  150. */
  151. int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv,
  152. struct sk_buff *skb)
  153. {
  154. struct mwifiex_adapter *adapter = priv->adapter;
  155. int ret = 0;
  156. struct rxpd *local_rx_pd;
  157. struct rx_packet_hdr *rx_pkt_hdr;
  158. u8 ta[ETH_ALEN];
  159. u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num;
  160. local_rx_pd = (struct rxpd *) (skb->data);
  161. rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type);
  162. rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset);
  163. rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length);
  164. seq_num = le16_to_cpu(local_rx_pd->seq_num);
  165. rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset;
  166. if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) {
  167. dev_err(adapter->dev,
  168. "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n",
  169. skb->len, rx_pkt_offset, rx_pkt_length);
  170. priv->stats.rx_dropped++;
  171. dev_kfree_skb_any(skb);
  172. return ret;
  173. }
  174. if (rx_pkt_type == PKT_TYPE_AMSDU) {
  175. struct sk_buff_head list;
  176. struct sk_buff *rx_skb;
  177. __skb_queue_head_init(&list);
  178. skb_pull(skb, rx_pkt_offset);
  179. skb_trim(skb, rx_pkt_length);
  180. ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr,
  181. priv->wdev->iftype, 0, false);
  182. while (!skb_queue_empty(&list)) {
  183. rx_skb = __skb_dequeue(&list);
  184. ret = mwifiex_recv_packet(priv, rx_skb);
  185. if (ret == -1)
  186. dev_err(adapter->dev, "Rx of A-MSDU failed");
  187. }
  188. return 0;
  189. } else if (rx_pkt_type == PKT_TYPE_MGMT) {
  190. ret = mwifiex_process_mgmt_packet(priv, skb);
  191. if (ret)
  192. dev_err(adapter->dev, "Rx of mgmt packet failed");
  193. dev_kfree_skb_any(skb);
  194. return ret;
  195. }
  196. /*
  197. * If the packet is not an unicast packet then send the packet
  198. * directly to os. Don't pass thru rx reordering
  199. */
  200. if (!IS_11N_ENABLED(priv) ||
  201. !ether_addr_equal_unaligned(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest)) {
  202. mwifiex_process_rx_packet(priv, skb);
  203. return ret;
  204. }
  205. if (mwifiex_queuing_ra_based(priv)) {
  206. memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN);
  207. } else {
  208. if (rx_pkt_type != PKT_TYPE_BAR)
  209. priv->rx_seq[local_rx_pd->priority] = seq_num;
  210. memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address,
  211. ETH_ALEN);
  212. }
  213. /* Reorder and send to OS */
  214. ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority,
  215. ta, (u8) rx_pkt_type, skb);
  216. if (ret || (rx_pkt_type == PKT_TYPE_BAR))
  217. dev_kfree_skb_any(skb);
  218. if (ret)
  219. priv->stats.rx_dropped++;
  220. return ret;
  221. }