19#if COAP_MEMORY_TYPE_TRACK
26#if defined(RIOT_VERSION) && defined(MODULE_MEMARRAY)
48#ifndef COAP_MAX_STRING_SIZE
49#define COAP_MAX_STRING_SIZE (64U)
56#ifndef COAP_MAX_STRINGS
57#define COAP_MAX_STRINGS (16U)
64#ifndef COAP_MAX_ENDPOINTS
66#define COAP_MAX_ENDPOINTS (4U)
68#define COAP_MAX_ENDPOINTS (2U)
76#ifndef COAP_MAX_RESOURCES
77#define COAP_MAX_RESOURCES (8U)
84#ifndef COAP_MAX_ATTRIBUTES
85#define COAP_MAX_ATTRIBUTES \
86 ((COAP_MAX_RESOURCES) * 4U)
95#ifndef COAP_MAX_ATTRIBUTE_STRINGS
96#define COAP_MAX_ATTRIBUTE_STRINGS (COAP_MAX_ATTRIBUTES)
103#ifndef COAP_MAX_ATTRIBUTE_SIZE
104#define COAP_MAX_ATTRIBUTE_SIZE (16U)
111#ifndef COAP_MAX_PACKETS
112#define COAP_MAX_PACKETS (4U)
119#ifndef COAP_MAX_NODES
120#define COAP_MAX_NODES (COAP_MAX_PACKETS)
127#ifndef COAP_MAX_CONTEXTS
128#define COAP_MAX_CONTEXTS (1U)
136#define COAP_MAX_PDUS (4U)
143#ifndef COAP_MAX_DTLS_SESSIONS
144#define COAP_MAX_DTLS_SESSIONS (2U)
151#ifndef COAP_MAX_SESSIONS
152#define COAP_MAX_SESSIONS (4U)
159#ifndef COAP_MAX_OPTIONS
160#define COAP_MAX_OPTIONS (16U)
167#ifndef COAP_MAX_OPTION_SIZE
168#define COAP_MAX_OPTION_SIZE (16U)
175#ifndef COAP_MAX_CACHE_KEYS
176#define COAP_MAX_CACHE_KEYS (2U)
183#ifndef COAP_MAX_CACHE_ENTRIES
184#define COAP_MAX_CACHE_ENTRIES (2U)
191#ifndef COAP_MAX_LG_CRCVS
192#if COAP_CLIENT_SUPPORT
193#define COAP_MAX_LG_CRCVS (1U)
195#define COAP_MAX_LG_CRCVS (0U)
203#ifndef COAP_MAX_LG_SRCVS
204#if COAP_SERVER_SUPPORT
205#define COAP_MAX_LG_SRCVS (2U)
207#define COAP_MAX_LG_SRCVS (0U)
215#ifndef COAP_MAX_LG_XMITS
216#if COAP_SERVER_SUPPORT
217#define COAP_MAX_LG_XMITS (2U)
219#define COAP_MAX_LG_XMITS (1U)
238static union memstr_t string_storage_data[COAP_MAX_STRINGS];
239static memarray_t string_storage;
241#if COAP_SERVER_SUPPORT
243static memarray_t endpoint_storage;
245static union attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
246static memarray_t attr_storage;
248static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
249static memarray_t resattr_storage;
253static memarray_t pkt_storage;
256static memarray_t node_storage;
259static memarray_t context_storage;
261static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
262static memarray_t pdu_storage;
268 char buf[COAP_DEFAULT_MAX_PDU_RX_SIZE];
271static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
272static memarray_t pdubuf_storage;
274#if COAP_SERVER_SUPPORT
276static memarray_t resource_storage;
279#ifdef COAP_WITH_LIBTINYDTLS
280#undef PACKAGE_BUGREPORT
283static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
284static memarray_t dtls_storage;
288static memarray_t session_storage;
293 char optbuf[COAP_MAX_OPTION_SIZE];
295static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
296static memarray_t option_storage;
298#if COAP_SERVER_SUPPORT
300static memarray_t cache_key_storage;
303static memarray_t cache_entry_storage;
306#if COAP_CLIENT_SUPPORT
307static coap_lg_crcv_t cache_lg_crcv_storage_data[COAP_MAX_LG_CRCVS];
308static memarray_t cache_lg_crcv_storage;
311#if COAP_SERVER_SUPPORT
312static coap_lg_srcv_t cache_lg_srcv_storage_data[COAP_MAX_LG_SRCVS];
313static memarray_t cache_lg_srcv_storage;
315static coap_lg_xmit_t cache_lg_xmit_storage_data[COAP_MAX_LG_XMITS];
316static memarray_t cache_lg_xmit_storage;
319#define INIT_STORAGE(Storage, Count) \
320 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
322#define STORAGE_PTR(Storage) (&(Storage ## _storage))
326 INIT_STORAGE(
string, COAP_MAX_STRINGS);
327#if COAP_SERVER_SUPPORT
328 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
329 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
331 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
332 INIT_STORAGE(node, COAP_MAX_NODES);
333 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
334 INIT_STORAGE(pdu, COAP_MAX_PDUS);
335 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
336#if COAP_SERVER_SUPPORT
337 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
338 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
340#ifdef COAP_WITH_LIBTINYDTLS
341 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
343 INIT_STORAGE(session, COAP_MAX_SESSIONS);
344 INIT_STORAGE(option, COAP_MAX_OPTIONS);
345#if COAP_SERVER_SUPPORT
346 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
347 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
349#if COAP_CLIENT_SUPPORT
350 INIT_STORAGE(cache_lg_crcv, COAP_MAX_LG_CRCVS);
352#if COAP_SERVER_SUPPORT
353 INIT_STORAGE(cache_lg_srcv, COAP_MAX_LG_SRCVS);
354 INIT_STORAGE(cache_lg_xmit, COAP_MAX_LG_XMITS);
361#if COAP_SERVER_SUPPORT
365 return &attr_storage;
370 return &node_storage;
372 return STORAGE_PTR(context);
373#if COAP_SERVER_SUPPORT
375 return &endpoint_storage;
380 return &pdubuf_storage;
381#if COAP_SERVER_SUPPORT
383 return &resource_storage;
385 return &resattr_storage;
387#ifdef COAP_WITH_LIBTINYDTLS
389 return &dtls_storage;
392 return &session_storage;
394 return &option_storage;
395#if COAP_SERVER_SUPPORT
397 return &cache_key_storage;
399 return &cache_entry_storage;
401#if COAP_CLIENT_SUPPORT
403 return &cache_lg_crcv_storage;
405#if COAP_SERVER_SUPPORT
407 return &cache_lg_srcv_storage;
409 return &cache_lg_xmit_storage;
414 return &string_storage;
420 memarray_t *container = get_container(type);
424 if (size > container->size) {
425 coap_log_warn(
"coap_malloc_type: Requested memory exceeds maximum object "
426 "size (type %d, size %zu, max %zd)\n",
427 type, size, container->size);
431 ptr = memarray_alloc(container);
433 coap_log_warn(
"coap_malloc_type: Failure (no free blocks) for type %d\n",
435#if COAP_MEMORY_TYPE_TRACK
438 track_counts[type]++;
439 if (track_counts[type] > peak_counts[type])
440 peak_counts[type] = track_counts[type];
450#if COAP_MEMORY_TYPE_TRACK
453 track_counts[type]--;
456 memarray_free(get_container(type),
object);
461 memarray_t *container = get_container(type);
466 if (size > container->size) {
467 coap_log_warn(
"coap_realloc_type: Requested memory exceeds maximum object "
468 "size (type %d, size %zu, max %zd)\n",
469 type, size, container->size);
483#if defined(__ZEPHYR__)
485#include <zephyr/kernel.h>
496 ptr = k_malloc(size);
497#if COAP_MEMORY_TYPE_TRACK
500 track_counts[type]++;
501 if (track_counts[type] > peak_counts[type])
502 peak_counts[type] = track_counts[type];
515#if KERNEL_VERSION_NUMBER >= 0x30700
516 ptr = k_realloc(p, size);
519 ptr = k_malloc(size);
525#if COAP_MEMORY_TYPE_TRACK
529 track_counts[type]++;
530 if (track_counts[type] > peak_counts[type])
531 peak_counts[type] = track_counts[type];
542#if COAP_MEMORY_TYPE_TRACK
545 track_counts[type]--;
550#elif defined(HAVE_MALLOC) || defined(__MINGW32__)
563#if COAP_MEMORY_TYPE_TRACK
566 track_counts[type]++;
567 if (track_counts[type] > peak_counts[type])
568 peak_counts[type] = track_counts[type];
581 ptr = realloc(p, size);
582#if COAP_MEMORY_TYPE_TRACK
586 track_counts[type]++;
587 if (track_counts[type] > peak_counts[type])
588 peak_counts[type] = track_counts[type];
599#if COAP_MEMORY_TYPE_TRACK
602 track_counts[type]--;
610#include "lib/heapmem.h"
618 void *ptr = heapmem_alloc(size);
620#if COAP_MEMORY_TYPE_TRACK
623 track_counts[type]++;
624 if (track_counts[type] > peak_counts[type])
625 peak_counts[type] = track_counts[type];
635 void *ptr = heapmem_realloc(p, size);
636#if COAP_MEMORY_TYPE_TRACK
640 track_counts[type]++;
641 if (track_counts[type] > peak_counts[type])
642 peak_counts[type] = track_counts[type];
652#if COAP_MEMORY_TYPE_TRACK
655 track_counts[type]--;
668#define MAKE_CASE(n) case n: name = #n; break
671#if COAP_MEMORY_TYPE_TRACK
674 coap_log(level,
"* Memory type counts\n");
676 const char *name =
"?";
713 coap_log(level,
"* %-20s in-use %3d peak %3d failed %2d\n",
714 name, track_counts[i], peak_counts[i], fail_counts[i]);
Library specific build wrapper for coap_internal.h.
void coap_dump_memory_type_counts(coap_log_t level)
Dumps the current usage of malloc'd memory types.
void coap_memory_init(void)
Initializes libcoap's memory management.
coap_memory_tag_t
Type specifiers for coap_malloc_type().
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
Pre-defined constants that reflect defaults for CoAP.
Generic resource handling.
Defines the application visible session information.
#define coap_log_warn(...)
#define coap_log(level,...)
Logging function.
struct coap_string_t coap_string_t
CoAP string data definition.
Limits the number of subscribers for each resource that this server support.
The CoAP stack's global state is stored in a coap_context_t object.
Abstraction of virtual endpoint that can be attached to coap_context_t.
Structure to hold large body (many blocks) client receive information.
Structure to hold large body (many blocks) server receive information.
Structure to hold large body (many blocks) transmission information.
Representation of chained list of CoAP options to install.
Abstraction of resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition.