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