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 #include "lwip/prot/iana.h" 42 43 /** 44 * @defgroup sntp_opts Options 45 * @ingroup sntp 46 * @{ 47 */ 48 49 /** SNTP macro to change system time in seconds 50 * Define SNTP_SET_SYSTEM_TIME_US(sec, us) to set the time in microseconds 51 * instead of this one if you need the additional precision. Alternatively, 52 * define SNTP_SET_SYSTEM_TIME_NTP(sec, frac) in order to work with native 53 * NTP timestamps instead. 54 */ 55 #if !defined SNTP_SET_SYSTEM_TIME || defined __DOXYGEN__ 56 #define SNTP_SET_SYSTEM_TIME(sec) LWIP_UNUSED_ARG(sec) 57 #endif 58 59 /** The maximum number of SNTP servers that can be set */ 60 #if !defined SNTP_MAX_SERVERS || defined __DOXYGEN__ 61 #define SNTP_MAX_SERVERS LWIP_DHCP_MAX_NTP_SERVERS 62 #endif 63 64 /** Set this to 1 to implement the callback function called by dhcp when 65 * NTP servers are received. */ 66 #if !defined SNTP_GET_SERVERS_FROM_DHCP || defined __DOXYGEN__ 67 #define SNTP_GET_SERVERS_FROM_DHCP LWIP_DHCP_GET_NTP_SRV 68 #endif 69 70 /** Set this to 1 to support DNS names (or IP address strings) to set sntp servers 71 * One server address/name can be defined as default if SNTP_SERVER_DNS == 1: 72 * \#define SNTP_SERVER_ADDRESS "pool.ntp.org" 73 */ 74 #if !defined SNTP_SERVER_DNS || defined __DOXYGEN__ 75 #define SNTP_SERVER_DNS 0 76 #endif 77 78 /** 79 * SNTP_DEBUG: Enable debugging for SNTP. 80 */ 81 #if !defined SNTP_DEBUG || defined __DOXYGEN__ 82 #define SNTP_DEBUG LWIP_DBG_OFF 83 #endif 84 85 /** SNTP server port */ 86 #if !defined SNTP_PORT || defined __DOXYGEN__ 87 #define SNTP_PORT LWIP_IANA_PORT_SNTP 88 #endif 89 90 /** Sanity check: 91 * Define this to 92 * - 0 to turn off sanity checks (default; smaller code) 93 * - >= 1 to check address and port of the response packet to ensure the 94 * response comes from the server we sent the request to. 95 * - >= 2 to check returned Originate Timestamp against Transmit Timestamp 96 * sent to the server (to ensure response to older request). 97 * - >= 3 @todo: discard reply if any of the VN, Stratum, or Transmit Timestamp 98 * fields is 0 or the Mode field is not 4 (unicast) or 5 (broadcast). 99 * - >= 4 @todo: to check that the Root Delay and Root Dispersion fields are each 100 * greater than or equal to 0 and less than infinity, where infinity is 101 * currently a cozy number like one second. This check avoids using a 102 * server whose synchronization source has expired for a very long time. 103 */ 104 #if !defined SNTP_CHECK_RESPONSE || defined __DOXYGEN__ 105 #define SNTP_CHECK_RESPONSE 0 106 #endif 107 108 /** Enable round-trip delay compensation. 109 * Compensate for the round-trip delay by calculating the clock offset from 110 * the originate, receive, transmit and destination timestamps, as per RFC. 111 * 112 * The calculation requires compiler support for 64-bit integers. Also, either 113 * SNTP_SET_SYSTEM_TIME_US or SNTP_SET_SYSTEM_TIME_NTP has to be implemented 114 * for setting the system clock with sub-second precision. Likewise, either 115 * SNTP_GET_SYSTEM_TIME or SNTP_GET_SYSTEM_TIME_NTP needs to be implemented 116 * with sub-second precision. 117 * 118 * Although not strictly required, it makes sense to combine this option with 119 * SNTP_CHECK_RESPONSE >= 2 for sanity-checking of the received timestamps. 120 * Also, in order for the round-trip calculation to work, the difference 121 * between the local clock and the NTP server clock must not be larger than 122 * about 34 years. If that limit is exceeded, the implementation will fall back 123 * to setting the clock without compensation. In order to ensure that the local 124 * clock is always within the permitted range for compensation, even at first 125 * try, it may be necessary to store at least the current year in non-volatile 126 * memory. 127 */ 128 #if !defined SNTP_COMP_ROUNDTRIP || defined __DOXYGEN__ 129 #define SNTP_COMP_ROUNDTRIP 0 130 #endif 131 132 /** According to the RFC, this shall be a random delay 133 * between 1 and 5 minutes (in milliseconds) to prevent load peaks. 134 * This can be defined to a random generation function, 135 * which must return the delay in milliseconds as u32_t. 136 * Turned off by default. 137 */ 138 #if !defined SNTP_STARTUP_DELAY || defined __DOXYGEN__ 139 #ifdef LWIP_RAND 140 #define SNTP_STARTUP_DELAY 1 141 #else 142 #define SNTP_STARTUP_DELAY 0 143 #endif 144 #endif 145 146 /** If you want the startup delay to be a function, define this 147 * to a function (including the brackets) and define SNTP_STARTUP_DELAY to 1. 148 */ 149 #if !defined SNTP_STARTUP_DELAY_FUNC || defined __DOXYGEN__ 150 #define SNTP_STARTUP_DELAY_FUNC (LWIP_RAND() % 5000) 151 #endif 152 153 /** SNTP receive timeout - in milliseconds 154 * Also used as retry timeout - this shouldn't be too low. 155 * Default is 15 seconds. Must not be beolw 15 seconds by specification (i.e. 15000) 156 */ 157 #if !defined SNTP_RECV_TIMEOUT || defined __DOXYGEN__ 158 #define SNTP_RECV_TIMEOUT 15000 159 #endif 160 161 /** SNTP update delay - in milliseconds 162 * Default is 1 hour. Must not be beolw 60 seconds by specification (i.e. 60000) 163 */ 164 #if !defined SNTP_UPDATE_DELAY || defined __DOXYGEN__ 165 #define SNTP_UPDATE_DELAY 3600000 166 #endif 167 168 /** SNTP macro to get system time, used with SNTP_CHECK_RESPONSE >= 2 169 * to send in request and compare in response. Also used for round-trip 170 * delay compensation if SNTP_COMP_ROUNDTRIP != 0. 171 * Alternatively, define SNTP_GET_SYSTEM_TIME_NTP(sec, frac) in order to 172 * work with native NTP timestamps instead. 173 */ 174 #if !defined SNTP_GET_SYSTEM_TIME || defined __DOXYGEN__ 175 #define SNTP_GET_SYSTEM_TIME(sec, us) do { (sec) = 0; (us) = 0; } while(0) 176 #endif 177 178 /** Default retry timeout (in milliseconds) if the response 179 * received is invalid. 180 * This is doubled with each retry until SNTP_RETRY_TIMEOUT_MAX is reached. 181 */ 182 #if !defined SNTP_RETRY_TIMEOUT || defined __DOXYGEN__ 183 #define SNTP_RETRY_TIMEOUT SNTP_RECV_TIMEOUT 184 #endif 185 186 /** Maximum retry timeout (in milliseconds). */ 187 #if !defined SNTP_RETRY_TIMEOUT_MAX || defined __DOXYGEN__ 188 #define SNTP_RETRY_TIMEOUT_MAX (SNTP_RETRY_TIMEOUT * 10) 189 #endif 190 191 /** Increase retry timeout with every retry sent 192 * Default is on to conform to RFC. 193 */ 194 #if !defined SNTP_RETRY_TIMEOUT_EXP || defined __DOXYGEN__ 195 #define SNTP_RETRY_TIMEOUT_EXP 1 196 #endif 197 198 /** Keep a reachability shift register per server 199 * Default is on to conform to RFC. 200 */ 201 #if !defined SNTP_MONITOR_SERVER_REACHABILITY || defined __DOXYGEN__ 202 #define SNTP_MONITOR_SERVER_REACHABILITY 1 203 #endif 204 205 /** 206 * @} 207 */ 208 209 #endif /* LWIP_HDR_APPS_SNTP_OPTS_H */ 210