recv_linux.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /******************************************************************************
  2. * recv_linux.c
  3. *
  4. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  5. * Linux device driver for RTL8192SU
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * Modifications for inclusion into the Linux staging tree are
  21. * Copyright(c) 2010 Larry Finger. All rights reserved.
  22. *
  23. * Contact information:
  24. * WLAN FAE <wlanfae@realtek.com>.
  25. * Larry Finger <Larry.Finger@lwfinger.net>
  26. *
  27. ******************************************************************************/
  28. #define _RECV_OSDEP_C_
  29. #include <linux/usb.h>
  30. #include "osdep_service.h"
  31. #include "drv_types.h"
  32. #include "wifi.h"
  33. #include "recv_osdep.h"
  34. #include "osdep_intf.h"
  35. #include "ethernet.h"
  36. #include <linux/if_arp.h>
  37. #include "usb_ops.h"
  38. /*init os related resource in struct recv_priv*/
  39. /*alloc os related resource in union recv_frame*/
  40. int r8712_os_recv_resource_alloc(struct _adapter *padapter,
  41. union recv_frame *precvframe)
  42. {
  43. precvframe->u.hdr.pkt_newalloc = precvframe->u.hdr.pkt = NULL;
  44. return _SUCCESS;
  45. }
  46. /*alloc os related resource in struct recv_buf*/
  47. int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter,
  48. struct recv_buf *precvbuf)
  49. {
  50. int res = _SUCCESS;
  51. precvbuf->irp_pending = false;
  52. precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
  53. if (precvbuf->purb == NULL)
  54. res = _FAIL;
  55. precvbuf->pskb = NULL;
  56. precvbuf->reuse = false;
  57. precvbuf->pallocated_buf = NULL;
  58. precvbuf->pbuf = NULL;
  59. precvbuf->pdata = NULL;
  60. precvbuf->phead = NULL;
  61. precvbuf->ptail = NULL;
  62. precvbuf->pend = NULL;
  63. precvbuf->transfer_len = 0;
  64. precvbuf->len = 0;
  65. return res;
  66. }
  67. /*free os related resource in struct recv_buf*/
  68. int r8712_os_recvbuf_resource_free(struct _adapter *padapter,
  69. struct recv_buf *precvbuf)
  70. {
  71. if (precvbuf->pskb)
  72. dev_kfree_skb_any(precvbuf->pskb);
  73. if (precvbuf->purb) {
  74. usb_kill_urb(precvbuf->purb);
  75. usb_free_urb(precvbuf->purb);
  76. }
  77. return _SUCCESS;
  78. }
  79. void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup)
  80. {
  81. union iwreq_data wrqu;
  82. struct iw_michaelmicfailure ev;
  83. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  84. memset(&ev, 0x00, sizeof(ev));
  85. if (bgroup)
  86. ev.flags |= IW_MICFAILURE_GROUP;
  87. else
  88. ev.flags |= IW_MICFAILURE_PAIRWISE;
  89. ev.src_addr.sa_family = ARPHRD_ETHER;
  90. ether_addr_copy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0]);
  91. memset(&wrqu, 0x00, sizeof(wrqu));
  92. wrqu.data.length = sizeof(ev);
  93. wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu,
  94. (char *)&ev);
  95. }
  96. void r8712_recv_indicatepkt(struct _adapter *padapter,
  97. union recv_frame *precv_frame)
  98. {
  99. struct recv_priv *precvpriv;
  100. struct __queue *pfree_recv_queue;
  101. _pkt *skb;
  102. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  103. precvpriv = &(padapter->recvpriv);
  104. pfree_recv_queue = &(precvpriv->free_recv_queue);
  105. skb = precv_frame->u.hdr.pkt;
  106. if (skb == NULL)
  107. goto _recv_indicatepkt_drop;
  108. skb->data = precv_frame->u.hdr.rx_data;
  109. skb->len = precv_frame->u.hdr.len;
  110. skb_set_tail_pointer(skb, skb->len);
  111. if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1))
  112. skb->ip_summed = CHECKSUM_UNNECESSARY;
  113. else
  114. skb->ip_summed = CHECKSUM_NONE;
  115. skb->dev = padapter->pnetdev;
  116. skb->protocol = eth_type_trans(skb, padapter->pnetdev);
  117. netif_rx(skb);
  118. precv_frame->u.hdr.pkt = NULL; /* pointers to NULL before
  119. * r8712_free_recvframe()
  120. */
  121. r8712_free_recvframe(precv_frame, pfree_recv_queue);
  122. return;
  123. _recv_indicatepkt_drop:
  124. /*enqueue back to free_recv_queue*/
  125. if (precv_frame)
  126. r8712_free_recvframe(precv_frame, pfree_recv_queue);
  127. precvpriv->rx_drop++;
  128. }
  129. static void _r8712_reordering_ctrl_timeout_handler (unsigned long data)
  130. {
  131. struct recv_reorder_ctrl *preorder_ctrl =
  132. (struct recv_reorder_ctrl *)data;
  133. r8712_reordering_ctrl_timeout_handler(preorder_ctrl);
  134. }
  135. void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
  136. {
  137. setup_timer(&preorder_ctrl->reordering_ctrl_timer,
  138. _r8712_reordering_ctrl_timeout_handler,
  139. (unsigned long)preorder_ctrl);
  140. }