sta_rx.c 8.5 KB

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