dpc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. *
  16. * File: dpc.c
  17. *
  18. * Purpose: handle dpc rx functions
  19. *
  20. * Author: Lyndon Chen
  21. *
  22. * Date: May 20, 2003
  23. *
  24. * Functions:
  25. *
  26. * Revision History:
  27. *
  28. */
  29. #include "dpc.h"
  30. #include "device.h"
  31. #include "mac.h"
  32. #include "baseband.h"
  33. #include "rf.h"
  34. int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
  35. unsigned long bytes_received)
  36. {
  37. struct ieee80211_hw *hw = priv->hw;
  38. struct ieee80211_supported_band *sband;
  39. struct sk_buff *skb;
  40. struct ieee80211_rx_status rx_status = { 0 };
  41. struct ieee80211_hdr *hdr;
  42. __le16 fc;
  43. u8 *rsr, *new_rsr, *rssi, *frame;
  44. __le64 *tsf_time;
  45. u32 frame_size;
  46. int ii, r;
  47. u8 *rx_rate, *sq, *sq_3;
  48. u32 wbk_status;
  49. u8 *skb_data;
  50. u16 *pay_load_len;
  51. u16 pay_load_with_padding;
  52. u8 rate_idx = 0;
  53. u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  54. long rx_dbm;
  55. skb = ptr_rcb->skb;
  56. /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  57. wbk_status = *((u32 *)(skb->data));
  58. frame_size = wbk_status >> 16;
  59. frame_size += 4;
  60. if (bytes_received != frame_size) {
  61. dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n");
  62. return false;
  63. }
  64. if ((bytes_received > 2372) || (bytes_received <= 40)) {
  65. /* Frame Size error drop this packet.*/
  66. dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n");
  67. return false;
  68. }
  69. skb_data = (u8 *)skb->data;
  70. rx_rate = skb_data + 5;
  71. /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
  72. /* -8TSF - 4RSR - 4SQ3 - ?Padding */
  73. /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
  74. pay_load_len = (u16 *)(skb_data + 6);
  75. /*Fix hardware bug => PLCP_Length error */
  76. if (((bytes_received - (*pay_load_len)) > 27) ||
  77. ((bytes_received - (*pay_load_len)) < 24) ||
  78. (bytes_received < (*pay_load_len))) {
  79. dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n",
  80. *pay_load_len);
  81. return false;
  82. }
  83. sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  84. for (r = RATE_1M; r < MAX_RATE; r++) {
  85. if (*rx_rate == rate[r])
  86. break;
  87. }
  88. priv->rx_rate = r;
  89. for (ii = 0; ii < sband->n_bitrates; ii++) {
  90. if (sband->bitrates[ii].hw_value == r) {
  91. rate_idx = ii;
  92. break;
  93. }
  94. }
  95. if (ii == sband->n_bitrates) {
  96. dev_dbg(&priv->usb->dev, "Wrong RxRate %x\n", *rx_rate);
  97. return false;
  98. }
  99. pay_load_with_padding = ((*pay_load_len / 4) +
  100. ((*pay_load_len % 4) ? 1 : 0)) * 4;
  101. tsf_time = (__le64 *)(skb_data + 8 + pay_load_with_padding);
  102. priv->tsf_time = le64_to_cpu(*tsf_time);
  103. if (priv->bb_type == BB_TYPE_11G) {
  104. sq_3 = skb_data + 8 + pay_load_with_padding + 12;
  105. sq = sq_3;
  106. } else {
  107. sq = skb_data + 8 + pay_load_with_padding + 8;
  108. sq_3 = sq;
  109. }
  110. new_rsr = skb_data + 8 + pay_load_with_padding + 9;
  111. rssi = skb_data + 8 + pay_load_with_padding + 10;
  112. rsr = skb_data + 8 + pay_load_with_padding + 11;
  113. if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  114. return false;
  115. frame_size = *pay_load_len;
  116. vnt_rf_rssi_to_dbm(priv, *rssi, &rx_dbm);
  117. priv->bb_pre_ed_rssi = (u8)rx_dbm + 1;
  118. priv->current_rssi = priv->bb_pre_ed_rssi;
  119. frame = skb_data + 8;
  120. skb_pull(skb, 8);
  121. skb_trim(skb, frame_size);
  122. rx_status.mactime = priv->tsf_time;
  123. rx_status.band = hw->conf.chandef.chan->band;
  124. rx_status.signal = rx_dbm;
  125. rx_status.flag = 0;
  126. rx_status.freq = hw->conf.chandef.chan->center_freq;
  127. if (!(*rsr & RSR_CRCOK))
  128. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  129. hdr = (struct ieee80211_hdr *)(skb->data);
  130. fc = hdr->frame_control;
  131. rx_status.rate_idx = rate_idx;
  132. if (ieee80211_has_protected(fc)) {
  133. if (priv->local_id > REV_ID_VT3253_A1) {
  134. rx_status.flag |= RX_FLAG_DECRYPTED;
  135. /* Drop packet */
  136. if (!(*new_rsr & NEWRSR_DECRYPTOK)) {
  137. dev_kfree_skb(skb);
  138. return true;
  139. }
  140. }
  141. }
  142. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  143. ieee80211_rx_irqsafe(priv->hw, skb);
  144. return true;
  145. }