1 /*
2  *  Copyright (c) 2016-2022, The OpenThread Authors.
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 are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  *   This file includes types and constants for IPv6 processing.
32  */
33 
34 #ifndef IP6_TYPES_HPP_
35 #define IP6_TYPES_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <stddef.h>
40 #include <stdint.h>
41 
42 namespace ot {
43 namespace Ip6 {
44 
45 /**
46  * @addtogroup core-ip6-ip6
47  *
48  * @brief
49  *   This module includes definitions for core IPv6 networking.
50  *
51  * @{
52  *
53  */
54 
55 // Internet Protocol Numbers
56 static constexpr uint8_t kProtoHopOpts  = OT_IP6_PROTO_HOP_OPTS; ///< IPv6 Hop-by-Hop Option
57 static constexpr uint8_t kProtoTcp      = OT_IP6_PROTO_TCP;      ///< Transmission Control Protocol
58 static constexpr uint8_t kProtoUdp      = OT_IP6_PROTO_UDP;      ///< User Datagram
59 static constexpr uint8_t kProtoIp6      = OT_IP6_PROTO_IP6;      ///< IPv6 encapsulation
60 static constexpr uint8_t kProtoRouting  = OT_IP6_PROTO_ROUTING;  ///< Routing Header for IPv6
61 static constexpr uint8_t kProtoFragment = OT_IP6_PROTO_FRAGMENT; ///< Fragment Header for IPv6
62 static constexpr uint8_t kProtoIcmp6    = OT_IP6_PROTO_ICMP6;    ///< ICMP for IPv6
63 static constexpr uint8_t kProtoNone     = OT_IP6_PROTO_NONE;     ///< No Next Header for IPv6
64 static constexpr uint8_t kProtoDstOpts  = OT_IP6_PROTO_DST_OPTS; ///< Destination Options for IPv6
65 
66 /**
67  * The max datagram length (in bytes) of an IPv6 message.
68  *
69  */
70 static constexpr uint16_t kMaxDatagramLength = OPENTHREAD_CONFIG_IP6_MAX_DATAGRAM_LENGTH;
71 
72 /**
73  * The max datagram length (in bytes) of an unfragmented IPv6 message.
74  *
75  */
76 static constexpr uint16_t kMaxAssembledDatagramLength = OPENTHREAD_CONFIG_IP6_MAX_ASSEMBLED_DATAGRAM;
77 
78 /**
79  * 6-bit Differentiated Services Code Point (DSCP) values.
80  *
81  */
82 enum IpDscpCs : uint8_t
83 {
84     kDscpCs0    = 0,    ///< Class selector codepoint 0
85     kDscpCs1    = 8,    ///< Class selector codepoint 8
86     kDscpCs2    = 16,   ///< Class selector codepoint 16
87     kDscpCs3    = 24,   ///< Class selector codepoint 24
88     kDscpCs4    = 32,   ///< Class selector codepoint 32
89     kDscpCs5    = 40,   ///< Class selector codepoint 40
90     kDscpCs6    = 48,   ///< Class selector codepoint 48
91     kDscpCs7    = 56,   ///< Class selector codepoint 56
92     kDscpCsMask = 0x38, ///< Class selector mask (0b111000)
93 
94     // DSCP values to use within Thread mesh (from local codepoint space 0bxxxx11 [RFC 2474 - section 6]).
95 
96     kDscpTmfNetPriority    = 0x07, ///< TMF network priority (0b000111).
97     kDscpTmfNormalPriority = 0x0f, ///< TMF normal priority  (0b001111).
98     kDscpTmfLowPriority    = 0x17, ///< TMF low priority     (0b010111).
99 };
100 
101 /**
102  * Represents the 2-bit Explicit Congestion Notification (ECN) values.
103  *
104  */
105 enum Ecn : uint8_t
106 {
107     kEcnNotCapable = OT_ECN_NOT_CAPABLE, ///< Non ECN-Capable Transport (ECT).
108     kEcnCapable0   = OT_ECN_CAPABLE_0,   ///< ECN Capable Transport, ECT(0).
109     kEcnCapable1   = OT_ECN_CAPABLE_1,   ///< ECN Capable Transport, ECT(1).
110     kEcnMarked     = OT_ECN_MARKED,      ///< Congestion encountered.
111 };
112 
113 /**
114  * @}
115  *
116  */
117 
118 } // namespace Ip6
119 } // namespace ot
120 
121 #endif // IP6_TYPES_HPP_
122