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