Prusa MINI Firmware overview
sntp_opts.h
Go to the documentation of this file.
1 /**
2  * @file
3  * SNTP client options list
4  */
5 
6 /*
7  * Copyright (c) 2007-2009 Frédéric Bernon, Simon Goldschmidt
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Frédéric Bernon, Simon Goldschmidt
35  *
36  */
37 #ifndef LWIP_HDR_APPS_SNTP_OPTS_H
38 #define LWIP_HDR_APPS_SNTP_OPTS_H
39 
40 #include "lwip/opt.h"
41 
42 /**
43  * @defgroup sntp_opts Options
44  * @ingroup sntp
45  * @{
46  */
47 
48 /** SNTP macro to change system time in seconds
49  * Define SNTP_SET_SYSTEM_TIME_US(sec, us) to set the time in microseconds instead of this one
50  * if you need the additional precision.
51  */
52 #if !defined SNTP_SET_SYSTEM_TIME || defined __DOXYGEN__
53 #define SNTP_SET_SYSTEM_TIME(sec) LWIP_UNUSED_ARG(sec)
54 #endif
55 
56 /** The maximum number of SNTP servers that can be set */
57 #if !defined SNTP_MAX_SERVERS || defined __DOXYGEN__
58 #define SNTP_MAX_SERVERS LWIP_DHCP_MAX_NTP_SERVERS
59 #endif
60 
61 /** Set this to 1 to implement the callback function called by dhcp when
62  * NTP servers are received. */
63 #if !defined SNTP_GET_SERVERS_FROM_DHCP || defined __DOXYGEN__
64 #define SNTP_GET_SERVERS_FROM_DHCP LWIP_DHCP_GET_NTP_SRV
65 #endif
66 
67 /** Set this to 1 to support DNS names (or IP address strings) to set sntp servers
68  * One server address/name can be defined as default if SNTP_SERVER_DNS == 1:
69  * \#define SNTP_SERVER_ADDRESS "pool.ntp.org"
70  */
71 #if !defined SNTP_SERVER_DNS || defined __DOXYGEN__
72 #define SNTP_SERVER_DNS 0
73 #endif
74 
75 /**
76  * SNTP_DEBUG: Enable debugging for SNTP.
77  */
78 #if !defined SNTP_DEBUG || defined __DOXYGEN__
79 #define SNTP_DEBUG LWIP_DBG_OFF
80 #endif
81 
82 /** SNTP server port */
83 #if !defined SNTP_PORT || defined __DOXYGEN__
84 #define SNTP_PORT 123
85 #endif
86 
87 /** Set this to 1 to allow config of SNTP server(s) by DNS name */
88 #if !defined SNTP_SERVER_DNS || defined __DOXYGEN__
89 #define SNTP_SERVER_DNS 0
90 #endif
91 
92 /** Sanity check:
93  * Define this to
94  * - 0 to turn off sanity checks (default; smaller code)
95  * - >= 1 to check address and port of the response packet to ensure the
96  * response comes from the server we sent the request to.
97  * - >= 2 to check returned Originate Timestamp against Transmit Timestamp
98  * sent to the server (to ensure response to older request).
99  * - >= 3 @todo: discard reply if any of the LI, Stratum, or Transmit Timestamp
100  * fields is 0 or the Mode field is not 4 (unicast) or 5 (broadcast).
101  * - >= 4 @todo: to check that the Root Delay and Root Dispersion fields are each
102  * greater than or equal to 0 and less than infinity, where infinity is
103  * currently a cozy number like one second. This check avoids using a
104  * server whose synchronization source has expired for a very long time.
105  */
106 #if !defined SNTP_CHECK_RESPONSE || defined __DOXYGEN__
107 #define SNTP_CHECK_RESPONSE 0
108 #endif
109 
110 /** According to the RFC, this shall be a random delay
111  * between 1 and 5 minutes (in milliseconds) to prevent load peaks.
112  * This can be defined to a random generation function,
113  * which must return the delay in milliseconds as u32_t.
114  * Turned off by default.
115  */
116 #if !defined SNTP_STARTUP_DELAY || defined __DOXYGEN__
117 #define SNTP_STARTUP_DELAY 0
118 #endif
119 
120 /** If you want the startup delay to be a function, define this
121  * to a function (including the brackets) and define SNTP_STARTUP_DELAY to 1.
122  */
123 #if !defined SNTP_STARTUP_DELAY_FUNC || defined __DOXYGEN__
124 #define SNTP_STARTUP_DELAY_FUNC SNTP_STARTUP_DELAY
125 #endif
126 
127 /** SNTP receive timeout - in milliseconds
128  * Also used as retry timeout - this shouldn't be too low.
129  * Default is 3 seconds.
130  */
131 #if !defined SNTP_RECV_TIMEOUT || defined __DOXYGEN__
132 #define SNTP_RECV_TIMEOUT 3000
133 #endif
134 
135 /** SNTP update delay - in milliseconds
136  * Default is 1 hour. Must not be beolw 15 seconds by specification (i.e. 15000)
137  */
138 #if !defined SNTP_UPDATE_DELAY || defined __DOXYGEN__
139 #define SNTP_UPDATE_DELAY 3600000
140 #endif
141 
142 /** SNTP macro to get system time, used with SNTP_CHECK_RESPONSE >= 2
143  * to send in request and compare in response.
144  */
145 #if !defined SNTP_GET_SYSTEM_TIME || defined __DOXYGEN__
146 #define SNTP_GET_SYSTEM_TIME(sec, us) do { (sec) = 0; (us) = 0; } while(0)
147 #endif
148 
149 /** Default retry timeout (in milliseconds) if the response
150  * received is invalid.
151  * This is doubled with each retry until SNTP_RETRY_TIMEOUT_MAX is reached.
152  */
153 #if !defined SNTP_RETRY_TIMEOUT || defined __DOXYGEN__
154 #define SNTP_RETRY_TIMEOUT SNTP_RECV_TIMEOUT
155 #endif
156 
157 /** Maximum retry timeout (in milliseconds). */
158 #if !defined SNTP_RETRY_TIMEOUT_MAX || defined __DOXYGEN__
159 #define SNTP_RETRY_TIMEOUT_MAX (SNTP_RETRY_TIMEOUT * 10)
160 #endif
161 
162 /** Increase retry timeout with every retry sent
163  * Default is on to conform to RFC.
164  */
165 #if !defined SNTP_RETRY_TIMEOUT_EXP || defined __DOXYGEN__
166 #define SNTP_RETRY_TIMEOUT_EXP 1
167 #endif
168 
169 /**
170  * @}
171  */
172 
173 #endif /* LWIP_HDR_APPS_SNTP_OPTS_H */
opt.h