static void emac_receive(FAR struct emac_driver_s *priv) { do { /* Check for errors and update statistics */ /* Check if the packet is a valid size for the uIP buffer configuration */ /* Copy the data data from the hardware to priv->d_dev.d_buf. Set * amount of data in priv->d_dev.d_len */ /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) #else if (BUF->type == HTONS(ETHTYPE_IP)) #endif { arp_ipin(&priv->d_dev); devif_input(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->d_dev.d_len > 0) { arp_out(&priv->d_dev); emac_transmit(priv); } } else if (BUF->type == htons(ETHTYPE_ARP)) { arp_arpin(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. */ if (priv->d_dev.d_len > 0) { emac_transmit(priv); } } } while (true); /* While there are more packets to be processed */ }
void netdriver_loop(void) { /* netdev_read will return 0 on a timeout event and >0 on a data received event */ g_sim_dev.d_len = netdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_ETH_MTU); /* Disable preemption through to the following so that it behaves a little more * like an interrupt (otherwise, the following logic gets pre-empted an behaves * oddly. */ sched_lock(); if (g_sim_dev.d_len > 0) { /* Data received event. Check for valid Ethernet header with destination == our * MAC address */ if (g_sim_dev.d_len > ETH_HDRLEN && up_comparemac(BUF->ether_dhost, &g_sim_dev.d_mac) == 0) { /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 if (BUF->ether_type == htons(ETHTYPE_IP6)) #else if (BUF->ether_type == htons(ETHTYPE_IP)) #endif { arp_ipin(&g_sim_dev); devif_input(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable * d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { arp_out(&g_sim_dev); netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else if (BUF->ether_type == htons(ETHTYPE_ARP)) { arp_arpin(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable * d_len is set to a value > 0. */ if (g_sim_dev.d_len > 0) { netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } } } /* Otherwise, it must be a timeout event */ else if (timer_expired(&g_periodic_timer)) { timer_reset(&g_periodic_timer); devif_timer(&g_sim_dev, sim_txpoll, 1); } sched_unlock(); }