📄 tether.c
字号:
/* * Copyright (c) 2003 VIA Networking, Inc. All rights reserved. * * This software is copyrighted by and is the sole property of * VIA Networking, Inc. This software may only be used in accordance * with the corresponding license agreement. Any unauthorized use, * duplication, transmission, distribution, or disclosure of this * software is expressly forbidden. * * This software is provided by VIA Networking, Inc. "as is" and any * express or implied warranties, including, but not limited to, the * implied warranties of merchantability and fitness for a particular * purpose are disclaimed. In no event shall VIA Networking, Inc. be * liable for any direct, indirect, incidental, special, exemplary, or * consequential damages. * * * File: tether.c * * Purpose: * * Author: Tevin Chen * * Date: May 21, 1996 * * Functions: * ETHbyGetHashIndexByCrc32 - Caculate multicast hash value by CRC32 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not * * Revision History: * */#if !defined(__DEVICE_H__)#include "device.h"#endif#if !defined(__TMACRO_H__)#include "tmacro.h"#endif#if !defined(__TBIT_H__)#include "tbit.h"#endif#if !defined(__TCRC_H__)#include "tcrc.h"#endif#if !defined(__TETHER_H__)#include "tether.h"#endif/*--------------------- Static Definitions -------------------------*//*--------------------- Static Classes ----------------------------*//*--------------------- Static Variables --------------------------*//*--------------------- Static Functions --------------------------*//*--------------------- Export Variables --------------------------*//* * Description: Caculate multicast hash value by CRC32 * * Parameters: * In: * pbyMultiAddr - Multicast Address * Out: * none * * Return Value: Hash value * */BYTE ETHbyGetHashIndexByCrc32 (PBYTE pbyMultiAddr){ int ii; BYTE byTmpHash; BYTE byHash = 0; // get the least 6-bits from CRC generator byTmpHash = (BYTE)(CRCdwCrc32(pbyMultiAddr, U_ETHER_ADDR_LEN, 0xFFFFFFFFL) & 0x3F); // reverse most bit to least bit for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) { byHash <<= 1; if (BITbIsBitOn(byTmpHash, 0x01)) byHash |= 1; byTmpHash >>= 1; } // adjust 6-bits to the right most return (byHash >> 2);}/* * Description: Check CRC value of the buffer if Ok or not * * Parameters: * In: * pbyBuffer - pointer of buffer (normally is rx buffer) * cbFrameLength - length of buffer, including CRC portion * Out: * none * * Return Value: TRUE if ok; FALSE if error. * */BOOL ETHbIsBufferCrc32Ok (PBYTE pbyBuffer, UINT cbFrameLength){ DWORD dwCRC; dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) { return FALSE; } return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -