1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: handle dpc rx functions
26 int vnt_rx_data(struct vnt_private
*priv
, struct vnt_rcb
*ptr_rcb
,
27 unsigned long bytes_received
)
29 struct ieee80211_hw
*hw
= priv
->hw
;
30 struct ieee80211_supported_band
*sband
;
32 struct ieee80211_rx_status rx_status
= { 0 };
33 struct ieee80211_hdr
*hdr
;
35 u8
*rsr
, *new_rsr
, *rssi
;
39 u8
*rx_rate
, *sq
, *sq_3
;
43 u16 pay_load_with_padding
;
45 u8 rate
[MAX_RATE
] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
50 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
51 wbk_status
= *((u32
*)(skb
->data
));
52 frame_size
= wbk_status
>> 16;
55 if (bytes_received
!= frame_size
) {
56 dev_dbg(&priv
->usb
->dev
, "------- WRONG Length 1\n");
60 if ((bytes_received
> 2372) || (bytes_received
<= 40)) {
61 /* Frame Size error drop this packet.*/
62 dev_dbg(&priv
->usb
->dev
, "------ WRONG Length 2\n");
66 skb_data
= (u8
*)skb
->data
;
68 rx_rate
= skb_data
+ 5;
70 /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
71 /* -8TSF - 4RSR - 4SQ3 - ?Padding */
73 /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
75 pay_load_len
= (u16
*)(skb_data
+ 6);
77 /*Fix hardware bug => PLCP_Length error */
78 if (((bytes_received
- (*pay_load_len
)) > 27) ||
79 ((bytes_received
- (*pay_load_len
)) < 24) ||
80 (bytes_received
< (*pay_load_len
))) {
81 dev_dbg(&priv
->usb
->dev
, "Wrong PLCP Length %x\n",
86 sband
= hw
->wiphy
->bands
[hw
->conf
.chandef
.chan
->band
];
88 for (r
= RATE_1M
; r
< MAX_RATE
; r
++) {
89 if (*rx_rate
== rate
[r
])
95 for (ii
= 0; ii
< sband
->n_bitrates
; ii
++) {
96 if (sband
->bitrates
[ii
].hw_value
== r
) {
102 if (ii
== sband
->n_bitrates
) {
103 dev_dbg(&priv
->usb
->dev
, "Wrong RxRate %x\n", *rx_rate
);
107 pay_load_with_padding
= ((*pay_load_len
/ 4) +
108 ((*pay_load_len
% 4) ? 1 : 0)) * 4;
110 tsf_time
= (__le64
*)(skb_data
+ 8 + pay_load_with_padding
);
112 priv
->tsf_time
= le64_to_cpu(*tsf_time
);
114 if (priv
->bb_type
== BB_TYPE_11G
) {
115 sq_3
= skb_data
+ 8 + pay_load_with_padding
+ 12;
118 sq
= skb_data
+ 8 + pay_load_with_padding
+ 8;
122 new_rsr
= skb_data
+ 8 + pay_load_with_padding
+ 9;
123 rssi
= skb_data
+ 8 + pay_load_with_padding
+ 10;
125 rsr
= skb_data
+ 8 + pay_load_with_padding
+ 11;
126 if (*rsr
& (RSR_IVLDTYP
| RSR_IVLDLEN
))
129 frame_size
= *pay_load_len
;
131 vnt_rf_rssi_to_dbm(priv
, *rssi
, &rx_dbm
);
133 priv
->bb_pre_ed_rssi
= (u8
)-rx_dbm
+ 1;
134 priv
->current_rssi
= priv
->bb_pre_ed_rssi
;
137 skb_trim(skb
, frame_size
);
139 rx_status
.mactime
= priv
->tsf_time
;
140 rx_status
.band
= hw
->conf
.chandef
.chan
->band
;
141 rx_status
.signal
= rx_dbm
;
143 rx_status
.freq
= hw
->conf
.chandef
.chan
->center_freq
;
145 if (!(*rsr
& RSR_CRCOK
))
146 rx_status
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
148 hdr
= (struct ieee80211_hdr
*)(skb
->data
);
149 fc
= hdr
->frame_control
;
151 rx_status
.rate_idx
= rate_idx
;
153 if (ieee80211_has_protected(fc
)) {
154 if (priv
->local_id
> REV_ID_VT3253_A1
) {
155 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
158 if (!(*new_rsr
& NEWRSR_DECRYPTOK
)) {
165 memcpy(IEEE80211_SKB_RXCB(skb
), &rx_status
, sizeof(rx_status
));
167 ieee80211_rx_irqsafe(priv
->hw
, skb
);