1 /*
2  * FreeRTOS V202212.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  */
26 
27 #ifndef DEMO_CONFIG_H
28 #define DEMO_CONFIG_H
29 
30 /**************************************************/
31 /******* DO NOT CHANGE the following order ********/
32 /**************************************************/
33 
34 /* Include logging header files and define logging macros in the following order:
35  * 1. Include the header file "logging_levels.h".
36  * 2. Define the LIBRARY_LOG_NAME and LIBRARY_LOG_LEVEL macros depending on
37  * the logging configuration for DEMO.
38  * 3. Include the header file "logging_stack.h", if logging is enabled for DEMO.
39  */
40 
41 #include "logging_levels.h"
42 
43 /* Logging configuration for the Demo. */
44 #ifndef LIBRARY_LOG_NAME
45     #define LIBRARY_LOG_NAME    "SNTPDemo"
46 #endif
47 
48 #ifndef LIBRARY_LOG_LEVEL
49     #define LIBRARY_LOG_LEVEL    LOG_INFO
50 #endif
51 
52 /* Prototype for the function used to print to console on Windows simulator
53  * of FreeRTOS.
54  * The function prints to the console before the network is connected;
55  * then a UDP port after the network has connected. */
56 extern void vLoggingPrintf( const char * pcFormatString,
57                             ... );
58 
59 /* Map the SdkLog macro to the logging function to enable logging
60  * on Windows simulator. */
61 #ifndef SdkLog
62     #define SdkLog( message )    vLoggingPrintf message
63 #endif
64 
65 #include "logging_stack.h"
66 
67 /************ End of logging configuration ****************/
68 
69 /**
70  * @brief The time period between consecutive time polling requests that are sent by the
71  * SNTP client in the demo application.
72  *
73  * @note According to the SNTPv4 specification, the polling interval MUST NOT be less
74  * than 15 seconds for responsible use of time servers by SNTP clients.
75  *
76  *
77  * #define democonfigSNTP_CLIENT_POLLING_INTERVAL_SECONDS                  ( 16 )
78  */
79 
80 /**
81  * @brief The set of time servers, in decreasing order of priority, for configuring the SNTP client.
82  * The servers SHOULD be listed as comma-separated list of strings. For example, the following
83  * can be a configuration used:
84  *
85  * #define democonfigLIST_OF_TIME_SERVERS          "<custom-timeserver-1>", "<custom-timeserver-2>", "pool.ntp.org"
86  */
87 
88 /**
89  * @brief The list of 128-bit (or 16 bytes) symmetric keys for authenticating communication with the NTP/SNTP time servers
90  * corresponding to the list in democonfigLIST_OF_TIME_SERVERS. A symmetric key is used for generating authentication code
91  * in client request to related NTP/SNTP server as well as validating server from the time response received.
92  *
93  * This demo shows use of AES-128-CMAC algorithm for a mutual authentication mechanism in the SNTP communication
94  * between the NTP/SNTP server and client. The demo generates a Message Authentication Code (MAC) using
95  * the algorithm and appends it to the client request packet before the coreSNTP library sends it over
96  * the network to the server. The server validates the client from the request from the authentication code
97  * present in the request packet. Similarly, this demo validates the server from the response received on
98  * the network by verifying the authentication code present in the response packet.
99  *
100  * It is RECOMMENDED to use an authentication mechanism for protecting devices against server spoofing
101  * attacks.
102  *
103  * @note Even though this demo shows the use of AES-128-CMAC, a symmetric-key cryptographic based
104  * solution, for authenticating SNTP communication between the demo (SNTP client) and
105  * SNTP/NTP server, we instead RECOMMEND that production devices use the most secure authentication
106  * mechanism alternative available with the Network Time Security (NTS) protocol, an asymmetric-key
107  * cryptographic protocol. For more information, refer to the NTS specification here:
108  * https://datatracker.ietf.org/doc/html/rfc8915
109  *
110  * @note Please provide the 128-bit keys as comma separated list of hexadecimal strings in the order matching
111  * the list of time servers configured in democonfigLIST_OF_TIME_SERVERS configuration. If a time server does
112  * not support authentication, then NULL should be used to indicate use of no authentication mechanism for the
113  * time server.
114  *
115  * @note Use of the AES-128-CMAC based authentication scheme in the demo requires that the symmetric key
116  * is shared safely between the time server and the client device.
117  *
118  * #define democonfigLIST_OF_AUTHENTICATION_SYMMETRIC_KEYS  "<hexstring-key-1>", "<hexstring-key-2>", NULL
119  */
120 
121 /**
122  * @brief The list of key IDs of the shared @ref democonfigLIST_OF_AUTHENTICATION_SYMMETRIC_KEYS keys between
123  * the client and the corresponding NTP/SNTP servers, in democonfigLIST_OF_TIME_SERVERS, for authenticating
124  * the SNTP communication between the client and server.
125  *
126  * The ID for a key usually represents the ID used to reference the symmetric key in the NTP/SNTP server system.
127  *
128  * @note This Key IDs should be configured as a comma-separated list of integer Key IDs that match the order of
129  * keys in democonfigLIST_OF_AUTHENTICATION_SYMMETRIC_KEYS. If there is a NULL (or no key) in the list of keys,
130  * then -1 can be used as the corresponding key ID.
131  *
132  * #define democonfigLIST_OF_AUTHENTICATION_KEY_IDS    <key-ID-1>, <key-ID-2>, -1
133  */
134 
135 /**
136  * @brief The year to bake in the demo application for initializing the system clock with.
137  * The demo initializes the system clock time for the starting second of the 1st January of
138  * the configured year. So for example, with a configuration of year 2021, the demo will
139  * initialize the system clock time as 1st January 2021 00h:00m:00s.
140  *
141  * @note The coreSNTP library REQUIRES that the client system time is within ~68 years of internet
142  * time. Thus, for systems that do not have an Real-Time Clock module, this demo shows how
143  * a starting time can be baked in the device firmware to keep the starting time of the system
144  * close to actual time on the first boot-up of device.
145  * For such systems without Real-Time Clock module, all device boot ups from subsequent device resets
146  * or power cycles can continue to carry close to correct time by EITHER
147  *  * (RECOMMENDED) Saving the most recent time in non-volatile memory
148  *     OR
149  *  * Using the same firmware baked-in starting time of device for every boot-up.
150  */
151 #define democonfigSYSTEM_START_YEAR                        ( 2021 )
152 
153 /**
154  * @brief The timeout (in milliseconds) for the time response to a time request made to a
155  * time server.
156  */
157 #define democonfigSERVER_RESPONSE_TIMEOUT_MS               ( 5000 )
158 
159 /**
160  * @brief The maximum block time (in milliseconds) for an attempt to send time request over the network
161  * to a time server when through the Sntp_SendTimeRequest API.
162  */
163 #define democonfigSEND_TIME_REQUEST_TIMEOUT_MS             ( 50 )
164 
165 /**
166  * @brief The maximum block time (in milliseconds) for an attempt to read server response (to a time request)
167  * from the network through the Sntp_ReceiveTimeResponse API.
168  *
169  * @note This value MAY BE less than the server response timeout (configured in democonfigSERVER_RESPONSE_TIMEOUT_MS)
170  * to support use-cases when application DOES NOT want to block for the entire server response timeout period.
171  * In such a case, the Sntp_ReceiveTimeResponse API can be called multiple times (with block time duration
172  * that is orders of degree shorter than the response timeout value) to check whether an expected server response
173  * has been received as well as performing other application logic in the same thread context.
174  */
175 #define democonfigRECEIVE_SERVER_RESPONSE_BLOCK_TIME_MS    ( 200 )
176 
177 /**
178  * @brief Set the stack size of the main demo task.
179  *
180  * In the Windows port, this stack only holds a structure. The actual
181  * stack is created by an operating system thread.
182  */
183 #define democonfigDEMO_STACKSIZE                           configMINIMAL_STACK_SIZE
184 
185 
186 #endif /* DEMO_CONFIG_H */
187