48#define UNICOAP_DEBUG_PREFIX "coap"
51# define _UNICOAP_NEED_HAVE "(need %" PRIuSIZE ", have %" PRIuSIZE ")"
62# define _UNICOAP_PREFIX_DEBUG(category, ...) DEBUG(UNICOAP_DEBUG_PREFIX category ": " __VA_ARGS__)
63# define UNICOAP_DEBUG(...) _UNICOAP_PREFIX_DEBUG("", __VA_ARGS__)
64# define _OPTIONS_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".options", __VA_ARGS__)
65# define _MESSAGING_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".messaging", __VA_ARGS__)
66# define _STATE_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".state", __VA_ARGS__)
67# define _TRANSPORT_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".transport", __VA_ARGS__)
68# define _SERVER_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".server", __VA_ARGS__)
69# define API_WARNING(message) "WARNING: " message "\n"
70# define API_ERROR(message) "ERROR: " message "\n"
71# define API_MISUSE(message) "API MISUSE: " message "\n"
72# define INTERNAL_ERROR(message) "BUG: " message "\n"
73# define FIXIT(message) "+++ FIXIT: " message "\n"
80# define DEBUG_ENDPOINT(endpoint) unicoap_print_endpoint(endpoint)
84# define DEBUG_FLAGS(flags, role) unicoap_print_flags(flags, role)
89# define DEBUG_ENDPOINT(endpoint) (void)endpoint
93# define DEBUG_FLAGS(flags, role) \
99# if IS_ACTIVE(CONFIG_UNICOAP_ASSIST)
102# define unicoap_assist(...) \
104 if (IS_ACTIVE(CONFIG_UNICOAP_ASSIST) || IS_ACTIVE(CONFIG_UNICOAP_DEBUG_LOGGING)) { \
105 printf(__VA_ARGS__); \
122#define UNICOAP_THREAD_IDENTIFIER "unicoap"
145#if IS_USED(MODULE_UNICOAP_SERVER) || defined(DOXYGEN)
155#if IS_USED(MODULE_UNICOAP_SERVER)
165#if IS_USED(MODULE_UNICOAP_SERVER)
258#define UNICOAP_DECL_RECEIVER_STORAGE \
259 uint8_t unicoap_receiver_buffer[CONFIG_UNICOAP_PDU_SIZE_MAX]
264#define UNICOAP_DECL_RECEIVER_STORAGE_EXTERN extern UNICOAP_DECL_RECEIVER_STORAGE
296 _TRANSPORT_DEBUG(
"truncated\n");
297 _TRANSPORT_DEBUG(
"warning: recv storage too small, need at least %" PRIdSIZE "\n",
298 received + *chunk_size);
307static inline void __debug_hex(
const uint8_t* buffer,
size_t size)
309 for (
size_t i = 0; i < size; i += 1) {
310 printf(
"%02X", buffer[i]);
314# define _UNICOAP_DEBUG_HEX(bytes, size) \
316 if (ENABLE_DEBUG) { \
317 __debug_hex(bytes, size); \
Platform-independent access to architecture details.
Bitfield operations on bitfields of arbitrary length.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
#define CONFIG_UNICOAP_PDU_SIZE_MAX
Capacity of internal buffers.
static unicoap_listener_t * unicoap_get_listeners(unicoap_state_t *state)
Gets listener array from state object.
int unicoap_init_rfc7252_common(event_queue_t *queue)
Initializes the common RFC 7252 driver on the given queue.
void unicoap_state_unlock(void)
Unlocks internal state lock.
int unicoap_init_udp(event_queue_t *queue)
Initializes the CoAP over UDP driver on the given queue.
int unicoap_resource_find(const unicoap_packet_t *packet, const unicoap_resource_t **resource_ptr, const unicoap_listener_t **listener_ptr)
Tries to find a resource for the given packet.
int unicoap_init_dtls(event_queue_t *queue)
Initializes the CoAP over DTLS over UDP driver on the given queue.
void unicoap_assist_emit_diagnostic_missing_driver(unicoap_proto_t proto)
Emit a diagnostic stating that a driver is missing.
static bool unicoap_transport_truncate_received(size_t *chunk_size, size_t received)
Determines whether the chunk of the given size must be truncated to fit into a buffer of size CONFIG_...
int unicoap_resource_handle_well_known_core(unicoap_message_t *message, const unicoap_aux_t *aux, unicoap_request_context_t *ctx, void *arg)
Default resource handler for /.well-known/core
int unicoap_deinit_dtls(event_queue_t *queue)
Deinitializes the CoAP over DTLS over UDP driver on the given queue.
void unicoap_state_lock(void)
Locks internal state lock.
int unicoap_resource_match_request_default(const unicoap_listener_t *listener, const unicoap_resource_t **resource_ptr, const unicoap_message_t *request, const unicoap_endpoint_t *endpoint)
Default request-resource matcher for listeners.
int unicoap_deinit_rfc7252_common(event_queue_t *queue)
DeiInitializes the common RFC 7252 driver on the given queue.
int unicoap_deinit_udp(event_queue_t *queue)
Deinitializes the CoAP over UDP driver on the given queue.
static void unicoap_set_listeners(unicoap_state_t *state, unicoap_listener_t *listeners)
Sets listener array on state object to listeners.
struct unicoap_listener unicoap_listener_t
Typealias for unicoap_listener.
struct unicoap_resource unicoap_resource_t
CoAP resource.
unicoap_proto_t
Transport protocol CoAP is used over.
#define PRIdSIZE
Macro holding the format specifier to print an ssize_t variable in decimal representation.
struct PTRTAG event_queue_t
event queue structure
Mutex for thread synchronization.
Common interface to the software PRNG.
Auxiliary exchange information.
A type acting as an envelope for a message and data connected, like endpoints.
Request context used to send a response to a given request.
Container the unicoap stacks keeps state in.
unicoap_listener_t * listeners
Groups of resources.
mutex_t lock
Used when allocating listener, transaction, carbon copy, observer, or registration.