blob: 28554bf75549e40a2913bf5a6bff87fda297492e [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:
Justin P. Mattock7664ec82012-08-20 08:43:15 -070028 * ETHbyGetHashIndexByCrc32 - Calculate multicast hash value by CRC32
Forest Bond5449c682009-04-25 10:30:44 -040029 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
30 *
31 * Revision History:
32 *
33 */
34
Forest Bond5449c682009-04-25 10:30:44 -040035#include "device.h"
Forest Bond5449c682009-04-25 10:30:44 -040036#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040037#include "tcrc.h"
Forest Bond5449c682009-04-25 10:30:44 -040038#include "tether.h"
Forest Bond5449c682009-04-25 10:30:44 -040039
40/*--------------------- Static Definitions -------------------------*/
41
42/*--------------------- Static Classes ----------------------------*/
43
44/*--------------------- Static Variables --------------------------*/
45
46/*--------------------- Static Functions --------------------------*/
47
48/*--------------------- Export Variables --------------------------*/
49
50
51
52/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -070053 * Description: Calculate multicast hash value by CRC32
Forest Bond5449c682009-04-25 10:30:44 -040054 *
55 * Parameters:
56 * In:
57 * pbyMultiAddr - Multicast Address
58 * Out:
59 * none
60 *
61 * Return Value: Hash value
62 *
63 */
Charles Clément3fc9b582010-06-24 11:02:27 -070064unsigned char ETHbyGetHashIndexByCrc32 (unsigned char *pbyMultiAddr)
Forest Bond5449c682009-04-25 10:30:44 -040065{
66 int ii;
Charles Clément3fc9b582010-06-24 11:02:27 -070067 unsigned char byTmpHash;
68 unsigned char byHash = 0;
Forest Bond5449c682009-04-25 10:30:44 -040069
70 // get the least 6-bits from CRC generator
Charles Clément3fc9b582010-06-24 11:02:27 -070071 byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN,
Forest Bond5449c682009-04-25 10:30:44 -040072 0xFFFFFFFFL) & 0x3F);
73 // reverse most bit to least bit
74 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
75 byHash <<= 1;
Jim Lieb256a8162009-08-12 14:54:16 -070076 if (byTmpHash & 0x01)
Forest Bond5449c682009-04-25 10:30:44 -040077 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 *
Charles Clément5a5a2a62010-08-01 17:15:49 +020096 * Return Value: true if ok; false if error.
Forest Bond5449c682009-04-25 10:30:44 -040097 *
98 */
Charles Clément7b6a0012010-08-01 17:15:50 +020099bool ETHbIsBufferCrc32Ok (unsigned char *pbyBuffer, unsigned int cbFrameLength)
Forest Bond5449c682009-04-25 10:30:44 -0400100{
Charles Clément0f4c60d2010-06-24 11:02:25 -0700101 unsigned long dwCRC;
Forest Bond5449c682009-04-25 10:30:44 -0400102
103 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
Charles Clément9d828c42010-06-05 15:13:49 -0700104 if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
Charles Clément5a5a2a62010-08-01 17:15:49 +0200105 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400106 }
Charles Clément1b120682010-08-01 17:15:48 +0200107 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400108}
109