dpc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: dpc.c
  20. *
  21. * Purpose: handle dpc rx functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: May 20, 2003
  26. *
  27. * Functions:
  28. *
  29. * Revision History:
  30. *
  31. */
  32. #include "dpc.h"
  33. #include "device.h"
  34. #include "mac.h"
  35. #include "baseband.h"
  36. #include "rf.h"
  37. int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
  38. unsigned long bytes_received)
  39. {
  40. struct ieee80211_hw *hw = priv->hw;
  41. struct ieee80211_supported_band *sband;
  42. struct sk_buff *skb;
  43. struct ieee80211_rx_status rx_status = { 0 };
  44. struct ieee80211_hdr *hdr;
  45. __le16 fc;
  46. u8 *rsr, *new_rsr, *rssi, *frame;
  47. __le64 *tsf_time;
  48. u32 frame_size;
  49. int ii, r;
  50. u8 *rx_sts, *rx_rate, *sq, *sq_3;
  51. u32 wbk_status;
  52. u8 *skb_data;
  53. u16 *pay_load_len;
  54. u16 pay_load_with_padding;
  55. u8 rate_idx = 0;
  56. u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  57. long rx_dbm;
  58. skb = ptr_rcb->skb;
  59. /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  60. wbk_status = *((u32 *)(skb->data));
  61. frame_size = wbk_status >> 16;
  62. frame_size += 4;
  63. if (bytes_received != frame_size) {
  64. dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n");
  65. return false;
  66. }
  67. if ((bytes_received > 2372) || (bytes_received <= 40)) {
  68. /* Frame Size error drop this packet.*/
  69. dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n");
  70. return false;
  71. }
  72. skb_data = (u8 *)skb->data;
  73. rx_sts = skb_data+4;
  74. rx_rate = skb_data+5;
  75. /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
  76. /* -8TSF - 4RSR - 4SQ3 - ?Padding */
  77. /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
  78. pay_load_len = (u16 *) (skb_data + 6);
  79. /*Fix hardware bug => PLCP_Length error */
  80. if (((bytes_received - (*pay_load_len)) > 27) ||
  81. ((bytes_received - (*pay_load_len)) < 24) ||
  82. (bytes_received < (*pay_load_len))) {
  83. dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n",
  84. *pay_load_len);
  85. return false;
  86. }
  87. sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  88. for (r = RATE_1M; r < MAX_RATE; r++) {
  89. if (*rx_rate == rate[r])
  90. break;
  91. }
  92. priv->rx_rate = r;
  93. for (ii = 0; ii < sband->n_bitrates; ii++) {
  94. if (sband->bitrates[ii].hw_value == r) {
  95. rate_idx = ii;
  96. break;
  97. }
  98. }
  99. if (ii == sband->n_bitrates) {
  100. dev_dbg(&priv->usb->dev, "Wrong RxRate %x\n", *rx_rate);
  101. return false;
  102. }
  103. pay_load_with_padding = ((*pay_load_len / 4) +
  104. ((*pay_load_len % 4) ? 1 : 0)) * 4;
  105. tsf_time = (__le64 *)(skb_data + 8 + pay_load_with_padding);
  106. priv->tsf_time = le64_to_cpu(*tsf_time);
  107. if (priv->bb_type == BB_TYPE_11G) {
  108. sq_3 = skb_data + 8 + pay_load_with_padding + 12;
  109. sq = sq_3;
  110. } else {
  111. sq = skb_data + 8 + pay_load_with_padding + 8;
  112. sq_3 = sq;
  113. }
  114. new_rsr = skb_data + 8 + pay_load_with_padding + 9;
  115. rssi = skb_data + 8 + pay_load_with_padding + 10;
  116. rsr = skb_data + 8 + pay_load_with_padding + 11;
  117. if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  118. return false;
  119. frame_size = *pay_load_len;
  120. vnt_rf_rssi_to_dbm(priv, *rssi, &rx_dbm);
  121. priv->bb_pre_ed_rssi = (u8)rx_dbm + 1;
  122. priv->current_rssi = priv->bb_pre_ed_rssi;
  123. frame = skb_data + 8;
  124. skb_pull(skb, 8);
  125. skb_trim(skb, frame_size);
  126. rx_status.mactime = priv->tsf_time;
  127. rx_status.band = hw->conf.chandef.chan->band;
  128. rx_status.signal = rx_dbm;
  129. rx_status.flag = 0;
  130. rx_status.freq = hw->conf.chandef.chan->center_freq;
  131. if (!(*rsr & RSR_CRCOK))
  132. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  133. hdr = (struct ieee80211_hdr *)(skb->data);
  134. fc = hdr->frame_control;
  135. rx_status.rate_idx = rate_idx;
  136. if (ieee80211_has_protected(fc)) {
  137. if (priv->local_id > REV_ID_VT3253_A1) {
  138. rx_status.flag |= RX_FLAG_DECRYPTED;
  139. /* Drop packet */
  140. if (!(*new_rsr & NEWRSR_DECRYPTOK)) {
  141. dev_kfree_skb(skb);
  142. return true;
  143. }
  144. }
  145. }
  146. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  147. ieee80211_rx_irqsafe(priv->hw, skb);
  148. return true;
  149. }