Merge branch 'drm-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[deliverable/linux.git] / drivers / staging / vt6656 / wctl.c
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 * File: wctl.c
20 *
21 * Purpose: handle WMAC duplicate filter & defragment
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 * Functions:
28 * WCTLbIsDuplicate - Test if duplicate packet
29 * WCTLuSearchDFCB - Search DeFragment Control Database
30 * WCTLuInsertDFCB - Insert DeFragment Control Database
31 * WCTLbHandleFragment - Handle received fragment packet
32 *
33 * Revision History:
34 *
35 */
36
37 #include "wctl.h"
38 #include "device.h"
39 #include "card.h"
40 #include "tmacro.h"
41
42 /*--------------------- Static Definitions -------------------------*/
43
44 /*--------------------- Static Classes ----------------------------*/
45
46 /*--------------------- Static Variables --------------------------*/
47 // static int msglevel =MSG_LEVEL_INFO;
48 /*--------------------- Static Functions --------------------------*/
49
50 /*--------------------- Export Variables --------------------------*/
51
52
53
54 /*
55 * Description:
56 * Scan Rx cache. Return TRUE if packet is duplicate, else
57 * inserts in receive cache and returns FALSE.
58 *
59 * Parameters:
60 * In:
61 * pCache - Receive packets history
62 * pMACHeader - 802.11 MAC Header of received packet
63 * Out:
64 * none
65 *
66 * Return Value: TRUE if packet duplicate; otherwise FALSE
67 *
68 */
69
70 BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
71 {
72 UINT uIndex;
73 UINT ii;
74 PSCacheEntry pCacheEntry;
75
76 if (IS_FC_RETRY(pMACHeader)) {
77
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))
84 ) {
85 /* Duplicate match */
86 return TRUE;
87 }
88 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
89 }
90 }
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);
97 return FALSE;
98 }
99
100 /*
101 * Description:
102 * Found if sequence number of received fragment packet in Defragment Database
103 *
104 * Parameters:
105 * In:
106 * pDevice - Pointer to adapter
107 * pMACHeader - 802.11 MAC Header of received packet
108 * Out:
109 * none
110 *
111 * Return Value: index number in Defragment Database
112 *
113 */
114 UINT WCTLuSearchDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
115 {
116 UINT ii;
117
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])))
121 ) {
122 //
123 return(ii);
124 }
125 }
126 return(pDevice->cbDFCB);
127 }
128
129
130 /*
131 * Description:
132 * Insert received fragment packet in Defragment Database
133 *
134 * Parameters:
135 * In:
136 * pDevice - Pointer to adapter
137 * pMACHeader - 802.11 MAC Header of received packet
138 * Out:
139 * none
140 *
141 * Return Value: index number in Defragment Database
142 *
143 */
144 UINT WCTLuInsertDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
145 {
146 UINT ii;
147
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);
158 return(ii);
159 }
160 }
161 return(pDevice->cbDFCB);
162 }
163
164
165 /*
166 * Description:
167 * Handle received fragment packet
168 *
169 * Parameters:
170 * In:
171 * pDevice - Pointer to adapter
172 * pMACHeader - 802.11 MAC Header of received packet
173 * cbFrameLength - Frame length
174 * bWEP - is WEP packet
175 * Out:
176 * none
177 *
178 * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE
179 *
180 */
181 BOOL WCTLbHandleFragment (PSDevice pDevice, PS802_11Header pMACHeader, UINT cbFrameLength, BOOL bWEP, BOOL bExtIV)
182 {
183 UINT uHeaderSize;
184
185
186 if (bWEP == TRUE) {
187 uHeaderSize = 28;
188 if (bExtIV)
189 // ExtIV
190 uHeaderSize +=4;
191 }
192 else {
193 uHeaderSize = 24;
194 }
195
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);
203 }
204 else {
205 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
206 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
207 return(FALSE);
208 }
209 }
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);
218 return(FALSE);
219 }
220 else {
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)) {
226
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);
232 }
233 else {
234 // seq error or frag # error flush DFCB
235 pDevice->cbFreeDFCB++;
236 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE;
237 return(FALSE);
238 }
239 }
240 else {
241 return(FALSE);
242 }
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);
248 return(TRUE);
249 }
250 return(FALSE);
251 }
252 }
253
254
This page took 0.05086 seconds and 5 git commands to generate.