2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @file
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Ethernet Interface Skeleton
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/*
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * All rights reserved.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Redistribution and use in source and binary forms, with or without modification,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * are permitted provided that the following conditions are met:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * 1. Redistributions of source code must retain the above copyright notice,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * this list of conditions and the following disclaimer.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * 2. Redistributions in binary form must reproduce the above copyright notice,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * this list of conditions and the following disclaimer in the documentation
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * and/or other materials provided with the distribution.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * 3. The name of the author may not be used to endorse or promote products
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * derived from this software without specific prior written permission.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * OF SUCH DAMAGE.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This file is part of the lwIP TCP/IP stack.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Author: Adam Dunkels <adam@sics.se>
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/*
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This file is a skeleton for developing Ethernet network interface
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * drivers for lwIP. Add code to the low_level functions and do a
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * search-and-replace for the word "ethernetif" to replace it with
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * something that better describes your network interface.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/opt.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if 0 /* don't build, this is only a skeleton, see previous comment */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/def.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/mem.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/pbuf.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/stats.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/snmp.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "lwip/ethip6.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "netif/etharp.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#include "netif/ppp_oe.h"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/* Define those to better describe your network interface. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#define IFNAME0 'e'
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#define IFNAME1 'n'
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Helper struct to hold private data used to operate your ethernet interface.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Keeping the ethernet address of the MAC in this struct is not necessary
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * as it is already kept in the struct netif.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * But this is only an example, anyway...
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstruct ethernetif {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct eth_addr *ethaddr;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Add whatever per-interface state that is needed here. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync};
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/* Forward declarations. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic void ethernetif_input(struct netif *netif);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * In this function, the hardware should be initialized.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Called from ethernetif_init().
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param netif the already initialized lwip network interface structure
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * for this ethernetif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic void
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsynclow_level_init(struct netif *netif)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync{
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ethernetif *ethernetif = netif->state;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* set MAC hardware address length */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->hwaddr_len = ETHARP_HWADDR_LEN;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* set MAC hardware address */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->hwaddr[0] = ;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ...
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->hwaddr[5] = ;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* maximum transfer unit */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->mtu = 1500;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* device capabilities */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Do whatever else is needed to initialize interface. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync}
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This function should do the actual transmission of the packet. The packet is
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * contained in the pbuf that is passed to the function. This pbuf
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * might be chained.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param netif the lwip network interface structure for this ethernetif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @return ERR_OK if the packet could be sent
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * an err_t value if the packet couldn't be sent
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * strange results. You might consider waiting for space in the DMA queue
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * to become availale since the stack doesn't retry to send a packet
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * dropped because of memory failure (except for the TCP timers).
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic err_t
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsynclow_level_output(struct netif *netif, struct pbuf *p)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync{
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ethernetif *ethernetif = netif->state;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct pbuf *q;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync initiate transfer();
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if ETH_PAD_SIZE
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync for(q = p; q != NULL; q = q->next) {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Send the data from the pbuf to the interface, one pbuf at a
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync time. The size of the data in each pbuf is kept in the ->len
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync variable. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync send data from(q->payload, q->len);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync signal that packet should be sent();
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if ETH_PAD_SIZE
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LINK_STATS_INC(link.xmit);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync return ERR_OK;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync}
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Should allocate a pbuf and transfer the bytes of the incoming
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * packet from the interface into the pbuf.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param netif the lwip network interface structure for this ethernetif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @return a pbuf filled with the received packet (including MAC header)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * NULL on memory error
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic struct pbuf *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsynclow_level_input(struct netif *netif)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync{
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ethernetif *ethernetif = netif->state;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct pbuf *p, *q;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync u16_t len;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Obtain the size of the packet and put it into the "len"
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync variable. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync len = ;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if ETH_PAD_SIZE
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* We allocate a pbuf chain of pbufs from the pool. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync if (p != NULL) {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if ETH_PAD_SIZE
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* We iterate over the pbuf chain until we have read the entire
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * packet into the pbuf. */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync for(q = p; q != NULL; q = q->next) {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Read enough bytes to fill this pbuf in the chain. The
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * available data in the pbuf is given by the q->len
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * variable.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This does not necessarily have to be a memcpy, you can also preallocate
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * pbufs for a DMA-enabled MAC and after receiving truncate it to the
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * actually received size. In this case, ensure the tot_len member of the
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * pbuf is the sum of the chained pbuf len members.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync read data into(q->payload, q->len);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync acknowledge that packet has been read();
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if ETH_PAD_SIZE
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LINK_STATS_INC(link.recv);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync } else {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync drop packet();
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LINK_STATS_INC(link.memerr);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LINK_STATS_INC(link.drop);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync return p;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync}
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This function should be called when a packet is ready to be read
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * from the interface. It uses the function low_level_input() that
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * should handle the actual reception of bytes from the network
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * interface. Then the type of the received packet is determined and
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * the appropriate input function is called.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param netif the lwip network interface structure for this ethernetif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic void
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncethernetif_input(struct netif *netif)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync{
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ethernetif *ethernetif;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct eth_hdr *ethhdr;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct pbuf *p;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ethernetif = netif->state;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* move received packet into a new pbuf */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync p = low_level_input(netif);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* no packet could be read, silently ignore this */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync if (p == NULL) return;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* points to packet payload, which starts with an Ethernet header */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ethhdr = p->payload;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync switch (htons(ethhdr->type)) {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* IP or ARP packet? */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync case ETHTYPE_IP:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync case ETHTYPE_IPV6:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync case ETHTYPE_ARP:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if PPPOE_SUPPORT
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* PPPoE packet? */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync case ETHTYPE_PPPOEDISC:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync case ETHTYPE_PPPOE:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif /* PPPOE_SUPPORT */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* full packet send to tcpip_thread to process */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync if (netif->input(p, netif)!=ERR_OK)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_free(p);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync p = NULL;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync break;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync default:
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync pbuf_free(p);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync p = NULL;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync break;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync}
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync/**
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Should be called at the beginning of the program to set up the
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * network interface. It calls the function low_level_init() to do the
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * actual setup of the hardware.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * This function should be passed as a parameter to netif_add().
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync *
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @param netif the lwip network interface structure for this ethernetif
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * @return ERR_OK if the loopif is initialized
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * ERR_MEM if private data couldn't be allocated
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * any other err_t on error
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncerr_t
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncethernetif_init(struct netif *netif)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync{
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ethernetif *ethernetif;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LWIP_ASSERT("netif != NULL", (netif != NULL));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ethernetif = mem_malloc(sizeof(struct ethernetif));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync if (ethernetif == NULL) {
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync return ERR_MEM;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync }
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if LWIP_NETIF_HOSTNAME
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* Initialize interface hostname */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->hostname = "lwip";
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif /* LWIP_NETIF_HOSTNAME */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /*
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * Initialize the snmp variables and counters inside the struct netif.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * The last argument should be replaced with your link speed, in units
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * of bits per second.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->state = ethernetif;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->name[0] = IFNAME0;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->name[1] = IFNAME1;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* We directly use etharp_output() here to save a function call.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * You can instead declare your own function an call etharp_output()
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * from it if you have to do some checks before sending (e.g. if link
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * is available...) */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->output = etharp_output;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#if LWIP_IPV6
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->output_ip6 = ethip6_output;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif /* LWIP_IPV6 */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync netif->linkoutput = low_level_output;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* initialize the hardware */
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync low_level_init(netif);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync return ERR_OK;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync}
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync#endif /* 0 */