Port of LwIP performed by Ralf in 2010. Not recommended for use with recent mbed libraries, but good demos of raw LwIP possible
Dependents: LwIP_raw_API_serverExample tiny-dtls
Core/lwIP/netif/ethernetif.c@0:0791c1fece8e, 2012-09-18 (annotated)
- Committer:
- RodColeman
- Date:
- Tue Sep 18 14:41:24 2012 +0000
- Revision:
- 0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 0:0791c1fece8e | 1 | /** |
RodColeman | 0:0791c1fece8e | 2 | * @file |
RodColeman | 0:0791c1fece8e | 3 | * Ethernet Interface Skeleton |
RodColeman | 0:0791c1fece8e | 4 | * |
RodColeman | 0:0791c1fece8e | 5 | */ |
RodColeman | 0:0791c1fece8e | 6 | |
RodColeman | 0:0791c1fece8e | 7 | /* |
RodColeman | 0:0791c1fece8e | 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
RodColeman | 0:0791c1fece8e | 9 | * All rights reserved. |
RodColeman | 0:0791c1fece8e | 10 | * |
RodColeman | 0:0791c1fece8e | 11 | * Redistribution and use in source and binary forms, with or without modification, |
RodColeman | 0:0791c1fece8e | 12 | * are permitted provided that the following conditions are met: |
RodColeman | 0:0791c1fece8e | 13 | * |
RodColeman | 0:0791c1fece8e | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
RodColeman | 0:0791c1fece8e | 15 | * this list of conditions and the following disclaimer. |
RodColeman | 0:0791c1fece8e | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
RodColeman | 0:0791c1fece8e | 17 | * this list of conditions and the following disclaimer in the documentation |
RodColeman | 0:0791c1fece8e | 18 | * and/or other materials provided with the distribution. |
RodColeman | 0:0791c1fece8e | 19 | * 3. The name of the author may not be used to endorse or promote products |
RodColeman | 0:0791c1fece8e | 20 | * derived from this software without specific prior written permission. |
RodColeman | 0:0791c1fece8e | 21 | * |
RodColeman | 0:0791c1fece8e | 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
RodColeman | 0:0791c1fece8e | 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
RodColeman | 0:0791c1fece8e | 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
RodColeman | 0:0791c1fece8e | 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
RodColeman | 0:0791c1fece8e | 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
RodColeman | 0:0791c1fece8e | 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
RodColeman | 0:0791c1fece8e | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
RodColeman | 0:0791c1fece8e | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
RodColeman | 0:0791c1fece8e | 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
RodColeman | 0:0791c1fece8e | 31 | * OF SUCH DAMAGE. |
RodColeman | 0:0791c1fece8e | 32 | * |
RodColeman | 0:0791c1fece8e | 33 | * This file is part of the lwIP TCP/IP stack. |
RodColeman | 0:0791c1fece8e | 34 | * |
RodColeman | 0:0791c1fece8e | 35 | * Author: Adam Dunkels <adam@sics.se> |
RodColeman | 0:0791c1fece8e | 36 | * |
RodColeman | 0:0791c1fece8e | 37 | */ |
RodColeman | 0:0791c1fece8e | 38 | |
RodColeman | 0:0791c1fece8e | 39 | /* |
RodColeman | 0:0791c1fece8e | 40 | * This file is a skeleton for developing Ethernet network interface |
RodColeman | 0:0791c1fece8e | 41 | * drivers for lwIP. Add code to the low_level functions and do a |
RodColeman | 0:0791c1fece8e | 42 | * search-and-replace for the word "ethernetif" to replace it with |
RodColeman | 0:0791c1fece8e | 43 | * something that better describes your network interface. |
RodColeman | 0:0791c1fece8e | 44 | */ |
RodColeman | 0:0791c1fece8e | 45 | |
RodColeman | 0:0791c1fece8e | 46 | #include "lwip/opt.h" |
RodColeman | 0:0791c1fece8e | 47 | |
RodColeman | 0:0791c1fece8e | 48 | #if 0 /* don't build, this is only a skeleton, see previous comment */ |
RodColeman | 0:0791c1fece8e | 49 | |
RodColeman | 0:0791c1fece8e | 50 | #include "lwip/def.h" |
RodColeman | 0:0791c1fece8e | 51 | #include "lwip/mem.h" |
RodColeman | 0:0791c1fece8e | 52 | #include "lwip/pbuf.h" |
RodColeman | 0:0791c1fece8e | 53 | #include "lwip/sys.h" |
RodColeman | 0:0791c1fece8e | 54 | #include <lwip/stats.h> |
RodColeman | 0:0791c1fece8e | 55 | #include <lwip/snmp.h> |
RodColeman | 0:0791c1fece8e | 56 | #include "netif/etharp.h" |
RodColeman | 0:0791c1fece8e | 57 | #include "netif/ppp_oe.h" |
RodColeman | 0:0791c1fece8e | 58 | |
RodColeman | 0:0791c1fece8e | 59 | /* Define those to better describe your network interface. */ |
RodColeman | 0:0791c1fece8e | 60 | #define IFNAME0 'e' |
RodColeman | 0:0791c1fece8e | 61 | #define IFNAME1 'n' |
RodColeman | 0:0791c1fece8e | 62 | |
RodColeman | 0:0791c1fece8e | 63 | /** |
RodColeman | 0:0791c1fece8e | 64 | * Helper struct to hold private data used to operate your ethernet interface. |
RodColeman | 0:0791c1fece8e | 65 | * Keeping the ethernet address of the MAC in this struct is not necessary |
RodColeman | 0:0791c1fece8e | 66 | * as it is already kept in the struct netif. |
RodColeman | 0:0791c1fece8e | 67 | * But this is only an example, anyway... |
RodColeman | 0:0791c1fece8e | 68 | */ |
RodColeman | 0:0791c1fece8e | 69 | struct ethernetif { |
RodColeman | 0:0791c1fece8e | 70 | struct eth_addr *ethaddr; |
RodColeman | 0:0791c1fece8e | 71 | /* Add whatever per-interface state that is needed here. */ |
RodColeman | 0:0791c1fece8e | 72 | }; |
RodColeman | 0:0791c1fece8e | 73 | |
RodColeman | 0:0791c1fece8e | 74 | /* Forward declarations. */ |
RodColeman | 0:0791c1fece8e | 75 | static void ethernetif_input(struct netif *netif); |
RodColeman | 0:0791c1fece8e | 76 | |
RodColeman | 0:0791c1fece8e | 77 | /** |
RodColeman | 0:0791c1fece8e | 78 | * In this function, the hardware should be initialized. |
RodColeman | 0:0791c1fece8e | 79 | * Called from ethernetif_init(). |
RodColeman | 0:0791c1fece8e | 80 | * |
RodColeman | 0:0791c1fece8e | 81 | * @param netif the already initialized lwip network interface structure |
RodColeman | 0:0791c1fece8e | 82 | * for this ethernetif |
RodColeman | 0:0791c1fece8e | 83 | */ |
RodColeman | 0:0791c1fece8e | 84 | static void |
RodColeman | 0:0791c1fece8e | 85 | low_level_init(struct netif *netif) |
RodColeman | 0:0791c1fece8e | 86 | { |
RodColeman | 0:0791c1fece8e | 87 | struct ethernetif *ethernetif = netif->state; |
RodColeman | 0:0791c1fece8e | 88 | |
RodColeman | 0:0791c1fece8e | 89 | /* set MAC hardware address length */ |
RodColeman | 0:0791c1fece8e | 90 | netif->hwaddr_len = ETHARP_HWADDR_LEN; |
RodColeman | 0:0791c1fece8e | 91 | |
RodColeman | 0:0791c1fece8e | 92 | /* set MAC hardware address */ |
RodColeman | 0:0791c1fece8e | 93 | netif->hwaddr[0] = ; |
RodColeman | 0:0791c1fece8e | 94 | ... |
RodColeman | 0:0791c1fece8e | 95 | netif->hwaddr[5] = ; |
RodColeman | 0:0791c1fece8e | 96 | |
RodColeman | 0:0791c1fece8e | 97 | /* maximum transfer unit */ |
RodColeman | 0:0791c1fece8e | 98 | netif->mtu = 1500; |
RodColeman | 0:0791c1fece8e | 99 | |
RodColeman | 0:0791c1fece8e | 100 | /* device capabilities */ |
RodColeman | 0:0791c1fece8e | 101 | /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ |
RodColeman | 0:0791c1fece8e | 102 | netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; |
RodColeman | 0:0791c1fece8e | 103 | |
RodColeman | 0:0791c1fece8e | 104 | /* Do whatever else is needed to initialize interface. */ |
RodColeman | 0:0791c1fece8e | 105 | } |
RodColeman | 0:0791c1fece8e | 106 | |
RodColeman | 0:0791c1fece8e | 107 | /** |
RodColeman | 0:0791c1fece8e | 108 | * This function should do the actual transmission of the packet. The packet is |
RodColeman | 0:0791c1fece8e | 109 | * contained in the pbuf that is passed to the function. This pbuf |
RodColeman | 0:0791c1fece8e | 110 | * might be chained. |
RodColeman | 0:0791c1fece8e | 111 | * |
RodColeman | 0:0791c1fece8e | 112 | * @param netif the lwip network interface structure for this ethernetif |
RodColeman | 0:0791c1fece8e | 113 | * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) |
RodColeman | 0:0791c1fece8e | 114 | * @return ERR_OK if the packet could be sent |
RodColeman | 0:0791c1fece8e | 115 | * an err_t value if the packet couldn't be sent |
RodColeman | 0:0791c1fece8e | 116 | * |
RodColeman | 0:0791c1fece8e | 117 | * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to |
RodColeman | 0:0791c1fece8e | 118 | * strange results. You might consider waiting for space in the DMA queue |
RodColeman | 0:0791c1fece8e | 119 | * to become availale since the stack doesn't retry to send a packet |
RodColeman | 0:0791c1fece8e | 120 | * dropped because of memory failure (except for the TCP timers). |
RodColeman | 0:0791c1fece8e | 121 | */ |
RodColeman | 0:0791c1fece8e | 122 | |
RodColeman | 0:0791c1fece8e | 123 | static err_t |
RodColeman | 0:0791c1fece8e | 124 | low_level_output(struct netif *netif, struct pbuf *p) |
RodColeman | 0:0791c1fece8e | 125 | { |
RodColeman | 0:0791c1fece8e | 126 | struct ethernetif *ethernetif = netif->state; |
RodColeman | 0:0791c1fece8e | 127 | struct pbuf *q; |
RodColeman | 0:0791c1fece8e | 128 | |
RodColeman | 0:0791c1fece8e | 129 | initiate transfer(); |
RodColeman | 0:0791c1fece8e | 130 | |
RodColeman | 0:0791c1fece8e | 131 | #if ETH_PAD_SIZE |
RodColeman | 0:0791c1fece8e | 132 | pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ |
RodColeman | 0:0791c1fece8e | 133 | #endif |
RodColeman | 0:0791c1fece8e | 134 | |
RodColeman | 0:0791c1fece8e | 135 | for(q = p; q != NULL; q = q->next) { |
RodColeman | 0:0791c1fece8e | 136 | /* Send the data from the pbuf to the interface, one pbuf at a |
RodColeman | 0:0791c1fece8e | 137 | time. The size of the data in each pbuf is kept in the ->len |
RodColeman | 0:0791c1fece8e | 138 | variable. */ |
RodColeman | 0:0791c1fece8e | 139 | send data from(q->payload, q->len); |
RodColeman | 0:0791c1fece8e | 140 | } |
RodColeman | 0:0791c1fece8e | 141 | |
RodColeman | 0:0791c1fece8e | 142 | signal that packet should be sent(); |
RodColeman | 0:0791c1fece8e | 143 | |
RodColeman | 0:0791c1fece8e | 144 | #if ETH_PAD_SIZE |
RodColeman | 0:0791c1fece8e | 145 | pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ |
RodColeman | 0:0791c1fece8e | 146 | #endif |
RodColeman | 0:0791c1fece8e | 147 | |
RodColeman | 0:0791c1fece8e | 148 | LINK_STATS_INC(link.xmit); |
RodColeman | 0:0791c1fece8e | 149 | |
RodColeman | 0:0791c1fece8e | 150 | return ERR_OK; |
RodColeman | 0:0791c1fece8e | 151 | } |
RodColeman | 0:0791c1fece8e | 152 | |
RodColeman | 0:0791c1fece8e | 153 | /** |
RodColeman | 0:0791c1fece8e | 154 | * Should allocate a pbuf and transfer the bytes of the incoming |
RodColeman | 0:0791c1fece8e | 155 | * packet from the interface into the pbuf. |
RodColeman | 0:0791c1fece8e | 156 | * |
RodColeman | 0:0791c1fece8e | 157 | * @param netif the lwip network interface structure for this ethernetif |
RodColeman | 0:0791c1fece8e | 158 | * @return a pbuf filled with the received packet (including MAC header) |
RodColeman | 0:0791c1fece8e | 159 | * NULL on memory error |
RodColeman | 0:0791c1fece8e | 160 | */ |
RodColeman | 0:0791c1fece8e | 161 | static struct pbuf * |
RodColeman | 0:0791c1fece8e | 162 | low_level_input(struct netif *netif) |
RodColeman | 0:0791c1fece8e | 163 | { |
RodColeman | 0:0791c1fece8e | 164 | struct ethernetif *ethernetif = netif->state; |
RodColeman | 0:0791c1fece8e | 165 | struct pbuf *p, *q; |
RodColeman | 0:0791c1fece8e | 166 | u16_t len; |
RodColeman | 0:0791c1fece8e | 167 | |
RodColeman | 0:0791c1fece8e | 168 | /* Obtain the size of the packet and put it into the "len" |
RodColeman | 0:0791c1fece8e | 169 | variable. */ |
RodColeman | 0:0791c1fece8e | 170 | len = ; |
RodColeman | 0:0791c1fece8e | 171 | |
RodColeman | 0:0791c1fece8e | 172 | #if ETH_PAD_SIZE |
RodColeman | 0:0791c1fece8e | 173 | len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ |
RodColeman | 0:0791c1fece8e | 174 | #endif |
RodColeman | 0:0791c1fece8e | 175 | |
RodColeman | 0:0791c1fece8e | 176 | /* We allocate a pbuf chain of pbufs from the pool. */ |
RodColeman | 0:0791c1fece8e | 177 | p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); |
RodColeman | 0:0791c1fece8e | 178 | |
RodColeman | 0:0791c1fece8e | 179 | if (p != NULL) { |
RodColeman | 0:0791c1fece8e | 180 | |
RodColeman | 0:0791c1fece8e | 181 | #if ETH_PAD_SIZE |
RodColeman | 0:0791c1fece8e | 182 | pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ |
RodColeman | 0:0791c1fece8e | 183 | #endif |
RodColeman | 0:0791c1fece8e | 184 | |
RodColeman | 0:0791c1fece8e | 185 | /* We iterate over the pbuf chain until we have read the entire |
RodColeman | 0:0791c1fece8e | 186 | * packet into the pbuf. */ |
RodColeman | 0:0791c1fece8e | 187 | for(q = p; q != NULL; q = q->next) { |
RodColeman | 0:0791c1fece8e | 188 | /* Read enough bytes to fill this pbuf in the chain. The |
RodColeman | 0:0791c1fece8e | 189 | * available data in the pbuf is given by the q->len |
RodColeman | 0:0791c1fece8e | 190 | * variable. |
RodColeman | 0:0791c1fece8e | 191 | * This does not necessarily have to be a memcpy, you can also preallocate |
RodColeman | 0:0791c1fece8e | 192 | * pbufs for a DMA-enabled MAC and after receiving truncate it to the |
RodColeman | 0:0791c1fece8e | 193 | * actually received size. In this case, ensure the tot_len member of the |
RodColeman | 0:0791c1fece8e | 194 | * pbuf is the sum of the chained pbuf len members. |
RodColeman | 0:0791c1fece8e | 195 | */ |
RodColeman | 0:0791c1fece8e | 196 | read data into(q->payload, q->len); |
RodColeman | 0:0791c1fece8e | 197 | } |
RodColeman | 0:0791c1fece8e | 198 | acknowledge that packet has been read(); |
RodColeman | 0:0791c1fece8e | 199 | |
RodColeman | 0:0791c1fece8e | 200 | #if ETH_PAD_SIZE |
RodColeman | 0:0791c1fece8e | 201 | pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ |
RodColeman | 0:0791c1fece8e | 202 | #endif |
RodColeman | 0:0791c1fece8e | 203 | |
RodColeman | 0:0791c1fece8e | 204 | LINK_STATS_INC(link.recv); |
RodColeman | 0:0791c1fece8e | 205 | } else { |
RodColeman | 0:0791c1fece8e | 206 | drop packet(); |
RodColeman | 0:0791c1fece8e | 207 | LINK_STATS_INC(link.memerr); |
RodColeman | 0:0791c1fece8e | 208 | LINK_STATS_INC(link.drop); |
RodColeman | 0:0791c1fece8e | 209 | } |
RodColeman | 0:0791c1fece8e | 210 | |
RodColeman | 0:0791c1fece8e | 211 | return p; |
RodColeman | 0:0791c1fece8e | 212 | } |
RodColeman | 0:0791c1fece8e | 213 | |
RodColeman | 0:0791c1fece8e | 214 | /** |
RodColeman | 0:0791c1fece8e | 215 | * This function should be called when a packet is ready to be read |
RodColeman | 0:0791c1fece8e | 216 | * from the interface. It uses the function low_level_input() that |
RodColeman | 0:0791c1fece8e | 217 | * should handle the actual reception of bytes from the network |
RodColeman | 0:0791c1fece8e | 218 | * interface. Then the type of the received packet is determined and |
RodColeman | 0:0791c1fece8e | 219 | * the appropriate input function is called. |
RodColeman | 0:0791c1fece8e | 220 | * |
RodColeman | 0:0791c1fece8e | 221 | * @param netif the lwip network interface structure for this ethernetif |
RodColeman | 0:0791c1fece8e | 222 | */ |
RodColeman | 0:0791c1fece8e | 223 | static void |
RodColeman | 0:0791c1fece8e | 224 | ethernetif_input(struct netif *netif) |
RodColeman | 0:0791c1fece8e | 225 | { |
RodColeman | 0:0791c1fece8e | 226 | struct ethernetif *ethernetif; |
RodColeman | 0:0791c1fece8e | 227 | struct eth_hdr *ethhdr; |
RodColeman | 0:0791c1fece8e | 228 | struct pbuf *p; |
RodColeman | 0:0791c1fece8e | 229 | |
RodColeman | 0:0791c1fece8e | 230 | ethernetif = netif->state; |
RodColeman | 0:0791c1fece8e | 231 | |
RodColeman | 0:0791c1fece8e | 232 | /* move received packet into a new pbuf */ |
RodColeman | 0:0791c1fece8e | 233 | p = low_level_input(netif); |
RodColeman | 0:0791c1fece8e | 234 | /* no packet could be read, silently ignore this */ |
RodColeman | 0:0791c1fece8e | 235 | if (p == NULL) return; |
RodColeman | 0:0791c1fece8e | 236 | /* points to packet payload, which starts with an Ethernet header */ |
RodColeman | 0:0791c1fece8e | 237 | ethhdr = p->payload; |
RodColeman | 0:0791c1fece8e | 238 | |
RodColeman | 0:0791c1fece8e | 239 | switch (htons(ethhdr->type)) { |
RodColeman | 0:0791c1fece8e | 240 | /* IP or ARP packet? */ |
RodColeman | 0:0791c1fece8e | 241 | case ETHTYPE_IP: |
RodColeman | 0:0791c1fece8e | 242 | case ETHTYPE_ARP: |
RodColeman | 0:0791c1fece8e | 243 | #if PPPOE_SUPPORT |
RodColeman | 0:0791c1fece8e | 244 | /* PPPoE packet? */ |
RodColeman | 0:0791c1fece8e | 245 | case ETHTYPE_PPPOEDISC: |
RodColeman | 0:0791c1fece8e | 246 | case ETHTYPE_PPPOE: |
RodColeman | 0:0791c1fece8e | 247 | #endif /* PPPOE_SUPPORT */ |
RodColeman | 0:0791c1fece8e | 248 | /* full packet send to tcpip_thread to process */ |
RodColeman | 0:0791c1fece8e | 249 | if (netif->input(p, netif)!=ERR_OK) |
RodColeman | 0:0791c1fece8e | 250 | { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); |
RodColeman | 0:0791c1fece8e | 251 | pbuf_free(p); |
RodColeman | 0:0791c1fece8e | 252 | p = NULL; |
RodColeman | 0:0791c1fece8e | 253 | } |
RodColeman | 0:0791c1fece8e | 254 | break; |
RodColeman | 0:0791c1fece8e | 255 | |
RodColeman | 0:0791c1fece8e | 256 | default: |
RodColeman | 0:0791c1fece8e | 257 | pbuf_free(p); |
RodColeman | 0:0791c1fece8e | 258 | p = NULL; |
RodColeman | 0:0791c1fece8e | 259 | break; |
RodColeman | 0:0791c1fece8e | 260 | } |
RodColeman | 0:0791c1fece8e | 261 | } |
RodColeman | 0:0791c1fece8e | 262 | |
RodColeman | 0:0791c1fece8e | 263 | /** |
RodColeman | 0:0791c1fece8e | 264 | * Should be called at the beginning of the program to set up the |
RodColeman | 0:0791c1fece8e | 265 | * network interface. It calls the function low_level_init() to do the |
RodColeman | 0:0791c1fece8e | 266 | * actual setup of the hardware. |
RodColeman | 0:0791c1fece8e | 267 | * |
RodColeman | 0:0791c1fece8e | 268 | * This function should be passed as a parameter to netif_add(). |
RodColeman | 0:0791c1fece8e | 269 | * |
RodColeman | 0:0791c1fece8e | 270 | * @param netif the lwip network interface structure for this ethernetif |
RodColeman | 0:0791c1fece8e | 271 | * @return ERR_OK if the loopif is initialized |
RodColeman | 0:0791c1fece8e | 272 | * ERR_MEM if private data couldn't be allocated |
RodColeman | 0:0791c1fece8e | 273 | * any other err_t on error |
RodColeman | 0:0791c1fece8e | 274 | */ |
RodColeman | 0:0791c1fece8e | 275 | err_t |
RodColeman | 0:0791c1fece8e | 276 | ethernetif_init(struct netif *netif) |
RodColeman | 0:0791c1fece8e | 277 | { |
RodColeman | 0:0791c1fece8e | 278 | struct ethernetif *ethernetif; |
RodColeman | 0:0791c1fece8e | 279 | |
RodColeman | 0:0791c1fece8e | 280 | LWIP_ASSERT("netif != NULL", (netif != NULL)); |
RodColeman | 0:0791c1fece8e | 281 | |
RodColeman | 0:0791c1fece8e | 282 | ethernetif = mem_malloc(sizeof(struct ethernetif)); |
RodColeman | 0:0791c1fece8e | 283 | if (ethernetif == NULL) { |
RodColeman | 0:0791c1fece8e | 284 | LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n")); |
RodColeman | 0:0791c1fece8e | 285 | return ERR_MEM; |
RodColeman | 0:0791c1fece8e | 286 | } |
RodColeman | 0:0791c1fece8e | 287 | |
RodColeman | 0:0791c1fece8e | 288 | #if LWIP_NETIF_HOSTNAME |
RodColeman | 0:0791c1fece8e | 289 | /* Initialize interface hostname */ |
RodColeman | 0:0791c1fece8e | 290 | netif->hostname = "lwip"; |
RodColeman | 0:0791c1fece8e | 291 | #endif /* LWIP_NETIF_HOSTNAME */ |
RodColeman | 0:0791c1fece8e | 292 | |
RodColeman | 0:0791c1fece8e | 293 | /* |
RodColeman | 0:0791c1fece8e | 294 | * Initialize the snmp variables and counters inside the struct netif. |
RodColeman | 0:0791c1fece8e | 295 | * The last argument should be replaced with your link speed, in units |
RodColeman | 0:0791c1fece8e | 296 | * of bits per second. |
RodColeman | 0:0791c1fece8e | 297 | */ |
RodColeman | 0:0791c1fece8e | 298 | NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS); |
RodColeman | 0:0791c1fece8e | 299 | |
RodColeman | 0:0791c1fece8e | 300 | netif->state = ethernetif; |
RodColeman | 0:0791c1fece8e | 301 | netif->name[0] = IFNAME0; |
RodColeman | 0:0791c1fece8e | 302 | netif->name[1] = IFNAME1; |
RodColeman | 0:0791c1fece8e | 303 | /* We directly use etharp_output() here to save a function call. |
RodColeman | 0:0791c1fece8e | 304 | * You can instead declare your own function an call etharp_output() |
RodColeman | 0:0791c1fece8e | 305 | * from it if you have to do some checks before sending (e.g. if link |
RodColeman | 0:0791c1fece8e | 306 | * is available...) */ |
RodColeman | 0:0791c1fece8e | 307 | netif->output = etharp_output; |
RodColeman | 0:0791c1fece8e | 308 | netif->linkoutput = low_level_output; |
RodColeman | 0:0791c1fece8e | 309 | |
RodColeman | 0:0791c1fece8e | 310 | ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); |
RodColeman | 0:0791c1fece8e | 311 | |
RodColeman | 0:0791c1fece8e | 312 | /* initialize the hardware */ |
RodColeman | 0:0791c1fece8e | 313 | low_level_init(netif); |
RodColeman | 0:0791c1fece8e | 314 | |
RodColeman | 0:0791c1fece8e | 315 | return ERR_OK; |
RodColeman | 0:0791c1fece8e | 316 | } |
RodColeman | 0:0791c1fece8e | 317 | |
RodColeman | 0:0791c1fece8e | 318 | #endif /* 0 */ |