Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 37 | #include "wctl.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 38 | #include "device.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 39 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | |
| 41 | /*--------------------- Static Definitions -------------------------*/ |
| 42 | |
| 43 | /*--------------------- Static Classes ----------------------------*/ |
| 44 | |
| 45 | /*--------------------- Static Variables --------------------------*/ |
| 46 | // static int msglevel =MSG_LEVEL_INFO; |
| 47 | /*--------------------- Static Functions --------------------------*/ |
| 48 | |
| 49 | /*--------------------- Export Variables --------------------------*/ |
| 50 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 51 | /* |
| 52 | * Description: |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 53 | * Scan Rx cache. Return true if packet is duplicate, else |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 54 | * inserts in receive cache and returns false. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 55 | * |
| 56 | * Parameters: |
| 57 | * In: |
| 58 | * pCache - Receive packets history |
| 59 | * pMACHeader - 802.11 MAC Header of received packet |
| 60 | * Out: |
| 61 | * none |
| 62 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 63 | * Return Value: true if packet duplicate; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 64 | * |
| 65 | */ |
| 66 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 67 | bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 68 | { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 69 | unsigned int uIndex; |
| 70 | unsigned int ii; |
| 71 | PSCacheEntry pCacheEntry; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 72 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 73 | if (IS_FC_RETRY(pMACHeader)) { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 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 | (!compare_ether_addr(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]))) |
| 79 | ) { |
| 80 | /* Duplicate match */ |
| 81 | return true; |
| 82 | } |
| 83 | ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH); |
| 84 | } |
| 85 | } |
| 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); |
| 91 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Description: |
| 96 | * Found if sequence number of received fragment packet in Defragment Database |
| 97 | * |
| 98 | * Parameters: |
| 99 | * In: |
| 100 | * pDevice - Pointer to adapter |
| 101 | * pMACHeader - 802.11 MAC Header of received packet |
| 102 | * Out: |
| 103 | * none |
| 104 | * |
| 105 | * Return Value: index number in Defragment Database |
| 106 | * |
| 107 | */ |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 108 | unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 109 | { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 110 | unsigned int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 111 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 112 | for (ii = 0; ii < pDevice->cbDFCB; ii++) { |
| 113 | if ((pDevice->sRxDFCB[ii].bInUse == true) && |
| 114 | (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]))) |
| 115 | ) { |
| 116 | // |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 117 | return ii; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 120 | return pDevice->cbDFCB; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 123 | /* |
| 124 | * Description: |
| 125 | * Insert received fragment packet in Defragment Database |
| 126 | * |
| 127 | * Parameters: |
| 128 | * In: |
| 129 | * pDevice - Pointer to adapter |
| 130 | * pMACHeader - 802.11 MAC Header of received packet |
| 131 | * Out: |
| 132 | * none |
| 133 | * |
| 134 | * Return Value: index number in Defragment Database |
| 135 | * |
| 136 | */ |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 137 | unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 138 | { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 139 | unsigned int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 140 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 141 | if (pDevice->cbFreeDFCB == 0) |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 142 | return pDevice->cbDFCB; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 143 | for (ii = 0; ii < pDevice->cbDFCB; ii++) { |
| 144 | if (pDevice->sRxDFCB[ii].bInUse == false) { |
| 145 | pDevice->cbFreeDFCB--; |
| 146 | pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime; |
| 147 | pDevice->sRxDFCB[ii].bInUse = true; |
| 148 | pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4); |
| 149 | pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F); |
| 150 | memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN); |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 151 | return ii; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 154 | return pDevice->cbDFCB; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 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 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 170 | * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 171 | * |
| 172 | */ |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 173 | bool WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 174 | { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 175 | unsigned int uHeaderSize; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 176 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 177 | if (bWEP == true) { |
| 178 | uHeaderSize = 28; |
| 179 | if (bExtIV) |
| 180 | // ExtIV |
| 181 | uHeaderSize += 4; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 182 | } else { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 183 | uHeaderSize = 24; |
| 184 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 185 | |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 186 | if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) { |
| 187 | pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); |
| 188 | if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) { |
| 189 | // duplicate, we must flush previous DCB |
| 190 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime; |
| 191 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4); |
| 192 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 193 | } else { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 194 | pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader); |
| 195 | if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 196 | return false; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | // reserve 4 byte to match MAC RX Buffer |
| 200 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (unsigned char *)(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4); |
| 201 | memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength); |
| 202 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength; |
| 203 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength; |
| 204 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; |
| 205 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 206 | return false; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 207 | } else { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 208 | pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); |
| 209 | if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) { |
| 210 | if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) && |
| 211 | (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) && |
| 212 | ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 213 | memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((unsigned char *)(pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize)); |
| 214 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize); |
| 215 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize); |
| 216 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; |
| 217 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 218 | } else { |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 219 | // seq error or frag # error flush DFCB |
| 220 | pDevice->cbFreeDFCB++; |
| 221 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 222 | return false; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 223 | } |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 224 | } else { |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 225 | return false; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 226 | } |
| 227 | if (IS_LAST_FRAGMENT_PKT(pMACHeader)) { |
| 228 | //enq defragcontrolblock |
| 229 | pDevice->cbFreeDFCB++; |
| 230 | pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false; |
| 231 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 232 | return true; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 233 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 234 | return false; |
Joe Perches | e2b8c6d | 2013-03-18 10:45:10 -0700 | [diff] [blame] | 235 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 236 | } |