Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file ipv6_frag.h
Sergunb 0:8918a71cdbe9 3 * @brief IPv6 fragmentation and reassembly
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This file is part of CycloneTCP Open.
Sergunb 0:8918a71cdbe9 10 *
Sergunb 0:8918a71cdbe9 11 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 12 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 13 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 14 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 15 *
Sergunb 0:8918a71cdbe9 16 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 19 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 20 *
Sergunb 0:8918a71cdbe9 21 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 22 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 24 *
Sergunb 0:8918a71cdbe9 25 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 26 * @version 1.7.6
Sergunb 0:8918a71cdbe9 27 **/
Sergunb 0:8918a71cdbe9 28
Sergunb 0:8918a71cdbe9 29 #ifndef _IPV6_FRAG_H
Sergunb 0:8918a71cdbe9 30 #define _IPV6_FRAG_H
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Dependencies
Sergunb 0:8918a71cdbe9 33 #include "core/net.h"
Sergunb 0:8918a71cdbe9 34 #include "ipv6/ipv6.h"
Sergunb 0:8918a71cdbe9 35
Sergunb 0:8918a71cdbe9 36 //IPv6 fragmentation support
Sergunb 0:8918a71cdbe9 37 #ifndef IPV6_FRAG_SUPPORT
Sergunb 0:8918a71cdbe9 38 #define IPV6_FRAG_SUPPORT DISABLED
Sergunb 0:8918a71cdbe9 39 #elif (IPV6_FRAG_SUPPORT != ENABLED && IPV6_FRAG_SUPPORT != DISABLED)
Sergunb 0:8918a71cdbe9 40 #error IPV6_FRAG_SUPPORT parameter is not valid
Sergunb 0:8918a71cdbe9 41 #endif
Sergunb 0:8918a71cdbe9 42
Sergunb 0:8918a71cdbe9 43 //Reassembly algorithm tick interval
Sergunb 0:8918a71cdbe9 44 #ifndef IPV6_FRAG_TICK_INTERVAL
Sergunb 0:8918a71cdbe9 45 #define IPV6_FRAG_TICK_INTERVAL 1000
Sergunb 0:8918a71cdbe9 46 #elif (IPV6_FRAG_TICK_INTERVAL < 10)
Sergunb 0:8918a71cdbe9 47 #error IPV6_FRAG_TICK_INTERVAL parameter is not valid
Sergunb 0:8918a71cdbe9 48 #endif
Sergunb 0:8918a71cdbe9 49
Sergunb 0:8918a71cdbe9 50 //Maximum number of fragmented packets the host will accept
Sergunb 0:8918a71cdbe9 51 //and hold in the reassembly queue simultaneously
Sergunb 0:8918a71cdbe9 52 #ifndef IPV6_MAX_FRAG_DATAGRAMS
Sergunb 0:8918a71cdbe9 53 #define IPV6_MAX_FRAG_DATAGRAMS 4
Sergunb 0:8918a71cdbe9 54 #elif (IPV6_MAX_FRAG_DATAGRAMS < 1)
Sergunb 0:8918a71cdbe9 55 #error IPV6_MAX_FRAG_DATAGRAMS parameter is not valid
Sergunb 0:8918a71cdbe9 56 #endif
Sergunb 0:8918a71cdbe9 57
Sergunb 0:8918a71cdbe9 58 //Maximum datagram size the host will accept when reassembling fragments
Sergunb 0:8918a71cdbe9 59 #ifndef IPV6_MAX_FRAG_DATAGRAM_SIZE
Sergunb 0:8918a71cdbe9 60 #define IPV6_MAX_FRAG_DATAGRAM_SIZE 8192
Sergunb 0:8918a71cdbe9 61 #elif (IPV6_MAX_FRAG_DATAGRAM_SIZE < 1280)
Sergunb 0:8918a71cdbe9 62 #error IPV6_MAX_FRAG_DATAGRAM_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 63 #endif
Sergunb 0:8918a71cdbe9 64
Sergunb 0:8918a71cdbe9 65 //Maximum time an IPv6 fragment can spend waiting to be reassembled
Sergunb 0:8918a71cdbe9 66 #ifndef IPV6_FRAG_TIME_TO_LIVE
Sergunb 0:8918a71cdbe9 67 #define IPV6_FRAG_TIME_TO_LIVE 15000
Sergunb 0:8918a71cdbe9 68 #elif (IPV6_FRAG_TIME_TO_LIVE < 1000)
Sergunb 0:8918a71cdbe9 69 #error IPV6_FRAG_TIME_TO_LIVE parameter is not valid
Sergunb 0:8918a71cdbe9 70 #endif
Sergunb 0:8918a71cdbe9 71
Sergunb 0:8918a71cdbe9 72 //Infinity is implemented by a very large integer
Sergunb 0:8918a71cdbe9 73 #define IPV6_INFINITY 0xFFFF
Sergunb 0:8918a71cdbe9 74
Sergunb 0:8918a71cdbe9 75
Sergunb 0:8918a71cdbe9 76 //CodeWarrior or Win32 compiler?
Sergunb 0:8918a71cdbe9 77 #if defined(__CWCC__) || defined(_WIN32)
Sergunb 0:8918a71cdbe9 78 #pragma pack(push, 1)
Sergunb 0:8918a71cdbe9 79 #endif
Sergunb 0:8918a71cdbe9 80
Sergunb 0:8918a71cdbe9 81
Sergunb 0:8918a71cdbe9 82 /**
Sergunb 0:8918a71cdbe9 83 * @brief Hole descriptor
Sergunb 0:8918a71cdbe9 84 **/
Sergunb 0:8918a71cdbe9 85
Sergunb 0:8918a71cdbe9 86 typedef __start_packed struct
Sergunb 0:8918a71cdbe9 87 {
Sergunb 0:8918a71cdbe9 88 uint16_t first;
Sergunb 0:8918a71cdbe9 89 uint16_t last;
Sergunb 0:8918a71cdbe9 90 uint16_t next;
Sergunb 0:8918a71cdbe9 91 } __end_packed Ipv6HoleDesc;
Sergunb 0:8918a71cdbe9 92
Sergunb 0:8918a71cdbe9 93
Sergunb 0:8918a71cdbe9 94 //CodeWarrior or Win32 compiler?
Sergunb 0:8918a71cdbe9 95 #if defined(__CWCC__) || defined(_WIN32)
Sergunb 0:8918a71cdbe9 96 #pragma pack(pop)
Sergunb 0:8918a71cdbe9 97 #endif
Sergunb 0:8918a71cdbe9 98
Sergunb 0:8918a71cdbe9 99
Sergunb 0:8918a71cdbe9 100 /**
Sergunb 0:8918a71cdbe9 101 * @brief Reassembly buffer
Sergunb 0:8918a71cdbe9 102 **/
Sergunb 0:8918a71cdbe9 103
Sergunb 0:8918a71cdbe9 104 typedef struct
Sergunb 0:8918a71cdbe9 105 {
Sergunb 0:8918a71cdbe9 106 uint_t chunkCount;
Sergunb 0:8918a71cdbe9 107 uint_t maxChunkCount;
Sergunb 0:8918a71cdbe9 108 ChunkDesc chunk[N(IPV6_MAX_FRAG_DATAGRAM_SIZE) + 1];
Sergunb 0:8918a71cdbe9 109 } Ipv6ReassemblyBuffer;
Sergunb 0:8918a71cdbe9 110
Sergunb 0:8918a71cdbe9 111
Sergunb 0:8918a71cdbe9 112 /**
Sergunb 0:8918a71cdbe9 113 * @brief Fragmented packet descriptor
Sergunb 0:8918a71cdbe9 114 **/
Sergunb 0:8918a71cdbe9 115
Sergunb 0:8918a71cdbe9 116 typedef struct
Sergunb 0:8918a71cdbe9 117 {
Sergunb 0:8918a71cdbe9 118 systime_t timestamp; ///<Time at which the first fragment was received
Sergunb 0:8918a71cdbe9 119 uint32_t identification; ///<Fragment identification field
Sergunb 0:8918a71cdbe9 120 size_t unfragPartLength; ///<Length of the unfragmentable part
Sergunb 0:8918a71cdbe9 121 size_t fragPartLength; ///<Length of the fragmentable part
Sergunb 0:8918a71cdbe9 122 uint16_t firstHole; ///<Index of the first hole
Sergunb 0:8918a71cdbe9 123 Ipv6ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram
Sergunb 0:8918a71cdbe9 124 } Ipv6FragDesc;
Sergunb 0:8918a71cdbe9 125
Sergunb 0:8918a71cdbe9 126
Sergunb 0:8918a71cdbe9 127 //Tick counter to handle periodic operations
Sergunb 0:8918a71cdbe9 128 extern systime_t ipv6FragTickCounter;
Sergunb 0:8918a71cdbe9 129
Sergunb 0:8918a71cdbe9 130 //IPv6 datagram fragmentation and reassembly
Sergunb 0:8918a71cdbe9 131 error_t ipv6FragmentDatagram(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
Sergunb 0:8918a71cdbe9 132 const NetBuffer *payload, size_t payloadOffset, size_t pathMtu, uint8_t hopLimit);
Sergunb 0:8918a71cdbe9 133
Sergunb 0:8918a71cdbe9 134 void ipv6ParseFragmentHeader(NetInterface *interface, const NetBuffer *ipPacket,
Sergunb 0:8918a71cdbe9 135 size_t ipPacketOffset, size_t fragHeaderOffset, size_t nextHeaderOffset);
Sergunb 0:8918a71cdbe9 136
Sergunb 0:8918a71cdbe9 137 void ipv6FragTick(NetInterface *interface);
Sergunb 0:8918a71cdbe9 138
Sergunb 0:8918a71cdbe9 139 Ipv6FragDesc *ipv6SearchFragQueue(NetInterface *interface,
Sergunb 0:8918a71cdbe9 140 Ipv6Header *packet, Ipv6FragmentHeader *header);
Sergunb 0:8918a71cdbe9 141
Sergunb 0:8918a71cdbe9 142 void ipv6FlushFragQueue(NetInterface *interface);
Sergunb 0:8918a71cdbe9 143
Sergunb 0:8918a71cdbe9 144 Ipv6HoleDesc *ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset);
Sergunb 0:8918a71cdbe9 145 void ipv6DumpHoleList(Ipv6FragDesc *frag);
Sergunb 0:8918a71cdbe9 146
Sergunb 0:8918a71cdbe9 147 #endif
Sergunb 0:8918a71cdbe9 148