sta_rx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "11n_aggr.h"
  25. #include "11n_rxreorder.h"
  26. /*
  27. * This function processes the received packet and forwards it
  28. * to kernel/upper layer.
  29. *
  30. * This function parses through the received packet and determines
  31. * if it is a debug packet or normal packet.
  32. *
  33. * For non-debug packets, the function chops off unnecessary leading
  34. * header bytes, reconstructs the packet as an ethernet frame or
  35. * 802.2/llc/snap frame as required, and sends it to kernel/upper layer.
  36. *
  37. * The completion callback is called after processing in complete.
  38. */
  39. int mwifiex_process_rx_packet(struct mwifiex_private *priv,
  40. struct sk_buff *skb)
  41. {
  42. int ret;
  43. struct rx_packet_hdr *rx_pkt_hdr;
  44. struct rxpd *local_rx_pd;
  45. int hdr_chop;
  46. struct ethhdr *eth_hdr;
  47. u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  48. local_rx_pd = (struct rxpd *) (skb->data);
  49. rx_pkt_hdr = (void *)local_rx_pd +
  50. le16_to_cpu(local_rx_pd->rx_pkt_offset);
  51. if (!memcmp(&rx_pkt_hdr->rfc1042_hdr,
  52. rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) {
  53. /*
  54. * Replace the 803 header and rfc1042 header (llc/snap) with an
  55. * EthernetII header, keep the src/dst and snap_type
  56. * (ethertype).
  57. * The firmware only passes up SNAP frames converting
  58. * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
  59. * To create the Ethernet II, just move the src, dst address
  60. * right before the snap_type.
  61. */
  62. eth_hdr = (struct ethhdr *)
  63. ((u8 *) &rx_pkt_hdr->eth803_hdr
  64. + sizeof(rx_pkt_hdr->eth803_hdr) +
  65. sizeof(rx_pkt_hdr->rfc1042_hdr)
  66. - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
  67. - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
  68. - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
  69. memcpy(eth_hdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
  70. sizeof(eth_hdr->h_source));
  71. memcpy(eth_hdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
  72. sizeof(eth_hdr->h_dest));
  73. /* Chop off the rxpd + the excess memory from the 802.2/llc/snap
  74. header that was removed. */
  75. hdr_chop = (u8 *) eth_hdr - (u8 *) local_rx_pd;
  76. } else {
  77. /* Chop off the rxpd */
  78. hdr_chop = (u8 *) &rx_pkt_hdr->eth803_hdr -
  79. (u8 *) local_rx_pd;
  80. }
  81. /* Chop off the leading header bytes so the it points to the start of
  82. either the reconstructed EthII frame or the 802.2/llc/snap frame */
  83. skb_pull(skb, hdr_chop);
  84. priv->rxpd_rate = local_rx_pd->rx_rate;
  85. priv->rxpd_htinfo = local_rx_pd->ht_info;
  86. ret = mwifiex_recv_packet(priv, skb);
  87. if (ret == -1)
  88. dev_err(priv->adapter->dev, "recv packet failed\n");
  89. return ret;
  90. }
  91. /*
  92. * This function processes the received buffer.
  93. *
  94. * The function looks into the RxPD and performs sanity tests on the
  95. * received buffer to ensure its a valid packet, before processing it
  96. * further. If the packet is determined to be aggregated, it is
  97. * de-aggregated accordingly. Non-unicast packets are sent directly to
  98. * the kernel/upper layers. Unicast packets are handed over to the
  99. * Rx reordering routine if 11n is enabled.
  100. *
  101. * The completion callback is called after processing in complete.
  102. */
  103. int mwifiex_process_sta_rx_packet(struct mwifiex_private *priv,
  104. struct sk_buff *skb)
  105. {
  106. struct mwifiex_adapter *adapter = priv->adapter;
  107. int ret = 0;
  108. struct rxpd *local_rx_pd;
  109. struct rx_packet_hdr *rx_pkt_hdr;
  110. u8 ta[ETH_ALEN];
  111. u16 rx_pkt_type, rx_pkt_offset, rx_pkt_length, seq_num;
  112. local_rx_pd = (struct rxpd *) (skb->data);
  113. rx_pkt_type = le16_to_cpu(local_rx_pd->rx_pkt_type);
  114. rx_pkt_offset = le16_to_cpu(local_rx_pd->rx_pkt_offset);
  115. rx_pkt_length = le16_to_cpu(local_rx_pd->rx_pkt_length);
  116. seq_num = le16_to_cpu(local_rx_pd->seq_num);
  117. rx_pkt_hdr = (void *)local_rx_pd + rx_pkt_offset;
  118. if ((rx_pkt_offset + rx_pkt_length) > (u16) skb->len) {
  119. dev_err(adapter->dev,
  120. "wrong rx packet: len=%d, rx_pkt_offset=%d, rx_pkt_length=%d\n",
  121. skb->len, rx_pkt_offset, rx_pkt_length);
  122. priv->stats.rx_dropped++;
  123. if (adapter->if_ops.data_complete)
  124. adapter->if_ops.data_complete(adapter, skb);
  125. else
  126. dev_kfree_skb_any(skb);
  127. return ret;
  128. }
  129. if (rx_pkt_type == PKT_TYPE_AMSDU) {
  130. struct sk_buff_head list;
  131. struct sk_buff *rx_skb;
  132. __skb_queue_head_init(&list);
  133. skb_pull(skb, rx_pkt_offset);
  134. skb_trim(skb, rx_pkt_length);
  135. ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr,
  136. priv->wdev->iftype, 0, false);
  137. while (!skb_queue_empty(&list)) {
  138. rx_skb = __skb_dequeue(&list);
  139. ret = mwifiex_recv_packet(priv, rx_skb);
  140. if (ret == -1)
  141. dev_err(adapter->dev, "Rx of A-MSDU failed");
  142. }
  143. return 0;
  144. } else if (rx_pkt_type == PKT_TYPE_MGMT) {
  145. ret = mwifiex_process_mgmt_packet(priv, skb);
  146. if (ret)
  147. dev_err(adapter->dev, "Rx of mgmt packet failed");
  148. dev_kfree_skb_any(skb);
  149. return ret;
  150. }
  151. /*
  152. * If the packet is not an unicast packet then send the packet
  153. * directly to os. Don't pass thru rx reordering
  154. */
  155. if (!IS_11N_ENABLED(priv) ||
  156. memcmp(priv->curr_addr, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN)) {
  157. mwifiex_process_rx_packet(priv, skb);
  158. return ret;
  159. }
  160. if (mwifiex_queuing_ra_based(priv)) {
  161. memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN);
  162. } else {
  163. if (rx_pkt_type != PKT_TYPE_BAR)
  164. priv->rx_seq[local_rx_pd->priority] = seq_num;
  165. memcpy(ta, priv->curr_bss_params.bss_descriptor.mac_address,
  166. ETH_ALEN);
  167. }
  168. /* Reorder and send to OS */
  169. ret = mwifiex_11n_rx_reorder_pkt(priv, seq_num, local_rx_pd->priority,
  170. ta, (u8) rx_pkt_type, skb);
  171. if (ret || (rx_pkt_type == PKT_TYPE_BAR)) {
  172. if (adapter->if_ops.data_complete)
  173. adapter->if_ops.data_complete(adapter, skb);
  174. else
  175. dev_kfree_skb_any(skb);
  176. }
  177. if (ret)
  178. priv->stats.rx_dropped++;
  179. return ret;
  180. }