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