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
38 #if !defined(__WCTL_H__)
41 #if !defined(__DEVICE_H__)
44 #if !defined(__CARD_H__)
48 /*--------------------- Static Definitions -------------------------*/
50 /*--------------------- Static Classes ----------------------------*/
52 /*--------------------- Static Variables --------------------------*/
53 // static int msglevel =MSG_LEVEL_INFO;
54 /*--------------------- Static Functions --------------------------*/
56 /*--------------------- Export Variables --------------------------*/
62 * Scan Rx cache. Return TRUE if packet is duplicate, else
63 * inserts in receive cache and returns FALSE.
67 * pCache - Receive packets history
68 * pMACHeader - 802.11 MAC Header of received packet
72 * Return Value: TRUE if packet duplicate; otherwise FALSE
76 BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
80 PSCacheEntry pCacheEntry;
82 if (IS_FC_RETRY(pMACHeader)) {
84 uIndex = pCache->uInPtr;
85 for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
86 pCacheEntry = &(pCache->asCacheEntry[uIndex]);
87 if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
88 (IS_ETH_ADDRESS_EQUAL (&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
93 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
96 /* Not fount in cache - insert */
97 pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
98 pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
99 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), U_ETHER_ADDR_LEN);
100 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
106 * Found if sequence number of received fragment packet in Defragment Database
110 * pDevice - Pointer to adapter
111 * pMACHeader - 802.11 MAC Header of received packet
115 * Return Value: index number in Defragment Database
118 UINT WCTLuSearchDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
122 for(ii=0;ii<pDevice->cbDFCB;ii++) {
123 if ((pDevice->sRxDFCB[ii].bInUse == TRUE) &&
124 (IS_ETH_ADDRESS_EQUAL (&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
130 return(pDevice->cbDFCB);
136 * Insert received fragment packet in Defragment Database
140 * pDevice - Pointer to adapter
141 * pMACHeader - 802.11 MAC Header of received packet
145 * Return Value: index number in Defragment Database
148 UINT WCTLuInsertDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
152 if (pDevice->cbFreeDFCB == 0)
153 return(pDevice->cbDFCB);
154 for(ii=0;ii<pDevice->cbDFCB;ii++) {
155 if (pDevice->sRxDFCB[ii].bInUse == FALSE) {
156 pDevice->cbFreeDFCB--;
157 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
158 pDevice->sRxDFCB[ii].bInUse = TRUE;
159 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
160 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
161 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), U_ETHER_ADDR_LEN);
165 return(pDevice->cbDFCB);
171 * Handle received fragment packet
175 * pDevice - Pointer to adapter
176 * pMACHeader - 802.11 MAC Header of received packet
177 * cbFrameLength - Frame length
178 * bWEP - is WEP packet
182 * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE
185 BOOL WCTLbHandleFragment (PSDevice pDevice, PS802_11Header pMACHeader, UINT cbFrameLength, BOOL bWEP, BOOL bExtIV)
200 if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
201 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
202 if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
203 // duplicate, we must flush previous DCB
204 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
205 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
206 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
209 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
210 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
214 // reserve 4 byte to match MAC RX Buffer
216 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].ref_skb.data + 4);
218 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
220 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
221 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
222 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
223 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
224 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
228 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
229 if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
230 if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
231 (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
232 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
234 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((PBYTE) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
235 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
236 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
237 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
238 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
241 // seq error or frag # error flush DFCB
242 pDevice->cbFreeDFCB++;
243 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE;
250 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
251 //enq defragcontrolblock
252 pDevice->cbFreeDFCB++;
253 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE;
254 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);