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)
193static union memstr_t string_storage_data[COAP_MAX_STRINGS];
194static memarray_t string_storage;
197static memarray_t endpoint_storage;
199static union attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
200static memarray_t attr_storage;
202static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
203static memarray_t resattr_storage;
206static memarray_t pkt_storage;
209static memarray_t node_storage;
212static memarray_t context_storage;
214static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
215static memarray_t pdu_storage;
221 char buf[COAP_DEFAULT_MAX_PDU_RX_SIZE];
224static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
225static memarray_t pdubuf_storage;
228static memarray_t resource_storage;
230#ifdef HAVE_LIBTINYDTLS
231static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
232static memarray_t dtls_storage;
236static memarray_t session_storage;
241 char optbuf[COAP_MAX_OPTION_SIZE];
243static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
244static memarray_t option_storage;
247static memarray_t cache_key_storage;
250static memarray_t cache_entry_storage;
252#define INIT_STORAGE(Storage, Count) \
253 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
255#define STORAGE_PTR(Storage) (&(Storage ## _storage))
259 INIT_STORAGE(
string, COAP_MAX_STRINGS);
260 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
261 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
262 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
263 INIT_STORAGE(node, COAP_MAX_NODES);
264 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
265 INIT_STORAGE(pdu, COAP_MAX_PDUS);
266 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
267 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
268 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
269#ifdef HAVE_LIBTINYDTLS
270 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
272 INIT_STORAGE(session, COAP_MAX_SESSIONS);
273 INIT_STORAGE(option, COAP_MAX_OPTIONS);
274 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
275 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
292#ifdef HAVE_LIBTINYDTLS
293 case COAP_DTLS_SESSION:
return &dtls_storage;
302 return &string_storage;
308 memarray_t *container = get_container(type);
312 if (size > container->size) {
314 "coap_malloc_type: Requested memory exceeds maximum object "
315 "size (type %d, size %zu, max %d)\n",
316 type, size, container->size);
320 ptr = memarray_alloc(container);
323 "coap_malloc_type: Failure (no free blocks) for type %d\n",
331 memarray_free(get_container(type),
object);
351 return realloc(p, size);
368#ifndef COAP_MAX_STRING_SIZE
369#define COAP_MAX_STRING_SIZE 64
376#ifndef COAP_MAX_STRINGS
377#define COAP_MAX_STRINGS 10
380struct coap_stringbuf_t {
381 char data[COAP_MAX_STRING_SIZE];
385#define COAP_MAX_PACKET_SIZE (sizeof(coap_packet_t) + COAP_RXBUFFER_SIZE)
386#ifndef COAP_MAX_PACKETS
387#define COAP_MAX_PACKETS 2
392 char buf[COAP_MAX_PACKET_SIZE];
395MEMB(string_storage,
struct coap_stringbuf_t, COAP_MAX_STRINGS);
396MEMB(packet_storage, coap_packetbuf_t, COAP_MAX_PACKETS);
399MEMB(pdu_storage,
coap_pdu_t, COAP_PDU_MAXCNT);
400MEMB(pdu_buf_storage, coap_packetbuf_t, COAP_PDU_MAXCNT);
402MEMB(attribute_storage,
coap_attr_t, COAP_MAX_ATTRIBUTES);
425 return &string_storage;
431 memb_init(&string_storage);
432 memb_init(&packet_storage);
433 memb_init(&node_storage);
434 memb_init(&session_storage);
435 memb_init(&pdu_storage);
436 memb_init(&pdu_buf_storage);
437 memb_init(&resource_storage);
438 memb_init(&attribute_storage);
439 memb_init(&cache_key_storage);
440 memb_init(&cache_entry_storage);
441 memb_init(&lg_xmit_storage);
442 memb_init(&lg_crcv_storage);
443 memb_init(&lg_srcv_storage);
448 struct memb *container = get_container(type);
453 if (size > container->size) {
455 "coap_malloc_type: Requested memory exceeds maximum object "
456 "size (type %d, size %d, max %d)\n",
457 type, (
int)size, container->size);
461 ptr = memb_alloc(container);
464 "coap_malloc_type: Failure (no free blocks) for type %d\n",
471 memb_free(get_container(type),
object);
Pulls together all the internal only header files.
Defines the application visible session information.
#define coap_log(level,...)
Logging function.
struct coap_string_t coap_string_t
CoAP string data definition.
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.
Abstraction of attribute associated with a resource.
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.