2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
18 * Purpose: handle dpc rx functions
36 int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
37 unsigned long bytes_received)
39 struct ieee80211_hw *hw = priv->hw;
40 struct ieee80211_supported_band *sband;
42 struct ieee80211_rx_status rx_status = { 0 };
43 struct ieee80211_hdr *hdr;
45 u8 *rsr, *new_rsr, *rssi, *frame;
49 u8 *rx_sts, *rx_rate, *sq, *sq_3;
53 u16 pay_load_with_padding;
55 u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
60 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
61 wbk_status = *((u32 *)(skb->data));
62 frame_size = wbk_status >> 16;
65 if (bytes_received != frame_size) {
66 dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n");
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");
76 skb_data = (u8 *)skb->data;
81 /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
82 /* -8TSF - 4RSR - 4SQ3 - ?Padding */
84 /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
86 pay_load_len = (u16 *) (skb_data + 6);
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",
97 sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
99 for (r = RATE_1M; r < MAX_RATE; r++) {
100 if (*rx_rate == rate[r])
106 for (ii = 0; ii < sband->n_bitrates; ii++) {
107 if (sband->bitrates[ii].hw_value == r) {
113 if (ii == sband->n_bitrates) {
114 dev_dbg(&priv->usb->dev, "Wrong RxRate %x\n", *rx_rate);
118 pay_load_with_padding = ((*pay_load_len / 4) +
119 ((*pay_load_len % 4) ? 1 : 0)) * 4;
121 tsf_time = (__le64 *)(skb_data + 8 + pay_load_with_padding);
123 priv->tsf_time = le64_to_cpu(*tsf_time);
125 if (priv->bb_type == BB_TYPE_11G) {
126 sq_3 = skb_data + 8 + pay_load_with_padding + 12;
129 sq = skb_data + 8 + pay_load_with_padding + 8;
133 new_rsr = skb_data + 8 + pay_load_with_padding + 9;
134 rssi = skb_data + 8 + pay_load_with_padding + 10;
136 rsr = skb_data + 8 + pay_load_with_padding + 11;
137 if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
140 frame_size = *pay_load_len;
142 vnt_rf_rssi_to_dbm(priv, *rssi, &rx_dbm);
144 priv->bb_pre_ed_rssi = (u8)rx_dbm + 1;
145 priv->current_rssi = priv->bb_pre_ed_rssi;
147 frame = skb_data + 8;
150 skb_trim(skb, frame_size);
152 rx_status.mactime = priv->tsf_time;
153 rx_status.band = hw->conf.chandef.chan->band;
154 rx_status.signal = rx_dbm;
156 rx_status.freq = hw->conf.chandef.chan->center_freq;
158 if (!(*rsr & RSR_CRCOK))
159 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
161 hdr = (struct ieee80211_hdr *)(skb->data);
162 fc = hdr->frame_control;
164 rx_status.rate_idx = rate_idx;
166 if (ieee80211_has_protected(fc)) {
167 if (priv->local_id > REV_ID_VT3253_A1) {
168 rx_status.flag |= RX_FLAG_DECRYPTED;
171 if (!(*new_rsr & NEWRSR_DECRYPTOK)) {
178 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
180 ieee80211_rx_irqsafe(priv->hw, skb);