dpc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "device.h"
  33. #include "baseband.h"
  34. #include "rf.h"
  35. #include "dpc.h"
  36. static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
  37. u16 bytes_received)
  38. {
  39. struct ieee80211_hw *hw = priv->hw;
  40. struct ieee80211_supported_band *sband;
  41. struct ieee80211_rx_status rx_status = { 0 };
  42. struct ieee80211_hdr *hdr;
  43. __le16 fc;
  44. u8 *rsr, *new_rsr, *rssi;
  45. __le64 *tsf_time;
  46. u16 frame_size;
  47. int ii, r;
  48. u8 *rx_sts, *rx_rate, *sq;
  49. u8 *skb_data;
  50. u8 rate_idx = 0;
  51. u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  52. long rx_dbm;
  53. /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  54. frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
  55. if (frame_size > 2346 || frame_size < 14) {
  56. dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
  57. return false;
  58. }
  59. skb_data = (u8 *)skb->data;
  60. rx_sts = skb_data;
  61. rx_rate = skb_data + 1;
  62. sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  63. for (r = RATE_1M; r < MAX_RATE; r++) {
  64. if (*rx_rate == rate[r])
  65. break;
  66. }
  67. priv->rx_rate = r;
  68. for (ii = 0; ii < sband->n_bitrates; ii++) {
  69. if (sband->bitrates[ii].hw_value == r) {
  70. rate_idx = ii;
  71. break;
  72. }
  73. }
  74. if (ii == sband->n_bitrates) {
  75. dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
  76. return false;
  77. }
  78. tsf_time = (__le64 *)(skb_data + bytes_received - 12);
  79. sq = skb_data + bytes_received - 4;
  80. new_rsr = skb_data + bytes_received - 3;
  81. rssi = skb_data + bytes_received - 2;
  82. rsr = skb_data + bytes_received - 1;
  83. if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  84. return false;
  85. RFvRSSITodBm(priv, *rssi, &rx_dbm);
  86. priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
  87. priv->uCurrRSSI = *rssi;
  88. skb_pull(skb, 4);
  89. skb_trim(skb, frame_size);
  90. rx_status.mactime = le64_to_cpu(*tsf_time);
  91. rx_status.band = hw->conf.chandef.chan->band;
  92. rx_status.signal = rx_dbm;
  93. rx_status.flag = 0;
  94. rx_status.freq = hw->conf.chandef.chan->center_freq;
  95. if (!(*rsr & RSR_CRCOK))
  96. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  97. hdr = (struct ieee80211_hdr *)(skb->data);
  98. fc = hdr->frame_control;
  99. rx_status.rate_idx = rate_idx;
  100. if (ieee80211_has_protected(fc)) {
  101. if (priv->byLocalID > REV_ID_VT3253_A1)
  102. rx_status.flag |= RX_FLAG_DECRYPTED;
  103. /* Drop packet */
  104. if (!(*new_rsr & NEWRSR_DECRYPTOK))
  105. return false;
  106. }
  107. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  108. ieee80211_rx_irqsafe(priv->hw, skb);
  109. return true;
  110. }
  111. bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd)
  112. {
  113. struct vnt_rd_info *rd_info = curr_rd->rd_info;
  114. struct sk_buff *skb;
  115. u16 frame_size;
  116. skb = rd_info->skb;
  117. dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
  118. priv->rx_buf_sz, DMA_FROM_DEVICE);
  119. frame_size = le16_to_cpu(curr_rd->rd1.req_count)
  120. - le16_to_cpu(curr_rd->rd0.res_count);
  121. if ((frame_size > 2364) || (frame_size < 33)) {
  122. /* Frame Size error drop this packet.*/
  123. dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
  124. dev_kfree_skb_irq(skb);
  125. return true;
  126. }
  127. if (vnt_rx_data(priv, skb, frame_size))
  128. return true;
  129. dev_kfree_skb_irq(skb);
  130. return true;
  131. }