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(); }
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(); }
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; } }
void handle_frame(struct eth_dev *e, struct net_dev *nd, struct pcnet_rx_32 *f) { //int i; uint8 *b = (uint8 *)(0L + f->RBADR); struct eth_frame *tmp; struct ip_hdr *iph; /* printf("handle_frame:\n" "ENP:%x STP:%x BUFF:%x CRC:%x OFLO:%x FRAM:%x\n" "ERR:%x OWN:%x BCNT:%x MCNT:%x\n", f->ENP, f->STP, f->BUFF, f->CRC, f->OFLO, f->FRAM, f->ERR, f->OWN, f->BCNT, f->MCNT); */ tmp = kmalloc(f->BCNT, "eth_frame", NULL); memcpy(tmp, b, f->BCNT); tmp->len = ntohs(tmp->len); // printf("src: "); // print_mac(tmp->src); // printf(" dst: "); // print_mac(tmp->dst), // printf(" len: %lx\n", tmp->len); // printf("nd->upper: %x\n", nd->upper); switch(tmp->len) { case ETHPROTO_IP: iph = (struct ip_hdr *)&tmp->data; update_arp_entry( ntohl(iph->src), tmp->src, nd ); break; case ETHPROTO_ARP: arp_handle(nd, (uint8 *)&tmp->data, f->MCNT-(6+6+2)); break; } nd->upper->ops->recv(nd, nd->upper, (uint8 *)&tmp->data, f->MCNT-(6+6+2)); kfree(tmp); }