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.
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.
21 * Purpose: handle WMAC duplicate filter & defragment
28 * WCTLbIsDuplicate - Test if duplicate packet
29 * WCTLuSearchDFCB - Search DeFragment Control Database
30 * WCTLuInsertDFCB - Insert DeFragment Control Database
31 * WCTLbHandleFragment - Handle received fragment packet
42 /*--------------------- Static Definitions -------------------------*/
44 /*--------------------- Static Classes ----------------------------*/
46 /*--------------------- Static Variables --------------------------*/
47 // static int msglevel =MSG_LEVEL_INFO;
48 /*--------------------- Static Functions --------------------------*/
50 /*--------------------- Export Variables --------------------------*/
56 * Scan Rx cache. Return TRUE if packet is duplicate, else
57 * inserts in receive cache and returns FALSE.
61 * pCache - Receive packets history
62 * pMACHeader - 802.11 MAC Header of received packet
66 * Return Value: TRUE if packet duplicate; otherwise FALSE
70 BOOL
WCTLbIsDuplicate (PSCache pCache
, PS802_11Header pMACHeader
)
74 PSCacheEntry pCacheEntry
;
76 if (IS_FC_RETRY(pMACHeader
)) {
78 uIndex
= pCache
->uInPtr
;
79 for (ii
= 0; ii
< DUPLICATE_RX_CACHE_LENGTH
; ii
++) {
80 pCacheEntry
= &(pCache
->asCacheEntry
[uIndex
]);
81 if ((pCacheEntry
->wFmSequence
== pMACHeader
->wSeqCtl
) &&
82 (IS_ETH_ADDRESS_EQUAL (&(pCacheEntry
->abyAddr2
[0]), &(pMACHeader
->abyAddr2
[0]))) &&
83 (LOBYTE(pCacheEntry
->wFrameCtl
) == LOBYTE(pMACHeader
->wFrameCtl
))
88 ADD_ONE_WITH_WRAP_AROUND(uIndex
, DUPLICATE_RX_CACHE_LENGTH
);
91 /* Not fount in cache - insert */
92 pCacheEntry
= &pCache
->asCacheEntry
[pCache
->uInPtr
];
93 pCacheEntry
->wFmSequence
= pMACHeader
->wSeqCtl
;
94 memcpy(&(pCacheEntry
->abyAddr2
[0]), &(pMACHeader
->abyAddr2
[0]), U_ETHER_ADDR_LEN
);
95 pCacheEntry
->wFrameCtl
= pMACHeader
->wFrameCtl
;
96 ADD_ONE_WITH_WRAP_AROUND(pCache
->uInPtr
, DUPLICATE_RX_CACHE_LENGTH
);
102 * Found if sequence number of received fragment packet in Defragment Database
106 * pDevice - Pointer to adapter
107 * pMACHeader - 802.11 MAC Header of received packet
111 * Return Value: index number in Defragment Database
114 UINT
WCTLuSearchDFCB (PSDevice pDevice
, PS802_11Header pMACHeader
)
118 for(ii
=0;ii
<pDevice
->cbDFCB
;ii
++) {
119 if ((pDevice
->sRxDFCB
[ii
].bInUse
== TRUE
) &&
120 (IS_ETH_ADDRESS_EQUAL (&(pDevice
->sRxDFCB
[ii
].abyAddr2
[0]), &(pMACHeader
->abyAddr2
[0])))
126 return(pDevice
->cbDFCB
);
132 * Insert received fragment packet in Defragment Database
136 * pDevice - Pointer to adapter
137 * pMACHeader - 802.11 MAC Header of received packet
141 * Return Value: index number in Defragment Database
144 UINT
WCTLuInsertDFCB (PSDevice pDevice
, PS802_11Header pMACHeader
)
148 if (pDevice
->cbFreeDFCB
== 0)
149 return(pDevice
->cbDFCB
);
150 for(ii
=0;ii
<pDevice
->cbDFCB
;ii
++) {
151 if (pDevice
->sRxDFCB
[ii
].bInUse
== FALSE
) {
152 pDevice
->cbFreeDFCB
--;
153 pDevice
->sRxDFCB
[ii
].uLifetime
= pDevice
->dwMaxReceiveLifetime
;
154 pDevice
->sRxDFCB
[ii
].bInUse
= TRUE
;
155 pDevice
->sRxDFCB
[ii
].wSequence
= (pMACHeader
->wSeqCtl
>> 4);
156 pDevice
->sRxDFCB
[ii
].wFragNum
= (pMACHeader
->wSeqCtl
& 0x000F);
157 memcpy(&(pDevice
->sRxDFCB
[ii
].abyAddr2
[0]), &(pMACHeader
->abyAddr2
[0]), U_ETHER_ADDR_LEN
);
161 return(pDevice
->cbDFCB
);
167 * Handle received fragment packet
171 * pDevice - Pointer to adapter
172 * pMACHeader - 802.11 MAC Header of received packet
173 * cbFrameLength - Frame length
174 * bWEP - is WEP packet
178 * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE
181 BOOL
WCTLbHandleFragment (PSDevice pDevice
, PS802_11Header pMACHeader
, UINT cbFrameLength
, BOOL bWEP
, BOOL bExtIV
)
196 if (IS_FIRST_FRAGMENT_PKT(pMACHeader
)) {
197 pDevice
->uCurrentDFCBIdx
= WCTLuSearchDFCB(pDevice
, pMACHeader
);
198 if (pDevice
->uCurrentDFCBIdx
< pDevice
->cbDFCB
) {
199 // duplicate, we must flush previous DCB
200 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].uLifetime
= pDevice
->dwMaxReceiveLifetime
;
201 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wSequence
= (pMACHeader
->wSeqCtl
>> 4);
202 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wFragNum
= (pMACHeader
->wSeqCtl
& 0x000F);
205 pDevice
->uCurrentDFCBIdx
= WCTLuInsertDFCB(pDevice
, pMACHeader
);
206 if (pDevice
->uCurrentDFCBIdx
== pDevice
->cbDFCB
) {
210 // reserve 8 byte to match MAC RX Buffer
211 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].pbyRxBuffer
= (PBYTE
) (pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
->data
+ 8);
212 // pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
213 memcpy(pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].pbyRxBuffer
, pMACHeader
, cbFrameLength
);
214 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
= cbFrameLength
;
215 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].pbyRxBuffer
+= cbFrameLength
;
216 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wFragNum
++;
217 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
221 pDevice
->uCurrentDFCBIdx
= WCTLuSearchDFCB(pDevice
, pMACHeader
);
222 if (pDevice
->uCurrentDFCBIdx
!= pDevice
->cbDFCB
) {
223 if ((pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wSequence
== (pMACHeader
->wSeqCtl
>> 4)) &&
224 (pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wFragNum
== (pMACHeader
->wSeqCtl
& 0x000F)) &&
225 ((pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
+ cbFrameLength
- uHeaderSize
) < 2346)) {
227 memcpy(pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].pbyRxBuffer
, ((PBYTE
) (pMACHeader
) + uHeaderSize
), (cbFrameLength
- uHeaderSize
));
228 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
+= (cbFrameLength
- uHeaderSize
);
229 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].pbyRxBuffer
+= (cbFrameLength
- uHeaderSize
);
230 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].wFragNum
++;
231 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
234 // seq error or frag # error flush DFCB
235 pDevice
->cbFreeDFCB
++;
236 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].bInUse
= FALSE
;
243 if (IS_LAST_FRAGMENT_PKT(pMACHeader
)) {
244 //enq defragcontrolblock
245 pDevice
->cbFreeDFCB
++;
246 pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].bInUse
= FALSE
;
247 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);