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-2004 Swedish Institute of Computer Science.
simon 0:350011bf8be7 3 * All rights reserved.
simon 0:350011bf8be7 4 *
simon 0:350011bf8be7 5 * Redistribution and use in source and binary forms, with or without modification,
simon 0:350011bf8be7 6 * are permitted provided that the following conditions are met:
simon 0:350011bf8be7 7 *
simon 0:350011bf8be7 8 * 1. Redistributions of source code must retain the above copyright notice,
simon 0:350011bf8be7 9 * this list of conditions and the following disclaimer.
simon 0:350011bf8be7 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
simon 0:350011bf8be7 11 * this list of conditions and the following disclaimer in the documentation
simon 0:350011bf8be7 12 * and/or other materials provided with the distribution.
simon 0:350011bf8be7 13 * 3. The name of the author may not be used to endorse or promote products
simon 0:350011bf8be7 14 * derived from this software without specific prior written permission.
simon 0:350011bf8be7 15 *
simon 0:350011bf8be7 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
simon 0:350011bf8be7 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
simon 0:350011bf8be7 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
simon 0:350011bf8be7 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
simon 0:350011bf8be7 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
simon 0:350011bf8be7 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
simon 0:350011bf8be7 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
simon 0:350011bf8be7 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
simon 0:350011bf8be7 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
simon 0:350011bf8be7 25 * OF SUCH DAMAGE.
simon 0:350011bf8be7 26 *
simon 0:350011bf8be7 27 * This file is part of the lwIP TCP/IP stack.
simon 0:350011bf8be7 28 *
simon 0:350011bf8be7 29 * Author: Adam Dunkels <adam@sics.se>
simon 0:350011bf8be7 30 *
simon 0:350011bf8be7 31 */
simon 0:350011bf8be7 32 #ifndef __LWIP_IP_H__
simon 0:350011bf8be7 33 #define __LWIP_IP_H__
simon 0:350011bf8be7 34
simon 0:350011bf8be7 35 #include "lwip/opt.h"
simon 0:350011bf8be7 36
simon 0:350011bf8be7 37 #include "lwip/def.h"
simon 0:350011bf8be7 38 #include "lwip/pbuf.h"
simon 0:350011bf8be7 39 #include "lwip/ip_addr.h"
simon 0:350011bf8be7 40 #include "lwip/err.h"
simon 0:350011bf8be7 41 #include "lwip/netif.h"
simon 0:350011bf8be7 42
simon 0:350011bf8be7 43 #ifdef __cplusplus
simon 0:350011bf8be7 44 extern "C" {
simon 0:350011bf8be7 45 #endif
simon 0:350011bf8be7 46
simon 0:350011bf8be7 47 /** Currently, the function ip_output_if_opt() is only used with IGMP */
simon 0:350011bf8be7 48 #define IP_OPTIONS_SEND LWIP_IGMP
simon 0:350011bf8be7 49
simon 0:350011bf8be7 50 #define IP_HLEN 20
simon 0:350011bf8be7 51
simon 0:350011bf8be7 52 #define IP_PROTO_ICMP 1
simon 0:350011bf8be7 53 #define IP_PROTO_IGMP 2
simon 0:350011bf8be7 54 #define IP_PROTO_UDP 17
simon 0:350011bf8be7 55 #define IP_PROTO_UDPLITE 136
simon 0:350011bf8be7 56 #define IP_PROTO_TCP 6
simon 0:350011bf8be7 57
simon 0:350011bf8be7 58 /* This is passed as the destination address to ip_output_if (not
simon 0:350011bf8be7 59 to ip_output), meaning that an IP header already is constructed
simon 0:350011bf8be7 60 in the pbuf. This is used when TCP retransmits. */
simon 0:350011bf8be7 61 #ifdef IP_HDRINCL
simon 0:350011bf8be7 62 #undef IP_HDRINCL
simon 0:350011bf8be7 63 #endif /* IP_HDRINCL */
simon 0:350011bf8be7 64 #define IP_HDRINCL NULL
simon 0:350011bf8be7 65
simon 0:350011bf8be7 66 #if LWIP_NETIF_HWADDRHINT
simon 0:350011bf8be7 67 #define IP_PCB_ADDRHINT ;u8_t addr_hint
simon 0:350011bf8be7 68 #else
simon 0:350011bf8be7 69 #define IP_PCB_ADDRHINT
simon 0:350011bf8be7 70 #endif /* LWIP_NETIF_HWADDRHINT */
simon 0:350011bf8be7 71
simon 0:350011bf8be7 72 /* This is the common part of all PCB types. It needs to be at the
simon 0:350011bf8be7 73 beginning of a PCB type definition. It is located here so that
simon 0:350011bf8be7 74 changes to this common part are made in one location instead of
simon 0:350011bf8be7 75 having to change all PCB structs. */
simon 0:350011bf8be7 76 #define IP_PCB \
simon 0:350011bf8be7 77 /* ip addresses in network byte order */ \
simon 0:350011bf8be7 78 ip_addr_t local_ip; \
simon 0:350011bf8be7 79 ip_addr_t remote_ip; \
simon 0:350011bf8be7 80 /* Socket options */ \
simon 0:350011bf8be7 81 u8_t so_options; \
simon 0:350011bf8be7 82 /* Type Of Service */ \
simon 0:350011bf8be7 83 u8_t tos; \
simon 0:350011bf8be7 84 /* Time To Live */ \
simon 0:350011bf8be7 85 u8_t ttl \
simon 0:350011bf8be7 86 /* link layer address resolution hint */ \
simon 0:350011bf8be7 87 IP_PCB_ADDRHINT
simon 0:350011bf8be7 88
simon 0:350011bf8be7 89 struct ip_pcb {
simon 0:350011bf8be7 90 /* Common members of all PCB types */
simon 0:350011bf8be7 91 IP_PCB;
simon 0:350011bf8be7 92 };
simon 0:350011bf8be7 93
simon 0:350011bf8be7 94 /*
simon 0:350011bf8be7 95 * Option flags per-socket. These are the same like SO_XXX.
simon 0:350011bf8be7 96 */
simon 0:350011bf8be7 97 /*#define SOF_DEBUG (u8_t)0x01U Unimplemented: turn on debugging info recording */
simon 0:350011bf8be7 98 #define SOF_ACCEPTCONN (u8_t)0x02U /* socket has had listen() */
simon 0:350011bf8be7 99 #define SOF_REUSEADDR (u8_t)0x04U /* allow local address reuse */
simon 0:350011bf8be7 100 #define SOF_KEEPALIVE (u8_t)0x08U /* keep connections alive */
simon 0:350011bf8be7 101 /*#define SOF_DONTROUTE (u8_t)0x10U Unimplemented: just use interface addresses */
simon 0:350011bf8be7 102 #define SOF_BROADCAST (u8_t)0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
simon 0:350011bf8be7 103 /*#define SOF_USELOOPBACK (u8_t)0x40U Unimplemented: bypass hardware when possible */
simon 0:350011bf8be7 104 #define SOF_LINGER (u8_t)0x80U /* linger on close if data present */
simon 0:350011bf8be7 105 /*#define SOF_OOBINLINE (u16_t)0x0100U Unimplemented: leave received OOB data in line */
simon 0:350011bf8be7 106 /*#define SOF_REUSEPORT (u16_t)0x0200U Unimplemented: allow local address & port reuse */
simon 0:350011bf8be7 107
simon 0:350011bf8be7 108 /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
simon 0:350011bf8be7 109 #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
simon 0:350011bf8be7 110
simon 0:350011bf8be7 111
simon 0:350011bf8be7 112 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 113 # include "arch/bpstruct.h"
simon 0:350011bf8be7 114 #endif
simon 0:350011bf8be7 115 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 116 struct ip_hdr {
simon 0:350011bf8be7 117 /* version / header length / type of service */
simon 0:350011bf8be7 118 PACK_STRUCT_FIELD(u16_t _v_hl_tos);
simon 0:350011bf8be7 119 /* total length */
simon 0:350011bf8be7 120 PACK_STRUCT_FIELD(u16_t _len);
simon 0:350011bf8be7 121 /* identification */
simon 0:350011bf8be7 122 PACK_STRUCT_FIELD(u16_t _id);
simon 0:350011bf8be7 123 /* fragment offset field */
simon 0:350011bf8be7 124 PACK_STRUCT_FIELD(u16_t _offset);
simon 0:350011bf8be7 125 #define IP_RF 0x8000 /* reserved fragment flag */
simon 0:350011bf8be7 126 #define IP_DF 0x4000 /* dont fragment flag */
simon 0:350011bf8be7 127 #define IP_MF 0x2000 /* more fragments flag */
simon 0:350011bf8be7 128 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
simon 0:350011bf8be7 129 /* time to live */
simon 0:350011bf8be7 130 PACK_STRUCT_FIELD(u8_t _ttl);
simon 0:350011bf8be7 131 /* protocol*/
simon 0:350011bf8be7 132 PACK_STRUCT_FIELD(u8_t _proto);
simon 0:350011bf8be7 133 /* checksum */
simon 0:350011bf8be7 134 PACK_STRUCT_FIELD(u16_t _chksum);
simon 0:350011bf8be7 135 /* source and destination IP addresses */
simon 0:350011bf8be7 136 PACK_STRUCT_FIELD(ip_addr_p_t src);
simon 0:350011bf8be7 137 PACK_STRUCT_FIELD(ip_addr_p_t dest);
simon 0:350011bf8be7 138 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 139 PACK_STRUCT_END
simon 0:350011bf8be7 140 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 141 # include "arch/epstruct.h"
simon 0:350011bf8be7 142 #endif
simon 0:350011bf8be7 143
simon 0:350011bf8be7 144 #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
simon 0:350011bf8be7 145 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
simon 0:350011bf8be7 146 #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
simon 0:350011bf8be7 147 #define IPH_LEN(hdr) ((hdr)->_len)
simon 0:350011bf8be7 148 #define IPH_ID(hdr) ((hdr)->_id)
simon 0:350011bf8be7 149 #define IPH_OFFSET(hdr) ((hdr)->_offset)
simon 0:350011bf8be7 150 #define IPH_TTL(hdr) ((hdr)->_ttl)
simon 0:350011bf8be7 151 #define IPH_PROTO(hdr) ((hdr)->_proto)
simon 0:350011bf8be7 152 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
simon 0:350011bf8be7 153
simon 0:350011bf8be7 154 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
simon 0:350011bf8be7 155 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
simon 0:350011bf8be7 156 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
simon 0:350011bf8be7 157 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
simon 0:350011bf8be7 158 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
simon 0:350011bf8be7 159 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
simon 0:350011bf8be7 160 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
simon 0:350011bf8be7 161
simon 0:350011bf8be7 162 /** The interface that provided the packet for the current callback invocation. */
simon 0:350011bf8be7 163 extern struct netif *current_netif;
simon 0:350011bf8be7 164 /** Header of the input packet currently being processed. */
simon 0:350011bf8be7 165 extern const struct ip_hdr *current_header;
simon 0:350011bf8be7 166 /** Source IP address of current_header */
simon 0:350011bf8be7 167 extern ip_addr_t current_iphdr_src;
simon 0:350011bf8be7 168 /** Destination IP address of current_header */
simon 0:350011bf8be7 169 extern ip_addr_t current_iphdr_dest;
simon 0:350011bf8be7 170
simon 0:350011bf8be7 171 #define ip_init() /* Compatibility define, not init needed. */
simon 0:350011bf8be7 172 struct netif *ip_route(ip_addr_t *dest);
simon 0:350011bf8be7 173 err_t ip_input(struct pbuf *p, struct netif *inp);
simon 0:350011bf8be7 174 err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
simon 0:350011bf8be7 175 u8_t ttl, u8_t tos, u8_t proto);
simon 0:350011bf8be7 176 err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
simon 0:350011bf8be7 177 u8_t ttl, u8_t tos, u8_t proto,
simon 0:350011bf8be7 178 struct netif *netif);
simon 0:350011bf8be7 179 #if LWIP_NETIF_HWADDRHINT
simon 0:350011bf8be7 180 err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
simon 0:350011bf8be7 181 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
simon 0:350011bf8be7 182 #endif /* LWIP_NETIF_HWADDRHINT */
simon 0:350011bf8be7 183 #if IP_OPTIONS_SEND
simon 0:350011bf8be7 184 err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
simon 0:350011bf8be7 185 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
simon 0:350011bf8be7 186 u16_t optlen);
simon 0:350011bf8be7 187 #endif /* IP_OPTIONS_SEND */
simon 0:350011bf8be7 188 /** Get the interface that received the current packet.
simon 0:350011bf8be7 189 * This function must only be called from a receive callback (udp_recv,
simon 0:350011bf8be7 190 * raw_recv, tcp_accept). It will return NULL otherwise. */
simon 0:350011bf8be7 191 #define ip_current_netif() (current_netif)
simon 0:350011bf8be7 192 /** Get the IP header of the current packet.
simon 0:350011bf8be7 193 * This function must only be called from a receive callback (udp_recv,
simon 0:350011bf8be7 194 * raw_recv, tcp_accept). It will return NULL otherwise. */
simon 0:350011bf8be7 195 #define ip_current_header() (current_header)
simon 0:350011bf8be7 196 /** Source IP address of current_header */
simon 0:350011bf8be7 197 #define ip_current_src_addr() (&current_iphdr_src)
simon 0:350011bf8be7 198 /** Destination IP address of current_header */
simon 0:350011bf8be7 199 #define ip_current_dest_addr() (&current_iphdr_dest)
simon 0:350011bf8be7 200
simon 0:350011bf8be7 201 #if IP_DEBUG
simon 0:350011bf8be7 202 void ip_debug_print(struct pbuf *p);
simon 0:350011bf8be7 203 #else
simon 0:350011bf8be7 204 #define ip_debug_print(p)
simon 0:350011bf8be7 205 #endif /* IP_DEBUG */
simon 0:350011bf8be7 206
simon 0:350011bf8be7 207 #ifdef __cplusplus
simon 0:350011bf8be7 208 }
simon 0:350011bf8be7 209 #endif
simon 0:350011bf8be7 210
simon 0:350011bf8be7 211 #endif /* __LWIP_IP_H__ */
simon 0:350011bf8be7 212
simon 0:350011bf8be7 213