mikroSDK Reference Manual
ipv6.h
Go to the documentation of this file.
1
31#ifndef _IPV6_H
32#define _IPV6_H
33
34//Forward declaration of structures
35struct _Ipv6Header;
36#define Ipv6Header struct _Ipv6Header
37
39#define Ipv6FragmentHeader struct _Ipv6FragmentHeader
40
42#define Ipv6PseudoHeader struct _Ipv6PseudoHeader
43
44//Dependencies
45#include "core/net.h"
46#include "core/ethernet.h"
47#include "ipv6/ipv6_frag.h"
48
49//IPv6 support
50#ifndef IPV6_SUPPORT
51 #define IPV6_SUPPORT DISABLED
52#elif (IPV6_SUPPORT != ENABLED && IPV6_SUPPORT != DISABLED)
53 #error IPV6_SUPPORT parameter is not valid
54#endif
55
56//Default IPv6 Hop Limit field
57#ifndef IPV6_DEFAULT_HOP_LIMIT
58 #define IPV6_DEFAULT_HOP_LIMIT 64
59#elif (IPV6_DEFAULT_HOP_LIMIT < 1)
60 #error IPV6_DEFAULT_HOP_LIMIT parameter is not valid
61#endif
62
63//Maximum number of IPv6 unicast addresses
64#ifndef IPV6_ADDR_LIST_SIZE
65 #define IPV6_ADDR_LIST_SIZE 3
66#elif (IPV6_ADDR_LIST_SIZE < 2)
67 #error IPV6_ADDR_LIST_SIZE parameter is not valid
68#endif
69
70//Maximum number of IPv6 anycast addresses
71#ifndef IPV6_ANYCAST_ADDR_LIST_SIZE
72 #define IPV6_ANYCAST_ADDR_LIST_SIZE 1
73#elif (IPV6_ANYCAST_ADDR_LIST_SIZE < 1)
74 #error IPV6_ANYCAST_ADDR_LIST_SIZE parameter is not valid
75#endif
76
77//Size of the prefix list
78#ifndef IPV6_PREFIX_LIST_SIZE
79 #define IPV6_PREFIX_LIST_SIZE 2
80#elif (IPV6_PREFIX_LIST_SIZE < 1)
81 #error IPV6_PREFIX_LIST_SIZE parameter is not valid
82#endif
83
84//Maximum number number of default routers
85#ifndef IPV6_ROUTER_LIST_SIZE
86 #define IPV6_ROUTER_LIST_SIZE 2
87#elif (IPV6_ROUTER_LIST_SIZE < 1)
88 #error IPV6_ROUTER_LIST_SIZE parameter is not valid
89#endif
90
91//Maximum number of DNS servers
92#ifndef IPV6_DNS_SERVER_LIST_SIZE
93 #define IPV6_DNS_SERVER_LIST_SIZE 2
94#elif (IPV6_DNS_SERVER_LIST_SIZE < 1)
95 #error IPV6_DNS_SERVER_LIST_SIZE parameter is not valid
96#endif
97
98//Size of the IPv6 multicast filter
99#ifndef IPV6_MULTICAST_FILTER_SIZE
100 #define IPV6_MULTICAST_FILTER_SIZE 8
101#elif (IPV6_MULTICAST_FILTER_SIZE < 1)
102 #error IPV6_MULTICAST_FILTER_SIZE parameter is not valid
103#endif
104
105//Version number for IPv6
106#define IPV6_VERSION 6
107//Minimum MTU that routers and physical links are required to handle
108#define IPV6_DEFAULT_MTU 1280
109
110//Macro used for defining an IPv6 address
111#define IPV6_ADDR(a, b, c, d, e, f, g, h) {{{ \
112 MSB(a), LSB(a), MSB(b), LSB(b), MSB(c), LSB(c), MSB(d), LSB(d), \
113 MSB(e), LSB(e), MSB(f), LSB(f), MSB(g), LSB(g), MSB(h), LSB(h)}}}
114
115//Copy IPv6 address
116#define ipv6CopyAddr(destIpAddr, srcIpAddr) \
117 osMemcpy(destIpAddr, srcIpAddr, sizeof(Ipv6Addr))
118
119//Compare IPv6 addresses
120#define ipv6CompAddr(ipAddr1, ipAddr2) \
121 (!osMemcmp(ipAddr1, ipAddr2, sizeof(Ipv6Addr)))
122
123//Determine whether an IPv6 address is a link-local unicast address
124#define ipv6IsLinkLocalUnicastAddr(ipAddr) \
125 ((ipAddr)->b[0] == 0xFE && ((ipAddr)->b[1] & 0xC0) == 0x80)
126
127//Determine whether an IPv6 address is a site-local unicast address
128#define ipv6IsSiteLocalUnicastAddr(ipAddr) \
129 ((ipAddr)->b[0] == 0xFE && ((ipAddr)->b[1] & 0xC0) == 0xC0)
130
131//Determine whether an IPv6 address is a multicast address
132#define ipv6IsMulticastAddr(ipAddr) \
133 ((ipAddr)->b[0] == 0xFF)
134
135//Determine whether an IPv6 address is a solicited-node address
136#define ipv6IsSolicitedNodeAddr(ipAddr) \
137 ipv6CompPrefix(ipAddr, &IPV6_SOLICITED_NODE_ADDR_PREFIX, 104)
138
139//C++ guard
140#ifdef __cplusplus
141extern "C" {
142#endif
143
144
149typedef enum
150{
151 IPV6_ADDR_SCOPE_INTERFACE_LOCAL = 1,
152 IPV6_ADDR_SCOPE_LINK_LOCAL = 2,
153 IPV6_ADDR_SCOPE_ADMIN_LOCAL = 4,
154 IPV6_ADDR_SCOPE_SITE_LOCAL = 5,
155 IPV6_ADDR_SCOPE_ORGANIZATION_LOCAL = 8,
156 IPV6_ADDR_SCOPE_GLOBAL = 14
158
159
171
172
177typedef enum
178{
179 IPV6_HOP_BY_HOP_OPT_HEADER = 0,
180 IPV6_TCP_HEADER = 6,
181 IPV6_UDP_HEADER = 17,
182 IPV6_ROUTING_HEADER = 43,
183 IPV6_FRAGMENT_HEADER = 44,
184 IPV6_ESP_HEADER = 50,
185 IPV6_AH_HEADER = 51,
186 IPV6_ICMPV6_HEADER = 58,
187 IPV6_NO_NEXT_HEADER = 59,
188 IPV6_DEST_OPT_HEADER = 60
190
191
196typedef enum
197{
198 IPV6_OFFSET_MASK = 0xFFF8,
199 IPV6_FLAG_RES1 = 0x0004,
200 IPV6_FLAG_RES2 = 0x0002,
201 IPV6_FLAG_M = 0x0001
203
204
209typedef enum
210{
211 IPV6_OPTION_TYPE_MASK = 0x1F,
212 IPV6_OPTION_TYPE_PAD1 = 0x00,
213 IPV6_OPTION_TYPE_PADN = 0x01
215
216
221typedef enum
222{
223 IPV6_ACTION_MASK = 0xC0,
224 IPV6_ACTION_SKIP_OPTION = 0x00,
225 IPV6_ACTION_DISCARD_PACKET = 0x40,
226 IPV6_ACTION_SEND_ICMP_ERROR_ALL = 0x80,
227 IPV6_ACTION_SEND_ICMP_ERROR_UNI = 0xC0
229
230
231//CodeWarrior or Win32 compiler?
232#if defined(__CWCC__) || defined(_WIN32)
233 #pragma pack(push, 1)
234#endif
235
236
242{
243 __packed_union
244 {
245 uint8_t b[16];
246 uint16_t w[8];
247 uint32_t dw[4];
248 };
249} Ipv6Addr;
250
251
257{
258#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
259 uint8_t version : 4; //0
260 uint8_t trafficClassH : 4;
261 uint8_t trafficClassL : 4; //1
262 uint8_t flowLabelH : 4;
263#else
264 uint8_t trafficClassH : 4; //0
265 uint8_t version : 4;
266 uint8_t flowLabelH : 4; //1
267 uint8_t trafficClassL : 4;
268#endif
269 uint16_t flowLabelL; //2-3
270 uint16_t payloadLen; //4-5
271 uint8_t nextHeader; //6
272 uint8_t hopLimit; //7
273 Ipv6Addr srcAddr; //8-23
274 Ipv6Addr destAddr; //24-39
275 uint8_t payload[]; //40
276};
277
278
283typedef __packed_struct
284{
285 uint8_t nextHeader; //0
286 uint8_t hdrExtLen; //1
287 uint8_t options[]; //2
288} Ipv6HopByHopOptHeader;
289
290
295typedef __packed_struct
296{
297 uint8_t nextHeader; //0
298 uint8_t hdrExtLen; //1
299 uint8_t options[]; //2
300} Ipv6DestOptHeader;
301
302
307typedef __packed_struct
308{
309 uint8_t nextHeader; //0
310 uint8_t hdrExtLen; //1
311 uint8_t routingType; //2
312 uint8_t segmentsLeft; //3
313 uint32_t reserved; //4-7
314 Ipv6Addr address[]; //8
315} Ipv6RoutingHeader;
316
317
323{
324 uint8_t nextHeader; //0
325 uint8_t reserved; //1
326 uint16_t fragmentOffset; //2-3
327 uint32_t identification; //4-7
328};
329
330
335typedef __packed_struct
336{
337 uint8_t nextHeader; //0
338 uint8_t payloadLen; //1
339 uint16_t reserved; //2-3
340 uint32_t securityParamIndex; //4-7
341 uint32_t sequenceNumber; //8-11
342 uint8_t authData[]; //12
343} Ipv6AuthHeader;
344
345
350typedef __packed_struct
351{
352 uint32_t securityParamIndex; //0-3
353 uint32_t sequenceNumber; //4-7
354 uint8_t payloadData[]; //8
355} Ipv6EspHeader;
356
357
362typedef __packed_struct
363{
364 uint8_t type; //0
365 uint8_t length; //1
366 uint8_t data[]; //2
367} Ipv6Option;
368
369
375{
376 Ipv6Addr srcAddr; //0-15
377 Ipv6Addr destAddr; //16-31
378 uint32_t length; //32-35
379 uint8_t reserved[3]; //36-38
380 uint8_t nextHeader; //39
381};
382
383
384//CodeWarrior or Win32 compiler?
385#if defined(__CWCC__) || defined(_WIN32)
386 #pragma pack(pop)
387#endif
388
389
406
407
423
424
437
438
443typedef struct
444{
445 Ipv6Addr addr;
446 uint_t refCount;
447 uint_t state;
448 bool_t flag;
451
452
457typedef struct
458{
459 size_t linkMtu;
460 bool_t isRouter;
462 uint8_t curHopLimit;
465 Ipv6AddrEntry addrList[IPV6_ADDR_LIST_SIZE];
466 Ipv6Addr anycastAddrList[IPV6_ANYCAST_ADDR_LIST_SIZE];
467 Ipv6PrefixEntry prefixList[IPV6_PREFIX_LIST_SIZE];
468 Ipv6RouterEntry routerList[IPV6_ROUTER_LIST_SIZE];
469 Ipv6Addr dnsServerList[IPV6_DNS_SERVER_LIST_SIZE];
470 Ipv6FilterEntry multicastFilter[IPV6_MULTICAST_FILTER_SIZE];
471#if (IPV6_FRAG_SUPPORT == ENABLED)
472 uint32_t identification;
473 Ipv6FragDesc fragQueue[IPV6_MAX_FRAG_DATAGRAMS];
474#endif
476
477
478//IPv6 related constants
479extern const Ipv6Addr IPV6_UNSPECIFIED_ADDR;
480extern const Ipv6Addr IPV6_LOOPBACK_ADDR;
481extern const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR;
482extern const Ipv6Addr IPV6_LINK_LOCAL_ALL_ROUTERS_ADDR;
483extern const Ipv6Addr IPV6_LINK_LOCAL_ADDR_PREFIX;
484extern const Ipv6Addr IPV6_SOLICITED_NODE_ADDR_PREFIX;
485
486//IPv6 related functions
487error_t ipv6Init(NetInterface *interface);
488
489error_t ipv6SetMtu(NetInterface *interface, size_t mtu);
490error_t ipv6GetMtu(NetInterface *interface, size_t *mtu);
491
492error_t ipv6SetDefaultHopLimit(NetInterface *interface, uint8_t hopLimit);
493
494error_t ipv6SetLinkLocalAddr(NetInterface *interface, const Ipv6Addr *addr);
495error_t ipv6GetLinkLocalAddr(NetInterface *interface, Ipv6Addr *addr);
496Ipv6AddrState ipv6GetLinkLocalAddrState(NetInterface *interface);
497
498error_t ipv6SetGlobalAddr(NetInterface *interface, uint_t index, const Ipv6Addr *addr);
499error_t ipv6GetGlobalAddr(NetInterface *interface, uint_t index, Ipv6Addr *addr);
500Ipv6AddrState ipv6GetGlobalAddrState(NetInterface *interface, uint_t index);
501
502error_t ipv6SetAnycastAddr(NetInterface *interface, uint_t index, const Ipv6Addr *addr);
503error_t ipv6GetAnycastAddr(NetInterface *interface, uint_t index, Ipv6Addr *addr);
504
505error_t ipv6SetPrefix(NetInterface *interface,
506 uint_t index, const Ipv6Addr *prefix, uint_t length);
507
508error_t ipv6GetPrefix(NetInterface *interface,
509 uint_t index, Ipv6Addr *prefix, uint_t *length);
510
511error_t ipv6SetDefaultRouter(NetInterface *interface, uint_t index, const Ipv6Addr *addr);
512error_t ipv6GetDefaultRouter(NetInterface *interface, uint_t index, Ipv6Addr *addr);
513
514error_t ipv6SetDnsServer(NetInterface *interface, uint_t index, const Ipv6Addr *addr);
515error_t ipv6GetDnsServer(NetInterface *interface, uint_t index, Ipv6Addr *addr);
516
517void ipv6LinkChangeEvent(NetInterface *interface);
518
519void ipv6ProcessPacket(NetInterface *interface, NetBuffer *ipPacket,
520 size_t ipPacketOffset, NetRxAncillary *ancillary);
521
522error_t ipv6ParseHopByHopOptHeader(NetInterface *interface, const NetBuffer *ipPacket,
523 size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset);
524
525error_t ipv6ParseDestOptHeader(NetInterface *interface, const NetBuffer *ipPacket,
526 size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset);
527
528error_t ipv6ParseRoutingHeader(NetInterface *interface, const NetBuffer *ipPacket,
529 size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset);
530
531error_t ipv6ParseAhHeader(NetInterface *interface, const NetBuffer *ipPacket,
532 size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset);
533
534error_t ipv6ParseEspHeader(NetInterface *interface, const NetBuffer *ipPacket,
535 size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset);
536
537error_t ipv6ParseOptions(NetInterface *interface, const NetBuffer *ipPacket,
538 size_t ipPacketOffset, size_t optionOffset, size_t optionLen);
539
540error_t ipv6SendDatagram(NetInterface *interface,
541 const Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset,
542 NetTxAncillary *ancillary);
543
544error_t ipv6SendPacket(NetInterface *interface,
545 const Ipv6PseudoHeader *pseudoHeader, uint32_t fragId, size_t fragOffset,
546 NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
547
548error_t ipv6JoinMulticastGroup(NetInterface *interface, const Ipv6Addr *groupAddr);
549error_t ipv6LeaveMulticastGroup(NetInterface *interface, const Ipv6Addr *groupAddr);
550
551error_t ipv6StringToAddr(const char_t *str, Ipv6Addr *ipAddr);
552char_t *ipv6AddrToString(const Ipv6Addr *ipAddr, char_t *str);
553
554void ipv6DumpHeader(const Ipv6Header *ipHeader);
555
556//C++ guard
557#ifdef __cplusplus
558}
559#endif
560
561#endif
error_t
Error codes.
Definition error.h:43
Ethernet.
Ipv6NextHeaderType
IPv6 Next Header types.
Definition ipv6.h:178
__packed_struct _Ipv6FragmentHeader
IPv6 Fragment header.
Definition ipv6.h:323
Ipv6AddrScope
IPv6 address scopes.
Definition ipv6.h:150
Ipv6OptionType
IPv6 option types.
Definition ipv6.h:210
Ipv6Actions
Actions to be taken for unrecognized options.
Definition ipv6.h:222
Ipv6FragmentOffset
IPv6 fragment offset field.
Definition ipv6.h:197
__packed_struct _Ipv6Header
IPv6 header.
Definition ipv6.h:257
typedef __packed_struct
IPv6 network address.
Definition ipv6.h:242
Ipv6AddrState
IPv6 address state.
Definition ipv6.h:165
@ IPV6_ADDR_STATE_DEPRECATED
An address assigned to an interface whose use is discouraged.
Definition ipv6.h:169
@ IPV6_ADDR_STATE_PREFERRED
An address assigned to an interface whose use is unrestricted.
Definition ipv6.h:168
@ IPV6_ADDR_STATE_INVALID
An address that is not assigned to any interface.
Definition ipv6.h:166
@ IPV6_ADDR_STATE_TENTATIVE
An address whose uniqueness on a link is being verified.
Definition ipv6.h:167
__packed_struct _Ipv6PseudoHeader
IPv6 pseudo header.
Definition ipv6.h:375
IPv6 fragmentation and reassembly.
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
IPv6 address entry.
Definition ipv6.h:395
bool_t permanent
Permanently assigned address.
Definition ipv6.h:401
systime_t preferredLifetime
Preferred lifetime.
Definition ipv6.h:400
Ipv6Addr addr
IPv6 address.
Definition ipv6.h:396
systime_t timestamp
Timestamp to manage entry lifetime.
Definition ipv6.h:402
systime_t validLifetime
Valid lifetime.
Definition ipv6.h:399
uint_t dadRetransmitCount
Retransmission counter for Duplicate Address Detection.
Definition ipv6.h:404
systime_t dadTimeout
Timeout value for Duplicate Address Detection.
Definition ipv6.h:403
Ipv6AddrState state
IPv6 address state.
Definition ipv6.h:397
bool_t duplicate
The address is a duplicate.
Definition ipv6.h:398
IPv6 context.
Definition ipv6.h:458
bool_t isRouter
A flag indicating whether routing is enabled on this interface.
Definition ipv6.h:460
uint8_t defaultHopLimit
Default Hop Limit value.
Definition ipv6.h:461
size_t linkMtu
Maximum transmission unit.
Definition ipv6.h:459
bool_t enableEchoReq
Support for ICMPv6 Echo Request messages.
Definition ipv6.h:463
uint8_t curHopLimit
Current Hop Limit value.
Definition ipv6.h:462
uint32_t identification
IPv6 fragment identification field.
Definition ipv6.h:472
bool_t enableMulticastEchoReq
Support for multicast ICMPv6 Echo Request messages.
Definition ipv6.h:464
IPv6 multicast filter entry.
Definition ipv6.h:444
uint_t state
MLD node state.
Definition ipv6.h:447
uint_t refCount
Reference count for the current entry.
Definition ipv6.h:446
systime_t timer
Delay timer.
Definition ipv6.h:449
bool_t flag
MLD flag.
Definition ipv6.h:448
Ipv6Addr addr
Multicast address.
Definition ipv6.h:445
Fragmented packet descriptor.
Definition ipv6_frag.h:131
Prefix list entry.
Definition ipv6.h:413
bool_t autonomousFlag
Autonomous flag.
Definition ipv6.h:417
bool_t onLinkFlag
On-link flag.
Definition ipv6.h:416
systime_t timestamp
Timestamp to manage entry lifetime.
Definition ipv6.h:421
uint8_t prefixLen
IPv6 prefix length.
Definition ipv6.h:415
bool_t permanent
Permanently assigned prefix.
Definition ipv6.h:420
systime_t validLifetime
Valid lifetime.
Definition ipv6.h:418
Ipv6Addr prefix
IPv6 prefix information.
Definition ipv6.h:414
systime_t preferredLifetime
Preferred lifetime.
Definition ipv6.h:419
Default router list entry.
Definition ipv6.h:430
systime_t timestamp
Timestamp to manage entry lifetime.
Definition ipv6.h:435
bool_t permanent
Permanently assigned router.
Definition ipv6.h:434
uint8_t preference
Preference value.
Definition ipv6.h:433
Ipv6Addr addr
Router address.
Definition ipv6.h:431
systime_t lifetime
Router lifetime.
Definition ipv6.h:432
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89