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
41 /*--------------------- Static Definitions -------------------------*/
43 /*--------------------- Static Classes ----------------------------*/
45 /*--------------------- Static Variables --------------------------*/
47 /*--------------------- Static Functions --------------------------*/
49 /*--------------------- Export Variables --------------------------*/
53 * Scan Rx cache. Return true if packet is duplicate, else
54 * inserts in receive cache and returns false.
58 * pCache - Receive packets history
59 * pMACHeader - 802.11 MAC Header of received packet
63 * Return Value: true if packet duplicate; otherwise false
67 bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader)
71 PSCacheEntry pCacheEntry;
73 if (IS_FC_RETRY(pMACHeader)) {
74 uIndex = pCache->uInPtr;
75 for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
76 pCacheEntry = &(pCache->asCacheEntry[uIndex]);
77 if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
78 ether_addr_equal(pCacheEntry->abyAddr2,
79 pMACHeader->abyAddr2)) {
83 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
86 /* Not fount in cache - insert */
87 pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
88 pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
89 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
90 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
96 * Found if sequence number of received fragment packet in Defragment Database
100 * pDevice - Pointer to adapter
101 * pMACHeader - 802.11 MAC Header of received packet
105 * Return Value: index number in Defragment Database
108 unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
112 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
113 if (pDevice->sRxDFCB[ii].bInUse &&
114 ether_addr_equal(pDevice->sRxDFCB[ii].abyAddr2,
115 pMACHeader->abyAddr2)) {
119 return pDevice->cbDFCB;
124 * Insert received fragment packet in Defragment Database
128 * pDevice - Pointer to adapter
129 * pMACHeader - 802.11 MAC Header of received packet
133 * Return Value: index number in Defragment Database
136 unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
140 if (pDevice->cbFreeDFCB == 0)
141 return pDevice->cbDFCB;
142 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
143 if (!pDevice->sRxDFCB[ii].bInUse) {
144 pDevice->cbFreeDFCB--;
145 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
146 pDevice->sRxDFCB[ii].bInUse = true;
147 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
148 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
149 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
153 return pDevice->cbDFCB;
158 * Handle received fragment packet
162 * pDevice - Pointer to adapter
163 * pMACHeader - 802.11 MAC Header of received packet
164 * cbFrameLength - Frame length
165 * bWEP - is WEP packet
169 * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
172 bool WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV)
174 unsigned int uHeaderSize;
185 if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
186 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
187 if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
188 // duplicate, we must flush previous DCB
189 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
190 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
191 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
193 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
194 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB)
197 // reserve 4 byte to match MAC RX Buffer
198 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (unsigned char *)(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
199 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
200 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
201 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
202 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
205 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
206 if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
207 if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
208 (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
209 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
210 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((unsigned char *)(pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
211 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
212 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
213 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
215 // seq error or frag # error flush DFCB
216 pDevice->cbFreeDFCB++;
217 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
223 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
224 //enq defragcontrolblock
225 pDevice->cbFreeDFCB++;
226 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;