12 #if defined(RIOT_VERSION) && defined(MODULE_MEMARRAY)
17 #undef PACKAGE_TARNAME
18 #undef PACKAGE_VERSION
22 #undef PACKAGE_TARNAME
23 #undef PACKAGE_VERSION
34 #ifndef COAP_MAX_STRING_SIZE
35 #define COAP_MAX_STRING_SIZE (64U)
42 #ifndef COAP_MAX_STRINGS
43 #define COAP_MAX_STRINGS (16U)
50 #ifndef COAP_MAX_ENDPOINTS
51 #define COAP_MAX_ENDPOINTS (4U)
58 #ifndef COAP_MAX_RESOURCES
59 #define COAP_MAX_RESOURCES (8U)
66 #ifndef COAP_MAX_ATTRIBUTES
67 #define COAP_MAX_ATTRIBUTES \
68 ((COAP_MAX_RESOURCES) * 4U)
77 #ifndef COAP_MAX_ATTRIBUTE_STRINGS
78 #define COAP_MAX_ATTRIBUTE_STRINGS (COAP_MAX_ATTRIBUTES)
85 #ifndef COAP_MAX_ATTRIBUTE_SIZE
86 #define COAP_MAX_ATTRIBUTE_SIZE (16U)
93 #ifndef COAP_MAX_PACKETS
94 #define COAP_MAX_PACKETS (4U)
102 #ifndef COAP_MAX_NODES
103 #define COAP_MAX_NODES \
104 ((COAP_MAX_ENDPOINTS) * (COAP_MAX_PACKETS))
111 #ifndef COAP_MAX_CONTEXTS
112 #define COAP_MAX_CONTEXTS (1U)
120 #ifndef COAP_MAX_PDUS
121 #define COAP_MAX_PDUS ((COAP_MAX_ENDPOINTS) * 4U)
128 #ifndef COAP_MAX_DTLS_SESSIONS
129 #define COAP_MAX_DTLS_SESSIONS (2U)
136 #ifndef COAP_MAX_SESSIONS
137 #define COAP_MAX_SESSIONS (COAP_MAX_ENDPOINTS)
144 #ifndef COAP_MAX_OPTIONS
145 #define COAP_MAX_OPTIONS (16U)
152 #ifndef COAP_MAX_OPTION_SIZE
153 #define COAP_MAX_OPTION_SIZE (16U)
160 #ifndef COAP_MAX_CACHE_KEYS
161 #define COAP_MAX_CACHE_KEYS (2U)
168 #ifndef COAP_MAX_CACHE_ENTRIES
169 #define COAP_MAX_CACHE_ENTRIES (2U)
187 static union memstr_t string_storage_data[COAP_MAX_STRINGS];
188 static memarray_t string_storage;
191 static memarray_t endpoint_storage;
193 static union attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
194 static memarray_t attr_storage;
196 static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
197 static memarray_t resattr_storage;
200 static memarray_t pkt_storage;
203 static memarray_t node_storage;
206 static memarray_t context_storage;
208 static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
209 static memarray_t pdu_storage;
218 static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
219 static memarray_t pdubuf_storage;
222 static memarray_t resource_storage;
224 #ifdef HAVE_LIBTINYDTLS
225 static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
226 static memarray_t dtls_storage;
230 static memarray_t session_storage;
235 char optbuf[COAP_MAX_OPTION_SIZE];
237 static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
238 static memarray_t option_storage;
241 static memarray_t cache_key_storage;
244 static memarray_t cache_entry_storage;
246 #define INIT_STORAGE(Storage, Count) \
247 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
249 #define STORAGE_PTR(Storage) (&(Storage ## _storage))
253 INIT_STORAGE(
string, COAP_MAX_STRINGS);
254 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
255 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
256 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
257 INIT_STORAGE(node, COAP_MAX_NODES);
258 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
259 INIT_STORAGE(pdu, COAP_MAX_PDUS);
260 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
261 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
262 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
263 #ifdef HAVE_LIBTINYDTLS
264 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
266 INIT_STORAGE(session, COAP_MAX_SESSIONS);
267 INIT_STORAGE(option, COAP_MAX_OPTIONS);
268 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
269 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
286 #ifdef HAVE_LIBTINYDTLS
287 case COAP_DTLS_SESSION:
return &dtls_storage;
296 return &string_storage;
302 memarray_t *container = get_container(type);
306 if (size > container->size) {
308 "coap_malloc_type: Requested memory exceeds maximum object "
309 "size (type %d, size %zu, max %d)\n",
310 type, size, container->size);
314 ptr = memarray_alloc(container);
317 "coap_malloc_type: Failure (no free blocks) for type %d\n",
325 memarray_free(get_container(type),
object);
345 return realloc(p, size);
362 #ifndef COAP_MAX_STRING_SIZE
363 #define COAP_MAX_STRING_SIZE 64
370 #ifndef COAP_MAX_STRINGS
371 #define COAP_MAX_STRINGS 10
374 struct coap_stringbuf_t {
375 char data[COAP_MAX_STRING_SIZE];
379 #define COAP_MAX_PACKET_SIZE (sizeof(coap_packet_t) + COAP_RXBUFFER_SIZE)
380 #ifndef COAP_MAX_PACKETS
381 #define COAP_MAX_PACKETS 2
386 char buf[COAP_MAX_PACKET_SIZE];
389 MEMB(string_storage,
struct coap_stringbuf_t, COAP_MAX_STRINGS);
390 MEMB(packet_storage, coap_packetbuf_t, COAP_MAX_PACKETS);
393 MEMB(pdu_storage,
coap_pdu_t, COAP_PDU_MAXCNT);
394 MEMB(pdu_buf_storage, coap_packetbuf_t, COAP_PDU_MAXCNT);
396 MEMB(attribute_storage,
coap_attr_t, COAP_MAX_ATTRIBUTES);
419 return &string_storage;
425 memb_init(&string_storage);
426 memb_init(&packet_storage);
427 memb_init(&node_storage);
428 memb_init(&session_storage);
429 memb_init(&pdu_storage);
430 memb_init(&pdu_buf_storage);
431 memb_init(&resource_storage);
432 memb_init(&attribute_storage);
433 memb_init(&cache_key_storage);
434 memb_init(&cache_entry_storage);
435 memb_init(&lg_xmit_storage);
436 memb_init(&lg_crcv_storage);
437 memb_init(&lg_srcv_storage);
442 struct memb *container = get_container(type);
447 if (size > container->size) {
449 "coap_malloc_type: Requested memory exceeds maximum object "
450 "size (type %d, size %d, max %d)\n",
451 type, (
int)size, container->size);
455 ptr = memb_alloc(container);
458 "coap_malloc_type: Failure (no free blocks) for type %d\n",
465 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_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_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_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.
#define COAP_DEFAULT_MAX_PDU_RX_SIZE
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.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Abstraction of resource that can be attached to coap_context_t.
CoAP string data definition.