| [21580dd] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup tcp
|
|---|
| [89e57cee] | 30 | * @{
|
|---|
| [21580dd] | 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /** @file
|
|---|
| [89e57cee] | 34 | * TCP header definition.
|
|---|
| 35 | * Based on the RFC 793.
|
|---|
| [21580dd] | 36 | */
|
|---|
| 37 |
|
|---|
| [89e57cee] | 38 | #ifndef NET_TCP_HEADER_H_
|
|---|
| 39 | #define NET_TCP_HEADER_H_
|
|---|
| [21580dd] | 40 |
|
|---|
| 41 | #include <sys/types.h>
|
|---|
| 42 |
|
|---|
| [89e57cee] | 43 | /** TCP header size in bytes. */
|
|---|
| 44 | #define TCP_HEADER_SIZE sizeof(tcp_header_t)
|
|---|
| [ede63e4] | 45 |
|
|---|
| [21580dd] | 46 | /** Returns the actual TCP header length in bytes.
|
|---|
| [89e57cee] | 47 | * @param[in] header The TCP packet header.
|
|---|
| [21580dd] | 48 | */
|
|---|
| [89e57cee] | 49 | #define TCP_HEADER_LENGTH(header) ((header)->header_length * 4U)
|
|---|
| [21580dd] | 50 |
|
|---|
| 51 | /** Returns the TCP header length.
|
|---|
| [89e57cee] | 52 | * @param[in] length The TCP header length in bytes.
|
|---|
| [21580dd] | 53 | */
|
|---|
| [89e57cee] | 54 | #define TCP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4U))
|
|---|
| [21580dd] | 55 |
|
|---|
| 56 | /** Type definition of the transmission datagram header.
|
|---|
| [89e57cee] | 57 | * @see tcp_header
|
|---|
| [21580dd] | 58 | */
|
|---|
| [89e57cee] | 59 | typedef struct tcp_header tcp_header_t;
|
|---|
| [21580dd] | 60 |
|
|---|
| 61 | /** Type definition of the transmission datagram header pointer.
|
|---|
| [89e57cee] | 62 | * @see tcp_header
|
|---|
| [21580dd] | 63 | */
|
|---|
| [89e57cee] | 64 | typedef tcp_header_t *tcp_header_ref;
|
|---|
| [21580dd] | 65 |
|
|---|
| 66 | /** Type definition of the transmission datagram header option.
|
|---|
| [89e57cee] | 67 | * @see tcp_option
|
|---|
| [21580dd] | 68 | */
|
|---|
| [89e57cee] | 69 | typedef struct tcp_option tcp_option_t;
|
|---|
| [21580dd] | 70 |
|
|---|
| 71 | /** Type definition of the transmission datagram header option pointer.
|
|---|
| [89e57cee] | 72 | * @see tcp_option
|
|---|
| [21580dd] | 73 | */
|
|---|
| [89e57cee] | 74 | typedef tcp_option_t *tcp_option_ref;
|
|---|
| [21580dd] | 75 |
|
|---|
| [89e57cee] | 76 | /** Type definition of the Maximum segment size TCP option. */
|
|---|
| 77 | typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
|
|---|
| [21580dd] | 78 |
|
|---|
| 79 | /** Type definition of the Maximum segment size TCP option pointer.
|
|---|
| [89e57cee] | 80 | * @see tcp_max_segment_size_option
|
|---|
| [21580dd] | 81 | */
|
|---|
| [89e57cee] | 82 | typedef tcp_max_segment_size_option_t *tcp_max_segment_size_option_ref;
|
|---|
| [21580dd] | 83 |
|
|---|
| [89e57cee] | 84 | /** Transmission datagram header. */
|
|---|
| 85 | struct tcp_header {
|
|---|
| [aadf01e] | 86 | uint16_t source_port;
|
|---|
| 87 | uint16_t destination_port;
|
|---|
| 88 | uint32_t sequence_number;
|
|---|
| 89 | uint32_t acknowledgement_number;
|
|---|
| [89e57cee] | 90 |
|
|---|
| [21580dd] | 91 | #ifdef ARCH_IS_BIG_ENDIAN
|
|---|
| [aadf01e] | 92 | uint8_t header_length:4;
|
|---|
| 93 | uint8_t reserved1:4;
|
|---|
| [21580dd] | 94 | #else
|
|---|
| [aadf01e] | 95 | uint8_t reserved1:4;
|
|---|
| 96 | uint8_t header_length:4;
|
|---|
| [21580dd] | 97 | #endif
|
|---|
| [89e57cee] | 98 |
|
|---|
| [21580dd] | 99 | #ifdef ARCH_IS_BIG_ENDIAN
|
|---|
| [aadf01e] | 100 | uint8_t reserved2:2;
|
|---|
| 101 | uint8_t urgent:1;
|
|---|
| 102 | uint8_t acknowledge:1;
|
|---|
| 103 | uint8_t push:1;
|
|---|
| 104 | uint8_t reset:1;
|
|---|
| 105 | uint8_t synchronize:1;
|
|---|
| 106 | uint8_t finalize:1;
|
|---|
| [21580dd] | 107 | #else
|
|---|
| [aadf01e] | 108 | uint8_t finalize:1;
|
|---|
| 109 | uint8_t synchronize:1;
|
|---|
| 110 | uint8_t reset:1;
|
|---|
| 111 | uint8_t push:1;
|
|---|
| 112 | uint8_t acknowledge:1;
|
|---|
| 113 | uint8_t urgent:1;
|
|---|
| 114 | uint8_t reserved2:2;
|
|---|
| [21580dd] | 115 | #endif
|
|---|
| [89e57cee] | 116 |
|
|---|
| [aadf01e] | 117 | uint16_t window;
|
|---|
| 118 | uint16_t checksum;
|
|---|
| 119 | uint16_t urgent_pointer;
|
|---|
| [21580dd] | 120 | } __attribute__ ((packed));
|
|---|
| 121 |
|
|---|
| [89e57cee] | 122 | /** Transmission datagram header option. */
|
|---|
| 123 | struct tcp_option {
|
|---|
| 124 | /** Option type. */
|
|---|
| [aadf01e] | 125 | uint8_t type;
|
|---|
| [89e57cee] | 126 | /** Option length. */
|
|---|
| [aadf01e] | 127 | uint8_t length;
|
|---|
| [21580dd] | 128 | };
|
|---|
| 129 |
|
|---|
| [89e57cee] | 130 | /** Maximum segment size TCP option. */
|
|---|
| 131 | struct tcp_max_segment_size_option {
|
|---|
| [21580dd] | 132 | /** TCP option.
|
|---|
| [89e57cee] | 133 | * @see TCPOPT_MAX_SEGMENT_SIZE
|
|---|
| 134 | * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
|
|---|
| [21580dd] | 135 | */
|
|---|
| [aadf01e] | 136 | tcp_option_t option;
|
|---|
| [89e57cee] | 137 |
|
|---|
| 138 | /** Maximum segment size in bytes. */
|
|---|
| [aadf01e] | 139 | uint16_t max_segment_size;
|
|---|
| [21580dd] | 140 | } __attribute__ ((packed));
|
|---|
| 141 |
|
|---|
| 142 | #endif
|
|---|
| 143 |
|
|---|
| 144 | /** @}
|
|---|
| 145 | */
|
|---|