staging: vt6656: remove code placeholders
[platform/adaptation/renesas_rcar/renesas_kernel.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
43
44 // static int          msglevel                =MSG_LEVEL_INFO;
45
46
47
48
49 /*
50  * Description:
51  *      Scan Rx cache.  Return true if packet is duplicate, else
52  *      inserts in receive cache and returns false.
53  *
54  * Parameters:
55  *  In:
56  *      pCache      - Receive packets history
57  *      pMACHeader  - 802.11 MAC Header of received packet
58  *  Out:
59  *      none
60  *
61  * Return Value: true if packet duplicate; otherwise false
62  *
63  */
64
65 bool WCTLbIsDuplicate (PSCache pCache, struct ieee80211_hdr *pMACHeader)
66 {
67     unsigned int            uIndex;
68     unsigned int            ii;
69     PSCacheEntry    pCacheEntry;
70
71     if (IS_FC_RETRY(pMACHeader)) {
72
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))
80                 ) {
81                 /* Duplicate match */
82                 return true;
83             }
84             ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
85         }
86     }
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);
93     return false;
94 }
95
96 /*
97  * Description:
98  *      Found if sequence number of received fragment packet in Defragment Database
99  *
100  * Parameters:
101  *  In:
102  *      pDevice     - Pointer to adapter
103  *      pMACHeader  - 802.11 MAC Header of received packet
104  *  Out:
105  *      none
106  *
107  * Return Value: index number in Defragment Database
108  *
109  */
110
111 unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
112                              struct ieee80211_hdr *pMACHeader)
113 {
114         unsigned int ii;
115
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])))) {
120                         return ii;
121                 }
122         }
123         return pDevice->cbDFCB;
124 }
125
126 /*
127  * Description:
128  *      Insert received fragment packet in Defragment Database
129  *
130  * Parameters:
131  *  In:
132  *      pDevice     - Pointer to adapter
133  *      pMACHeader  - 802.11 MAC Header of received packet
134  *  Out:
135  *      none
136  *
137  * Return Value: index number in Defragment Database
138  *
139  */
140 unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
141                              struct ieee80211_hdr *pMACHeader)
142 {
143         unsigned int ii;
144
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]),
156                    ETH_ALEN);
157             return(ii);
158         }
159     }
160     return(pDevice->cbDFCB);
161 }
162
163
164 /*
165  * Description:
166  *      Handle received fragment packet
167  *
168  * Parameters:
169  *  In:
170  *      pDevice         - Pointer to adapter
171  *      pMACHeader      - 802.11 MAC Header of received packet
172  *      cbFrameLength   - Frame length
173  *      bWEP            - is WEP packet
174  *  Out:
175  *      none
176  *
177  * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
178  *
179  */
180 bool WCTLbHandleFragment(struct vnt_private *pDevice, struct ieee80211_hdr *pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV)
181 {
182         unsigned int uHeaderSize;
183
184
185     if (bWEP == true) {
186         uHeaderSize = 28;
187         if (bExtIV)
188         // ExtIV
189             uHeaderSize +=4;
190     }
191     else {
192         uHeaderSize = 24;
193     }
194
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);
202         }
203         else {
204             pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
205             if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
206                 return(false);
207             }
208         }
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);
217         return(false);
218     }
219     else {
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)) {
225
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);
231             }
232             else {
233                 // seq error or frag # error flush DFCB
234                 pDevice->cbFreeDFCB++;
235                 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
236                 return(false);
237             }
238         }
239         else {
240             return(false);
241         }
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);
247             return(true);
248         }
249         return(false);
250     }
251 }
252
253