[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 option.
|
---|
[89e57cee] | 62 | * @see tcp_option
|
---|
[21580dd] | 63 | */
|
---|
[89e57cee] | 64 | typedef struct tcp_option tcp_option_t;
|
---|
[21580dd] | 65 |
|
---|
[89e57cee] | 66 | /** Type definition of the Maximum segment size TCP option. */
|
---|
| 67 | typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
|
---|
[21580dd] | 68 |
|
---|
[89e57cee] | 69 | /** Transmission datagram header. */
|
---|
| 70 | struct tcp_header {
|
---|
[aadf01e] | 71 | uint16_t source_port;
|
---|
| 72 | uint16_t destination_port;
|
---|
| 73 | uint32_t sequence_number;
|
---|
| 74 | uint32_t acknowledgement_number;
|
---|
[89e57cee] | 75 |
|
---|
[21580dd] | 76 | #ifdef ARCH_IS_BIG_ENDIAN
|
---|
[aadf01e] | 77 | uint8_t header_length:4;
|
---|
| 78 | uint8_t reserved1:4;
|
---|
[21580dd] | 79 | #else
|
---|
[aadf01e] | 80 | uint8_t reserved1:4;
|
---|
| 81 | uint8_t header_length:4;
|
---|
[21580dd] | 82 | #endif
|
---|
[89e57cee] | 83 |
|
---|
[21580dd] | 84 | #ifdef ARCH_IS_BIG_ENDIAN
|
---|
[aadf01e] | 85 | uint8_t reserved2:2;
|
---|
| 86 | uint8_t urgent:1;
|
---|
| 87 | uint8_t acknowledge:1;
|
---|
| 88 | uint8_t push:1;
|
---|
| 89 | uint8_t reset:1;
|
---|
| 90 | uint8_t synchronize:1;
|
---|
| 91 | uint8_t finalize:1;
|
---|
[21580dd] | 92 | #else
|
---|
[aadf01e] | 93 | uint8_t finalize:1;
|
---|
| 94 | uint8_t synchronize:1;
|
---|
| 95 | uint8_t reset:1;
|
---|
| 96 | uint8_t push:1;
|
---|
| 97 | uint8_t acknowledge:1;
|
---|
| 98 | uint8_t urgent:1;
|
---|
| 99 | uint8_t reserved2:2;
|
---|
[21580dd] | 100 | #endif
|
---|
[89e57cee] | 101 |
|
---|
[aadf01e] | 102 | uint16_t window;
|
---|
| 103 | uint16_t checksum;
|
---|
| 104 | uint16_t urgent_pointer;
|
---|
[21580dd] | 105 | } __attribute__ ((packed));
|
---|
| 106 |
|
---|
[89e57cee] | 107 | /** Transmission datagram header option. */
|
---|
| 108 | struct tcp_option {
|
---|
| 109 | /** Option type. */
|
---|
[aadf01e] | 110 | uint8_t type;
|
---|
[89e57cee] | 111 | /** Option length. */
|
---|
[aadf01e] | 112 | uint8_t length;
|
---|
[21580dd] | 113 | };
|
---|
| 114 |
|
---|
[89e57cee] | 115 | /** Maximum segment size TCP option. */
|
---|
| 116 | struct tcp_max_segment_size_option {
|
---|
[21580dd] | 117 | /** TCP option.
|
---|
[89e57cee] | 118 | * @see TCPOPT_MAX_SEGMENT_SIZE
|
---|
| 119 | * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
|
---|
[21580dd] | 120 | */
|
---|
[aadf01e] | 121 | tcp_option_t option;
|
---|
[89e57cee] | 122 |
|
---|
| 123 | /** Maximum segment size in bytes. */
|
---|
[aadf01e] | 124 | uint16_t max_segment_size;
|
---|
[21580dd] | 125 | } __attribute__ ((packed));
|
---|
| 126 |
|
---|
| 127 | #endif
|
---|
| 128 |
|
---|
| 129 | /** @}
|
---|
| 130 | */
|
---|