static int emac_txpoll(struct net_driver_s *dev) { FAR struct emac_driver_s *priv = (FAR struct emac_driver_s *)dev->d_private; /* If the polling resulted in data that should be sent out on the network, * the field d_len is set to a value > 0. */ if (priv->d_dev.d_len > 0) { arp_out(&priv->d_dev); emac_transmit(priv); /* Check if there is room in the device to hold another packet. If not, * return a non-zero value to terminate the poll. */ } /* If zero is returned, the polling will continue until all connections have * been examined. */ return 0; }
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 network 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 */ #ifdef CONFIG_NET_PKT /* When packet sockets are enabled, feed the frame into the packet tap */ pkt_input(&priv->d_dev); #endif /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv4 if (BUF->type == HTONS(ETHTYPE_IP)) { nllvdbg("IPv4 frame\n"); /* Handle ARP on input then give the IPv4 packet to the network * layer */ arp_ipin(&priv->d_dev); ipv4_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) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv6 if (IFF_IS_IPv4(priv->d_dev.d_flags)) #endif { arp_out(&priv->d_dev); } #ifdef CONFIG_NET_IPv6 else { neighbor_out(&priv->d_dev); } #endif /* And send the packet */ emac_transmit(priv); } } else #endif #ifdef CONFIG_NET_IPv6 if (BUF->type == HTONS(ETHTYPE_IP6)) { nllvdbg("Iv6 frame\n"); /* Give the IPv6 packet to the network layer */ ipv6_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) { /* Update the Ethernet header with the correct MAC address */ #ifdef CONFIG_NET_IPv4 if (IFF_IS_IPv4(priv->d_dev.d_flags)) { arp_out(&priv->d_dev); } else #endif #ifdef CONFIG_NET_IPv6 { neighbor_out(&priv->d_dev); } #endif /* And send the packet */ emac_transmit(priv); } } else #endif #ifdef CONFIG_NET_ARP 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); } } #endif } while (true); /* While there are more packets to be processed */ }