Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependents:   STM32F746_iothub_client_sample_mqtt DISCO-F746NG_Ethernet Nucleo_F746ZG_Ethernet thethingsiO-DISCO_F746NG-mqtt ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ip.h Source File

ip.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_IP_H__
00033 #define __LWIP_IP_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #include "lwip/def.h"
00038 #include "lwip/pbuf.h"
00039 #include "lwip/ip_addr.h"
00040 #include "lwip/err.h"
00041 #include "lwip/netif.h"
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 /** Currently, the function ip_output_if_opt() is only used with IGMP */
00048 #define IP_OPTIONS_SEND   LWIP_IGMP
00049 
00050 #define IP_HLEN 20
00051 
00052 #define IP_PROTO_ICMP    1
00053 #define IP_PROTO_IGMP    2
00054 #define IP_PROTO_UDP     17
00055 #define IP_PROTO_UDPLITE 136
00056 #define IP_PROTO_TCP     6
00057 
00058 /* This is passed as the destination address to ip_output_if (not
00059    to ip_output), meaning that an IP header already is constructed
00060    in the pbuf. This is used when TCP retransmits. */
00061 #ifdef IP_HDRINCL
00062 #undef IP_HDRINCL
00063 #endif /* IP_HDRINCL */
00064 #define IP_HDRINCL  NULL
00065 
00066 #if LWIP_NETIF_HWADDRHINT
00067 #define IP_PCB_ADDRHINT ;u8_t addr_hint
00068 #else
00069 #define IP_PCB_ADDRHINT
00070 #endif /* LWIP_NETIF_HWADDRHINT */
00071 
00072 /* This is the common part of all PCB types. It needs to be at the
00073    beginning of a PCB type definition. It is located here so that
00074    changes to this common part are made in one location instead of
00075    having to change all PCB structs. */
00076 #define IP_PCB \
00077   /* ip addresses in network byte order */ \
00078   ip_addr_t local_ip; \
00079   ip_addr_t remote_ip; \
00080    /* Socket options */  \
00081   u8_t so_options;      \
00082    /* Type Of Service */ \
00083   u8_t tos;              \
00084   /* Time To Live */     \
00085   u8_t ttl               \
00086   /* link layer address resolution hint */ \
00087   IP_PCB_ADDRHINT
00088 
00089 struct ip_pcb {
00090 /* Common members of all PCB types */
00091   IP_PCB;
00092 };
00093 
00094 /*
00095  * Option flags per-socket. These are the same like SO_XXX.
00096  */
00097 /*#define SOF_DEBUG       0x01U     Unimplemented: turn on debugging info recording */
00098 #define SOF_ACCEPTCONN    0x02U  /* socket has had listen() */
00099 #define SOF_REUSEADDR     0x04U  /* allow local address reuse */
00100 #define SOF_KEEPALIVE     0x08U  /* keep connections alive */
00101 /*#define SOF_DONTROUTE   0x10U     Unimplemented: just use interface addresses */
00102 #define SOF_BROADCAST     0x20U  /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
00103 /*#define SOF_USELOOPBACK 0x40U     Unimplemented: bypass hardware when possible */
00104 #define SOF_LINGER        0x80U  /* linger on close if data present */
00105 /*#define SOF_OOBINLINE   0x0100U   Unimplemented: leave received OOB data in line */
00106 /*#define SOF_REUSEPORT   0x0200U   Unimplemented: allow local address & port reuse */
00107 
00108 /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
00109 #define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
00110 
00111 
00112 #ifdef PACK_STRUCT_USE_INCLUDES
00113 #  include "arch/bpstruct.h"
00114 #endif
00115 PACK_STRUCT_BEGIN
00116 struct ip_hdr {
00117   /* version / header length */
00118   PACK_STRUCT_FIELD(u8_t _v_hl);
00119   /* type of service */
00120   PACK_STRUCT_FIELD(u8_t _tos);
00121   /* total length */
00122   PACK_STRUCT_FIELD(u16_t _len);
00123   /* identification */
00124   PACK_STRUCT_FIELD(u16_t _id);
00125   /* fragment offset field */
00126   PACK_STRUCT_FIELD(u16_t _offset);
00127 #define IP_RF 0x8000U        /* reserved fragment flag */
00128 #define IP_DF 0x4000U        /* dont fragment flag */
00129 #define IP_MF 0x2000U        /* more fragments flag */
00130 #define IP_OFFMASK 0x1fffU   /* mask for fragmenting bits */
00131   /* time to live */
00132   PACK_STRUCT_FIELD(u8_t _ttl);
00133   /* protocol*/
00134   PACK_STRUCT_FIELD(u8_t _proto);
00135   /* checksum */
00136   PACK_STRUCT_FIELD(u16_t _chksum);
00137   /* source and destination IP addresses */
00138   PACK_STRUCT_FIELD(ip_addr_p_t src);
00139   PACK_STRUCT_FIELD(ip_addr_p_t dest); 
00140 } PACK_STRUCT_STRUCT;
00141 PACK_STRUCT_END
00142 #ifdef PACK_STRUCT_USE_INCLUDES
00143 #  include "arch/epstruct.h"
00144 #endif
00145 
00146 #define IPH_V(hdr)  ((hdr)->_v_hl >> 4)
00147 #define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
00148 #define IPH_TOS(hdr) ((hdr)->_tos)
00149 #define IPH_LEN(hdr) ((hdr)->_len)
00150 #define IPH_ID(hdr) ((hdr)->_id)
00151 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00152 #define IPH_TTL(hdr) ((hdr)->_ttl)
00153 #define IPH_PROTO(hdr) ((hdr)->_proto)
00154 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00155 
00156 #define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (((v) << 4) | (hl))
00157 #define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
00158 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00159 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00160 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00161 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
00162 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
00163 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00164 
00165 /** The interface that provided the packet for the current callback invocation. */
00166 extern struct netif *current_netif;
00167 /** Header of the input packet currently being processed. */
00168 extern const struct ip_hdr *current_header;
00169 /** Source IP address of current_header */
00170 extern ip_addr_t current_iphdr_src;
00171 /** Destination IP address of current_header */
00172 extern ip_addr_t current_iphdr_dest;
00173 
00174 #define ip_init() /* Compatibility define, not init needed. */
00175 struct netif *ip_route(ip_addr_t *dest);
00176 err_t ip_input(struct pbuf *p, struct netif *inp);
00177 err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00178        u8_t ttl, u8_t tos, u8_t proto);
00179 err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00180        u8_t ttl, u8_t tos, u8_t proto,
00181        struct netif *netif);
00182 #if LWIP_NETIF_HWADDRHINT
00183 err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00184        u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
00185 #endif /* LWIP_NETIF_HWADDRHINT */
00186 #if IP_OPTIONS_SEND
00187 err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00188        u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
00189        u16_t optlen);
00190 #endif /* IP_OPTIONS_SEND */
00191 /** Get the interface that received the current packet.
00192  * This function must only be called from a receive callback (udp_recv,
00193  * raw_recv, tcp_accept). It will return NULL otherwise. */
00194 #define ip_current_netif()  (current_netif)
00195 /** Get the IP header of the current packet.
00196  * This function must only be called from a receive callback (udp_recv,
00197  * raw_recv, tcp_accept). It will return NULL otherwise. */
00198 #define ip_current_header() (current_header)
00199 /** Source IP address of current_header */
00200 #define ip_current_src_addr()  (&current_iphdr_src)
00201 /** Destination IP address of current_header */
00202 #define ip_current_dest_addr() (&current_iphdr_dest)
00203 
00204 /** Gets an IP pcb option (SOF_* flags) */
00205 #define ip_get_option(pcb, opt)   ((pcb)->so_options & (opt))
00206 /** Sets an IP pcb option (SOF_* flags) */
00207 #define ip_set_option(pcb, opt)   ((pcb)->so_options |= (opt))
00208 /** Resets an IP pcb option (SOF_* flags) */
00209 #define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
00210 
00211 #if IP_DEBUG
00212 void ip_debug_print(struct pbuf *p);
00213 #else
00214 #define ip_debug_print(p)
00215 #endif /* IP_DEBUG */
00216 
00217 #ifdef __cplusplus
00218 }
00219 #endif
00220 
00221 #endif /* __LWIP_IP_H__ */
00222 
00223