49#define UNICOAP_DEBUG_PREFIX "coap"
52# define _UNICOAP_NEED_HAVE "(need %" PRIuSIZE ", have %" PRIuSIZE ")"
63# define _UNICOAP_PREFIX_DEBUG(category, ...) DEBUG(UNICOAP_DEBUG_PREFIX category ": " __VA_ARGS__)
64# define UNICOAP_DEBUG(...) _UNICOAP_PREFIX_DEBUG("", __VA_ARGS__)
65# define _OPTIONS_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".options", __VA_ARGS__)
66# define _MESSAGING_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".messaging", __VA_ARGS__)
67# define _STATE_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".state", __VA_ARGS__)
68# define _STATE_EVENT_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".state.sched", __VA_ARGS__)
69# define _STATE_NOTIF_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".state.notif", __VA_ARGS__)
70# define _TRANSPORT_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".transport", __VA_ARGS__)
71# define _SERVER_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".server", __VA_ARGS__)
72# define _CLIENT_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".client", __VA_ARGS__)
73# define _URI_DEBUG(...) _UNICOAP_PREFIX_DEBUG(".uri", __VA_ARGS__)
74# define API_WARNING(message) "WARNING: " message "\n"
75# define API_ERROR(message) "ERROR: " message "\n"
76# define API_MISUSE(message) "API MISUSE: " message "\n"
77# define INTERNAL_ERROR(message) "BUG: " message "\n"
78# define FIXIT(message) "+++ FIXIT: " message "\n"
85# define DEBUG_ENDPOINT(endpoint) unicoap_print_endpoint(endpoint)
89# define DEBUG_FLAGS(flags, role) unicoap_print_flags(flags, role)
94# define DEBUG_ENDPOINT(endpoint) (void)endpoint
98# define DEBUG_FLAGS(flags, role) \
104# if IS_ACTIVE(CONFIG_UNICOAP_ASSIST)
107# define unicoap_assist(...) \
109 if (IS_ACTIVE(CONFIG_UNICOAP_ASSIST) || IS_ACTIVE(CONFIG_UNICOAP_DEBUG_LOGGING)) { \
110 printf(__VA_ARGS__); \
127#define UNICOAP_THREAD_IDENTIFIER "unicoap"
153#if IS_USED(MODULE_UNICOAP_SERVER) || defined(DOXYGEN)
158#if UNICOAP_HAVE_CLIENT_STATE
168#if IS_USED(MODULE_UNICOAP_SERVER)
178#if IS_USED(MODULE_UNICOAP_SERVER)
272# define _UNICOAP_OPTIONS_ALLOCA(_buf, _name, capacity, _static) \
273 uint8_t* _buf = alloca(capacity); \
274 unicoap_options_t* _name = alloca(sizeof(unicoap_options_t)); \
275 memset(_name, 0, sizeof(unicoap_options_t)); \
276 (_name)->entries->data = _buf; \
277 (_name)->storage_capacity = capacity;
293#define UNICOAP_OPTIONS_ALLOCA(name, capacity) \
294 _UNICOAP_OPTIONS_ALLOCA(_CONCAT3(name, _storage, __LINE__), name, capacity,)
308#define UNICOAP_DECL_RECEIVER_STORAGE \
309 uint8_t unicoap_receiver_buffer[CONFIG_UNICOAP_PDU_SIZE_MAX]
314#define UNICOAP_DECL_RECEIVER_STORAGE_EXTERN extern UNICOAP_DECL_RECEIVER_STORAGE
346 _TRANSPORT_DEBUG(
"truncated\n");
347 _TRANSPORT_DEBUG(
"warning: recv storage too small, need at least %" PRIdSIZE "\n",
348 received + *chunk_size);
357static inline void __debug_hex(
const uint8_t* buffer,
size_t size)
359 for (
size_t i = 0; i < size; i += 1) {
360 printf(
"%02X", buffer[i]);
364# define _UNICOAP_DEBUG_HEX(bytes, size) \
366 if (ENABLE_DEBUG) { \
367 __debug_hex(bytes, size); \
Platform-independent access to architecture details.
Bitfield operations on bitfields of arbitrary length.
int16_t kernel_pid_t
Unique process identifier.
#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.
#define CONFIG_UNICOAP_CLIENT_MEMOS_CAPACITY
Maximum number of pending requests that can be started using the client API.
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.
int unicoap_init_slipmux(event_queue_t *queue)
Initializes the CoAP over Slipmux driver on the given queue.
int unicoap_deinit_slipmux(event_queue_t *queue)
Deinitializes the CoAP over Slipmux 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.
kernel_pid_t _unicoap_pid
PID of unicoap thread.
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.