18#if defined(RIOT_VERSION) && defined(MODULE_MEMARRAY)
40#ifndef COAP_MAX_STRING_SIZE
41#define COAP_MAX_STRING_SIZE (64U)
48#ifndef COAP_MAX_STRINGS
49#define COAP_MAX_STRINGS (16U)
56#ifndef COAP_MAX_ENDPOINTS
57#define COAP_MAX_ENDPOINTS (4U)
64#ifndef COAP_MAX_RESOURCES
65#define COAP_MAX_RESOURCES (8U)
72#ifndef COAP_MAX_ATTRIBUTES
73#define COAP_MAX_ATTRIBUTES \
74 ((COAP_MAX_RESOURCES) * 4U)
83#ifndef COAP_MAX_ATTRIBUTE_STRINGS
84#define COAP_MAX_ATTRIBUTE_STRINGS (COAP_MAX_ATTRIBUTES)
91#ifndef COAP_MAX_ATTRIBUTE_SIZE
92#define COAP_MAX_ATTRIBUTE_SIZE (16U)
99#ifndef COAP_MAX_PACKETS
100#define COAP_MAX_PACKETS (4U)
108#ifndef COAP_MAX_NODES
109#define COAP_MAX_NODES \
110 ((COAP_MAX_ENDPOINTS) * (COAP_MAX_PACKETS))
117#ifndef COAP_MAX_CONTEXTS
118#define COAP_MAX_CONTEXTS (1U)
127#define COAP_MAX_PDUS ((COAP_MAX_ENDPOINTS) * 4U)
134#ifndef COAP_MAX_DTLS_SESSIONS
135#define COAP_MAX_DTLS_SESSIONS (2U)
142#ifndef COAP_MAX_SESSIONS
143#define COAP_MAX_SESSIONS (COAP_MAX_ENDPOINTS)
150#ifndef COAP_MAX_OPTIONS
151#define COAP_MAX_OPTIONS (16U)
158#ifndef COAP_MAX_OPTION_SIZE
159#define COAP_MAX_OPTION_SIZE (16U)
166#ifndef COAP_MAX_CACHE_KEYS
167#define COAP_MAX_CACHE_KEYS (2U)
174#ifndef COAP_MAX_CACHE_ENTRIES
175#define COAP_MAX_CACHE_ENTRIES (2U)
182#ifndef COAP_MAX_LG_CRCVS
183#if COAP_CLIENT_SUPPORT
184#define COAP_MAX_LG_CRCVS (1U)
186#define COAP_MAX_LG_CRCVS (0U)
194#ifndef COAP_MAX_LG_SRCVS
195#if COAP_SERVER_SUPPORT
196#define COAP_MAX_LG_SRCVS (2U)
198#define COAP_MAX_LG_SRCVS (0U)
206#ifndef COAP_MAX_LG_XMITS
207#if COAP_SERVER_SUPPORT
208#define COAP_MAX_LG_XMITS (2U)
210#define COAP_MAX_LG_XMITS (1U)
229static union memstr_t string_storage_data[COAP_MAX_STRINGS];
230static memarray_t string_storage;
232#if COAP_SERVER_SUPPORT
234static memarray_t endpoint_storage;
236static union attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
237static memarray_t attr_storage;
239static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
240static memarray_t resattr_storage;
244static memarray_t pkt_storage;
247static memarray_t node_storage;
250static memarray_t context_storage;
252static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
253static memarray_t pdu_storage;
259 char buf[COAP_DEFAULT_MAX_PDU_RX_SIZE];
262static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
263static memarray_t pdubuf_storage;
265#if COAP_SERVER_SUPPORT
267static memarray_t resource_storage;
270#ifdef COAP_WITH_LIBTINYDTLS
271#undef PACKAGE_BUGREPORT
273static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
274static memarray_t dtls_storage;
278static memarray_t session_storage;
283 char optbuf[COAP_MAX_OPTION_SIZE];
285static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
286static memarray_t option_storage;
288#if COAP_SERVER_SUPPORT
290static memarray_t cache_key_storage;
293static memarray_t cache_entry_storage;
296#if COAP_CLIENT_SUPPORT
297static coap_lg_crcv_t cache_lg_crcv_storage_data[COAP_MAX_LG_CRCVS];
298static memarray_t cache_lg_crcv_storage;
301#if COAP_SERVER_SUPPORT
302static coap_lg_srcv_t cache_lg_srcv_storage_data[COAP_MAX_LG_SRCVS];
303static memarray_t cache_lg_srcv_storage;
305static coap_lg_xmit_t cache_lg_xmit_storage_data[COAP_MAX_LG_XMITS];
306static memarray_t cache_lg_xmit_storage;
309#define INIT_STORAGE(Storage, Count) \
310 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
312#define STORAGE_PTR(Storage) (&(Storage ## _storage))
316 INIT_STORAGE(
string, COAP_MAX_STRINGS);
317#if COAP_SERVER_SUPPORT
318 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
319 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
321 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
322 INIT_STORAGE(node, COAP_MAX_NODES);
323 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
324 INIT_STORAGE(pdu, COAP_MAX_PDUS);
325 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
326#if COAP_SERVER_SUPPORT
327 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
328 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
330#ifdef COAP_WITH_LIBTINYDTLS
331 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
333 INIT_STORAGE(session, COAP_MAX_SESSIONS);
334 INIT_STORAGE(option, COAP_MAX_OPTIONS);
335#if COAP_SERVER_SUPPORT
336 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
337 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
339#if COAP_CLIENT_SUPPORT
340 INIT_STORAGE(cache_lg_crcv, COAP_MAX_LG_CRCVS);
342#if COAP_SERVER_SUPPORT
343 INIT_STORAGE(cache_lg_srcv, COAP_MAX_LG_SRCVS);
344 INIT_STORAGE(cache_lg_xmit, COAP_MAX_LG_XMITS);
351#if COAP_SERVER_SUPPORT
355 return &attr_storage;
360 return &node_storage;
362 return STORAGE_PTR(context);
363#if COAP_SERVER_SUPPORT
365 return &endpoint_storage;
370 return &pdubuf_storage;
371#if COAP_SERVER_SUPPORT
373 return &resource_storage;
375 return &resattr_storage;
377#ifdef COAP_WITH_LIBTINYDTLS
379 return &dtls_storage;
382 return &session_storage;
384 return &option_storage;
385#if COAP_SERVER_SUPPORT
387 return &cache_key_storage;
389 return &cache_entry_storage;
391#if COAP_CLIENT_SUPPORT
393 return &cache_lg_crcv_storage;
395#if COAP_SERVER_SUPPORT
397 return &cache_lg_srcv_storage;
399 return &cache_lg_xmit_storage;
404 return &string_storage;
410 memarray_t *container = get_container(type);
414 if (size > container->size) {
415 coap_log_warn(
"coap_malloc_type: Requested memory exceeds maximum object "
416 "size (type %d, size %zu, max %d)\n",
417 type, size, container->size);
421 ptr = memarray_alloc(container);
423 coap_log_warn(
"coap_malloc_type: Failure (no free blocks) for type %d\n",
431 memarray_free(get_container(type),
object);
436 memarray_t *container = get_container(type);
441 if (size > container->size) {
442 coap_log_warn(
"coap_realloc_type: Requested memory exceeds maximum object "
443 "size (type %d, size %zu, max %d)\n",
444 type, size, container->size);
457#if defined(HAVE_MALLOC) || defined(__MINGW32__)
473 return realloc(p, size);
485#include "lib/heapmem.h"
493 return heapmem_alloc(size);
498 return heapmem_realloc(p, size);
Pulls together all the internal only header files.
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(...)
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.