nts_common.h
Go to the documentation of this file.
1 /**
2  * @file nts_common.h
3  * @brief Definitions common to NTS client and server
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _NTS_COMMON_H
32 #define _NTS_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //NTS port number
38 #define NTS_PORT 4460
39 
40 //Critical flag
41 #define NTS_KE_CRITICAL 0x8000
42 //Record type mask
43 #define NTS_KE_RECORD_TYPE_MASK 0x7FFF
44 
45 //C++ guard
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 /**
52  * @brief NTS-KE record types
53  **/
54 
55 typedef enum
56 {
57  NTS_KE_RECORD_TYPE_END_OF_MESSAGE = 0, ///<End of Message
58  NTS_KE_RECORD_TYPE_NTS_NEXT_PROTO_NEGO = 1, ///<NTS Next Protocol Negotiation
59  NTS_KE_RECORD_TYPE_ERROR = 2, ///<Error
60  NTS_KE_RECORD_TYPE_WARNING = 3, ///<Warning
61  NTS_KE_RECORD_TYPE_AEAD_ALGO_NEGO = 4, ///<AEAD Algorithm Negotiation
62  NTS_KE_RECORD_TYPE_NEW_COOKIE_FOR_NTPV4 = 5, ///<New Cookie for NTPv4
63  NTS_KE_RECORD_TYPE_NTPV4_SERVER_NEGO = 6, ///<NTPv4 Server Negotiation
64  NTS_KE_RECORD_TYPE_NTPV4_PORT_NEGO = 7 ///<NTPv4 Port Negotiation
66 
67 
68 /**
69  * @brief Protocol IDs
70  **/
71 
72 typedef enum
73 {
74  NTS_PROTOCOL_ID_NTPV4 = 0 ///<Network Time Protocol version 4 (NTPv4)
76 
77 
78 /**
79  * @brief Error codes
80  **/
81 
82 typedef enum
83 {
84  NTS_ERROR_CODE_UNRECOGNIZED_CRITICAL_RECORD = 0, ///<Unrecognized Critical Record
85  NTS_ERROR_CODE_BAD_REQUEST = 1, ///<Bad Request
86  NTS_ERROR_CODE_INTERNAL_SERVER_ERROR = 2 ///<Internal Server Error
88 
89 
90 //CC-RX, CodeWarrior or Win32 compiler?
91 #if defined(__CCRX__)
92  #pragma pack
93 #elif defined(__CWCC__) || defined(_WIN32)
94  #pragma pack(push, 1)
95 #endif
96 
97 
98 /**
99  * @brief NTS-KE record
100  **/
101 
103 {
104  uint16_t type; //0-1
105  uint16_t bodyLength; //2-3
106  uint8_t body[]; //4
108 
109 
110 //CC-RX, CodeWarrior or Win32 compiler?
111 #if defined(__CCRX__)
112  #pragma unpack
113 #elif defined(__CWCC__) || defined(_WIN32)
114  #pragma pack(pop)
115 #endif
116 
117 //C++ guard
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif
typedef __packed_struct
NTS-KE record.
Definition: nts_common.h:103
uint8_t type
Definition: coap_common.h:176
@ NTS_KE_RECORD_TYPE_NTPV4_SERVER_NEGO
NTPv4 Server Negotiation.
Definition: nts_common.h:63
@ NTS_KE_RECORD_TYPE_END_OF_MESSAGE
End of Message.
Definition: nts_common.h:57
@ NTS_ERROR_CODE_INTERNAL_SERVER_ERROR
Internal Server Error.
Definition: nts_common.h:86
@ NTS_KE_RECORD_TYPE_NTS_NEXT_PROTO_NEGO
NTS Next Protocol Negotiation.
Definition: nts_common.h:58
@ NTS_ERROR_CODE_UNRECOGNIZED_CRITICAL_RECORD
Unrecognized Critical Record.
Definition: nts_common.h:84
NtsErrorCode
Error codes.
Definition: nts_common.h:83
@ NTS_KE_RECORD_TYPE_NEW_COOKIE_FOR_NTPV4
New Cookie for NTPv4.
Definition: nts_common.h:62
@ NTS_KE_RECORD_TYPE_AEAD_ALGO_NEGO
AEAD Algorithm Negotiation.
Definition: nts_common.h:61
uint16_t bodyLength
Definition: nts_common.h:105
NtsKeRecordType
NTS-KE record types.
Definition: nts_common.h:56
@ NTS_PROTOCOL_ID_NTPV4
Network Time Protocol version 4 (NTPv4)
Definition: nts_common.h:74
@ NTS_KE_RECORD_TYPE_ERROR
Error.
Definition: nts_common.h:59
NtsKeRecord
Definition: nts_common.h:107
@ NTS_ERROR_CODE_BAD_REQUEST
Bad Request.
Definition: nts_common.h:85
NtsProtocolId
Protocol IDs.
Definition: nts_common.h:73
@ NTS_KE_RECORD_TYPE_WARNING
Warning.
Definition: nts_common.h:60
TCP/IP stack core.
uint8_t body[]
Definition: nts_common.h:106
@ NTS_KE_RECORD_TYPE_NTPV4_PORT_NEGO
NTPv4 Port Negotiation.
Definition: nts_common.h:64