ethernetif.c revision 2e848e79ccf2e4285250a0af98ddb9eb28864878
128N/A * Ethernet Interface Skeleton 128N/A * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 128N/A * Redistribution and use in source and binary forms, with or without modification, 128N/A * are permitted provided that the following conditions are met: 128N/A * 1. Redistributions of source code must retain the above copyright notice, 128N/A * this list of conditions and the following disclaimer. 128N/A * 2. Redistributions in binary form must reproduce the above copyright notice, 128N/A * this list of conditions and the following disclaimer in the documentation 128N/A * and/or other materials provided with the distribution. 128N/A * 3. The name of the author may not be used to endorse or promote products 128N/A * derived from this software without specific prior written permission. 128N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 128N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 128N/A * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 128N/A * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 128N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 128N/A * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 128N/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 128N/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 128N/A * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 128N/A * Author: Adam Dunkels <adam@sics.se> 493N/A * This file is a skeleton for developing Ethernet network interface 128N/A * drivers for lwIP. Add code to the low_level functions and do a 128N/A * search-and-replace for the word "ethernetif" to replace it with 128N/A * something that better describes your network interface. 493N/A#
if 0
/* don't build, this is only a skeleton, see previous comment */ /* Define those to better describe your network interface. */ * Helper struct to hold private data used to operate your ethernet interface. * Keeping the ethernet address of the MAC in this struct is not necessary * as it is already kept in the struct netif. * But this is only an example, anyway... /* Add whatever per-interface state that is needed here. */ /* Forward declarations. */ * In this function, the hardware should be initialized. * Called from ethernetif_init(). * @param netif the already initialized lwip network interface structure /* set MAC hardware address length */ /* set MAC hardware address */ /* maximum transfer unit */ /* device capabilities */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ /* Do whatever else is needed to initialize interface. */ * This function should do the actual transmission of the packet. The packet is * contained in the pbuf that is passed to the function. This pbuf * @param netif the lwip network interface structure for this ethernetif * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) * @return ERR_OK if the packet could be sent * an err_t value if the packet couldn't be sent * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to * strange results. You might consider waiting for space in the DMA queue * to become availale since the stack doesn't retry to send a packet * dropped because of memory failure (except for the TCP timers). /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * @param netif the lwip network interface structure for this ethernetif * @return a pbuf filled with the received packet (including MAC header) /* Obtain the size of the packet and put it into the "len" /* We allocate a pbuf chain of pbufs from the pool. */ /* We iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * This does not necessarily have to be a memcpy, you can also preallocate * pbufs for a DMA-enabled MAC and after receiving truncate it to the * actually received size. In this case, ensure the tot_len member of the * pbuf is the sum of the chained pbuf len members. * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * @param netif the lwip network interface structure for this ethernetif /* move received packet into a new pbuf */ /* no packet could be read, silently ignore this */ /* points to packet payload, which starts with an Ethernet header */ #
endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ * Should be called at the beginning of the program to set up the * network interface. It calls the function low_level_init() to do the * actual setup of the hardware. * This function should be passed as a parameter to netif_add(). * @param netif the lwip network interface structure for this ethernetif * @return ERR_OK if the loopif is initialized * ERR_MEM if private data couldn't be allocated * any other err_t on error /* Initialize interface hostname */ #
endif /* LWIP_NETIF_HOSTNAME */ * Initialize the snmp variables and counters inside the struct netif. * The last argument should be replaced with your link speed, in units /* We directly use etharp_output() here to save a function call. * You can instead declare your own function an call etharp_output() * from it if you have to do some checks before sending (e.g. if link /* initialize the hardware */