STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ip6.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright (c) 2010 Inico Technologies Ltd.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  * derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Ivan Delamer <delamer@inicotech.com>
36  *
37  *
38  * Please coordinate changes and requests with Ivan Delamer
39  * <delamer@inicotech.com>
40  */
41 #ifndef LWIP_HDR_IP6_H
42 #define LWIP_HDR_IP6_H
43 
44 #include "lwip/opt.h"
45 
46 #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
47 
48 #include "lwip/ip6_addr.h"
49 #include "lwip/def.h"
50 #include "lwip/pbuf.h"
51 #include "lwip/netif.h"
52 
53 #include "lwip/err.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 #define IP6_HLEN 40
60 
61 #define IP6_NEXTH_HOPBYHOP 0
62 #define IP6_NEXTH_TCP 6
63 #define IP6_NEXTH_UDP 17
64 #define IP6_NEXTH_ENCAPS 41
65 #define IP6_NEXTH_ROUTING 43
66 #define IP6_NEXTH_FRAGMENT 44
67 #define IP6_NEXTH_ICMP6 58
68 #define IP6_NEXTH_NONE 59
69 #define IP6_NEXTH_DESTOPTS 60
70 #define IP6_NEXTH_UDPLITE 136
71 
72 
73 /* The IPv6 header. */
74 #ifdef PACK_STRUCT_USE_INCLUDES
75 # include "arch/bpstruct.h"
76 #endif
78 struct ip6_hdr {
79  /* version / traffic class / flow label */
80  PACK_STRUCT_FIELD(u32_t _v_tc_fl);
81  /* payload length */
82  PACK_STRUCT_FIELD(u16_t _plen);
83  /* next header */
84  PACK_STRUCT_FLD_8(u8_t _nexth);
85  /* hop limit */
86  PACK_STRUCT_FLD_8(u8_t _hoplim);
87  /* source and destination IP addresses */
88  PACK_STRUCT_FLD_S(ip6_addr_p_t src);
89  PACK_STRUCT_FLD_S(ip6_addr_p_t dest);
92 #ifdef PACK_STRUCT_USE_INCLUDES
93 # include "arch/epstruct.h"
94 #endif
95 
96 /* Hop-by-hop router alert option. */
97 #define IP6_HBH_HLEN 8
98 #define IP6_PAD1_OPTION 0
99 #define IP6_PADN_ALERT_OPTION 1
100 #define IP6_ROUTER_ALERT_OPTION 5
101 #define IP6_ROUTER_ALERT_VALUE_MLD 0
102 #ifdef PACK_STRUCT_USE_INCLUDES
103 # include "arch/bpstruct.h"
104 #endif
106 struct ip6_hbh_hdr {
107  /* next header */
108  PACK_STRUCT_FLD_8(u8_t _nexth);
109  /* header length */
110  PACK_STRUCT_FLD_8(u8_t _hlen);
111  /* router alert option type */
112  PACK_STRUCT_FLD_8(u8_t _ra_opt_type);
113  /* router alert option data len */
114  PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen);
115  /* router alert option data */
116  PACK_STRUCT_FIELD(u16_t _ra_opt_data);
117  /* PadN option type */
118  PACK_STRUCT_FLD_8(u8_t _padn_opt_type);
119  /* PadN option data len */
120  PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen);
123 #ifdef PACK_STRUCT_USE_INCLUDES
124 # include "arch/epstruct.h"
125 #endif
126 
127 /* Fragment header. */
128 #define IP6_FRAG_HLEN 8
129 #define IP6_FRAG_OFFSET_MASK 0xfff8
130 #define IP6_FRAG_MORE_FLAG 0x0001
131 #ifdef PACK_STRUCT_USE_INCLUDES
132 # include "arch/bpstruct.h"
133 #endif
135 struct ip6_frag_hdr {
136  /* next header */
137  PACK_STRUCT_FLD_8(u8_t _nexth);
138  /* reserved */
139  PACK_STRUCT_FLD_8(u8_t reserved);
140  /* fragment offset */
141  PACK_STRUCT_FIELD(u16_t _fragment_offset);
142  /* fragmented packet identification */
143  PACK_STRUCT_FIELD(u32_t _identification);
146 #ifdef PACK_STRUCT_USE_INCLUDES
147 # include "arch/epstruct.h"
148 #endif
149 
150 #define IP6H_V(hdr) ((ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f)
151 #define IP6H_TC(hdr) ((ntohl((hdr)->_v_tc_fl) >> 20) & 0xff)
152 #define IP6H_FL(hdr) (ntohl((hdr)->_v_tc_fl) & 0x000fffff)
153 #define IP6H_PLEN(hdr) (ntohs((hdr)->_plen))
154 #define IP6H_NEXTH(hdr) ((hdr)->_nexth)
155 #define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6)
156 #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim)
157 
158 #define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl)))
159 #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen)
160 #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth)
161 #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl)
162 
163 
164 struct netif *ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest);
165 const ip_addr_t *ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest);
166 err_t ip6_input(struct pbuf *p, struct netif *inp);
167 err_t ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
168  u8_t hl, u8_t tc, u8_t nexth);
169 err_t ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
170  u8_t hl, u8_t tc, u8_t nexth, struct netif *netif);
171 err_t ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
172  u8_t hl, u8_t tc, u8_t nexth, struct netif *netif);
173 #if LWIP_NETIF_HWADDRHINT
174 err_t ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
175  u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint);
176 #endif /* LWIP_NETIF_HWADDRHINT */
177 #if LWIP_IPV6_MLD
178 err_t ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value);
179 #endif /* LWIP_IPV6_MLD */
180 
181 #define ip6_netif_get_local_ip(netif, dest) (((netif) != NULL) ? \
182  ip6_select_source_address(netif, dest) : NULL)
183 
184 #if IP6_DEBUG
185 void ip6_debug_print(struct pbuf *p);
186 #else
187 #define ip6_debug_print(p)
188 #endif /* IP6_DEBUG */
189 
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif /* LWIP_IPV6 */
196 
197 #endif /* LWIP_HDR_IP6_H */
198 
#define PACK_STRUCT_STRUCT
Definition: arch.h:68
#define PACK_STRUCT_FLD_8(x)
Definition: arch.h:78
#define PACK_STRUCT_FIELD(x)
Definition: arch.h:72
unsigned long u32_t
Definition: cc.h:42
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
#define PACK_STRUCT_FLD_S(x)
Definition: arch.h:84
#define PACK_STRUCT_BEGIN
Definition: arch.h:60
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
#define PACK_STRUCT_END
Definition: arch.h:64
unsigned short u16_t
Definition: cc.h:40