Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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: |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 28 | * |
| 29 | * Revision History: |
| 30 | * |
| 31 | */ |
| 32 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 33 | #include "device.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 34 | #include "baseband.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 35 | #include "rf.h" |
James A Shackleford | 04d5219 | 2014-06-01 20:26:55 -0400 | [diff] [blame] | 36 | #include "dpc.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 37 | |
Malcolm Priestley | 33b1c8c | 2014-10-29 17:43:36 +0000 | [diff] [blame] | 38 | static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb, |
| 39 | u16 bytes_received) |
| 40 | { |
| 41 | struct ieee80211_hw *hw = priv->hw; |
| 42 | struct ieee80211_supported_band *sband; |
| 43 | struct ieee80211_rx_status rx_status = { 0 }; |
| 44 | struct ieee80211_hdr *hdr; |
| 45 | __le16 fc; |
| 46 | u8 *rsr, *new_rsr, *rssi; |
| 47 | __le64 *tsf_time; |
| 48 | u16 frame_size; |
| 49 | int ii, r; |
| 50 | u8 *rx_sts, *rx_rate, *sq; |
| 51 | u8 *skb_data; |
| 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 | |
| 56 | /* [31:16]RcvByteCount ( not include 4-byte Status ) */ |
| 57 | frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2))); |
| 58 | if (frame_size > 2346 || frame_size < 14) { |
| 59 | dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n"); |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | skb_data = (u8 *)skb->data; |
| 64 | |
| 65 | rx_sts = skb_data; |
| 66 | rx_rate = skb_data + 1; |
| 67 | |
| 68 | sband = hw->wiphy->bands[hw->conf.chandef.chan->band]; |
| 69 | |
| 70 | for (r = RATE_1M; r < MAX_RATE; r++) { |
| 71 | if (*rx_rate == rate[r]) |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | priv->rx_rate = r; |
| 76 | |
| 77 | for (ii = 0; ii < sband->n_bitrates; ii++) { |
| 78 | if (sband->bitrates[ii].hw_value == r) { |
| 79 | rate_idx = ii; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (ii == sband->n_bitrates) { |
| 85 | dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | tsf_time = (__le64 *)(skb_data + bytes_received - 12); |
| 90 | sq = skb_data + bytes_received - 4; |
| 91 | new_rsr = skb_data + bytes_received - 3; |
| 92 | rssi = skb_data + bytes_received - 2; |
| 93 | rsr = skb_data + bytes_received - 1; |
| 94 | |
| 95 | RFvRSSITodBm(priv, *rssi, &rx_dbm); |
| 96 | |
| 97 | priv->byBBPreEDRSSI = (u8)rx_dbm + 1; |
Malcolm Priestley | f218f40 | 2014-10-29 17:44:07 +0000 | [diff] [blame] | 98 | priv->uCurrRSSI = *rssi; |
Malcolm Priestley | 33b1c8c | 2014-10-29 17:43:36 +0000 | [diff] [blame] | 99 | |
| 100 | skb_pull(skb, 4); |
| 101 | skb_trim(skb, frame_size); |
| 102 | |
| 103 | rx_status.mactime = le64_to_cpu(*tsf_time); |
| 104 | rx_status.band = hw->conf.chandef.chan->band; |
| 105 | rx_status.signal = rx_dbm; |
| 106 | rx_status.flag = 0; |
| 107 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 108 | |
| 109 | hdr = (struct ieee80211_hdr *)(skb->data); |
| 110 | fc = hdr->frame_control; |
| 111 | |
| 112 | rx_status.rate_idx = rate_idx; |
| 113 | |
| 114 | if (ieee80211_has_protected(fc)) { |
| 115 | if (priv->byLocalID > REV_ID_VT3253_A1) |
| 116 | rx_status.flag = RX_FLAG_DECRYPTED; |
| 117 | } |
| 118 | |
| 119 | if (priv->vif && priv->bDiversityEnable) { |
| 120 | if (ieee80211_is_data(fc) && |
| 121 | (frame_size > 50) && priv->vif->bss_conf.assoc) |
| 122 | BBvAntennaDiversity(priv, priv->rx_rate, 0); |
| 123 | } |
| 124 | |
| 125 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); |
| 126 | |
| 127 | ieee80211_rx_irqsafe(priv->hw, skb); |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd) |
| 133 | { |
| 134 | PDEVICE_RD_INFO rd_info = curr_rd->pRDInfo; |
| 135 | struct sk_buff *skb; |
| 136 | u16 frame_size; |
| 137 | |
| 138 | skb = rd_info->skb; |
| 139 | |
| 140 | pci_unmap_single(priv->pcid, rd_info->skb_dma, |
| 141 | priv->rx_buf_sz, PCI_DMA_FROMDEVICE); |
| 142 | |
| 143 | frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount) |
| 144 | - cpu_to_le16(curr_rd->m_rd0RD0.wResCount); |
| 145 | |
| 146 | if ((frame_size > 2364) || (frame_size < 33)) { |
| 147 | /* Frame Size error drop this packet.*/ |
| 148 | dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size); |
| 149 | dev_kfree_skb_irq(skb); |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | if (vnt_rx_data(priv, skb, frame_size)) |
| 154 | return true; |
| 155 | |
| 156 | dev_kfree_skb_irq(skb); |
| 157 | |
| 158 | return true; |
| 159 | } |