Commit | Line | Data |
---|---|---|
92b96797 FB |
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 | ||
92b96797 | 37 | #include "wctl.h" |
92b96797 | 38 | #include "device.h" |
92b96797 | 39 | #include "card.h" |
92b96797 | 40 | #include "tmacro.h" |
92b96797 | 41 | |
92b96797 | 42 | // static int msglevel =MSG_LEVEL_INFO; |
92b96797 | 43 | |
92b96797 FB |
44 | /* |
45 | * Description: | |
4e9b5e2b | 46 | * Scan Rx cache. Return true if packet is duplicate, else |
e269fc2d | 47 | * inserts in receive cache and returns false. |
92b96797 FB |
48 | * |
49 | * Parameters: | |
50 | * In: | |
51 | * pCache - Receive packets history | |
52 | * pMACHeader - 802.11 MAC Header of received packet | |
53 | * Out: | |
54 | * none | |
55 | * | |
4e9b5e2b | 56 | * Return Value: true if packet duplicate; otherwise false |
92b96797 FB |
57 | * |
58 | */ | |
59 | ||
1cac4a4b | 60 | bool WCTLbIsDuplicate (PSCache pCache, struct ieee80211_hdr *pMACHeader) |
92b96797 | 61 | { |
cc856e61 AM |
62 | unsigned int uIndex; |
63 | unsigned int ii; | |
92b96797 FB |
64 | PSCacheEntry pCacheEntry; |
65 | ||
66 | if (IS_FC_RETRY(pMACHeader)) { | |
67 | ||
68 | uIndex = pCache->uInPtr; | |
69 | for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) { | |
70 | pCacheEntry = &(pCache->asCacheEntry[uIndex]); | |
1cac4a4b | 71 | if ((pCacheEntry->wFmSequence == pMACHeader->seq_ctrl) && |
8329419a | 72 | ether_addr_equal(pCacheEntry->abyAddr2, pMACHeader->addr2) && |
9046db51 | 73 | (pCacheEntry->wFrameCtl == pMACHeader->frame_control) |
92b96797 FB |
74 | ) { |
75 | /* Duplicate match */ | |
4e9b5e2b | 76 | return true; |
92b96797 FB |
77 | } |
78 | ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH); | |
79 | } | |
80 | } | |
a0a1f61a | 81 | /* Not found in cache - insert */ |
92b96797 | 82 | pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr]; |
1cac4a4b AM |
83 | pCacheEntry->wFmSequence = pMACHeader->seq_ctrl; |
84 | memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->addr2[0]), ETH_ALEN); | |
85 | pCacheEntry->wFrameCtl = pMACHeader->frame_control; | |
92b96797 | 86 | ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH); |
e269fc2d | 87 | return false; |
92b96797 FB |
88 | } |
89 | ||
90 | /* | |
91 | * Description: | |
92 | * Found if sequence number of received fragment packet in Defragment Database | |
93 | * | |
94 | * Parameters: | |
95 | * In: | |
96 | * pDevice - Pointer to adapter | |
97 | * pMACHeader - 802.11 MAC Header of received packet | |
98 | * Out: | |
99 | * none | |
100 | * | |
101 | * Return Value: index number in Defragment Database | |
102 | * | |
103 | */ | |
33d33e42 | 104 | |
98583c09 | 105 | unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice, |
1cac4a4b | 106 | struct ieee80211_hdr *pMACHeader) |
92b96797 | 107 | { |
cc856e61 | 108 | unsigned int ii; |
92b96797 | 109 | |
33d33e42 | 110 | for (ii = 0; ii < pDevice->cbDFCB; ii++) { |
4e9b5e2b | 111 | if ((pDevice->sRxDFCB[ii].bInUse == true) && |
8329419a JP |
112 | ether_addr_equal(pDevice->sRxDFCB[ii].abyAddr2, |
113 | pMACHeader->addr2)) { | |
33d33e42 AM |
114 | return ii; |
115 | } | |
116 | } | |
117 | return pDevice->cbDFCB; | |
92b96797 FB |
118 | } |
119 | ||
92b96797 FB |
120 | /* |
121 | * Description: | |
122 | * Insert received fragment packet in Defragment Database | |
123 | * | |
124 | * Parameters: | |
125 | * In: | |
126 | * pDevice - Pointer to adapter | |
127 | * pMACHeader - 802.11 MAC Header of received packet | |
128 | * Out: | |
129 | * none | |
130 | * | |
131 | * Return Value: index number in Defragment Database | |
132 | * | |
133 | */ | |
98583c09 | 134 | unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, |
1cac4a4b | 135 | struct ieee80211_hdr *pMACHeader) |
92b96797 | 136 | { |
cc856e61 | 137 | unsigned int ii; |
92b96797 FB |
138 | |
139 | if (pDevice->cbFreeDFCB == 0) | |
140 | return(pDevice->cbDFCB); | |
33d33e42 | 141 | for (ii = 0; ii < pDevice->cbDFCB; ii++) { |
e269fc2d | 142 | if (pDevice->sRxDFCB[ii].bInUse == false) { |
92b96797 FB |
143 | pDevice->cbFreeDFCB--; |
144 | pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime; | |
4e9b5e2b | 145 | pDevice->sRxDFCB[ii].bInUse = true; |
1cac4a4b AM |
146 | pDevice->sRxDFCB[ii].wSequence = (pMACHeader->seq_ctrl >> 4); |
147 | pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->seq_ctrl & 0x000F); | |
9a0e756c | 148 | memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), |
1cac4a4b | 149 | &(pMACHeader->addr2[0]), |
9a0e756c | 150 | ETH_ALEN); |
92b96797 FB |
151 | return(ii); |
152 | } | |
153 | } | |
154 | return(pDevice->cbDFCB); | |
155 | } | |
156 | ||
92b96797 FB |
157 | /* |
158 | * Description: | |
159 | * Handle received fragment packet | |
160 | * | |
161 | * Parameters: | |
162 | * In: | |
163 | * pDevice - Pointer to adapter | |
164 | * pMACHeader - 802.11 MAC Header of received packet | |
165 | * cbFrameLength - Frame length | |
166 | * bWEP - is WEP packet | |
167 | * Out: | |
168 | * none | |
169 | * | |
4e9b5e2b | 170 | * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false |
92b96797 FB |
171 | * |
172 | */ | |
1cac4a4b | 173 | bool WCTLbHandleFragment(struct vnt_private *pDevice, struct ieee80211_hdr *pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV) |
92b96797 | 174 | { |
98583c09 | 175 | unsigned int uHeaderSize; |
92b96797 | 176 | |
4e9b5e2b | 177 | if (bWEP == true) { |
92b96797 FB |
178 | uHeaderSize = 28; |
179 | if (bExtIV) | |
180 | // ExtIV | |
181 | uHeaderSize +=4; | |
182 | } | |
183 | else { | |
184 | uHeaderSize = 24; | |
185 | } | |
186 | ||
187 | if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) { | |
188 | pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); | |
189 | if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) { | |
190 | // duplicate, we must flush previous DCB | |
191 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime; | |
1cac4a4b AM |
192 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->seq_ctrl >> 4); |
193 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->seq_ctrl & 0x000F); | |
92b96797 FB |
194 | } |
195 | else { | |
196 | pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader); | |
197 | if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) { | |
e269fc2d | 198 | return(false); |
92b96797 FB |
199 | } |
200 | } | |
201 | // reserve 8 byte to match MAC RX Buffer | |
b902fbfe AM |
202 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 8); |
203 | // pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4); | |
92b96797 FB |
204 | memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength); |
205 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength; | |
206 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength; | |
207 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; | |
208 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); | |
e269fc2d | 209 | return(false); |
92b96797 FB |
210 | } |
211 | else { | |
212 | pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); | |
213 | if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) { | |
1cac4a4b AM |
214 | if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->seq_ctrl >> 4)) && |
215 | (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->seq_ctrl & 0x000F)) && | |
92b96797 FB |
216 | ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) { |
217 | ||
b902fbfe | 218 | memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((u8 *) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize)); |
92b96797 FB |
219 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize); |
220 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize); | |
221 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; | |
222 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); | |
223 | } | |
224 | else { | |
225 | // seq error or frag # error flush DFCB | |
226 | pDevice->cbFreeDFCB++; | |
e269fc2d AM |
227 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; |
228 | return(false); | |
92b96797 FB |
229 | } |
230 | } | |
231 | else { | |
e269fc2d | 232 | return(false); |
92b96797 FB |
233 | } |
234 | if (IS_LAST_FRAGMENT_PKT(pMACHeader)) { | |
235 | //enq defragcontrolblock | |
236 | pDevice->cbFreeDFCB++; | |
e269fc2d | 237 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; |
92b96797 | 238 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); |
4e9b5e2b | 239 | return(true); |
92b96797 | 240 | } |
e269fc2d | 241 | return(false); |
92b96797 FB |
242 | } |
243 | } | |
244 |