blob: fd69423fe14b33d9bba89914fb31ea7518699d2f [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
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.
8 *
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.
13 *
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.
17 *
18 *
19 * File: tether.c
20 *
21 * Purpose:
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * ETHbyGetHashIndexByCrc32 - Caculate multicast hash value by CRC32
29 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
30 *
31 * Revision History:
32 *
33 */
34
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
50
51
52
53
54/*--------------------- Static Definitions -------------------------*/
55
56/*--------------------- Static Classes ----------------------------*/
57
58/*--------------------- Static Variables --------------------------*/
59
60/*--------------------- Static Functions --------------------------*/
61
62/*--------------------- Export Variables --------------------------*/
63
64
65
66/*
67 * Description: Caculate multicast hash value by CRC32
68 *
69 * Parameters:
70 * In:
71 * pbyMultiAddr - Multicast Address
72 * Out:
73 * none
74 *
75 * Return Value: Hash value
76 *
77 */
78BYTE ETHbyGetHashIndexByCrc32 (PBYTE pbyMultiAddr)
79{
80 int ii;
81 BYTE byTmpHash;
82 BYTE byHash = 0;
83
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;
93 }
94
95 // adjust 6-bits to the right most
96 return (byHash >> 2);
97}
98
99
100/*
101 * Description: Check CRC value of the buffer if Ok or not
102 *
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
109 *
110 * Return Value: TRUE if ok; FALSE if error.
111 *
112 */
113BOOL ETHbIsBufferCrc32Ok (PBYTE pbyBuffer, UINT cbFrameLength)
114{
115 DWORD dwCRC;
116
117 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
118 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
119 return FALSE;
120 }
121 return TRUE;
122}
123