Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:350011bf8be7 1 /*
simon 0:350011bf8be7 2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
simon 0:350011bf8be7 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
simon 0:350011bf8be7 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
simon 0:350011bf8be7 5 * All rights reserved.
simon 0:350011bf8be7 6 *
simon 0:350011bf8be7 7 * Redistribution and use in source and binary forms, with or without modification,
simon 0:350011bf8be7 8 * are permitted provided that the following conditions are met:
simon 0:350011bf8be7 9 *
simon 0:350011bf8be7 10 * 1. Redistributions of source code must retain the above copyright notice,
simon 0:350011bf8be7 11 * this list of conditions and the following disclaimer.
simon 0:350011bf8be7 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
simon 0:350011bf8be7 13 * this list of conditions and the following disclaimer in the documentation
simon 0:350011bf8be7 14 * and/or other materials provided with the distribution.
simon 0:350011bf8be7 15 * 3. The name of the author may not be used to endorse or promote products
simon 0:350011bf8be7 16 * derived from this software without specific prior written permission.
simon 0:350011bf8be7 17 *
simon 0:350011bf8be7 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
simon 0:350011bf8be7 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
simon 0:350011bf8be7 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
simon 0:350011bf8be7 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
simon 0:350011bf8be7 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
simon 0:350011bf8be7 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
simon 0:350011bf8be7 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
simon 0:350011bf8be7 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
simon 0:350011bf8be7 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
simon 0:350011bf8be7 27 * OF SUCH DAMAGE.
simon 0:350011bf8be7 28 *
simon 0:350011bf8be7 29 * This file is part of the lwIP TCP/IP stack.
simon 0:350011bf8be7 30 *
simon 0:350011bf8be7 31 * Author: Adam Dunkels <adam@sics.se>
simon 0:350011bf8be7 32 *
simon 0:350011bf8be7 33 */
simon 0:350011bf8be7 34
simon 0:350011bf8be7 35 #ifndef __NETIF_ETHARP_H__
simon 0:350011bf8be7 36 #define __NETIF_ETHARP_H__
simon 0:350011bf8be7 37
simon 0:350011bf8be7 38 #include "lwip/opt.h"
simon 0:350011bf8be7 39
simon 0:350011bf8be7 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
simon 0:350011bf8be7 41
simon 0:350011bf8be7 42 #include "lwip/pbuf.h"
simon 0:350011bf8be7 43 #include "lwip/ip_addr.h"
simon 0:350011bf8be7 44 #include "lwip/netif.h"
simon 0:350011bf8be7 45 #include "lwip/ip.h"
simon 0:350011bf8be7 46
simon 0:350011bf8be7 47 #ifdef __cplusplus
simon 0:350011bf8be7 48 extern "C" {
simon 0:350011bf8be7 49 #endif
simon 0:350011bf8be7 50
simon 0:350011bf8be7 51 #ifndef ETHARP_HWADDR_LEN
simon 0:350011bf8be7 52 #define ETHARP_HWADDR_LEN 6
simon 0:350011bf8be7 53 #endif
simon 0:350011bf8be7 54
simon 0:350011bf8be7 55 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 56 # include "arch/bpstruct.h"
simon 0:350011bf8be7 57 #endif
simon 0:350011bf8be7 58 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 59 struct eth_addr {
simon 0:350011bf8be7 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
simon 0:350011bf8be7 61 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 62 PACK_STRUCT_END
simon 0:350011bf8be7 63 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 64 # include "arch/epstruct.h"
simon 0:350011bf8be7 65 #endif
simon 0:350011bf8be7 66
simon 0:350011bf8be7 67 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 68 # include "arch/bpstruct.h"
simon 0:350011bf8be7 69 #endif
simon 0:350011bf8be7 70 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 71 /* Ethernet header */
simon 0:350011bf8be7 72 struct eth_hdr {
simon 0:350011bf8be7 73 #if ETH_PAD_SIZE
simon 0:350011bf8be7 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
simon 0:350011bf8be7 75 #endif
simon 0:350011bf8be7 76 PACK_STRUCT_FIELD(struct eth_addr dest);
simon 0:350011bf8be7 77 PACK_STRUCT_FIELD(struct eth_addr src);
simon 0:350011bf8be7 78 PACK_STRUCT_FIELD(u16_t type);
simon 0:350011bf8be7 79 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 80 PACK_STRUCT_END
simon 0:350011bf8be7 81 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 82 # include "arch/epstruct.h"
simon 0:350011bf8be7 83 #endif
simon 0:350011bf8be7 84
simon 0:350011bf8be7 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
simon 0:350011bf8be7 86
simon 0:350011bf8be7 87 #if ETHARP_SUPPORT_VLAN
simon 0:350011bf8be7 88
simon 0:350011bf8be7 89 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 90 # include "arch/bpstruct.h"
simon 0:350011bf8be7 91 #endif
simon 0:350011bf8be7 92 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 93 /* VLAN header inserted between ethernet header and payload
simon 0:350011bf8be7 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
simon 0:350011bf8be7 95 * See IEEE802.Q */
simon 0:350011bf8be7 96 struct eth_vlan_hdr {
simon 0:350011bf8be7 97 PACK_STRUCT_FIELD(u16_t tpid);
simon 0:350011bf8be7 98 PACK_STRUCT_FIELD(u16_t prio_vid);
simon 0:350011bf8be7 99 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 100 PACK_STRUCT_END
simon 0:350011bf8be7 101 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 102 # include "arch/epstruct.h"
simon 0:350011bf8be7 103 #endif
simon 0:350011bf8be7 104
simon 0:350011bf8be7 105 #define SIZEOF_VLAN_HDR 4
simon 0:350011bf8be7 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
simon 0:350011bf8be7 107
simon 0:350011bf8be7 108 #endif /* ETHARP_SUPPORT_VLAN */
simon 0:350011bf8be7 109
simon 0:350011bf8be7 110 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 111 # include "arch/bpstruct.h"
simon 0:350011bf8be7 112 #endif
simon 0:350011bf8be7 113 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 114 /* the ARP message, see RFC 826 ("Packet format") */
simon 0:350011bf8be7 115 struct etharp_hdr {
simon 0:350011bf8be7 116 PACK_STRUCT_FIELD(u16_t hwtype);
simon 0:350011bf8be7 117 PACK_STRUCT_FIELD(u16_t proto);
simon 0:350011bf8be7 118 PACK_STRUCT_FIELD(u8_t hwlen);
simon 0:350011bf8be7 119 PACK_STRUCT_FIELD(u8_t protolen);
simon 0:350011bf8be7 120 PACK_STRUCT_FIELD(u16_t opcode);
simon 0:350011bf8be7 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
simon 0:350011bf8be7 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
simon 0:350011bf8be7 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
simon 0:350011bf8be7 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
simon 0:350011bf8be7 125 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 126 PACK_STRUCT_END
simon 0:350011bf8be7 127 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 128 # include "arch/epstruct.h"
simon 0:350011bf8be7 129 #endif
simon 0:350011bf8be7 130
simon 0:350011bf8be7 131 #define SIZEOF_ETHARP_HDR 28
simon 0:350011bf8be7 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
simon 0:350011bf8be7 133
simon 0:350011bf8be7 134 /* 5 seconds period */
simon 0:350011bf8be7 135 #define ARP_TMR_INTERVAL 5000
simon 0:350011bf8be7 136
simon 0:350011bf8be7 137 #define ETHTYPE_ARP 0x0806
simon 0:350011bf8be7 138 #define ETHTYPE_IP 0x0800
simon 0:350011bf8be7 139 #define ETHTYPE_VLAN 0x8100
simon 0:350011bf8be7 140 #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
simon 0:350011bf8be7 141 #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
simon 0:350011bf8be7 142
simon 0:350011bf8be7 143 /* MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
simon 0:350011bf8be7 144 * or known to be 32-bit aligned within the protocol header. */
simon 0:350011bf8be7 145 #ifndef ETHADDR32_COPY
simon 0:350011bf8be7 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
simon 0:350011bf8be7 147 #endif
simon 0:350011bf8be7 148
simon 0:350011bf8be7 149 /* MEMCPY-like macro to copy to/from struct eth_addr's that are no local
simon 0:350011bf8be7 150 * variables and known to be 16-bit aligned within the protocol header. */
simon 0:350011bf8be7 151 #ifndef ETHADDR16_COPY
simon 0:350011bf8be7 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
simon 0:350011bf8be7 153 #endif
simon 0:350011bf8be7 154
simon 0:350011bf8be7 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
simon 0:350011bf8be7 156
simon 0:350011bf8be7 157 /* ARP message types (opcodes) */
simon 0:350011bf8be7 158 #define ARP_REQUEST 1
simon 0:350011bf8be7 159 #define ARP_REPLY 2
simon 0:350011bf8be7 160
simon 0:350011bf8be7 161 /* Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
simon 0:350011bf8be7 162 * to a filter function that returns the correct netif when using multiple
simon 0:350011bf8be7 163 * netifs on one hardware interface where the netif's low-level receive
simon 0:350011bf8be7 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
simon 0:350011bf8be7 165 * IP addresses to one hardware interface).
simon 0:350011bf8be7 166 */
simon 0:350011bf8be7 167 #ifndef LWIP_ARP_FILTER_NETIF
simon 0:350011bf8be7 168 #define LWIP_ARP_FILTER_NETIF 0
simon 0:350011bf8be7 169 #endif
simon 0:350011bf8be7 170
simon 0:350011bf8be7 171 #if ARP_QUEUEING
simon 0:350011bf8be7 172 /* struct for queueing outgoing packets for unknown address
simon 0:350011bf8be7 173 * defined here to be accessed by memp.h
simon 0:350011bf8be7 174 */
simon 0:350011bf8be7 175 struct etharp_q_entry {
simon 0:350011bf8be7 176 struct etharp_q_entry *next;
simon 0:350011bf8be7 177 struct pbuf *p;
simon 0:350011bf8be7 178 };
simon 0:350011bf8be7 179 #endif /* ARP_QUEUEING */
simon 0:350011bf8be7 180
simon 0:350011bf8be7 181 #define etharp_init() /* Compatibility define, not init needed. */
simon 0:350011bf8be7 182 void etharp_tmr(void);
simon 0:350011bf8be7 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
simon 0:350011bf8be7 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
simon 0:350011bf8be7 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
simon 0:350011bf8be7 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
simon 0:350011bf8be7 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
simon 0:350011bf8be7 188 /* For Ethernet network interfaces, we might want to send "gratuitous ARP";
simon 0:350011bf8be7 189 * this is an ARP packet sent by a node in order to spontaneously cause other
simon 0:350011bf8be7 190 * nodes to update an entry in their ARP cache.
simon 0:350011bf8be7 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
simon 0:350011bf8be7 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
simon 0:350011bf8be7 193
simon 0:350011bf8be7 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
simon 0:350011bf8be7 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
simon 0:350011bf8be7 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
simon 0:350011bf8be7 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
simon 0:350011bf8be7 198
simon 0:350011bf8be7 199 #if LWIP_AUTOIP
simon 0:350011bf8be7 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
simon 0:350011bf8be7 201 const struct eth_addr *ethdst_addr,
simon 0:350011bf8be7 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
simon 0:350011bf8be7 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
simon 0:350011bf8be7 204 const u16_t opcode);
simon 0:350011bf8be7 205 #endif /* LWIP_AUTOIP */
simon 0:350011bf8be7 206
simon 0:350011bf8be7 207 #endif /* LWIP_ARP */
simon 0:350011bf8be7 208
simon 0:350011bf8be7 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
simon 0:350011bf8be7 210
simon 0:350011bf8be7 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
simon 0:350011bf8be7 212
simon 0:350011bf8be7 213 extern const struct eth_addr ethbroadcast, ethzero;
simon 0:350011bf8be7 214
simon 0:350011bf8be7 215 #ifdef __cplusplus
simon 0:350011bf8be7 216 }
simon 0:350011bf8be7 217 #endif
simon 0:350011bf8be7 218
simon 0:350011bf8be7 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
simon 0:350011bf8be7 220
simon 0:350011bf8be7 221 #endif /* __NETIF_ARP_H__ */