1c87c5fbaSopenharmony_ci/*
2c87c5fbaSopenharmony_ci * coap_debug.h -- debug utilities
3c87c5fbaSopenharmony_ci *
4c87c5fbaSopenharmony_ci * Copyright (C) 2010-2011,2014-2023 Olaf Bergmann <bergmann@tzi.org>
5c87c5fbaSopenharmony_ci *
6c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
7c87c5fbaSopenharmony_ci *
8c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see README for terms
9c87c5fbaSopenharmony_ci * of use.
10c87c5fbaSopenharmony_ci */
11c87c5fbaSopenharmony_ci
12c87c5fbaSopenharmony_ci/**
13c87c5fbaSopenharmony_ci * @file coap_debug.h
14c87c5fbaSopenharmony_ci * @brief CoAP Logging support
15c87c5fbaSopenharmony_ci */
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci#ifndef COAP_DEBUG_H_
18c87c5fbaSopenharmony_ci#define COAP_DEBUG_H_
19c87c5fbaSopenharmony_ci
20c87c5fbaSopenharmony_ci/**
21c87c5fbaSopenharmony_ci * @ingroup application_api
22c87c5fbaSopenharmony_ci * @defgroup logging Logging Support
23c87c5fbaSopenharmony_ci * API for logging support
24c87c5fbaSopenharmony_ci * @{
25c87c5fbaSopenharmony_ci */
26c87c5fbaSopenharmony_ci
27c87c5fbaSopenharmony_ci#ifndef COAP_DEBUG_FD
28c87c5fbaSopenharmony_ci/**
29c87c5fbaSopenharmony_ci * Used for output for @c COAP_LOG_OSCORE to @c COAP_LOG_ERR.
30c87c5fbaSopenharmony_ci */
31c87c5fbaSopenharmony_ci#define COAP_DEBUG_FD stdout
32c87c5fbaSopenharmony_ci#endif
33c87c5fbaSopenharmony_ci
34c87c5fbaSopenharmony_ci#ifndef COAP_ERR_FD
35c87c5fbaSopenharmony_ci/**
36c87c5fbaSopenharmony_ci * Used for output for @c COAP_LOG_CRIT to @c COAP_LOG_EMERG.
37c87c5fbaSopenharmony_ci */
38c87c5fbaSopenharmony_ci#define COAP_ERR_FD stderr
39c87c5fbaSopenharmony_ci#endif
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_ci#ifndef COAP_MAX_LOGGING_LEVEL
42c87c5fbaSopenharmony_ci#define COAP_MAX_LOGGING_LEVEL 8
43c87c5fbaSopenharmony_ci#endif /* ! COAP_MAX_LOGGING_LEVEL */
44c87c5fbaSopenharmony_ci
45c87c5fbaSopenharmony_ci/**
46c87c5fbaSopenharmony_ci * Logging type.  These should be used where possible in the code instead
47c87c5fbaSopenharmony_ci * of the syslog definitions, or alternatively use the coap_log_*() functions
48c87c5fbaSopenharmony_ci * to reduce line length.
49c87c5fbaSopenharmony_ci */
50c87c5fbaSopenharmony_citypedef enum {
51c87c5fbaSopenharmony_ci  COAP_LOG_EMERG = 0,  /* 0 */
52c87c5fbaSopenharmony_ci  COAP_LOG_ALERT,      /* 1 */
53c87c5fbaSopenharmony_ci  COAP_LOG_CRIT,       /* 2 */
54c87c5fbaSopenharmony_ci  COAP_LOG_ERR,        /* 3 */
55c87c5fbaSopenharmony_ci  COAP_LOG_WARN,       /* 4 */
56c87c5fbaSopenharmony_ci  COAP_LOG_NOTICE,     /* 5 */
57c87c5fbaSopenharmony_ci  COAP_LOG_INFO,       /* 6 */
58c87c5fbaSopenharmony_ci  COAP_LOG_DEBUG,      /* 7 */
59c87c5fbaSopenharmony_ci  COAP_LOG_OSCORE,     /* 8 */
60c87c5fbaSopenharmony_ci  COAP_LOG_DTLS_BASE,
61c87c5fbaSopenharmony_ci#define COAP_LOG_CIPHERS COAP_LOG_DTLS_BASE /* For backward compatability */
62c87c5fbaSopenharmony_ci} coap_log_t;
63c87c5fbaSopenharmony_ci
64c87c5fbaSopenharmony_ci/*
65c87c5fbaSopenharmony_ci * These have the same values, but can be used in #if tests for better
66c87c5fbaSopenharmony_ci * readability
67c87c5fbaSopenharmony_ci */
68c87c5fbaSopenharmony_ci#define _COAP_LOG_EMERG  0
69c87c5fbaSopenharmony_ci#define _COAP_LOG_ALERT  1
70c87c5fbaSopenharmony_ci#define _COAP_LOG_CRIT   2
71c87c5fbaSopenharmony_ci#define _COAP_LOG_ERR    3
72c87c5fbaSopenharmony_ci#define _COAP_LOG_WARN   4
73c87c5fbaSopenharmony_ci#define _COAP_LOG_NOTICE 5
74c87c5fbaSopenharmony_ci#define _COAP_LOG_INFO   6
75c87c5fbaSopenharmony_ci#define _COAP_LOG_DEBUG  7
76c87c5fbaSopenharmony_ci#define _COAP_LOG_OSCORE 8
77c87c5fbaSopenharmony_ci
78c87c5fbaSopenharmony_ciCOAP_STATIC_INLINE void
79c87c5fbaSopenharmony_cicoap_no_log(void) { }
80c87c5fbaSopenharmony_ci
81c87c5fbaSopenharmony_ci#define coap_log_emerg(...) coap_log(COAP_LOG_EMERG, __VA_ARGS__)
82c87c5fbaSopenharmony_ci
83c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_ALERT)
84c87c5fbaSopenharmony_ci#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __VA_ARGS__)
85c87c5fbaSopenharmony_ci#else
86c87c5fbaSopenharmony_ci#define coap_log_alert(...) coap_no_log()
87c87c5fbaSopenharmony_ci#endif
88c87c5fbaSopenharmony_ci
89c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_CRIT)
90c87c5fbaSopenharmony_ci#define coap_log_crit(...) coap_log(COAP_LOG_CRIT, __VA_ARGS__)
91c87c5fbaSopenharmony_ci#else
92c87c5fbaSopenharmony_ci#define coap_log_crit(...) coap_no_log()
93c87c5fbaSopenharmony_ci#endif
94c87c5fbaSopenharmony_ci
95c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_ERR)
96c87c5fbaSopenharmony_ci#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
97c87c5fbaSopenharmony_ci#else
98c87c5fbaSopenharmony_ci#define coap_log_err(...) coap_no_log()
99c87c5fbaSopenharmony_ci#endif
100c87c5fbaSopenharmony_ci
101c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
102c87c5fbaSopenharmony_ci#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
103c87c5fbaSopenharmony_ci#else
104c87c5fbaSopenharmony_ci#define coap_log_warn(...) coap_no_log()
105c87c5fbaSopenharmony_ci#endif
106c87c5fbaSopenharmony_ci
107c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_INFO)
108c87c5fbaSopenharmony_ci#define coap_log_info(...) coap_log(COAP_LOG_INFO, __VA_ARGS__)
109c87c5fbaSopenharmony_ci#else
110c87c5fbaSopenharmony_ci#define coap_log_info(...) coap_no_log()
111c87c5fbaSopenharmony_ci#endif
112c87c5fbaSopenharmony_ci
113c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_NOTICE)
114c87c5fbaSopenharmony_ci#define coap_log_notice(...) coap_log(COAP_LOG_NOTICE, __VA_ARGS__)
115c87c5fbaSopenharmony_ci#else
116c87c5fbaSopenharmony_ci#define coap_log_notice(...) coap_no_log()
117c87c5fbaSopenharmony_ci#endif
118c87c5fbaSopenharmony_ci
119c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG)
120c87c5fbaSopenharmony_ci#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
121c87c5fbaSopenharmony_ci#else
122c87c5fbaSopenharmony_ci#define coap_log_debug(...) coap_no_log()
123c87c5fbaSopenharmony_ci#endif
124c87c5fbaSopenharmony_ci
125c87c5fbaSopenharmony_ci#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_OSCORE)
126c87c5fbaSopenharmony_ci#define coap_log_oscore(...) coap_log(COAP_LOG_OSCORE, __VA_ARGS__)
127c87c5fbaSopenharmony_ci#else
128c87c5fbaSopenharmony_ci#define coap_log_oscore(...) coap_no_log()
129c87c5fbaSopenharmony_ci#endif
130c87c5fbaSopenharmony_ci
131c87c5fbaSopenharmony_ci/*
132c87c5fbaSopenharmony_ci * These entries are left here for backward compatability in applications
133c87c5fbaSopenharmony_ci * (which should really "#include <syslog.h>").
134c87c5fbaSopenharmony_ci * and MUST NOT be used anywhere within the libcoap code.
135c87c5fbaSopenharmony_ci *
136c87c5fbaSopenharmony_ci * If clashes occur during a particilar OS port, they can be safely deleted.
137c87c5fbaSopenharmony_ci *
138c87c5fbaSopenharmony_ci * In a future update, they will get removed.
139c87c5fbaSopenharmony_ci */
140c87c5fbaSopenharmony_ci#if !defined(RIOT_VERSION) && !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
141c87c5fbaSopenharmony_ci#ifndef LOG_EMERG
142c87c5fbaSopenharmony_ci# define LOG_EMERG  COAP_LOG_EMERG
143c87c5fbaSopenharmony_ci#endif
144c87c5fbaSopenharmony_ci#ifndef LOG_ALERT
145c87c5fbaSopenharmony_ci# define LOG_ALERT  COAP_LOG_ALERT
146c87c5fbaSopenharmony_ci#endif
147c87c5fbaSopenharmony_ci#ifndef LOG_CRIT
148c87c5fbaSopenharmony_ci# define LOG_CRIT   COAP_LOG_CRIT
149c87c5fbaSopenharmony_ci#endif
150c87c5fbaSopenharmony_ci#ifndef LOG_ERR
151c87c5fbaSopenharmony_ci# define LOG_ERR    COAP_LOG_ERR
152c87c5fbaSopenharmony_ci#endif
153c87c5fbaSopenharmony_ci#ifndef LOG_WARNING
154c87c5fbaSopenharmony_ci# define LOG_WARNING COAP_LOG_WARN
155c87c5fbaSopenharmony_ci#endif
156c87c5fbaSopenharmony_ci#ifndef LOG_NOTICE
157c87c5fbaSopenharmony_ci# define LOG_NOTICE COAP_LOG_NOTICE
158c87c5fbaSopenharmony_ci#endif
159c87c5fbaSopenharmony_ci#ifndef LOG_INFO
160c87c5fbaSopenharmony_ci# define LOG_INFO   COAP_LOG_INFO
161c87c5fbaSopenharmony_ci#endif
162c87c5fbaSopenharmony_ci#ifndef LOG_DEBUG
163c87c5fbaSopenharmony_ci# define LOG_DEBUG  COAP_LOG_DEBUG
164c87c5fbaSopenharmony_ci#endif
165c87c5fbaSopenharmony_ci#endif /* ! RIOT_VERSION && ! WITH_LWIP && ! WITH_CONTIKI */
166c87c5fbaSopenharmony_ci
167c87c5fbaSopenharmony_ci/**
168c87c5fbaSopenharmony_ci * Get the current logging level.
169c87c5fbaSopenharmony_ci *
170c87c5fbaSopenharmony_ci * @return One of the COAP_LOG_* values.
171c87c5fbaSopenharmony_ci */
172c87c5fbaSopenharmony_cicoap_log_t coap_get_log_level(void);
173c87c5fbaSopenharmony_ci
174c87c5fbaSopenharmony_ci/**
175c87c5fbaSopenharmony_ci * Sets the log level to the specified value.
176c87c5fbaSopenharmony_ci *
177c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values.
178c87c5fbaSopenharmony_ci */
179c87c5fbaSopenharmony_civoid coap_set_log_level(coap_log_t level);
180c87c5fbaSopenharmony_ci
181c87c5fbaSopenharmony_ci/**
182c87c5fbaSopenharmony_ci * Sets the (D)TLS logging level to the specified @p level.
183c87c5fbaSopenharmony_ci *
184c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values.
185c87c5fbaSopenharmony_ci */
186c87c5fbaSopenharmony_civoid coap_dtls_set_log_level(coap_log_t level);
187c87c5fbaSopenharmony_ci
188c87c5fbaSopenharmony_ci/**
189c87c5fbaSopenharmony_ci * Get the current (D)TLS logging.
190c87c5fbaSopenharmony_ci *
191c87c5fbaSopenharmony_ci * @return One of the COAP_LOG_* values.
192c87c5fbaSopenharmony_ci */
193c87c5fbaSopenharmony_cicoap_log_t coap_dtls_get_log_level(void);
194c87c5fbaSopenharmony_ci
195c87c5fbaSopenharmony_ci/**
196c87c5fbaSopenharmony_ci * Logging callback handler definition.
197c87c5fbaSopenharmony_ci *
198c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values, or if used for (D)TLS logging,
199c87c5fbaSopenharmony_ci *              COAP_LOG_DTLS_BASE + one of the COAP_LOG_* values.
200c87c5fbaSopenharmony_ci * @param message Zero-terminated string message to log.
201c87c5fbaSopenharmony_ci */
202c87c5fbaSopenharmony_citypedef void (*coap_log_handler_t)(coap_log_t level, const char *message);
203c87c5fbaSopenharmony_ci
204c87c5fbaSopenharmony_ci/**
205c87c5fbaSopenharmony_ci * Add a custom log callback handler.
206c87c5fbaSopenharmony_ci *
207c87c5fbaSopenharmony_ci * @param handler The logging handler to use or @p NULL to use default handler.
208c87c5fbaSopenharmony_ci *                 This handler will be used for both CoAP and (D)TLS logging.
209c87c5fbaSopenharmony_ci */
210c87c5fbaSopenharmony_civoid coap_set_log_handler(coap_log_handler_t handler);
211c87c5fbaSopenharmony_ci
212c87c5fbaSopenharmony_ci/**
213c87c5fbaSopenharmony_ci * Get the library package name.
214c87c5fbaSopenharmony_ci *
215c87c5fbaSopenharmony_ci * @return Zero-terminated string with the name of this library.
216c87c5fbaSopenharmony_ci */
217c87c5fbaSopenharmony_ciconst char *coap_package_name(void);
218c87c5fbaSopenharmony_ci
219c87c5fbaSopenharmony_ci/**
220c87c5fbaSopenharmony_ci * Get the library package version.
221c87c5fbaSopenharmony_ci *
222c87c5fbaSopenharmony_ci * @return Zero-terminated string with the library version.
223c87c5fbaSopenharmony_ci */
224c87c5fbaSopenharmony_ciconst char *coap_package_version(void);
225c87c5fbaSopenharmony_ci
226c87c5fbaSopenharmony_ci/**
227c87c5fbaSopenharmony_ci * Get the library package build.
228c87c5fbaSopenharmony_ci *
229c87c5fbaSopenharmony_ci * @return Zero-terminated string with the library build.
230c87c5fbaSopenharmony_ci */
231c87c5fbaSopenharmony_ciconst char *coap_package_build(void);
232c87c5fbaSopenharmony_ci
233c87c5fbaSopenharmony_ci/**
234c87c5fbaSopenharmony_ci * Writes the given text to @c COAP_ERR_FD (for @p level <= @c COAP_LOG_CRIT) or
235c87c5fbaSopenharmony_ci * @c COAP_DEBUG_FD (for @p level >= @c COAP_LOG_ERR). The text is output only
236c87c5fbaSopenharmony_ci * when @p level is below or equal to the log level that set by
237c87c5fbaSopenharmony_ci * coap_set_log_level().
238c87c5fbaSopenharmony_ci *
239c87c5fbaSopenharmony_ci * Internal function.
240c87c5fbaSopenharmony_ci *
241c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values.
242c87c5fbaSopenharmony_ci & @param format The format string to use.
243c87c5fbaSopenharmony_ci */
244c87c5fbaSopenharmony_ci#if (defined(__GNUC__))
245c87c5fbaSopenharmony_civoid coap_log_impl(coap_log_t level,
246c87c5fbaSopenharmony_ci                   const char *format, ...) __attribute__((format(printf, 2, 3)));
247c87c5fbaSopenharmony_ci#else
248c87c5fbaSopenharmony_civoid coap_log_impl(coap_log_t level, const char *format, ...);
249c87c5fbaSopenharmony_ci#endif
250c87c5fbaSopenharmony_ci
251c87c5fbaSopenharmony_ci#ifndef coap_log
252c87c5fbaSopenharmony_ci#ifdef WITH_CONTIKI
253c87c5fbaSopenharmony_ci#include <stdio.h>
254c87c5fbaSopenharmony_ci
255c87c5fbaSopenharmony_ci#ifndef LOG_CONF_LEVEL_COAP
256c87c5fbaSopenharmony_ci#define LOG_CONF_LEVEL_COAP 0 /* = LOG_LEVEL_NONE */
257c87c5fbaSopenharmony_ci#endif
258c87c5fbaSopenharmony_ci
259c87c5fbaSopenharmony_civoid coap_print_contiki_prefix(coap_log_t level);
260c87c5fbaSopenharmony_ci
261c87c5fbaSopenharmony_ci#define coap_log(level, ...) do { \
262c87c5fbaSopenharmony_ci    if (LOG_CONF_LEVEL_COAP && \
263c87c5fbaSopenharmony_ci        ((int)((level)) <= (int)coap_get_log_level())) { \
264c87c5fbaSopenharmony_ci      coap_print_contiki_prefix(level); \
265c87c5fbaSopenharmony_ci      printf(__VA_ARGS__); \
266c87c5fbaSopenharmony_ci    } \
267c87c5fbaSopenharmony_ci  } while(0)
268c87c5fbaSopenharmony_ci#else /* !WITH_CONTIKI */
269c87c5fbaSopenharmony_ci/**
270c87c5fbaSopenharmony_ci * Logging function.
271c87c5fbaSopenharmony_ci * Writes the given text to @c COAP_ERR_FD (for @p level <= @c COAP_LOG_CRIT) or @c
272c87c5fbaSopenharmony_ci * COAP_DEBUG_FD (for @p level >= @c COAP_LOG_ERR). The text is output only when
273c87c5fbaSopenharmony_ci * @p level is below or equal to the log level that set by coap_set_log_level().
274c87c5fbaSopenharmony_ci *
275c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values.
276c87c5fbaSopenharmony_ci */
277c87c5fbaSopenharmony_ci#define coap_log(level, ...) do { \
278c87c5fbaSopenharmony_ci    if ((int)((level))<=(int)coap_get_log_level()) \
279c87c5fbaSopenharmony_ci      coap_log_impl((level), __VA_ARGS__); \
280c87c5fbaSopenharmony_ci  } while(0)
281c87c5fbaSopenharmony_ci#endif /* !WITH_CONTIKI */
282c87c5fbaSopenharmony_ci#endif
283c87c5fbaSopenharmony_ci
284c87c5fbaSopenharmony_ci#ifndef coap_dtls_log
285c87c5fbaSopenharmony_ci/**
286c87c5fbaSopenharmony_ci * Logging function.
287c87c5fbaSopenharmony_ci * Writes the given text to @c COAP_ERR_FD (for @p level <= @c COAP_LOG_CRIT) or @c
288c87c5fbaSopenharmony_ci * COAP_DEBUG_FD (for @p level >= @c COAP_LOG_ERR). The text is output only when
289c87c5fbaSopenharmony_ci * @p level is below or equal to the log level that set by coap_dtls_set_log_level().
290c87c5fbaSopenharmony_ci *
291c87c5fbaSopenharmony_ci * @param level One of the COAP_LOG_* values.
292c87c5fbaSopenharmony_ci */
293c87c5fbaSopenharmony_ci#define coap_dtls_log(level, ...) do { \
294c87c5fbaSopenharmony_ci    if ((int)((level))<=(int)coap_dtls_get_log_level()) \
295c87c5fbaSopenharmony_ci      coap_log_impl((level)+COAP_LOG_DTLS_BASE, __VA_ARGS__); \
296c87c5fbaSopenharmony_ci  } while(0)
297c87c5fbaSopenharmony_ci#endif
298c87c5fbaSopenharmony_ci
299c87c5fbaSopenharmony_ci#include "coap_pdu.h"
300c87c5fbaSopenharmony_ci
301c87c5fbaSopenharmony_ci/**
302c87c5fbaSopenharmony_ci * Defines the output mode for the coap_show_pdu() function.
303c87c5fbaSopenharmony_ci *
304c87c5fbaSopenharmony_ci * @param use_fprintf @p 1 if the output is to use fprintf() (the default)
305c87c5fbaSopenharmony_ci *                    @p 0 if the output is to use coap_log().
306c87c5fbaSopenharmony_ci */
307c87c5fbaSopenharmony_civoid coap_set_show_pdu_output(int use_fprintf);
308c87c5fbaSopenharmony_ci
309c87c5fbaSopenharmony_ci/**
310c87c5fbaSopenharmony_ci * Display the contents of the specified @p pdu.
311c87c5fbaSopenharmony_ci * Note: The output method of coap_show_pdu() is dependent on the setting of
312c87c5fbaSopenharmony_ci * coap_set_show_pdu_output().
313c87c5fbaSopenharmony_ci *
314c87c5fbaSopenharmony_ci * @param level The required minimum logging level.
315c87c5fbaSopenharmony_ci * @param pdu The PDU to decode.
316c87c5fbaSopenharmony_ci */
317c87c5fbaSopenharmony_civoid coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
318c87c5fbaSopenharmony_ci
319c87c5fbaSopenharmony_ci/**
320c87c5fbaSopenharmony_ci * Display the current (D)TLS library linked with and built for version.
321c87c5fbaSopenharmony_ci *
322c87c5fbaSopenharmony_ci * @param level The required minimum logging level.
323c87c5fbaSopenharmony_ci */
324c87c5fbaSopenharmony_civoid coap_show_tls_version(coap_log_t level);
325c87c5fbaSopenharmony_ci
326c87c5fbaSopenharmony_ci/**
327c87c5fbaSopenharmony_ci * Build a string containing the current (D)TLS library linked with and
328c87c5fbaSopenharmony_ci * built for version.
329c87c5fbaSopenharmony_ci *
330c87c5fbaSopenharmony_ci * @param buffer The buffer to put the string into.
331c87c5fbaSopenharmony_ci * @param bufsize The size of the buffer to put the string into.
332c87c5fbaSopenharmony_ci *
333c87c5fbaSopenharmony_ci * @return A pointer to the provided buffer.
334c87c5fbaSopenharmony_ci */
335c87c5fbaSopenharmony_cichar *coap_string_tls_version(char *buffer, size_t bufsize);
336c87c5fbaSopenharmony_ci
337c87c5fbaSopenharmony_ci/**
338c87c5fbaSopenharmony_ci * Build a string containing the current (D)TLS library support
339c87c5fbaSopenharmony_ci *
340c87c5fbaSopenharmony_ci * @param buffer The buffer to put the string into.
341c87c5fbaSopenharmony_ci * @param bufsize The size of the buffer to put the string into.
342c87c5fbaSopenharmony_ci *
343c87c5fbaSopenharmony_ci * @return A pointer to the provided buffer.
344c87c5fbaSopenharmony_ci */
345c87c5fbaSopenharmony_cichar *coap_string_tls_support(char *buffer, size_t bufsize);
346c87c5fbaSopenharmony_ci
347c87c5fbaSopenharmony_ci/**
348c87c5fbaSopenharmony_ci * Print the address into the defined buffer.
349c87c5fbaSopenharmony_ci *
350c87c5fbaSopenharmony_ci * @param address The address to print.
351c87c5fbaSopenharmony_ci * @param buffer The buffer to print into.
352c87c5fbaSopenharmony_ci * @param size The size of the buffer to print into.
353c87c5fbaSopenharmony_ci *
354c87c5fbaSopenharmony_ci * @return The amount written into the buffer.
355c87c5fbaSopenharmony_ci */
356c87c5fbaSopenharmony_cisize_t coap_print_addr(const coap_address_t *address,
357c87c5fbaSopenharmony_ci                       unsigned char *buffer, size_t size);
358c87c5fbaSopenharmony_ci
359c87c5fbaSopenharmony_ci/**
360c87c5fbaSopenharmony_ci * Print the IP address into the defined buffer.
361c87c5fbaSopenharmony_ci *
362c87c5fbaSopenharmony_ci * @param address The address to print.
363c87c5fbaSopenharmony_ci * @param buffer The buffer to print into.
364c87c5fbaSopenharmony_ci * @param size The size of the buffer to print into.
365c87c5fbaSopenharmony_ci *
366c87c5fbaSopenharmony_ci * @return The pointer to provided buffer with as much of the IP address added
367c87c5fbaSopenharmony_ci *         as possible.
368c87c5fbaSopenharmony_ci */
369c87c5fbaSopenharmony_ciconst char *coap_print_ip_addr(const coap_address_t *address,
370c87c5fbaSopenharmony_ci                               char *buffer, size_t size);
371c87c5fbaSopenharmony_ci
372c87c5fbaSopenharmony_ci/** @} */
373c87c5fbaSopenharmony_ci
374c87c5fbaSopenharmony_ci/**
375c87c5fbaSopenharmony_ci * Set the packet loss level for testing.  This can be in one of two forms.
376c87c5fbaSopenharmony_ci *
377c87c5fbaSopenharmony_ci * Percentage : 0% to 100%.  Use the specified probability.
378c87c5fbaSopenharmony_ci * 0% is send all packets, 100% is drop all packets.
379c87c5fbaSopenharmony_ci *
380c87c5fbaSopenharmony_ci * List: A comma separated list of numbers or number ranges that are the
381c87c5fbaSopenharmony_ci * packets to drop.
382c87c5fbaSopenharmony_ci *
383c87c5fbaSopenharmony_ci * @param loss_level The defined loss level (percentage or list).
384c87c5fbaSopenharmony_ci *
385c87c5fbaSopenharmony_ci * @return @c 1 If loss level set, @c 0 if there is an error.
386c87c5fbaSopenharmony_ci */
387c87c5fbaSopenharmony_ciint coap_debug_set_packet_loss(const char *loss_level);
388c87c5fbaSopenharmony_ci
389c87c5fbaSopenharmony_ci#endif /* COAP_DEBUG_H_ */
390