sta_rx.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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_hdr;
  38. struct ipv6hdr *ipv6;
  39. struct icmp6hdr *icmpv6;
  40. eth_hdr = (struct ethhdr *)skb->data;
  41. switch (ntohs(eth_hdr->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_hdr;
  86. u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  87. local_rx_pd = (struct rxpd *) (skb->data);
  88. rx_pkt_hdr = (void *)local_rx_pd +
  89. le16_to_cpu(local_rx_pd->rx_pkt_offset);
  90. if (!memcmp(&rx_pkt_hdr->rfc1042_hdr,
  91. rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) {
  92. /*
  93. * Replace the 803 header and rfc1042 header (llc/snap) with an
  94. * EthernetII header, keep the src/dst and snap_type
  95. * (ethertype).
  96. * The firmware only passes up SNAP frames converting
  97. * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
  98. * To create the Ethernet II, just move the src, dst address
  99. * right before the snap_type.
  100. */
  101. eth_hdr = (struct ethhdr *)
  102. ((u8 *) &rx_pkt_hdr->eth803_hdr
  103. + sizeof(rx_pkt_hdr->eth803_hdr) +
  104. sizeof(rx_pkt_hdr->rfc1042_hdr)
  105. - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
  106. - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
  107. - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
  108. memcpy(eth_hdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
  109. sizeof(eth_hdr->h_source));
  110. memcpy(eth_hdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
  111. sizeof(eth_hdr->h_dest));
  112. /* Chop off the rxpd + the excess memory from the 802.2/llc/snap
  113. header that was removed. */
  114. hdr_chop = (u8 *) eth_hdr - (u8 *) local_rx_pd;
  115. } else {
  116. /* Chop off the rxpd */
  117. hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr -
  118. (u8 *) local_rx_pd;
  119. }
  120. /* Chop off the leading header bytes so the it points to the start of
  121. either the reconstructed EthII frame or the 802.2/llc/snap frame */
  122. skb_pull(skb, hdr_chop);
  123. if (priv->hs2_enabled &&
  124. mwifiex_discard_gratuitous_arp(priv, skb)) {
  125. dev_dbg(priv->adapter->dev, "Bypassed Gratuitous ARP\n");
  126. dev_kfree_skb_any(skb);
  127. return 0;
  128. }
  129. priv->rxpd_rate = local_rx_pd->rx_rate;
  130. priv->rxpd_htinfo = local_rx_pd->ht_info;
  131. ret = mwifiex_recv_packet(priv, skb);
  132. if (ret == -1)
  133. dev_err(priv->adapter->dev, "recv packet failed\n");
  134. return ret;
  135. }
  136. /*
  137. * This function processes the received buffer.
  138. *
  139. * The function looks into the RxPD and performs sanity tests on the
  140. * received buffer to ensure its a valid packet, before processing it
  141. * further. If the packet is determined to be aggregated, it is
  142. * de-aggregated accordingly. Non-unicast packets are sent directly to
  143. * the kernel/upper layers. Unicast packets are handed over to the
  144. * Rx reordering routine if 11n is enabled.
  145. *
  146. * The completion callback is called after processing in complete.
  147. */
  148. int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv,
  149. struct sk_buff *skb)
  150. {
  151. struct mwifiex_adapter *adapter = priv->adapter;
  152. int ret = 0;
  153. struct rxpd *local_rx_pd;
  154. struct rx_packet_hdr *rx_pkt_hdr;
  155. u8 ta[ETH_ALEN];
  156. u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num;
  157. local_rx_pd = (struct rxpd *) (skb->data);
  158. rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type);
  159. rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset);
  160. rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length);
  161. seq_num = le16_to_cpu(local_rx_pd->seq_num);
  162. rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset;
  163. if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) {
  164. dev_err(adapter->dev,
  165. "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n",
  166. skb->len, rx_pkt_offset, rx_pkt_length);
  167. priv->stats.rx_dropped++;
  168. if (adapter->if_ops.data_complete)
  169. adapter->if_ops.data_complete(adapter, skb);
  170. else
  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. memcmp(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN)) {
  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. if (adapter->if_ops.data_complete)
  218. adapter->if_ops.data_complete(adapter, skb);
  219. else
  220. dev_kfree_skb_any(skb);
  221. }
  222. if (ret)
  223. priv->stats.rx_dropped++;
  224. return ret;
  225. }