summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/NTP/include/ntpClient.h
blob: 753743ae6dc94b0aa8300801df487be7e43d298e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * FreeRTOS V202212.00
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * https://www.FreeRTOS.org
 * https://github.com/FreeRTOS
 *
 */

/* */
/*	ntpClient.h */
/* */

#ifndef __NTPCLIENT_H__

#define __NTPCLIENT_H__

#define NTP_PORT    123

typedef uint32_t           quint32;
typedef int32_t            qint32;
typedef uint8_t            quint8;
typedef int8_t             qint8;

typedef union _SNtpFlags   SNtpFlags;

#ifdef _MSC_VER
    #define __attribute__( x )
#endif

/**
 * 64-bit NTP timestamp.
 */
struct __attribute__( ( __packed__ ) ) _SNtpTimestamp
{
    /** Number of seconds passed since Jan 1 1900, in big-endian format. */
    quint32 seconds;

    /** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */
    quint32 fraction;
};

typedef struct _SNtpTimestamp SNtpTimestamp;

/**
 * Mandatory part of an NTP packet
 */
struct SNtpPacket
{
    /** Flags. */
    unsigned char flags; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */

    /** Stratum of the clock. */
    quint8 stratum; /* value 0 : unspecified */

    /** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
    qint8 poll; /* 10 means 1 << 10 = 1024 seconds */

    /** Precision of the clock, in log2 seconds. Note that the value is signed. */
    qint8 precision; /* 0xFA = 250 = 0.015625 seconds */

    /** Round trip time to the primary reference source, in NTP short format. */
    qint32 rootDelay; /* 0x5D2E = 23854 or (23854/65535)= 0.3640 sec */

    /** Nominal error relative to the primary reference source. */
    qint32 rootDispersion; /* 0x0008 CAC8 = 8.7912  seconds */

    /** Reference identifier (either a 4 character string or an IP address). */
    qint8 referenceID[ 4 ]; /* or just 0000 */

    /** The time at which the clock was last set or corrected. */
    SNtpTimestamp referenceTimestamp; /* Current time */

    /** The time at which the request departed the client for the server. */
    SNtpTimestamp originateTimestamp; /* Keep 0 */

    /** The time at which the request arrived at the server. */
    SNtpTimestamp receiveTimestamp; /* Keep 0 */

    /** The time at which the reply departed the server for client. */
    SNtpTimestamp transmitTimestamp;
};

/* Add this number to get secs since 1-1-1900 */
#define TIME1970    2208988800UL

#endif /* __NTPCLIENT_H__ */