1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX SNTP Client Component                                            */
16 /**                                                                       */
17 /**   Simple Network Time Protocol (SNTP)                                 */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /**************************************************************************/
23 /*                                                                        */
24 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
25 /*                                                                        */
26 /*    nxd_sntp_client.h                                   PORTABLE C      */
27 /*                                                           6.1          */
28 /*  AUTHOR                                                                */
29 /*                                                                        */
30 /*    Yuxin Zhou, Microsoft Corporation                                   */
31 /*                                                                        */
32 /*  DESCRIPTION                                                           */
33 /*                                                                        */
34 /*    This file defines the NetX Simple Network Time Protocol (SNTP)      */
35 /*    Client component, including all data types and external references. */
36 /*    It is assumed that tx_api.h, tx_port.h, nx_api.h, and nx_port.h,    */
37 /*    have already been included.                                         */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
44 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
45 /*                                            resulting in version 6.1    */
46 /*                                                                        */
47 /**************************************************************************/
48 
49 #ifndef NXD_SNTP_CLIENT_H
50 #define NXD_SNTP_CLIENT_H
51 
52 #include "nx_ip.h"
53 
54 /* Determine if a C++ compiler is being used.  If so, ensure that standard
55    C is used to process the API information.  */
56 
57 #ifdef   __cplusplus
58 
59 /* Yes, C++ compiler is present.  Use standard C.  */
60 extern   "C" {
61 
62 #endif
63 
64 
65 #define NXD_SNTP_ID                              0x534E5460UL
66 
67 
68 /* Conversion between seconds and timer ticks. This must equal the
69    NetX timer tick to seconds ratio.  */
70 
71 #define NX_SNTP_MILLISECONDS_PER_TICK           (1000 / NX_IP_PERIODIC_RATE)
72 
73 /* Set minimum and maximum Client unicast poll period (in seconds) for requesting
74    time data.  RFC 4330 polling range is from 16 - 131072 seconds.
75    Note that the RFC 4330 strongly recommends polling intervals of at least
76    one minute to unnecessary reduce demand on public time servers.  */
77 
78 #define NX_SNTP_CLIENT_MIN_UNICAST_POLL_INTERVAL    64
79 #define NX_SNTP_CLIENT_MAX_UNICAST_POLL_INTERVAL    131072
80 
81 /* Define Client request types. Note that this does not limit the
82    NetX SNTP Client from using MANYCAST or MULTICAST discovery options.  */
83 
84 #define     BROADCAST_MODE      1
85 #define     UNICAST_MODE        2
86 
87 #define NX_SNTP_CLIENT_RECEIVE_EVENT                ((ULONG) 0x00000001)    /* Event flag to signal a receive packet event                          */
88 
89 /* Define the minimum size of the packet NTP/SNTP time message
90    (e.g. without authentication data).  */
91 
92 #define NX_SNTP_TIME_MESSAGE_MIN_SIZE           48
93 
94 
95 /* Define the maximum size of the packet NTP/SNTP time message (includes 20 bytes for
96    optional authentication data).  */
97 
98 #define NX_SNTP_TIME_MESSAGE_MAX_SIZE           68
99 
100 /* Define the largest IP4 size for ip address e.g. xxx.xxx.xxx.xxx */
101 
102 #define NX_SNTP_CLIENT_MAX_IP_ADDRESS_SIZE      15
103 
104 
105 
106 /* Define fields in the NTP message format.  */
107 
108 #define REFERENCE_TIME      0
109 #define ORIGINATE_TIME      1
110 #define RECEIVE_TIME        2
111 #define TRANSMIT_TIME       3
112 
113 /* Define masks for stratum levels.  */
114 
115 #define STRATUM_KISS_OF_DEATH   0x00
116 #define STRATUM_PRIMARY         0x01
117 #define STRATUM_SECONDARY       0x0E  /* 2 - 15 */
118 #define STRATUM_RESERVED        0xF0  /* 16 - 255*/
119 
120 
121 /* Kiss of death strings (see Codes below). Applicable when stratum = 0
122 
123                             Code    Meaning
124       --------------------------------------------------------------  */
125 
126 
127 #define       ANYCAST       "ACST"    /* The association belongs to an anycast server.  */
128 #define       AUTH_FAIL     "AUTH"    /* Server authentication failed.  */
129 #define       AUTOKEY_FAIL  "AUTO"    /* Autokey sequence failed.  */
130 #define       BROADCAST     "BCST"    /* The association belongs to a broadcast server.  */
131 #define       CRYP_FAIL     "CRYP"    /* Cryptographic authentication or identification failed.  */
132 #define       DENY          "DENY"    /* Access denied by remote server.  */
133 #define       DROP          "DROP"    /* Lost peer in symmetric mode.  */
134 #define       DENY_POLICY   "RSTR"    /* Access denied due to local policy.  */
135 #define       NOT_INIT      "INIT"    /* The association has not yet synchronized for the first time.  */
136 #define       MANYCAST      "MCST"    /* The association belongs to a manycast server.  */
137 #define       NO_KEY        "NKEY"    /* No key found.  Either the key was never installed or is not trusted.  */
138 #define       RATE          "RATE"    /* Rate exceeded.  The server temporarily denied access; client exceeded rate threshold.  */
139 #define       RMOT          "RMOT"    /* Somebody is tinkering with association from remote host running ntpdc.  OK unless they've stolen your keys.  */
140 #define       STEP          "STEP"    /* A step change in system time has occurred, but association has not yet resynchronized.  */
141 
142 /* Define Kiss of Death error codes.  Note: there should be a 1 : 1 correspondence of
143    KOD strings to KOD error codes! */
144 
145 #define       NX_SNTP_KISS_OF_DEATH_PACKET                  0xF00
146 
147 #define       NX_SNTP_KOD_ANYCAST               (NX_SNTP_KISS_OF_DEATH_PACKET | 0x01)
148 #define       NX_SNTP_KOD_AUTH_FAIL             (NX_SNTP_KISS_OF_DEATH_PACKET | 0x02)
149 #define       NX_SNTP_KOD_AUTOKEY_FAIL          (NX_SNTP_KISS_OF_DEATH_PACKET | 0x03)
150 #define       NX_SNTP_KOD_BROADCAST             (NX_SNTP_KISS_OF_DEATH_PACKET | 0x04)
151 #define       NX_SNTP_KOD_CRYP_FAIL             (NX_SNTP_KISS_OF_DEATH_PACKET | 0x05)
152 #define       NX_SNTP_KOD_DENY                  (NX_SNTP_KISS_OF_DEATH_PACKET | 0x06)
153 #define       NX_SNTP_KOD_DROP                  (NX_SNTP_KISS_OF_DEATH_PACKET | 0x07)
154 #define       NX_SNTP_KOD_DENY_POLICY           (NX_SNTP_KISS_OF_DEATH_PACKET | 0x08)
155 #define       NX_SNTP_KOD_NOT_INIT              (NX_SNTP_KISS_OF_DEATH_PACKET | 0x09)
156 #define       NX_SNTP_KOD_MANYCAST              (NX_SNTP_KISS_OF_DEATH_PACKET | 0x0A)
157 #define       NX_SNTP_KOD_NO_KEY                (NX_SNTP_KISS_OF_DEATH_PACKET | 0x0B)
158 #define       NX_SNTP_KOD_RATE                  (NX_SNTP_KISS_OF_DEATH_PACKET | 0x0C)
159 #define       NX_SNTP_KOD_RMOT                  (NX_SNTP_KISS_OF_DEATH_PACKET | 0x0D)
160 #define       NX_SNTP_KOD_STEP                  (NX_SNTP_KISS_OF_DEATH_PACKET | 0x0E)
161 
162 /* Define SNTP protocol modes. SNTP is limited to primarily Client, server and broadcast modes.  */
163 
164 #define     PROTOCOL_MODE_RESERVED          0
165 #define     PROTOCOL_MODE_SYMM_ACTIVE       1
166 #define     PROTOCOL_MODE_SYMM_PASSIVE      2
167 #define     PROTOCOL_MODE_CLIENT            3
168 #define     PROTOCOL_MODE_SERVER_UNICAST    4
169 #define     PROTOCOL_MODE_SERVER_BROADCAST  5
170 #define     PROTOCOL_MODE_NTP_CNTL_MSG      6
171 #define     PROTOCOL_MODE_PRIVATE           7
172 
173 
174 /* NX SNTP Client configurable options.  */
175 
176 
177 
178 /* Set the NetX SNTP client thread stack size .  */
179 
180 #ifndef NX_SNTP_CLIENT_THREAD_STACK_SIZE
181 #define NX_SNTP_CLIENT_THREAD_STACK_SIZE            2048
182 #endif
183 
184 
185 /* Set the client thread time slice.  */
186 
187 #ifndef NX_SNTP_CLIENT_THREAD_TIME_SLICE
188 #define NX_SNTP_CLIENT_THREAD_TIME_SLICE            TX_NO_TIME_SLICE
189 #endif
190 
191 
192 
193 #ifndef NX_SNTP_CLIENT_THREAD_PRIORITY
194 #define NX_SNTP_CLIENT_THREAD_PRIORITY              2
195 #endif
196 
197 
198 /* Set NetX SNTP client thread preemption threshold.  */
199 
200 #ifndef NX_SNTP_CLIENT_PREEMPTION_THRESHOLD
201 #define NX_SNTP_CLIENT_PREEMPTION_THRESHOLD         NX_SNTP_CLIENT_THREAD_PRIORITY
202 #endif
203 
204 
205 
206 /* Configure the NetX SNTP client network parameters */
207 
208 /* Set Client UDP socket name.  */
209 
210 #ifndef NX_SNTP_CLIENT_UDP_SOCKET_NAME
211 #define NX_SNTP_CLIENT_UDP_SOCKET_NAME              "SNTP Client socket"
212 #endif
213 
214 
215 /* Set port for client to bind UDP socket.  */
216 
217 #ifndef NX_SNTP_CLIENT_UDP_PORT
218 #define NX_SNTP_CLIENT_UDP_PORT                    123
219 #endif
220 
221 /* Set port for client to connect to SNTP server.  */
222 
223 #ifndef NX_SNTP_SERVER_UDP_PORT
224 #define NX_SNTP_SERVER_UDP_PORT                    123
225 #endif
226 
227 /* Set Time to Live (TTL) value for transmitted UDP packets, including manycast and
228    multicast transmissions. The default TTL for windows operating system time
229    server is used.  */
230 
231 #ifndef NX_SNTP_CLIENT_TIME_TO_LIVE
232 #define NX_SNTP_CLIENT_TIME_TO_LIVE                  NX_IP_TIME_TO_LIVE
233 #endif
234 
235 
236 /* Set maximum queue depth for client socket.*/
237 
238 #ifndef NX_SNTP_CLIENT_MAX_QUEUE_DEPTH
239 #define NX_SNTP_CLIENT_MAX_QUEUE_DEPTH               5
240 #endif
241 
242 
243 /* Set the time out (timer ticks) for packet allocation from the client packet pool.  */
244 
245 #ifndef NX_SNTP_CLIENT_PACKET_TIMEOUT
246 #define NX_SNTP_CLIENT_PACKET_TIMEOUT               (1 * NX_IP_PERIODIC_RATE)
247 #endif
248 
249 
250 /* Set the NTP/SNTP version of this NTP Client.  */
251 
252 #ifndef NX_SNTP_CLIENT_NTP_VERSION
253 #define NX_SNTP_CLIENT_NTP_VERSION                   3
254 #endif
255 
256 
257 /* Set minimum NTP/SNTP version the Client will accept from its time server.  */
258 
259 #ifndef NX_SNTP_CLIENT_MIN_NTP_VERSION
260 #define NX_SNTP_CLIENT_MIN_NTP_VERSION               3
261 #endif
262 
263 
264 
265 /* Define the minimum (numerically highest) stratum the Client will
266    accept for a time server. Valid range is 1 - 15.  */
267 
268 #ifndef NX_SNTP_CLIENT_MIN_SERVER_STRATUM
269 #define NX_SNTP_CLIENT_MIN_SERVER_STRATUM           2
270 #endif
271 
272 
273 /* Define minimum time difference (msec) between server and client time
274    the Client requires to change its local time.  */
275 
276 #ifndef NX_SNTP_CLIENT_MIN_TIME_ADJUSTMENT
277 #define NX_SNTP_CLIENT_MIN_TIME_ADJUSTMENT          10
278 #endif
279 
280 
281 /* Define maximum time update (msec) the Client will make to its local time
282    per update.  */
283 
284 #ifndef NX_SNTP_CLIENT_MAX_TIME_ADJUSTMENT
285 #define NX_SNTP_CLIENT_MAX_TIME_ADJUSTMENT          180000
286 #endif
287 
288 
289 /* Determine if the Client should ignore the maximum time adjustment on startup. If the
290    host application has a pretty accurate notion of time, this can be set to false. If not
291    the SNTP Client may be unable to apply the first (any) updates. */
292 
293 #ifndef NX_SNTP_CLIENT_IGNORE_MAX_ADJUST_STARTUP
294 #define NX_SNTP_CLIENT_IGNORE_MAX_ADJUST_STARTUP    NX_TRUE
295 #endif
296 
297 
298 /* Determine if the Client should create a random delay before starting SNTP polling. */
299 
300 #ifndef NX_SNTP_CLIENT_RANDOMIZE_ON_STARTUP
301 #define NX_SNTP_CLIENT_RANDOMIZE_ON_STARTUP         NX_FALSE
302 #endif
303 
304 
305 /* Set the maximum time lapse (in seconds) without a time update that can be tolerated by
306    the Client (application). This should be determined by application time sensitivity.
307    For unicast operation, the max lapse could be set to three successive poll requests
308    without an update.  Here we set it to 2 hour based on the RFC recommendation to limit
309    traffic congestion.  */
310 
311 #ifndef NX_SNTP_CLIENT_MAX_TIME_LAPSE
312 #define NX_SNTP_CLIENT_MAX_TIME_LAPSE              7200
313 #endif
314 
315 
316 /* Define a time out (seconds) for the SNTP Client timer.  */
317 
318 #ifndef NX_SNTP_UPDATE_TIMEOUT_INTERVAL
319 #define NX_SNTP_UPDATE_TIMEOUT_INTERVAL             1
320 #endif
321 
322 /* Define the SNTP Client task sleep interval in timer ticks when
323    the SNTP CLient thread is idle. */
324 
325 #ifndef NX_SNTP_CLIENT_SLEEP_INTERVAL
326 #define NX_SNTP_CLIENT_SLEEP_INTERVAL                1
327 #endif
328 
329 
330 /* Set the unicast poll interval (in seconds) for Client time update requests. RFC 4330
331    recommends a minimum polling interval of once per hour to minimize traffic congestion. */
332 
333 #ifndef NX_SNTP_CLIENT_UNICAST_POLL_INTERVAL
334 #define NX_SNTP_CLIENT_UNICAST_POLL_INTERVAL        3600
335 #endif
336 
337 
338 /* Set the Client exponential back off rate for extending Client poll interval.
339    To effectively disable, set to 1.  */
340 
341 #ifndef NX_SNTP_CLIENT_EXP_BACKOFF_RATE
342 #define NX_SNTP_CLIENT_EXP_BACKOFF_RATE             2
343 #endif
344 
345 /* Determine if the Client requires round trip calculation of SNTP messages.  */
346 
347 #ifndef NX_SNTP_CLIENT_RTT_REQUIRED
348 #define NX_SNTP_CLIENT_RTT_REQUIRED                 NX_FALSE
349 #endif
350 
351 
352 /* Define the upper limit of server clock dispersion (usec) the Client
353    will accept. To disable this check, set this parameter to 0x0.  */
354 
355 #ifndef NX_SNTP_CLIENT_MAX_ROOT_DISPERSION
356 #define NX_SNTP_CLIENT_MAX_ROOT_DISPERSION          50000
357 #endif
358 
359 
360 /* Set the limit on consecutive bad updates from server before Client
361    switches to alternate server.  */
362 
363 #ifndef NX_SNTP_CLIENT_INVALID_UPDATE_LIMIT
364 #define NX_SNTP_CLIENT_INVALID_UPDATE_LIMIT         3
365 #endif
366 
367 /* Set size of SNTP data in bytes, not including IP and UDP header fields or authentication.  */
368 #define NX_SNTP_CLIENT_PACKET_DATA_SIZE            48
369 
370 /* To display date in year/month/date format, set the current year (same year as in NTP time being evaluated) e.g 2015.
371    Otherwise set to zero. */
372 #ifndef NX_SNTP_CURRENT_YEAR
373 #define NX_SNTP_CURRENT_YEAR                        2015
374 #endif /* NX_SNTP_CURRENT_YEAR */
375 
376 
377 /* Define status levels for SNTP update processing */
378 
379 #define UPDATE_STATUS_CONTINUE                      1
380 #define UPDATE_STATUS_BREAK                         2
381 #define UPDATE_STATUS_ERROR                         3
382 #define UPDATE_STATUS_SUCCESS                       4
383 
384 
385 /* Define the number of seconds from 01-01-1990 00:00:00 to 01-01-1999 00:00:00 (last occurrance
386    of a leap second) to be able to define time in year, month, date. If zero,
387    no date time is displayed. */
388 #ifndef NTP_SECONDS_AT_01011999
389 #define NTP_SECONDS_AT_01011999                     0xBA368E80
390 #endif /* NTP_SECONDS_AT_01011999 */
391 
392 /* Define which epoch time is relative on the host system. */
393 
394 #define UNIX_EPOCH                 1
395 #define NTP_EPOCH                  2
396 
397 
398 
399 /* Enumerate months*/
400 
401 #define JANUARY         1
402 #define FEBRUARY        2
403 #define MARCH           3
404 #define APRIL           4
405 #define MAY             5
406 #define JUNE            6
407 #define JULY            7
408 #define AUGUST          8
409 #define SEPTEMBER       9
410 #define OCTOBER         10
411 #define NOVEMBER        11
412 #define DECEMBER        12
413 
414 
415 /* Compute seconds per month for convenience computating date and time. */
416 
417 #define SEC_IN_JAN           (31 * SECONDS_PER_DAY)
418 #define SEC_IN_LEAPFEB       (29 * SECONDS_PER_DAY)
419 #define SEC_IN_NONLEAPFEB    (28 * SECONDS_PER_DAY)
420 #define SEC_IN_MAR           (31 * SECONDS_PER_DAY)
421 #define SEC_IN_APR           (30 * SECONDS_PER_DAY)
422 #define SEC_IN_MAY           (31 * SECONDS_PER_DAY)
423 #define SEC_IN_JUN           (30 * SECONDS_PER_DAY)
424 #define SEC_IN_JUL           (31 * SECONDS_PER_DAY)
425 #define SEC_IN_AUG           (31 * SECONDS_PER_DAY)
426 #define SEC_IN_SEP           (30 * SECONDS_PER_DAY)
427 #define SEC_IN_OCT           (31 * SECONDS_PER_DAY)
428 #define SEC_IN_NOV           (30 * SECONDS_PER_DAY)
429 #define SEC_IN_DEC           (31 * SECONDS_PER_DAY)
430 
431 /* Compute seconds per year, month,day for convenience computating date and time. */
432 
433 #define SECONDS_PER_LEAPYEAR        (86400 * 366)
434 #define SECONDS_PER_NONLEAPYEAR     (86400 * 365)
435 #define SECONDS_PER_DAY             86400
436 #define SECONDS_PER_HOUR            3600
437 #define SECONDS_PER_MINUTE          60
438 
439 
440 /* Internal SNTP error processing codes.  */
441 
442 #define NX_SNTP_ERROR_CONSTANT                  0xD00
443 
444 
445 /* Client side errors.  */
446 #define NX_SNTP_CLIENT_NOT_INITIALIZED      (NX_SNTP_ERROR_CONSTANT | 0x01)       /* Client not properly initialized to receive time data.  */
447 #define NX_SNTP_OVER_LIMIT_ON_SERVERS       (NX_SNTP_ERROR_CONSTANT | 0x02)       /* Cannot accept server because client list has reached max # servers.  */
448 #define NX_SNTP_INVALID_DOMAIN              (NX_SNTP_ERROR_CONSTANT | 0x03)       /* Invalid domain such as bad IP format or empty string. Applicable to broadcast mode.  */
449 #define NX_SNTP_NO_AVAILABLE_SERVERS        (NX_SNTP_ERROR_CONSTANT | 0x04)       /* Client has no available time servers to contact.  */
450 #define NX_SNTP_INVALID_LOCAL_TIME          (NX_SNTP_ERROR_CONSTANT | 0x05)       /* Client local time has not been set or is invalid.  */
451 #define NX_SNTP_OUT_OF_DOMAIN_SERVER        (NX_SNTP_ERROR_CONSTANT | 0x06)       /* Broadcast server does not belong to client broadcast domain.  */
452 #define NX_SNTP_INVALID_DATETIME_BUFFER     (NX_SNTP_ERROR_CONSTANT | 0x07)       /* Insufficient or invalid buffer for writing human readable time date string.  */
453 #define NX_SNTP_ERROR_CONVERTING_DATETIME   (NX_SNTP_ERROR_CONSTANT | 0x08)       /* An internal error has occurred converting NTP time to mm-dd-yy time format.  */
454 #define NX_SNTP_UNABLE_TO_CONVERT_DATETIME  (NX_SNTP_ERROR_CONSTANT | 0x09)       /* An internal error has occurred converting NTP time to mm-dd-yy time format.  */
455 #define NX_SNTP_INVALID_SERVER_ADDRESS      (NX_SNTP_ERROR_CONSTANT | 0x0A)       /* Invalid server type e.g. IPv4 or IPv6 incompatible.                          */
456 #define NX_SNTP_CLIENT_NOT_STARTED          (NX_SNTP_ERROR_CONSTANT | 0x0B)       /* SNTP Client task is not running */
457 #define NX_SNTP_CLIENT_ALREADY_STARTED      (NX_SNTP_ERROR_CONSTANT | 0x0C)       /* SNTP Client task is already running */
458 #define NX_SNTP_PARAM_ERROR                 (NX_SNTP_ERROR_CONSTANT | 0x0D)       /* Invalid non pointer parameter.  */
459 
460     /* Server side errors */
461 #define NX_SNTP_SERVER_NOT_AVAILABLE        (NX_SNTP_ERROR_CONSTANT | 0x10)       /* Client will not get any time update service from current server.  */
462 #define NX_SNTP_NO_UNICAST_FROM_SERVER      (NX_SNTP_ERROR_CONSTANT | 0x11)       /* Client did not receive a valid unicast response from server.  */
463 #define NX_SNTP_SERVER_CLOCK_NOT_SYNC       (NX_SNTP_ERROR_CONSTANT | 0x12)       /* Server clock not synchronized.  */
464 #define NX_SNTP_KOD_SERVER_NOT_AVAILABLE    (NX_SNTP_ERROR_CONSTANT | 0x13)       /* Server sent a KOD packet indicating service temporarily not available.  */
465 #define NX_SNTP_KOD_REMOVE_SERVER           (NX_SNTP_ERROR_CONSTANT | 0x14)       /* Server sent a KOD packet indicating service is not available to client (ever).  */
466 #define NX_SNTP_SERVER_AUTH_FAIL            (NX_SNTP_ERROR_CONSTANT | 0x15)       /* Server rejects Client packet on basis of missing or invalid authorization data.  */
467 
468 /* Bad packet and time update errors */
469 #define NX_SNTP_INVALID_TIME_PACKET         (NX_SNTP_ERROR_CONSTANT | 0x20)       /* Invalid packet (length or data incorrect).   */
470 #define NX_SNTP_INVALID_NTP_VERSION         (NX_SNTP_ERROR_CONSTANT | 0x21)       /* Server NTP/SNTP version not incompatible with client.  */
471 #define NX_SNTP_INVALID_SERVER_MODE         (NX_SNTP_ERROR_CONSTANT | 0x22)       /* Server association invalid (out of protocol with client).  */
472 #define NX_SNTP_INVALID_SERVER_PORT         (NX_SNTP_ERROR_CONSTANT | 0x23)       /* Server port does not match what the client expects.  */
473 #define NX_SNTP_INVALID_IP_ADDRESS          (NX_SNTP_ERROR_CONSTANT | 0x24)       /* Server IP address does not match what the client expects.  */
474 #define NX_SNTP_INVALID_SERVER_STRATUM      (NX_SNTP_ERROR_CONSTANT | 0x25)       /* Server stratum is invalid or below client stratum.  */
475 #define NX_SNTP_BAD_SERVER_ROOT_DISPERSION  (NX_SNTP_ERROR_CONSTANT | 0x26)       /* Server root dispersion (clock precision) is too high or invalid value (0) reported.  */
476 #define NX_SNTP_OVER_INVALID_LIMIT          (NX_SNTP_ERROR_CONSTANT | 0x27)       /* Client over the limit on consecutive server updates with bad data received.  */
477 #define NX_SNTP_DUPE_SERVER_PACKET          (NX_SNTP_ERROR_CONSTANT | 0x28)       /* Client has received duplicate packets from server.  */
478 #define NX_SNTP_INVALID_TIMESTAMP           (NX_SNTP_ERROR_CONSTANT | 0x29)       /* Server time packet has one or more invalid time stamps in update message.  */
479 #define NX_SNTP_INSUFFICIENT_PACKET_PAYLOAD (NX_SNTP_ERROR_CONSTANT | 0x2A)       /* Packet payload not large enough for SNTP message.  */
480 #define NX_SNTP_INVALID_SNTP_PACKET         (NX_SNTP_ERROR_CONSTANT | 0x2B)       /* Server IP version does not match what the client expects.  */
481 
482 /* Arithmetic errors or invalid results */
483 #define NX_SNTP_INVALID_TIME                (NX_SNTP_ERROR_CONSTANT | 0x30)       /* Invalid time resulting from arithmetic operation.  */
484 #define NX_SNTP_INVALID_RTT_TIME            (NX_SNTP_ERROR_CONSTANT | 0x31)       /* Round trip time correction to server time yields invalid time (e.g. <0).  */
485 #define NX_SNTP_OVERFLOW_ERROR              (NX_SNTP_ERROR_CONSTANT | 0x32)       /* Overflow error resulting from multiplying/adding two 32 bit (timestamp) numbers.  */
486 #define NX_SNTP_SIGN_ERROR                  (NX_SNTP_ERROR_CONSTANT | 0x33)       /* Loss of sign error resulting from multiplying/adding two 32 bit (timestamp) numbers.  */
487 
488 /* Time out errors */
489 #define NX_SNTP_TIMED_OUT_ON_SERVER         (NX_SNTP_ERROR_CONSTANT | 0x44)       /* Client did not receive update from the current server within specified timeout.  */
490 #define NX_SNTP_MAX_TIME_LAPSE_EXCEEDED     (NX_SNTP_ERROR_CONSTANT | 0x45)       /* Client has not received update from any server within the max allowed time lapse.  */
491 
492 
493 
494 /* Define the Netx Date Time structure.  */
495 
496     typedef struct NX_SNTP_DATE_TIME_STRUCT
497     {
498         UINT     year;
499         UINT     month;
500         UINT     day;
501         UINT     hour;
502         UINT     minute;
503         UINT     second;
504         UINT     millisecond;                                               /* This is the fraction part of the NTP time data. */
505         UINT     time_zone;                                                 /* NTP time is represented in Coordinated Universal Time (UTC). */
506         UINT     leap_year;                                                 /* Indicates if current time is in a leap year. */
507 
508     } NX_SNTP_DATE_TIME;
509 
510 
511 /* Define the Netx SNTP Time structure.  */
512 
513     typedef struct NX_SNTP_TIME_STRUCT
514     {
515         ULONG    seconds;                                                   /* Seconds, in the 32 bit field of an NTP time data.  */
516         ULONG    fraction;                                                  /* Fraction of a second, in the 32 bit fraction field of an NTP time data.  */
517 
518     } NX_SNTP_TIME;
519 
520 
521 /* Define the NetX SNTP Time Message structure.  The Client only uses the flags field and the transmit_time_stamp field
522    in time requests it sends to its time server.  */
523 
524     typedef struct NX_SNTP_TIME_MESSAGE_STRUCT
525     {
526         /* These are represented as 8 bit data fields in the time message format.  */
527         UINT flags;                                                         /* Flag containing host's NTP version, mode and leap indicator.  */
528         UINT peer_clock_stratum;                                            /* Level of precision in the NTP network. Applicable only in server NTP messages.  */
529         UINT peer_poll_interval;                                            /* Frequency at which an NTP host polls its NTP peer. Applicable only in server NTP messages.  */
530         UINT peer_clock_precision;                                          /* Precision of the NTP server clock. Applicable only in server NTP messages.  */
531 
532         /* These are represented as 32 bit data fields in the time message format*/
533         ULONG root_delay;                                                   /* Round trip time from NTP Server to primary reference source. Applicable only in server NTP messages.  */
534         ULONG clock_dispersion;                                             /* Server reference clock type (but if stratum is zero, indicates server status when not able to send time updates.  */
535         UCHAR reference_clock_id[4];                                        /* Maximum error in server clock based to the clock frequency tolerance. Applicable only in server NTP messages.  */
536 
537         /* These are represented as 64 bit data fields in the time message format*/
538         ULONG reference_clock_update_time_stamp[2];                         /* Time at which the server clock was last set or corrected in a server time message.  */
539         ULONG originate_time_stamp[2];                                      /* Time at which the Client update request left the Client in a server time message.  */
540         ULONG receive_time_stamp[2];                                        /* Time at which the server received the Client request in a server time message.  */
541         ULONG transmit_time_stamp[2];                                       /* Time at which the server transmitted its reply to the Client in a server time message (or the time client request was sent in the client request message).  */
542 
543         /* Optional authenticator fields.  */
544         UCHAR KeyIdentifier[4];                                             /* Key Identifier and Message Digest fields contain the...  */
545         UCHAR MessageDigest[16];                                            /* ...message authentication code (MAC) information defined.  */
546 
547         /* These fields are used internally for 'convert' UCHAR data in NX_SNTP_TIME data e.g. seconds and fractions.  */
548         NX_SNTP_TIME reference_clock_update_time;                           /* Time at which the server clock was last set or corrected in a server time message.  */
549         NX_SNTP_TIME originate_time;                                        /* Time at which the Client update request left the Client in a server time message.  */
550         NX_SNTP_TIME receive_time;                                          /* Time at which the server received the Client request in a server time message.  */
551         NX_SNTP_TIME transmit_time;                                         /* Time at which the server transmitted its reply to the Client in a server time message (or the time client request was sent in the client request message).  */
552 
553     } NX_SNTP_TIME_MESSAGE;
554 
555 
556 /* Define the SNTP client structure.  */
557 
558     typedef struct NX_SNTP_CLIENT_STRUCT
559     {
560         ULONG                           nx_sntp_client_id;                       /* SNTP ID for identifying the client service task.  */
561         NX_IP                          *nx_sntp_client_ip_ptr;                   /* Pointer to the Client IP instance.  */
562         UINT                            nx_sntp_client_interface_index;          /* Index to SNTP network interface  */
563         NX_PACKET_POOL                 *nx_sntp_client_packet_pool_ptr;          /* Pointer to the Client packet pool.  */
564         UINT                            nx_sntp_client_sleep_flag;               /* The flag indicating the SNTP Client thread is sleeping          */
565         UINT                            nx_sntp_client_started;                  /* Flag indicating the SNTP Client task is running */
566         TX_THREAD                       nx_sntp_client_thread;                   /* The SNTP Client processing thread                               */
567         TX_MUTEX                        nx_sntp_client_mutex;                    /* The SNTP Client mutex for protecting access                     */
568         UCHAR                           nx_sntp_client_thread_stack[NX_SNTP_CLIENT_THREAD_STACK_SIZE];  /* Stack size for SNTP client thread        */
569         NXD_ADDRESS                     nx_sntp_server_ip_address;               /* Client's current time server IP address.  */
570         NX_UDP_SOCKET                   nx_sntp_client_udp_socket;               /* Client UDP socket for sending and receiving time updates.  */
571         UINT                            nx_sntp_client_first_update_pending;     /* First SNTP update not yet received with current server   */
572         UINT                            nx_sntp_client_time_start_wait;          /* Initial time at start of receiving broadcast SNTP updates */
573         UINT                            nx_sntp_client_sent_initial_unicast;     /* Status on initial unicast transmittal for clients in broadcast mode */
574         UINT                            nx_sntp_client_invalid_time_updates;     /* Number of invalid SNTP messages received */
575         UINT                            nx_sntp_valid_server_status;             /* Server status; if receiving valid updates, status is TRUE */
576         UINT                            nx_sntp_client_protocol_mode;            /* Mode of operation, either unicast or broadcast */
577         UINT                            nx_sntp_client_broadcast_initialized;    /* Client task is ready to receive broadcast time data.  */
578         NXD_ADDRESS                     nx_sntp_broadcast_time_server;           /* Client's broadcast SNTP server */
579         NXD_ADDRESS                     nx_sntp_multicast_server_address;        /* IP address Client should listen on to receive broadcasts from a multicast server.  */
580         UINT                            nx_sntp_client_unicast_initialized;      /* Client task is ready to receive unicast time data.  */
581         NXD_ADDRESS                     nx_sntp_unicast_time_server;             /* Client's unicast time server.  */
582         ULONG                           nx_sntp_client_unicast_poll_interval;    /* Unicast interval at which client is polling the time server.  */
583         UINT                            nx_sntp_client_backoff_count;            /* Count of times the back off rate has been applied to the poll interval */
584         TX_TIMER                        nx_sntp_update_timer;                    /* SNTP update timer; expires when no data received for specified time lapse.  */
585         ULONG                           nx_sntp_update_time_remaining;           /* Time (in seconds) remaining that the Client task can continue running without receiving a valid update.  */
586         LONG                            nx_sntp_client_roundtrip_time_msec;      /* Round trip time (msec) for a packet to travel to server and back to client. Does not include server processing time.  */
587         ULONG                           nx_sntp_client_local_ntp_time_elapsed;   /* Seconds elapsed since local time is updated last time. */
588         NX_SNTP_TIME_MESSAGE            nx_sntp_current_server_time_message;     /* Time update which the Client has just received from its server.  */
589         NX_SNTP_TIME_MESSAGE            nx_sntp_current_time_message_request;    /* Client request to send to its time server.  */
590         NX_SNTP_TIME_MESSAGE            nx_sntp_previous_server_time_message;    /* Previous valid time update received from the Client time server.  */
591         NX_SNTP_TIME                    nx_sntp_client_local_ntp_time;           /* Client's notion of local time.  */
592         NX_SNTP_TIME                    nx_sntp_server_update_time;              /* Time (based on client local time) when the server update was received in response to the current request.  */
593         UINT                            (*apply_custom_sanity_checks)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, NX_SNTP_TIME_MESSAGE *client_time_msg_ptr, NX_SNTP_TIME_MESSAGE *server_time_msg_ptr);
594                                                                                  /* Pointer to callback service for  performing additional sanity checks on received time data.  */
595         UINT                            (*leap_second_handler)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, UINT indicator);
596                                                                                  /* Pointer to callback service for handling an impending leap second.  */
597         UINT                            (*kiss_of_death_handler)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, UINT code);
598                                                                                  /* Pointer to callback service for handling kiss of death packets received from server.  */
599         VOID                            (*random_number_generator)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, ULONG *rand);
600                                                                                  /* Pointer to callback service for random number generator.  */
601 
602         VOID                            (*nx_sntp_client_time_update_notify)(NX_SNTP_TIME_MESSAGE *time_update_ptr, NX_SNTP_TIME *local_time);
603 
604     } NX_SNTP_CLIENT;
605 
606 
607 #ifndef     NX_SNTP_SOURCE_CODE
608 
609 /* Define the system API mappings based on the error checking selected by the user.   */
610 
611 
612 /* Determine if error checking is desired.  If so, map API functions
613    to the appropriate error checking front-ends.  Otherwise, map API
614    functions to the core functions that actually perform the work.
615    Note: error checking is enabled by default.  */
616 
617 
618 #ifdef NX_SNTP_DISABLE_ERROR_CHECKING
619 
620 /* Services without error checking.  */
621 
622 #define   nx_sntp_client_create                             _nx_sntp_client_create
623 #define   nx_sntp_client_delete                             _nx_sntp_client_delete
624 #define   nx_sntp_client_get_local_time                     _nx_sntp_client_get_local_time
625 #define   nx_sntp_client_get_local_time_extended            _nx_sntp_client_get_local_time_extended
626 #define   nxd_sntp_client_initialize_broadcast              _nxd_sntp_client_initialize_broadcast
627 #define   nxd_sntp_client_initialize_unicast                _nxd_sntp_client_initialize_unicast
628 #define   nx_sntp_client_initialize_broadcast               _nx_sntp_client_initialize_broadcast
629 #define   nx_sntp_client_initialize_unicast                 _nx_sntp_client_initialize_unicast
630 #define   nx_sntp_client_receiving_updates                  _nx_sntp_client_receiving_updates
631 #define   nx_sntp_client_run_broadcast                      _nx_sntp_client_run_broadcast
632 #define   nx_sntp_client_run_unicast                        _nx_sntp_client_run_unicast
633 #define   nx_sntp_client_set_local_time                     _nx_sntp_client_set_local_time
634 #define   nx_sntp_client_stop                               _nx_sntp_client_stop
635 #define   nx_sntp_client_utility_msecs_to_fraction          _nx_sntp_client_utility_msecs_to_fraction
636 #define   nx_sntp_client_utility_usecs_to_fraction          _nx_sntp_client_utility_usecs_to_fraction
637 #define   nx_sntp_client_utility_fraction_to_usecs          _nx_sntp_client_utility_fraction_to_usecs
638 #define   nx_sntp_client_utility_display_date_time          _nx_sntp_client_utility_display_date_time
639 #define   nx_sntp_client_request_unicast_time               _nx_sntp_client_request_unicast_time
640 #define   nx_sntp_client_set_time_update_notify             _nx_sntp_client_set_time_update_notify
641 
642 #else
643 
644 /* Services with error checking.  */
645 
646 #define   nx_sntp_client_create                             _nxe_sntp_client_create
647 #define   nx_sntp_client_delete                             _nxe_sntp_client_delete
648 #define   nx_sntp_client_get_local_time                     _nxe_sntp_client_get_local_time
649 #define   nx_sntp_client_get_local_time_extended            _nxe_sntp_client_get_local_time_extended
650 #define   nxd_sntp_client_initialize_broadcast              _nxde_sntp_client_initialize_broadcast
651 #define   nxd_sntp_client_initialize_unicast                _nxde_sntp_client_initialize_unicast
652 #define   nx_sntp_client_initialize_broadcast               _nxe_sntp_client_initialize_broadcast
653 #define   nx_sntp_client_initialize_unicast                 _nxe_sntp_client_initialize_unicast
654 #define   nx_sntp_client_receiving_updates                  _nxe_sntp_client_receiving_updates
655 #define   nx_sntp_client_run_broadcast                      _nxe_sntp_client_run_broadcast
656 #define   nx_sntp_client_run_unicast                        _nxe_sntp_client_run_unicast
657 #define   nx_sntp_client_set_local_time                     _nxe_sntp_client_set_local_time
658 #define   nx_sntp_client_stop                               _nxe_sntp_client_stop
659 #define   nx_sntp_client_utility_msecs_to_fraction          _nxe_sntp_client_utility_msecs_to_fraction
660 #define   nx_sntp_client_utility_usecs_to_fraction          _nxe_sntp_client_utility_usecs_to_fraction
661 #define   nx_sntp_client_utility_fraction_to_usecs          _nxe_sntp_client_utility_fraction_to_usecs
662 #define   nx_sntp_client_utility_display_date_time          _nxe_sntp_client_utility_display_date_time
663 #define   nx_sntp_client_request_unicast_time               _nxe_sntp_client_request_unicast_time
664 #define   nx_sntp_client_set_time_update_notify             _nxe_sntp_client_set_time_update_notify
665 
666 #endif /* NX_SNTP_DISABLE_ERROR_CHECKING */
667 
668 
669 /* Define the prototypes accessible to the application software.  */
670 
671 UINT   nx_sntp_client_create(NX_SNTP_CLIENT *client_ptr, NX_IP *ip_ptr, UINT iface_index, NX_PACKET_POOL *packet_pool_ptr,
672                              UINT (*leap_second_handler)(NX_SNTP_CLIENT *client_ptr, UINT indicator),
673                              UINT (*kiss_of_death_handler)(NX_SNTP_CLIENT *client_ptr, UINT code),
674                              VOID (random_number_generator)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, ULONG *rand));
675 UINT    nx_sntp_client_delete (NX_SNTP_CLIENT *client_ptr);
676 UINT    nx_sntp_client_get_local_time(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer);
677 UINT    nx_sntp_client_get_local_time_extended(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer, UINT buffer_size);
678 UINT    nxd_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *multicast_server_address, NXD_ADDRESS *broadcast_time_server);
679 UINT    nx_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr,  ULONG multicast_server_address, ULONG broadcast_time_server);
680 UINT    nxd_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *unicast_time_server);
681 UINT    nx_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, ULONG unicast_time_server);
682 UINT    nx_sntp_client_receiving_updates(NX_SNTP_CLIENT *client_ptr, UINT *server_status);
683 UINT    nx_sntp_client_run_broadcast(NX_SNTP_CLIENT *client_ptr);
684 UINT    nx_sntp_client_run_unicast(NX_SNTP_CLIENT *client_ptr);
685 UINT    nx_sntp_client_set_local_time(NX_SNTP_CLIENT *client_ptr, ULONG seconds, ULONG fraction);
686 UINT    nx_sntp_client_stop(NX_SNTP_CLIENT *client_ptr);
687 UINT    nx_sntp_client_utility_msecs_to_fraction(ULONG msecs, ULONG *fraction);
688 UINT    nx_sntp_client_utility_usecs_to_fraction(ULONG usecs, ULONG *fraction);
689 UINT    nx_sntp_client_utility_fraction_to_usecs(ULONG fraction, ULONG *usecs);
690 UINT    nx_sntp_client_utility_display_date_time(NX_SNTP_CLIENT *client_ptr, CHAR *buffer, UINT length);
691 UINT    nx_sntp_client_request_unicast_time(NX_SNTP_CLIENT *client_ptr, UINT wait_option);
692 UINT    nx_sntp_client_set_time_update_notify(NX_SNTP_CLIENT *client_ptr, VOID (time_update_cb)(NX_SNTP_TIME_MESSAGE *time_update_ptr, NX_SNTP_TIME *local_time));
693 
694 #else  /*  NX_SNTP_SOURCE_CODE */
695 
696 
697 /* SNTP source code is being compiled, do not perform any API mapping.  */
698 
699 UINT   _nx_sntp_client_create(NX_SNTP_CLIENT *client_ptr, NX_IP *ip_ptr, UINT iface_index, NX_PACKET_POOL *packet_pool_ptr,
700                             UINT (*leap_second_handler)(NX_SNTP_CLIENT *client_ptr, UINT indicator),
701                             UINT (*kiss_of_death_handler)(NX_SNTP_CLIENT *client_ptr, UINT code),
702                             VOID (random_number_generator)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, ULONG *rand));
703 UINT   _nxe_sntp_client_create(NX_SNTP_CLIENT *client_ptr, NX_IP *ip_ptr, UINT iface_index, NX_PACKET_POOL *packet_pool_ptr,
704                             UINT (*leap_second_handler)(NX_SNTP_CLIENT *client_ptr, UINT indicator),
705                             UINT (*kiss_of_death_handler)(NX_SNTP_CLIENT *client_ptr, UINT code),
706                             VOID (random_number_generator)(struct NX_SNTP_CLIENT_STRUCT *client_ptr, ULONG *rand));
707 UINT    _nx_sntp_client_delete (NX_SNTP_CLIENT *client_ptr);
708 UINT    _nxe_sntp_client_delete (NX_SNTP_CLIENT *client_ptr);
709 UINT    _nx_sntp_client_get_local_time(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer);
710 UINT    _nxe_sntp_client_get_local_time(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer);
711 UINT    _nx_sntp_client_get_local_time_extended(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer, UINT buffer_size);
712 UINT    _nxe_sntp_client_get_local_time_extended(NX_SNTP_CLIENT *client_ptr, ULONG *seconds, ULONG *fraction, CHAR *buffer, UINT buffer_size);
713 UINT    _nxde_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *multicast_server_address, NXD_ADDRESS *broadcast_time_server);
714 UINT    _nxd_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *multicast_server_address, NXD_ADDRESS *broadcast_time_server);
715 UINT    _nx_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr, ULONG multicast_server_address, ULONG broadcast_time_server);
716 UINT    _nxe_sntp_client_initialize_broadcast(NX_SNTP_CLIENT *client_ptr, ULONG multicast_server_address, ULONG broadcast_time_server);
717 UINT    _nxde_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *unicast_time_server);
718 UINT    _nxd_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, NXD_ADDRESS *unicast_time_server);
719 UINT    _nx_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, ULONG unicast_time_server);
720 UINT    _nxe_sntp_client_initialize_unicast(NX_SNTP_CLIENT *client_ptr, ULONG unicast_time_server);
721 UINT    _nx_sntp_client_receiving_updates(NX_SNTP_CLIENT *client_ptr, UINT *server_status);
722 UINT    _nxe_sntp_client_receiving_updates(NX_SNTP_CLIENT *client_ptr, UINT *server_status);
723 UINT    _nx_sntp_client_run_broadcast(NX_SNTP_CLIENT *client_ptr);
724 UINT    _nxe_sntp_client_run_broadcast(NX_SNTP_CLIENT *client_ptr);
725 UINT    _nx_sntp_client_run_unicast(NX_SNTP_CLIENT *client_ptr);
726 UINT    _nxe_sntp_client_run_unicast(NX_SNTP_CLIENT *client_ptr);
727 UINT    _nx_sntp_client_set_local_time(NX_SNTP_CLIENT *client_ptr, ULONG seconds, ULONG fraction);
728 UINT    _nxe_sntp_client_set_local_time(NX_SNTP_CLIENT *client_ptr, ULONG seconds, ULONG fraction);
729 UINT    _nx_sntp_client_stop(NX_SNTP_CLIENT *client_ptr);
730 UINT    _nxe_sntp_client_stop(NX_SNTP_CLIENT *client_ptr);
731 UINT    _nx_sntp_client_utility_msecs_to_fraction(ULONG msecs, ULONG *fraction);
732 UINT    _nxe_sntp_client_utility_msecs_to_fraction(ULONG msecs, ULONG *fraction);
733 UINT    _nx_sntp_client_utility_usecs_to_fraction(ULONG usecs, ULONG *fraction);
734 UINT    _nxe_sntp_client_utility_usecs_to_fraction(ULONG usecs, ULONG *fraction);
735 UINT    _nx_sntp_client_utility_fraction_to_usecs(ULONG fraction, ULONG *usecs);
736 UINT    _nxe_sntp_client_utility_fraction_to_usecs(ULONG fraction, ULONG *usecs);
737 UINT    _nx_sntp_client_utility_display_date_time(NX_SNTP_CLIENT *client_ptr, CHAR *buffer, UINT length);
738 UINT    _nxe_sntp_client_utility_display_date_time(NX_SNTP_CLIENT *client_ptr, CHAR *buffer, UINT length);
739 UINT    _nxe_sntp_client_utility_display_NTP_time(NX_SNTP_CLIENT *client_ptr, CHAR *buffer);
740 UINT    _nx_sntp_client_request_unicast_time(NX_SNTP_CLIENT *client_ptr, UINT wait_option);
741 UINT    _nxe_sntp_client_request_unicast_time(NX_SNTP_CLIENT *client_ptr, UINT wait_option);
742 UINT    _nx_sntp_client_set_time_update_notify(NX_SNTP_CLIENT *client_ptr, VOID (time_update_cb)(NX_SNTP_TIME_MESSAGE *time_update_ptr, NX_SNTP_TIME *local_time));
743 UINT    _nxe_sntp_client_set_time_update_notify(NX_SNTP_CLIENT *client_ptr, VOID (time_update_cb)(NX_SNTP_TIME_MESSAGE *time_update_ptr, NX_SNTP_TIME *local_time));
744 
745 /* Define internal SNTP Client functions.  */
746 
747 UINT    _nx_sntp_client_apply_sanity_checks(NX_SNTP_CLIENT *client_ptr);
748 UINT    _nx_sntp_client_calculate_roundtrip(LONG *roundtrip_time);
749 UINT    _nx_sntp_client_check_server_clock_dispersion(NX_SNTP_CLIENT *client_ptr);
750 UINT    _nx_sntp_client_create_time_request_packet(NX_SNTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, NX_SNTP_TIME_MESSAGE *time_message_ptr);
751 UINT    _nx_sntp_client_duplicate_update_check(NX_SNTP_TIME_MESSAGE *timeA_msg_ptr, NX_SNTP_TIME_MESSAGE *timeB_msg_ptr, UINT *is_a_dupe);
752 UINT    _nx_sntp_client_extract_time_message_from_packet(NX_SNTP_CLIENT *client_ptr, NX_PACKET *packet_ptr);
753 VOID    _nx_sntp_client_process(NX_SNTP_CLIENT *client_ptr);
754 VOID    _nx_sntp_client_process_broadcast(NX_SNTP_CLIENT *client_ptr);
755 VOID    _nx_sntp_client_process_unicast(NX_SNTP_CLIENT *client_ptr);
756 UINT    _nx_sntp_client_process_time_data(NX_SNTP_CLIENT *client_ptr);
757 UINT    _nx_sntp_client_process_update_packet(NX_SNTP_CLIENT *client_ptr);
758 VOID    _nx_sntp_client_receive_notify(NX_UDP_SOCKET *socket_ptr);
759 UINT    _nx_sntp_client_receive_time_update(NX_SNTP_CLIENT *client_ptr, ULONG timeout);
760 UINT    _nx_sntp_client_reset_current_time_message(NX_SNTP_CLIENT *client_ptr);
761 UINT    _nx_sntp_client_send_unicast_request(NX_SNTP_CLIENT *client_ptr);
762 VOID    _nx_sntp_client_thread_entry(ULONG sntp_instance);
763 VOID    _nx_sntp_client_update_timeout_entry(ULONG info);
764 UINT    _nx_sntp_client_utility_add_msecs_to_ntp_time(NX_SNTP_TIME *timeA_ptr, LONG msecs_to_add);
765 UINT    _nx_sntp_client_utility_convert_fraction_to_msecs(ULONG *milliseconds, NX_SNTP_TIME *time_ptr);
766 UINT    _nx_sntp_client_utility_convert_seconds_to_date(NX_SNTP_TIME *current_NTP_time_ptr, UINT current_year, NX_SNTP_DATE_TIME *current_date_time_ptr);
767 UINT    _nx_sntp_client_utility_convert_refID_KOD_code(UCHAR *reference_id, UINT *code_id);
768 UINT    _nx_sntp_client_utility_get_msec_diff(NX_SNTP_TIME *timeA_ptr, NX_SNTP_TIME *timeB_ptr, ULONG *total_difference_msecs, UINT *pos_diff);
769 UINT    _nx_sntp_client_utility_addition_overflow_check(ULONG temp1, ULONG temp2);
770 UINT    _nx_sntp_client_utility_convert_time_to_UCHAR(NX_SNTP_TIME *time, NX_SNTP_TIME_MESSAGE *time_message_ptr, UINT which_stamp);
771 UINT    _nx_sntp_client_utility_is_zero_data(UCHAR *data, UINT size);
772 
773 
774 
775 #endif   /*  NX_SNTP_SOURCE_CODE */
776 
777 /* If a C++ compiler is being used....*/
778 #ifdef   __cplusplus
779 }
780 #endif
781 
782 
783 #endif /* NXD_SNTP_CLIENT_H  */
784