Commit | Line | Data |
---|---|---|
5449c685 FB |
1 | /* |
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: | |
7664ec86 | 28 | * ETHbyGetHashIndexByCrc32 - Calculate multicast hash value by CRC32 |
5449c685 FB |
29 | * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not |
30 | * | |
31 | * Revision History: | |
32 | * | |
33 | */ | |
34 | ||
5449c685 | 35 | #include "device.h" |
5449c685 | 36 | #include "tmacro.h" |
5449c685 | 37 | #include "tcrc.h" |
5449c685 | 38 | #include "tether.h" |
5449c685 FB |
39 | |
40 | /*--------------------- Static Definitions -------------------------*/ | |
41 | ||
42 | /*--------------------- Static Classes ----------------------------*/ | |
43 | ||
44 | /*--------------------- Static Variables --------------------------*/ | |
45 | ||
46 | /*--------------------- Static Functions --------------------------*/ | |
47 | ||
48 | /*--------------------- Export Variables --------------------------*/ | |
49 | ||
50 | ||
51 | ||
52 | /* | |
7664ec86 | 53 | * Description: Calculate multicast hash value by CRC32 |
5449c685 FB |
54 | * |
55 | * Parameters: | |
56 | * In: | |
57 | * pbyMultiAddr - Multicast Address | |
58 | * Out: | |
59 | * none | |
60 | * | |
61 | * Return Value: Hash value | |
62 | * | |
63 | */ | |
3fc9b584 | 64 | unsigned char ETHbyGetHashIndexByCrc32 (unsigned char *pbyMultiAddr) |
5449c685 FB |
65 | { |
66 | int ii; | |
3fc9b584 CC |
67 | unsigned char byTmpHash; |
68 | unsigned char byHash = 0; | |
5449c685 FB |
69 | |
70 | // get the least 6-bits from CRC generator | |
3fc9b584 | 71 | byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN, |
5449c685 FB |
72 | 0xFFFFFFFFL) & 0x3F); |
73 | // reverse most bit to least bit | |
74 | for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) { | |
75 | byHash <<= 1; | |
256a816b | 76 | if (byTmpHash & 0x01) |
5449c685 FB |
77 | byHash |= 1; |
78 | byTmpHash >>= 1; | |
79 | } | |
80 | ||
81 | // adjust 6-bits to the right most | |
82 | return (byHash >> 2); | |
83 | } | |
84 | ||
85 | ||
86 | /* | |
87 | * Description: Check CRC value of the buffer if Ok or not | |
88 | * | |
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 | |
95 | * | |
5a5a2a6a | 96 | * Return Value: true if ok; false if error. |
5449c685 FB |
97 | * |
98 | */ | |
7b6a0013 | 99 | bool ETHbIsBufferCrc32Ok (unsigned char *pbyBuffer, unsigned int cbFrameLength) |
5449c685 | 100 | { |
0f4c60d6 | 101 | unsigned long dwCRC; |
5449c685 FB |
102 | |
103 | dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); | |
9d828c45 | 104 | if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC) { |
5a5a2a6a | 105 | return false; |
5449c685 | 106 | } |
1b12068a | 107 | return true; |
5449c685 FB |
108 | } |
109 |