Staging: Add pristine upstream vt6656 driver sources to drivers/staging/vt6656.
[firewire-audio.git] / drivers / staging / vt6656 / tether.c
blobfd69423fe14b33d9bba89914fb31ea7518699d2f
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 #if !defined(__DEVICE_H__)
36 #include "device.h"
37 #endif
38 #if !defined(__TMACRO_H__)
39 #include "tmacro.h"
40 #endif
41 #if !defined(__TBIT_H__)
42 #include "tbit.h"
43 #endif
44 #if !defined(__TCRC_H__)
45 #include "tcrc.h"
46 #endif
47 #if !defined(__TETHER_H__)
48 #include "tether.h"
49 #endif
54 /*--------------------- Static Definitions -------------------------*/
56 /*--------------------- Static Classes ----------------------------*/
58 /*--------------------- Static Variables --------------------------*/
60 /*--------------------- Static Functions --------------------------*/
62 /*--------------------- Export Variables --------------------------*/
67 * Description: Caculate multicast hash value by CRC32
69 * Parameters:
70 * In:
71 * pbyMultiAddr - Multicast Address
72 * Out:
73 * none
75 * Return Value: Hash value
78 BYTE ETHbyGetHashIndexByCrc32 (PBYTE pbyMultiAddr)
80 int ii;
81 BYTE byTmpHash;
82 BYTE byHash = 0;
84 // get the least 6-bits from CRC generator
85 byTmpHash = (BYTE)(CRCdwCrc32(pbyMultiAddr, U_ETHER_ADDR_LEN,
86 0xFFFFFFFFL) & 0x3F);
87 // reverse most bit to least bit
88 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
89 byHash <<= 1;
90 if (BITbIsBitOn(byTmpHash, 0x01))
91 byHash |= 1;
92 byTmpHash >>= 1;
95 // adjust 6-bits to the right most
96 return (byHash >> 2);
101 * Description: Check CRC value of the buffer if Ok or not
103 * Parameters:
104 * In:
105 * pbyBuffer - pointer of buffer (normally is rx buffer)
106 * cbFrameLength - length of buffer, including CRC portion
107 * Out:
108 * none
110 * Return Value: TRUE if ok; FALSE if error.
113 BOOL ETHbIsBufferCrc32Ok (PBYTE pbyBuffer, UINT cbFrameLength)
115 DWORD dwCRC;
117 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
118 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
119 return FALSE;
121 return TRUE;