Leest de waarde van een sensor binnen een maakt deze beschikbaar via internet

Dependencies:   NTPClient_NetServices mbed

Committer:
hendrikvincent
Date:
Mon Dec 02 09:01:23 2013 +0000
Revision:
0:05ccbd4f84f1
eerste programma;

Who changed what in which revision?

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