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