14 #if defined(RIOT_VERSION) && defined(MODULE_MEMARRAY)
19 #undef PACKAGE_TARNAME
20 #undef PACKAGE_VERSION
24 #undef PACKAGE_TARNAME
25 #undef PACKAGE_VERSION
36 #ifndef COAP_MAX_STRING_SIZE
37 #define COAP_MAX_STRING_SIZE (64U)
44 #ifndef COAP_MAX_STRINGS
45 #define COAP_MAX_STRINGS (16U)
52 #ifndef COAP_MAX_ENDPOINTS
53 #define COAP_MAX_ENDPOINTS (4U)
60 #ifndef COAP_MAX_RESOURCES
61 #define COAP_MAX_RESOURCES (8U)
68 #ifndef COAP_MAX_ATTRIBUTES
69 #define COAP_MAX_ATTRIBUTES \
70 ((COAP_MAX_RESOURCES) * 4U)
79 #ifndef COAP_MAX_ATTRIBUTE_STRINGS
80 #define COAP_MAX_ATTRIBUTE_STRINGS (COAP_MAX_ATTRIBUTES)
87 #ifndef COAP_MAX_ATTRIBUTE_SIZE
88 #define COAP_MAX_ATTRIBUTE_SIZE (16U)
95 #ifndef COAP_MAX_PACKETS
96 #define COAP_MAX_PACKETS (4U)
104 #ifndef COAP_MAX_NODES
105 #define COAP_MAX_NODES \
106 ((COAP_MAX_ENDPOINTS) * (COAP_MAX_PACKETS))
113 #ifndef COAP_MAX_CONTEXTS
114 #define COAP_MAX_CONTEXTS (1U)
122 #ifndef COAP_MAX_PDUS
123 #define COAP_MAX_PDUS ((COAP_MAX_ENDPOINTS) * 4U)
130 #ifndef COAP_MAX_DTLS_SESSIONS
131 #define COAP_MAX_DTLS_SESSIONS (2U)
138 #ifndef COAP_MAX_SESSIONS
139 #define COAP_MAX_SESSIONS (COAP_MAX_ENDPOINTS)
146 #ifndef COAP_MAX_OPTIONS
147 #define COAP_MAX_OPTIONS (16U)
154 #ifndef COAP_MAX_OPTION_SIZE
155 #define COAP_MAX_OPTION_SIZE (16U)
162 #ifndef COAP_MAX_CACHE_KEYS
163 #define COAP_MAX_CACHE_KEYS (2U)
170 #ifndef COAP_MAX_CACHE_ENTRIES
171 #define COAP_MAX_CACHE_ENTRIES (2U)
189 static union memstr_t string_storage_data[COAP_MAX_STRINGS];
190 static memarray_t string_storage;
193 static memarray_t endpoint_storage;
195 static union attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
196 static memarray_t attr_storage;
198 static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
199 static memarray_t resattr_storage;
202 static memarray_t pkt_storage;
205 static memarray_t node_storage;
208 static memarray_t context_storage;
210 static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
211 static memarray_t pdu_storage;
220 static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
221 static memarray_t pdubuf_storage;
224 static memarray_t resource_storage;
226 #ifdef HAVE_LIBTINYDTLS
227 static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
228 static memarray_t dtls_storage;
232 static memarray_t session_storage;
237 char optbuf[COAP_MAX_OPTION_SIZE];
239 static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
240 static memarray_t option_storage;
243 static memarray_t cache_key_storage;
246 static memarray_t cache_entry_storage;
248 #define INIT_STORAGE(Storage, Count) \
249 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
251 #define STORAGE_PTR(Storage) (&(Storage ## _storage))
255 INIT_STORAGE(
string, COAP_MAX_STRINGS);
256 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
257 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
258 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
259 INIT_STORAGE(node, COAP_MAX_NODES);
260 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
261 INIT_STORAGE(pdu, COAP_MAX_PDUS);
262 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
263 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
264 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
265 #ifdef HAVE_LIBTINYDTLS
266 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
268 INIT_STORAGE(session, COAP_MAX_SESSIONS);
269 INIT_STORAGE(option, COAP_MAX_OPTIONS);
270 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
271 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
288 #ifdef HAVE_LIBTINYDTLS
289 case COAP_DTLS_SESSION:
return &dtls_storage;
298 return &string_storage;
304 memarray_t *container = get_container(type);
308 if (size > container->size) {
310 "coap_malloc_type: Requested memory exceeds maximum object "
311 "size (type %d, size %zu, max %d)\n",
312 type, size, container->size);
316 ptr = memarray_alloc(container);
319 "coap_malloc_type: Failure (no free blocks) for type %d\n",
327 memarray_free(get_container(type),
object);
347 return realloc(p, size);
364 #ifndef COAP_MAX_STRING_SIZE
365 #define COAP_MAX_STRING_SIZE 64
372 #ifndef COAP_MAX_STRINGS
373 #define COAP_MAX_STRINGS 10
376 struct coap_stringbuf_t {
377 char data[COAP_MAX_STRING_SIZE];
381 #define COAP_MAX_PACKET_SIZE (sizeof(coap_packet_t) + COAP_RXBUFFER_SIZE)
382 #ifndef COAP_MAX_PACKETS
383 #define COAP_MAX_PACKETS 2
388 char buf[COAP_MAX_PACKET_SIZE];
391 MEMB(string_storage,
struct coap_stringbuf_t, COAP_MAX_STRINGS);
392 MEMB(packet_storage, coap_packetbuf_t, COAP_MAX_PACKETS);
395 MEMB(pdu_storage,
coap_pdu_t, COAP_PDU_MAXCNT);
396 MEMB(pdu_buf_storage, coap_packetbuf_t, COAP_PDU_MAXCNT);
398 MEMB(attribute_storage,
coap_attr_t, COAP_MAX_ATTRIBUTES);
421 return &string_storage;
427 memb_init(&string_storage);
428 memb_init(&packet_storage);
429 memb_init(&node_storage);
430 memb_init(&session_storage);
431 memb_init(&pdu_storage);
432 memb_init(&pdu_buf_storage);
433 memb_init(&resource_storage);
434 memb_init(&attribute_storage);
435 memb_init(&cache_key_storage);
436 memb_init(&cache_entry_storage);
437 memb_init(&lg_xmit_storage);
438 memb_init(&lg_crcv_storage);
439 memb_init(&lg_srcv_storage);
444 struct memb *container = get_container(type);
449 if (size > container->size) {
451 "coap_malloc_type: Requested memory exceeds maximum object "
452 "size (type %d, size %d, max %d)\n",
453 type, (
int)size, container->size);
457 ptr = memb_alloc(container);
460 "coap_malloc_type: Failure (no free blocks) for type %d\n",
467 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.
#define COAP_DEFAULT_MAX_PDU_RX_SIZE
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.
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.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition.