Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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