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