Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.18-rc3 105 lines 2.8 kB view raw
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: 28 * ETHbyGetHashIndexByCrc32 - Calculate 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#include "device.h" 36#include "tmacro.h" 37#include "tcrc.h" 38#include "tether.h" 39 40/*--------------------- Static Definitions -------------------------*/ 41 42/*--------------------- Static Classes ----------------------------*/ 43 44/*--------------------- Static Variables --------------------------*/ 45 46/*--------------------- Static Functions --------------------------*/ 47 48/*--------------------- Export Variables --------------------------*/ 49 50/* 51 * Description: Calculate multicast hash value by CRC32 52 * 53 * Parameters: 54 * In: 55 * pbyMultiAddr - Multicast Address 56 * Out: 57 * none 58 * 59 * Return Value: Hash value 60 * 61 */ 62unsigned char ETHbyGetHashIndexByCrc32(unsigned char *pbyMultiAddr) 63{ 64 int ii; 65 unsigned char byTmpHash; 66 unsigned char byHash = 0; 67 68 // get the least 6-bits from CRC generator 69 byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN, 70 0xFFFFFFFFL) & 0x3F); 71 // reverse most bit to least bit 72 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) { 73 byHash <<= 1; 74 if (byTmpHash & 0x01) 75 byHash |= 1; 76 byTmpHash >>= 1; 77 } 78 79 // adjust 6-bits to the right most 80 return byHash >> 2; 81} 82 83/* 84 * Description: Check CRC value of the buffer if Ok or not 85 * 86 * Parameters: 87 * In: 88 * pbyBuffer - pointer of buffer (normally is rx buffer) 89 * cbFrameLength - length of buffer, including CRC portion 90 * Out: 91 * none 92 * 93 * Return Value: true if ok; false if error. 94 * 95 */ 96bool ETHbIsBufferCrc32Ok(unsigned char *pbyBuffer, unsigned int cbFrameLength) 97{ 98 unsigned long dwCRC; 99 100 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); 101 if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC) 102 return false; 103 104 return true; 105}