Digi NS9215 User Manual
Page 337

. . . . .
E T H E R N E T C O M M U N I C A T I O N M O D U L E
Sample hash table code
www.digiembedded.com
337
*
* Return Values:
*
*
bit position to set in hash table
*
*/
#define POLYNOMIAL 0x4c11db6L
static int calculate_hash_bit (BYTE *mca)
{
WORD32 crc;
WORD16 *mcap, bp, bx;
int result, index, mca_word, bit_index;
BYTE lsb;
WORD16 copy_mca[3]
memcpy (copy_mca,mca,sizeof(copy_mca));
for (index = 0; index < 3; index++)
{
copy_mca [index] = SWAP16 (copy_mca [index]);
}
mcap = copy_mca;
crc = 0xffffffffL;
for (mca_word = 0; mca_word < 3; mca_word++)
{
bp = *mcap;
mcap++;
for (bit_index = 0; bit_index < 16; bit_index++)
{
bx = (WORD16) (crc >> 16);
/* get high word of crc*/
bx = rotate (bx, LEFT, 1);
/* bit 31 to lsb*/
bx ^= bp;
/* combine with incoming*/
crc <<= 1;
/* shift crc left 1 bit*/
bx &= 1;
/* get control bit*/
if (bx)
/* if bit set*/
{
crc ^= POLYNOMIAL;
/* xero crc with polynomial*/
}
crc |= bx:
/* or in control bit*/