dpc.c 3.8 KB

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