Forest Bond | 92b9679 | 2009-06-13 07:38:31 -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 | * |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 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: |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 25 | * |
| 26 | * Revision History: |
| 27 | * |
| 28 | */ |
| 29 | |
Malcolm Priestley | d820fa9 | 2014-01-13 16:17:04 +0000 | [diff] [blame] | 30 | #include "dpc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 31 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 32 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 33 | #include "baseband.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 34 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 35 | |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 36 | int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb, |
| 37 | unsigned long bytes_received) |
| 38 | { |
| 39 | struct ieee80211_hw *hw = priv->hw; |
| 40 | struct ieee80211_supported_band *sband; |
| 41 | struct sk_buff *skb; |
| 42 | struct ieee80211_rx_status rx_status = { 0 }; |
| 43 | struct ieee80211_hdr *hdr; |
| 44 | __le16 fc; |
| 45 | u8 *rsr, *new_rsr, *rssi, *frame; |
| 46 | __le64 *tsf_time; |
| 47 | u32 frame_size; |
| 48 | int ii, r; |
| 49 | u8 *rx_sts, *rx_rate, *sq, *sq_3; |
| 50 | u32 wbk_status; |
| 51 | u8 *skb_data; |
| 52 | u16 *pay_load_len; |
| 53 | u16 pay_load_with_padding; |
| 54 | u8 rate_idx = 0; |
| 55 | u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108}; |
| 56 | long rx_dbm; |
| 57 | |
| 58 | skb = ptr_rcb->skb; |
| 59 | |
| 60 | /* [31:16]RcvByteCount ( not include 4-byte Status ) */ |
| 61 | wbk_status = *((u32 *)(skb->data)); |
| 62 | frame_size = wbk_status >> 16; |
| 63 | frame_size += 4; |
| 64 | |
| 65 | if (bytes_received != frame_size) { |
| 66 | dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n"); |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | if ((bytes_received > 2372) || (bytes_received <= 40)) { |
| 71 | /* Frame Size error drop this packet.*/ |
| 72 | dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n"); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | skb_data = (u8 *)skb->data; |
| 77 | |
| 78 | rx_sts = skb_data+4; |
| 79 | rx_rate = skb_data+5; |
| 80 | |
| 81 | /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */ |
| 82 | /* -8TSF - 4RSR - 4SQ3 - ?Padding */ |
| 83 | |
| 84 | /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */ |
| 85 | |
| 86 | pay_load_len = (u16 *) (skb_data + 6); |
| 87 | |
| 88 | /*Fix hardware bug => PLCP_Length error */ |
| 89 | if (((bytes_received - (*pay_load_len)) > 27) || |
| 90 | ((bytes_received - (*pay_load_len)) < 24) || |
| 91 | (bytes_received < (*pay_load_len))) { |
| 92 | dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n", |
| 93 | *pay_load_len); |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | sband = hw->wiphy->bands[hw->conf.chandef.chan->band]; |
| 98 | |
| 99 | for (r = RATE_1M; r < MAX_RATE; r++) { |
| 100 | if (*rx_rate == rate[r]) |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | priv->rx_rate = r; |
| 105 | |
| 106 | for (ii = 0; ii < sband->n_bitrates; ii++) { |
| 107 | if (sband->bitrates[ii].hw_value == r) { |
| 108 | rate_idx = ii; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (ii == sband->n_bitrates) { |
| 114 | dev_dbg(&priv->usb->dev, "Wrong RxRate %x\n", *rx_rate); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | pay_load_with_padding = ((*pay_load_len / 4) + |
| 119 | ((*pay_load_len % 4) ? 1 : 0)) * 4; |
| 120 | |
| 121 | tsf_time = (__le64 *)(skb_data + 8 + pay_load_with_padding); |
| 122 | |
| 123 | priv->tsf_time = le64_to_cpu(*tsf_time); |
| 124 | |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 125 | if (priv->bb_type == BB_TYPE_11G) { |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 126 | sq_3 = skb_data + 8 + pay_load_with_padding + 12; |
| 127 | sq = sq_3; |
| 128 | } else { |
| 129 | sq = skb_data + 8 + pay_load_with_padding + 8; |
| 130 | sq_3 = sq; |
| 131 | } |
| 132 | |
| 133 | new_rsr = skb_data + 8 + pay_load_with_padding + 9; |
| 134 | rssi = skb_data + 8 + pay_load_with_padding + 10; |
Malcolm Priestley | 47b41d9 | 2014-07-05 19:24:24 +0100 | [diff] [blame] | 135 | |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 136 | rsr = skb_data + 8 + pay_load_with_padding + 11; |
Malcolm Priestley | 47b41d9 | 2014-07-05 19:24:24 +0100 | [diff] [blame] | 137 | if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN)) |
| 138 | return false; |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 139 | |
| 140 | frame_size = *pay_load_len; |
| 141 | |
| 142 | vnt_rf_rssi_to_dbm(priv, *rssi, &rx_dbm); |
| 143 | |
Malcolm Priestley | 1268722 | 2014-07-20 15:33:27 +0100 | [diff] [blame] | 144 | priv->bb_pre_ed_rssi = (u8)rx_dbm + 1; |
| 145 | priv->current_rssi = priv->bb_pre_ed_rssi; |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 146 | |
| 147 | frame = skb_data + 8; |
| 148 | |
| 149 | skb_pull(skb, 8); |
| 150 | skb_trim(skb, frame_size); |
| 151 | |
| 152 | rx_status.mactime = priv->tsf_time; |
| 153 | rx_status.band = hw->conf.chandef.chan->band; |
| 154 | rx_status.signal = rx_dbm; |
| 155 | rx_status.flag = 0; |
| 156 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 157 | |
Malcolm Priestley | 47b41d9 | 2014-07-05 19:24:24 +0100 | [diff] [blame] | 158 | if (!(*rsr & RSR_CRCOK)) |
| 159 | rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 160 | |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 161 | hdr = (struct ieee80211_hdr *)(skb->data); |
| 162 | fc = hdr->frame_control; |
| 163 | |
| 164 | rx_status.rate_idx = rate_idx; |
| 165 | |
| 166 | if (ieee80211_has_protected(fc)) { |
Malcolm Priestley | f1945a1 | 2014-07-19 12:30:06 +0100 | [diff] [blame] | 167 | if (priv->local_id > REV_ID_VT3253_A1) { |
Malcolm Priestley | 47b41d9 | 2014-07-05 19:24:24 +0100 | [diff] [blame] | 168 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 169 | |
| 170 | /* Drop packet */ |
| 171 | if (!(*new_rsr & NEWRSR_DECRYPTOK)) { |
| 172 | dev_kfree_skb(skb); |
| 173 | return true; |
| 174 | } |
| 175 | } |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); |
| 179 | |
| 180 | ieee80211_rx_irqsafe(priv->hw, skb); |
| 181 | |
| 182 | return true; |
| 183 | } |