1 /*
2  *  Copyright (c) 2020, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  *   This file includes compile-time configurations for the SRP (Service Registration Protocol) Client.
32  *
33  */
34 
35 #ifndef CONFIG_SRP_CLIENT_H_
36 #define CONFIG_SRP_CLIENT_H_
37 
38 /**
39  * @addtogroup config-srp-client
40  *
41  * @brief
42  *   This module includes configuration variables for the SRP Client.
43  *
44  * @{
45  *
46  */
47 
48 #include "config/misc.h"
49 
50 /**
51  * @def OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
52  *
53  * Define to 1 to enable SRP Client support.
54  *
55  */
56 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
57 #define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 0
58 #endif
59 
60 /**
61  * @def OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
62  *
63  * Define to 1 to enable SRP Client auto-start feature and its APIs.
64  *
65  * When enabled, the SRP client can be configured to automatically start when it detects the presence of an SRP server
66  * (by monitoring the Thread Network Data for SRP Server Service entries).
67  *
68  */
69 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
70 #define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE 1
71 #endif
72 
73 /**
74  * @def OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE
75  *
76  * Define the default mode (enabled or disabled) of auto-start mode.
77  *
78  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
79  *
80  */
81 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE
82 #define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE 1
83 #endif
84 
85 /**
86  * @def OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE
87  *
88  * Define to 1 to enable SRP client to switch server on failure (when auto-start feature is used).
89  *
90  * This config is only used when `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
91  *
92  * When enabled, the client will try to select the next server from entries in Thread Network Data when the current
93  * server rejects an SRP update or there is no response (timeout waiting for response from server).
94  *
95  */
96 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE
97 #define OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE 1
98 #endif
99 
100 /**
101  * @def OPENTHREAD_CONFIG_SRP_CLIENT_DISALLOW_SERVER_SWITCH_WITH_REGISTERED_HOST
102  *
103  * Define to 1 to disallow SRP client to switch server (when auto-start is used) on failure if host (or any services)
104  * were previously successfully registered with the currently selected server.
105  *
106  * This config is only applicable when `OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE` is enabled.
107  *
108  * If this is enabled, once SRP client successfully registers with an auto-start selected SRP server, it stays with
109  * the selected SRP server (even if future SRP updates fail or timeout) while the related server entry remains present
110  * in the Thread Network Data. If the entry is removed from Network Data, then SRP client will try to select a new
111  * server.
112  *
113  * Enabling this behavior would be useful allowing more aggressive switch logic (e.g., switch after fewer timeouts
114  * `OPENTHREAD_CONFIG_SRP_CLIENT_MAX_TIMEOUT_FAILURES_TO_SWITCH_SERVER`) while not allowing switch due to temporary
115  * failures on the currently selected server. This can help avoid situation where the old server may still remember the
116  * registered host/service info and client switching to a new server then failing due to name conflict (when new server
117  * probes for the host/service name original server would not allow new registration).
118  *
119  */
120 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_DISALLOW_SERVER_SWITCH_WITH_REGISTERED_HOST
121 #define OPENTHREAD_CONFIG_SRP_CLIENT_DISALLOW_SERVER_SWITCH_WITH_REGISTERED_HOST 1
122 #endif
123 
124 /**
125  * @def OPENTHREAD_CONFIG_SRP_CLIENT_MAX_TIMEOUT_FAILURES_TO_SWITCH_SERVER
126  *
127  * Specifies number of timeout failures to trigger a switch of server.
128  *
129  * This is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE` is used.
130  *
131  */
132 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_MAX_TIMEOUT_FAILURES_TO_SWITCH_SERVER
133 #define OPENTHREAD_CONFIG_SRP_CLIENT_MAX_TIMEOUT_FAILURES_TO_SWITCH_SERVER 3
134 #endif
135 
136 /**
137  * @def OPENTHREAD_CONFIG_SRP_CLIENT_DOMAIN_NAME_API_ENABLE
138  *
139  * Define to 1 for the SRP client implementation to provide APIs that get/set the domain name.
140  *
141  */
142 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_DOMAIN_NAME_API_ENABLE
143 #define OPENTHREAD_CONFIG_SRP_CLIENT_DOMAIN_NAME_API_ENABLE 0
144 #endif
145 
146 /**
147  * @def OPENTHREAD_CONFIG_SRP_CLIENT_SAVE_SELECTED_SERVER_ENABLE
148  *
149  * Define to 1 to enable SRP client feature to save the selected server in non-volatile settings.
150  *
151  * When enabled, the SRP client will save the selected server info by auto-start feature in the non-volatile settings
152  * and on a client restart (e.g., due to a device reset) it will select the same server when searching to discover and
153  * pick one from the Thread Network Data service entries. The server info is saved only after the host info is
154  * successfully registered with the server and if it is selected by auto-start from a network data SRP *unicast*
155  * service entry.
156  *
157  */
158 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_SAVE_SELECTED_SERVER_ENABLE
159 #define OPENTHREAD_CONFIG_SRP_CLIENT_SAVE_SELECTED_SERVER_ENABLE 1
160 #endif
161 
162 /**
163  * @def OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_LEASE
164  *
165  * Specifies the default requested lease interval (in seconds). Set to two hours.
166  *
167  */
168 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_LEASE
169 #define OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_LEASE (2 * 60 * 60)
170 #endif
171 
172 /**
173  * @def OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_KEY_LEASE
174  *
175  * Specifies the default requested key lease interval (in seconds). Set to 14 days.
176  *
177  */
178 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_KEY_LEASE
179 #define OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_KEY_LEASE (14 * 24 * 60 * 60)
180 #endif
181 
182 /**
183  * @def OPENTHREAD_CONFIG_SRP_CLIENT_LEASE_RENEW_GUARD_INTERVAL
184  *
185  * Specifies the guard interval (in seconds) for lease renew time. The guard interval determines how much earlier
186  * (relative to the lease expiration time) the SRP client will send an SRP update for lease renewal.
187  *
188  */
189 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_LEASE_RENEW_GUARD_INTERVAL
190 #define OPENTHREAD_CONFIG_SRP_CLIENT_LEASE_RENEW_GUARD_INTERVAL 120 // two minutes in seconds
191 #endif
192 
193 /**
194  * @def OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_NUMERATOR
195  *
196  * Specifies the numerator of early lease renewal factor.
197  *
198  * This value is used for opportunistic early refresh behave. When sending an SRP update, the services that are not yet
199  * expired but are close, are allowed to refresh early and are included in the SRP update.
200  *
201  * The "early lease renewal interval" is used to determine if a service can renew early. The interval is calculated by
202  * multiplying the accepted lease interval by the "early lease renewal factor" which is given as a fraction (numerator
203  * and denominator).
204  *
205  * If the factor is set to zero (numerator=0, denominator=1), the opportunistic early refresh behavior is disabled.
206  * If  denominator is set to zero (the factor is set to infinity), then all services (including previously registered
207  * ones) are always included in SRP update message.
208  *
209  * Default value is 1/2 (i.e., services that are within half of the lease interval are allowed to refresh early).
210  *
211  */
212 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_NUMERATOR
213 #define OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_NUMERATOR 1
214 #endif
215 
216 /**
217  * @def OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_DENOMINATOR
218  *
219  * Specifies the denominator of early lease renewal factor.
220  *
221  * Please see OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_NUMERATOR for more details.
222  *
223  */
224 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_DENOMINATOR
225 #define OPENTHREAD_CONFIG_SRP_CLIENT_EARLY_LEASE_RENEW_FACTOR_DENOMINATOR 2
226 #endif
227 
228 /**
229  * @def OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
230  *
231  * Specifies the minimum value (in msec) for the short random delay wait time before sending an update message.
232  *
233  * The random delay is chosen uniformly from the min up to max value `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY`.
234  *
235  * When there is a change (e.g., a new service is added/removed) that requires an update, the SRP client will wait for
236  * a short delay before preparing and sending an SRP update message to server. This allows user to provide more change
237  * that are then all sent in same update message. The delay is only applied on the first change that triggers an
238  * update message transmission. Subsequent changes (API calls) while waiting for the tx to start will not reset the
239  * delay timer.
240  *
241  */
242 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
243 #define OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY 10
244 #endif
245 
246 /**
247  * @def OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
248  *
249  * Specifies the maximum value (in msec) for the short random delay wait time before sending an update message.
250  *
251  * The random delay is chosen uniformly from the min `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY` up to max value.
252  *
253  * See `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY` for more details.
254  *
255  */
256 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY
257 #define OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY 700
258 #endif
259 
260 /**
261  * @def OPENTHREAD_CONFIG_SRP_CLIENT_MIN_RETRY_WAIT_INTERVAL
262  *
263  * Specifies the minimum wait interval (in msec) between SRP update message retries.
264  *
265  * The update message is retransmitted if there is no response from server or if server rejects the update. The wait
266  * interval starts from the minimum value and is increased by the growth factor every failure up to the max value.
267  *
268  */
269 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_MIN_RETRY_WAIT_INTERVAL
270 #define OPENTHREAD_CONFIG_SRP_CLIENT_MIN_RETRY_WAIT_INTERVAL 1800
271 #endif
272 
273 /**
274  * @def OPENTHREAD_CONFIG_SRP_CLIENT_MAX_RETRY_WAIT_INTERVAL
275  *
276  * Specifies the maximum wait interval (in msec) between SRP update message retries.
277  *
278  */
279 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_MAX_RETRY_WAIT_INTERVAL
280 #define OPENTHREAD_CONFIG_SRP_CLIENT_MAX_RETRY_WAIT_INTERVAL (1 * 60 * 60 * 1000) // 1 hour in ms.
281 #endif
282 
283 /**
284  * @def OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_WAIT_INTERVAL_JITTER
285  *
286  * Specifies jitter (in msec) for retry wait interval. If the current retry wait interval is smaller than the jitter
287  * then the wait interval itself is used as jitter (e.g., with jitter 500 msec and if retry interval is 300ms
288  * the retry interval is then randomly selected from [0, 2*300] ms).
289  *
290  */
291 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_WAIT_INTERVAL_JITTER
292 #define OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_WAIT_INTERVAL_JITTER 500
293 #endif
294 
295 /**
296  * @def OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_NUMERATOR
297  *
298  * Specifies the numerator of the retry wait interval growth factor fraction. The growth factor is represented as
299  * a fraction (e.g., for 1.5, we can use 15 as the numerator and 10 as the denominator).
300  *
301  */
302 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_NUMERATOR
303 #define OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_NUMERATOR 17
304 #endif
305 
306 /**
307  * @def OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_DENOMINATOR
308  *
309  * Specifies the denominator of the retry wait interval growth factor fraction.
310  *
311  */
312 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_DENOMINATOR
313 #define OPENTHREAD_CONFIG_SRP_CLIENT_RETRY_INTERVAL_GROWTH_FACTOR_DENOMINATOR 10
314 #endif
315 
316 /**
317  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE
318  *
319  * Define to 1 to enable SRP Client buffers and service pool feature.
320  *
321  */
322 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE
323 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
324 #endif
325 
326 /**
327  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_SERVICES
328  *
329  * Specifies number of service entries in the SRP client service pool.
330  *
331  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
332  *
333  */
334 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_SERVICES
335 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_SERVICES 2
336 #endif
337 
338 /**
339  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_HOST_ADDRESSES
340  *
341  * Specifies number of host IPv6 address entries in the SRP client buffers and service pool.
342  *
343  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
344  *
345  */
346 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_HOST_ADDRESSES
347 #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
348 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_HOST_ADDRESSES 10
349 #else
350 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_HOST_ADDRESSES 2
351 #endif
352 #endif
353 
354 /**
355  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_HOST_NAME_SIZE
356  *
357  * Specifies the size (number of chars) of host name string buffer in the SRP client buffers and service pool.
358  *
359  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
360  *
361  */
362 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_HOST_NAME_SIZE
363 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_HOST_NAME_SIZE 64
364 #endif
365 
366 /**
367  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_NAME_SIZE
368  *
369  * Specifies the size (number of chars) of service name string buffer in the SRP client buffers and service pool.
370  *
371  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
372  *
373  */
374 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_NAME_SIZE
375 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_NAME_SIZE 96
376 #endif
377 
378 /**
379  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_MAX_SUB_TYPES
380  *
381  * Specifies the maximum number of service subtype labels (array length) in the SRP client buffers and service pool.
382  *
383  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
384  *
385  */
386 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_MAX_SUB_TYPES
387 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_MAX_SUB_TYPES 6
388 #endif
389 
390 /**
391  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_INSTANCE_NAME_SIZE
392  *
393  * Specifies the size (number of chars) of service instance name string buffer in the SRP client buffers and service
394  * pool.
395  *
396  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
397  *
398  */
399 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_INSTANCE_NAME_SIZE
400 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_SERVICE_INSTANCE_NAME_SIZE 64
401 #endif
402 
403 /**
404  * @def OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_TXT_BUFFER_SIZE
405  *
406  * Specifies the size (number of bytes) of TXT record value buffer in the SRP client buffers and service pool.
407  *
408  * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE` is enabled.
409  *
410  */
411 #ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_TXT_BUFFER_SIZE
412 #define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_TXT_BUFFER_SIZE 64
413 #endif
414 
415 /**
416  * @}
417  *
418  */
419 
420 #endif // CONFIG_SRP_CLIENT_H_
421