Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with CRC in VHDL Ethernet MAC design

Status
Not open for further replies.

Mudugamuwa

Newbie level 6
Newbie level 6
Joined
Sep 26, 2006
Messages
12
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,361
Hi,

I'm designing a Ethernet MAC with VHDL. The problem I have is with respect to the CRC at the end of Ethernet frame.

I want to know from where I have to start calculating the CRC. From books it says from the data given from the upper layer (layer 3) in ISO hierarchy. According to that the First byte of Layer 3 is 'IP Version' which is 0x04. So the first bit becomes zero. This is a problem to me cos I think the first bit should be '1' to calculate a CRC. So I want to know should I start from the first '1' possition to calculate the CRC.

I really thankful to anyone who can help.

Best regards,
Sudeera.
 

Re: Ethernet MAC

The CRC value is calculated using the following algorithm. The pseudo header is added before the ip header.

Code:
struct pseudo_IP_header		/* The pseudo IP header (checksum calc) */
{

	unsigned long int source, destination;
	char zero_byte, protocol;
	unsigned short TCP_UDP_len;
};

/* caculate the checksum*/
unsigned short in_cksum(unsigned short *addr, int len)
{
	register int nleft = len;
	register unsigned short *w = addr;
	register int sum = 0;
	unsigned short answer = 0;

	while(nleft > 1)
	{
		sum += *w++;
		nleft -= 2;
	}

	if(nleft == 1)
	{
		*(u_char *) (&answer) = *(u_char *) w;
		sum += answer;
	}

	sum = (sum >> 16) + (sum & 0xffff);
	sum += (sum >> 16);
	answer = ~sum;
	return (answer);
}

/*
   fix the tcp checksum
*/
void fix_tcp_checksum(unsigned char *buf)
{
	char sp_pseudo_ip_construct[PKT_BUF_SIZE];
	struct tcphdr *sp_help_tcp;
	struct pseudo_IP_header *sp_help_pseudo;
	struct iphdr *ip_hdr;

	memset(sp_pseudo_ip_construct, 0, PKT_BUF_SIZE);

	sp_help_tcp = (struct tcphdr *) (buf + IP_HEAD_BASE);
	sp_help_pseudo = (struct pseudo_IP_header *) sp_pseudo_ip_construct;
	ip_hdr = (struct iphdr *) buf;

	sp_help_tcp->check = 0;

	sp_help_pseudo->source = ip_hdr->saddr;
	sp_help_pseudo->destination = ip_hdr->daddr;
	sp_help_pseudo->zero_byte = 0;
	sp_help_pseudo->protocol = 6;
	sp_help_pseudo->TCP_UDP_len =
		htons(ntohs(ip_hdr->tot_len) - ip_hdr->ihl * 4);

	memcpy(sp_pseudo_ip_construct + 12, sp_help_tcp,
		ntohs(ip_hdr->tot_len) - ip_hdr->ihl * 4); 
	sp_help_tcp->check =
		in_cksum((unsigned short *) sp_pseudo_ip_construct,
		ntohs(ip_hdr->tot_len) - ip_hdr->ihl * 4 + 12);
}
 

Ethernet MAC

No, that's an IP checksum. It's unrelated to the Ethernet frame CRC.
 

Re: Ethernet MAC

I already told you.... why you ask again ???
 

Ethernet MAC

CRC is usually calculated from MSB. So I think you should design in that way. "Data and Computer Networks" By Stallings is a good reference for you.
 

Re: Ethernet MAC

Could you please send me a link for that book. I searched the Edaboard ebook place. But there was only a solution manual. I guess you are not talking about that.

Thanks!
Mudu...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top