[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / staging / vt6655 / tether.c
blobc90b469ad545503ed7c76d2eea9ff88c80da1f2c
1 /*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: tether.c
21 * Purpose:
23 * Author: Tevin Chen
25 * Date: May 21, 1996
27 * Functions:
28 * ETHbyGetHashIndexByCrc32 - Caculate multicast hash value by CRC32
29 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
31 * Revision History:
35 #include "device.h"
36 #include "tmacro.h"
37 #include "tcrc.h"
38 #include "tether.h"
40 /*--------------------- Static Definitions -------------------------*/
42 /*--------------------- Static Classes ----------------------------*/
44 /*--------------------- Static Variables --------------------------*/
46 /*--------------------- Static Functions --------------------------*/
48 /*--------------------- Export Variables --------------------------*/
53 * Description: Caculate multicast hash value by CRC32
55 * Parameters:
56 * In:
57 * pbyMultiAddr - Multicast Address
58 * Out:
59 * none
61 * Return Value: Hash value
64 BYTE ETHbyGetHashIndexByCrc32 (PBYTE pbyMultiAddr)
66 int ii;
67 BYTE byTmpHash;
68 BYTE byHash = 0;
70 // get the least 6-bits from CRC generator
71 byTmpHash = (BYTE)(CRCdwCrc32(pbyMultiAddr, U_ETHER_ADDR_LEN,
72 0xFFFFFFFFL) & 0x3F);
73 // reverse most bit to least bit
74 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
75 byHash <<= 1;
76 if (byTmpHash & 0x01)
77 byHash |= 1;
78 byTmpHash >>= 1;
81 // adjust 6-bits to the right most
82 return (byHash >> 2);
87 * Description: Check CRC value of the buffer if Ok or not
89 * Parameters:
90 * In:
91 * pbyBuffer - pointer of buffer (normally is rx buffer)
92 * cbFrameLength - length of buffer, including CRC portion
93 * Out:
94 * none
96 * Return Value: TRUE if ok; FALSE if error.
99 BOOL ETHbIsBufferCrc32Ok (PBYTE pbyBuffer, UINT cbFrameLength)
101 DWORD dwCRC;
103 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
104 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
105 return FALSE;
107 return TRUE;