Ejemplo n.º 1
0
void net_handle(void) {
	uint8_t *p;

	const int length = emac_eth_recv(&p);

	if (__builtin_expect((length > 0), 1)) {
		const struct ether_packet *eth = (struct ether_packet *) p;

		switch (__builtin_bswap16(eth->type)) {
		case ETHER_TYPE_ARP:
			arp_handle((struct t_arp *) p);
			break;
		case ETHER_TYPE_IPv4:
			ip_handle((struct t_ip4 *) p);
			break;
		default:
			DEBUG_PRINTF("type %04x is not implemented", __builtin_bswap16(eth->type));
			break;
		}

		emac_free_pkt();
	}

	net_timers_run();
}
Ejemplo n.º 2
0
void ethernet_handle( void ){
	DEBUG_FUNC_ENTER();	

	if( buff.ethernet.len_or_type == ETHERNET_TYPE_ARP ){
		arp_handle( );
	}
	else if( buff.ethernet.len_or_type == ETHERNET_TYPE_IP ){
		ip_handle();
	}
	// else if( 
	
	DEBUG_FUNC_EXIT();
}
Ejemplo n.º 3
0
void NetReceive(volatile uchar *buf, int len)
{
	struct mac_header *p = (struct mac_header *)buf;

	switch (ntohs(p->proto)){
		case PROTO_ARP:
			buf += sizeof(struct mac_header);
			len -= sizeof(struct mac_header);
			arp_handle(buf, len);
			break;
		case PROTO_IP:
			buf += sizeof(struct mac_header);
			len -= sizeof(struct mac_header);
			ip_handle(buf, len);
			break;
		default:
			printf("Frame type error 0x%04x\n", p->proto);
			break;
	}
}