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