mikroSDK Reference Manual
ntp_common.h
Go to the documentation of this file.
1
31#ifndef _NTP_COMMON_H
32#define _NTP_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36
37//NTP port number
38#define NTP_PORT 123
39//Maximum size of NTP messages
40#define NTP_MAX_MSG_SIZE 68
41//Difference between NTP and Unix time scales
42#define NTP_UNIX_EPOCH 2208988800U
43
44//Kiss code definition
45#define NTP_KISS_CODE(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
46
47//C++ guard
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52
57typedef enum
58{
59 NTP_LI_NO_WARNING = 0,
60 NTP_LI_LAST_MIN_HAS_61_SECS = 1,
61 NTP_LI_LAST_MIN_HAS_59_SECS = 2,
62 NTP_LI_ALARM_CONDITION = 3
64
65
70typedef enum
71{
72 NTP_VERSION_1 = 1,
73 NTP_VERSION_2 = 2,
74 NTP_VERSION_3 = 3,
75 NTP_VERSION_4 = 4
77
78
83typedef enum
84{
85 NTP_MODE_SYMMETRIC_ACTIVE = 1,
86 NTP_MODE_SYMMETRIC_PASSIVE = 2,
87 NTP_MODE_CLIENT = 3,
88 NTP_MODE_SERVER = 4,
89 NTP_MODE_BROADCAST = 5
90} NtpMode;
91
92
102typedef enum
103{
104 NTP_KISS_CODE_ACST = NTP_KISS_CODE('A', 'C', 'S', 'T'),
105 NTP_KISS_CODE_AUTH = NTP_KISS_CODE('A', 'U', 'T', 'H'),
106 NTP_KISS_CODE_AUTO = NTP_KISS_CODE('A', 'U', 'T', 'O'),
107 NTP_KISS_CODE_BCST = NTP_KISS_CODE('B', 'C', 'S', 'T'),
108 NTP_KISS_CODE_CRYP = NTP_KISS_CODE('C', 'R', 'Y', 'P'),
109 NTP_KISS_CODE_DENY = NTP_KISS_CODE('D', 'E', 'N', 'Y'),
110 NTP_KISS_CODE_DROP = NTP_KISS_CODE('D', 'R', 'O', 'P'),
111 NTP_KISS_CODE_RSTR = NTP_KISS_CODE('R', 'S', 'T', 'R'),
112 NTP_KISS_CODE_INIT = NTP_KISS_CODE('I', 'N', 'I', 'T'),
113 NTP_KISS_CODE_MCST = NTP_KISS_CODE('M', 'C', 'S', 'T'),
114 NTP_KISS_CODE_NKEY = NTP_KISS_CODE('N', 'K', 'E', 'Y'),
115 NTP_KISS_CODE_RATE = NTP_KISS_CODE('R', 'A', 'T', 'E'),
116 NTP_KISS_CODE_RMOT = NTP_KISS_CODE('R', 'M', 'O', 'T'),
117 NTP_KISS_CODE_STEP = NTP_KISS_CODE('S', 'T', 'E', 'P')
119
120
121//CodeWarrior or Win32 compiler?
122#if defined(__CWCC__) || defined(_WIN32)
123 #pragma pack(push, 1)
124#endif
125
126
132{
133 uint32_t seconds;
134 uint32_t fraction;
135} NtpTimestamp;
136
137
142typedef __packed_struct
143{
144#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
145 uint8_t li : 2; //0
146 uint8_t vn : 3;
147 uint8_t mode : 3;
148#else
149 uint8_t mode : 3; //0
150 uint8_t vn : 3;
151 uint8_t li : 2;
152#endif
153 uint8_t stratum; //1
154 uint8_t poll; //2
155 int8_t precision; //3
156 uint32_t rootDelay; //4-7
157 uint32_t rootDispersion; //8-11
158 uint32_t referenceId; //12-15
159 NtpTimestamp referenceTimestamp; //16-23
160 NtpTimestamp originateTimestamp; //24-31
161 NtpTimestamp receiveTimestamp; //32-39
162 NtpTimestamp transmitTimestamp; //40-47
163} NtpHeader;
164
165
170typedef __packed_struct
171{
172 uint32_t keyId; //0-3
173 uint8_t messageDigest[16]; //4-19
174} NtpAuthenticator;
175
176
177//CodeWarrior or Win32 compiler?
178#if defined(__CWCC__) || defined(_WIN32)
179 #pragma pack(pop)
180#endif
181
182//C++ guard
183#ifdef __cplusplus
184}
185#endif
186
187#endif
TCP/IP stack core.
NtpLeapIndicator
Leap indicator.
Definition ntp_common.h:58
NtpKissCode
Kiss codes.
Definition ntp_common.h:103
@ NTP_KISS_CODE_RMOT
Somebody is tinkering with the association from a remote host running ntpdc.
Definition ntp_common.h:116
@ NTP_KISS_CODE_INIT
The association has not yet synchronized for the first time.
Definition ntp_common.h:112
@ NTP_KISS_CODE_MCST
The association belongs to a manycast server.
Definition ntp_common.h:113
@ NTP_KISS_CODE_CRYP
Cryptographic authentication or identification failed.
Definition ntp_common.h:108
@ NTP_KISS_CODE_RATE
Rate exceeded.
Definition ntp_common.h:115
@ NTP_KISS_CODE_NKEY
No key found.
Definition ntp_common.h:114
@ NTP_KISS_CODE_DROP
Lost peer in symmetric mode.
Definition ntp_common.h:110
@ NTP_KISS_CODE_ACST
The association belongs to a anycast server.
Definition ntp_common.h:104
@ NTP_KISS_CODE_BCST
The association belongs to a broadcast server.
Definition ntp_common.h:107
@ NTP_KISS_CODE_DENY
Access denied by remote server.
Definition ntp_common.h:109
@ NTP_KISS_CODE_RSTR
Access denied due to local policy.
Definition ntp_common.h:111
@ NTP_KISS_CODE_AUTH
Server authentication failed.
Definition ntp_common.h:105
@ NTP_KISS_CODE_STEP
A step change in system time has occurred.
Definition ntp_common.h:117
@ NTP_KISS_CODE_AUTO
Autokey sequence failed.
Definition ntp_common.h:106
NtpVersion
NTP version numbers.
Definition ntp_common.h:71
NtpMode
Protocol modes.
Definition ntp_common.h:84
typedef __packed_struct
NTP timestamp representation.
Definition ntp_common.h:132