Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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