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_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
;
78 rx_rate
= skb_data
+ 5;
80 /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
81 /* -8TSF - 4RSR - 4SQ3 - ?Padding */
83 /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
85 pay_load_len
= (u16
*)(skb_data
+ 6);
87 /*Fix hardware bug => PLCP_Length error */
88 if (((bytes_received
- (*pay_load_len
)) > 27) ||
89 ((bytes_received
- (*pay_load_len
)) < 24) ||
90 (bytes_received
< (*pay_load_len
))) {
91 dev_dbg(&priv
->usb
->dev
, "Wrong PLCP Length %x\n",
96 sband
= hw
->wiphy
->bands
[hw
->conf
.chandef
.chan
->band
];
98 for (r
= RATE_1M
; r
< MAX_RATE
; r
++) {
99 if (*rx_rate
== rate
[r
])
105 for (ii
= 0; ii
< sband
->n_bitrates
; ii
++) {
106 if (sband
->bitrates
[ii
].hw_value
== r
) {
112 if (ii
== sband
->n_bitrates
) {
113 dev_dbg(&priv
->usb
->dev
, "Wrong RxRate %x\n", *rx_rate
);
117 pay_load_with_padding
= ((*pay_load_len
/ 4) +
118 ((*pay_load_len
% 4) ? 1 : 0)) * 4;
120 tsf_time
= (__le64
*)(skb_data
+ 8 + pay_load_with_padding
);
122 priv
->tsf_time
= le64_to_cpu(*tsf_time
);
124 if (priv
->bb_type
== BB_TYPE_11G
) {
125 sq_3
= skb_data
+ 8 + pay_load_with_padding
+ 12;
128 sq
= skb_data
+ 8 + pay_load_with_padding
+ 8;
132 new_rsr
= skb_data
+ 8 + pay_load_with_padding
+ 9;
133 rssi
= skb_data
+ 8 + pay_load_with_padding
+ 10;
135 rsr
= skb_data
+ 8 + pay_load_with_padding
+ 11;
136 if (*rsr
& (RSR_IVLDTYP
| RSR_IVLDLEN
))
139 frame_size
= *pay_load_len
;
141 vnt_rf_rssi_to_dbm(priv
, *rssi
, &rx_dbm
);
143 priv
->bb_pre_ed_rssi
= (u8
)rx_dbm
+ 1;
144 priv
->current_rssi
= priv
->bb_pre_ed_rssi
;
146 frame
= skb_data
+ 8;
149 skb_trim(skb
, frame_size
);
151 rx_status
.mactime
= priv
->tsf_time
;
152 rx_status
.band
= hw
->conf
.chandef
.chan
->band
;
153 rx_status
.signal
= rx_dbm
;
155 rx_status
.freq
= hw
->conf
.chandef
.chan
->center_freq
;
157 if (!(*rsr
& RSR_CRCOK
))
158 rx_status
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
160 hdr
= (struct ieee80211_hdr
*)(skb
->data
);
161 fc
= hdr
->frame_control
;
163 rx_status
.rate_idx
= rate_idx
;
165 if (ieee80211_has_protected(fc
)) {
166 if (priv
->local_id
> REV_ID_VT3253_A1
) {
167 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
170 if (!(*new_rsr
& NEWRSR_DECRYPTOK
)) {
177 memcpy(IEEE80211_SKB_RXCB(skb
), &rx_status
, sizeof(rx_status
));
179 ieee80211_rx_irqsafe(priv
->hw
, skb
);