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