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
44 // static int msglevel =MSG_LEVEL_INFO;
51 * Scan Rx cache. Return true if packet is duplicate, else
52 * inserts in receive cache and returns false.
56 * pCache - Receive packets history
57 * pMACHeader - 802.11 MAC Header of received packet
61 * Return Value: true if packet duplicate; otherwise false
65 bool WCTLbIsDuplicate (PSCache pCache, struct ieee80211_hdr *pMACHeader)
69 PSCacheEntry pCacheEntry;
71 if (IS_FC_RETRY(pMACHeader)) {
73 uIndex = pCache->uInPtr;
74 for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
75 pCacheEntry = &(pCache->asCacheEntry[uIndex]);
76 if ((pCacheEntry->wFmSequence == pMACHeader->seq_ctrl) &&
77 (!compare_ether_addr(&(pCacheEntry->abyAddr2[0]),
78 &(pMACHeader->addr2[0]))) &&
79 (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->frame_control))
84 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
87 /* Not found in cache - insert */
88 pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
89 pCacheEntry->wFmSequence = pMACHeader->seq_ctrl;
90 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->addr2[0]), ETH_ALEN);
91 pCacheEntry->wFrameCtl = pMACHeader->frame_control;
92 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
98 * Found if sequence number of received fragment packet in Defragment Database
102 * pDevice - Pointer to adapter
103 * pMACHeader - 802.11 MAC Header of received packet
107 * Return Value: index number in Defragment Database
111 unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
112 struct ieee80211_hdr *pMACHeader)
116 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
117 if ((pDevice->sRxDFCB[ii].bInUse == true) &&
118 (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
119 &(pMACHeader->addr2[0])))) {
123 return pDevice->cbDFCB;
128 * Insert received fragment packet in Defragment Database
132 * pDevice - Pointer to adapter
133 * pMACHeader - 802.11 MAC Header of received packet
137 * Return Value: index number in Defragment Database
140 unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
141 struct ieee80211_hdr *pMACHeader)
145 if (pDevice->cbFreeDFCB == 0)
146 return(pDevice->cbDFCB);
147 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
148 if (pDevice->sRxDFCB[ii].bInUse == false) {
149 pDevice->cbFreeDFCB--;
150 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
151 pDevice->sRxDFCB[ii].bInUse = true;
152 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->seq_ctrl >> 4);
153 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->seq_ctrl & 0x000F);
154 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
155 &(pMACHeader->addr2[0]),
160 return(pDevice->cbDFCB);
166 * Handle received fragment packet
170 * pDevice - Pointer to adapter
171 * pMACHeader - 802.11 MAC Header of received packet
172 * cbFrameLength - Frame length
173 * bWEP - is WEP packet
177 * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
180 bool WCTLbHandleFragment(struct vnt_private *pDevice, struct ieee80211_hdr *pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV)
182 unsigned int uHeaderSize;
195 if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
196 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
197 if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
198 // duplicate, we must flush previous DCB
199 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
200 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->seq_ctrl >> 4);
201 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->seq_ctrl & 0x000F);
204 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
205 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
209 // reserve 8 byte to match MAC RX Buffer
210 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 8);
211 // pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
212 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
213 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
214 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
215 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
216 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
220 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
221 if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
222 if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->seq_ctrl >> 4)) &&
223 (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->seq_ctrl & 0x000F)) &&
224 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
226 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((u8 *) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
227 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
228 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
229 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
230 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
233 // seq error or frag # error flush DFCB
234 pDevice->cbFreeDFCB++;
235 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
242 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
243 //enq defragcontrolblock
244 pDevice->cbFreeDFCB++;
245 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
246 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);