Loading...
Searching...
No Matches
coap_mem.h
Go to the documentation of this file.
/*
* coap_mem.h -- CoAP memory handling
*
* Copyright (C) 2010-2011,2014-2015 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_MEM_H_
#define COAP_MEM_H_
#include "coap3/coap_oscore.h"
#include <stdlib.h>
#ifndef WITH_LWIP
void coap_memory_init(void);
#endif /* WITH_LWIP */
typedef enum {
COAP_STRING,
COAP_ATTRIBUTE_NAME,
COAP_ATTRIBUTE_VALUE,
COAP_PACKET,
COAP_NODE,
COAP_CONTEXT,
COAP_ENDPOINT,
COAP_PDU,
COAP_PDU_BUF,
COAP_RESOURCE,
COAP_RESOURCEATTR,
COAP_DTLS_SESSION,
COAP_SESSION,
COAP_OPTLIST,
COAP_CACHE_KEY,
COAP_CACHE_ENTRY,
COAP_LG_XMIT,
COAP_LG_CRCV,
COAP_LG_SRCV,
COAP_DIGEST_CTX,
COAP_SUBSCRIPTION,
COAP_DTLS_CONTEXT,
COAP_OSCORE_COM,
COAP_OSCORE_SEN,
COAP_OSCORE_REC,
COAP_OSCORE_EX,
COAP_OSCORE_EP,
COAP_OSCORE_BUF,
COAP_COSE,
} coap_memory_tag_t;
#ifndef WITH_LWIP
void *coap_malloc_type(coap_memory_tag_t type, size_t size);
void *coap_realloc_type(coap_memory_tag_t type, void *p, size_t size);
void coap_free_type(coap_memory_tag_t type, void *p);
COAP_STATIC_INLINE void *
coap_malloc(size_t size) {
return coap_malloc_type(COAP_STRING, size);
}
COAP_STATIC_INLINE void
coap_free(void *object) {
coap_free_type(COAP_STRING, object);
}
#endif /* not WITH_LWIP */
#ifdef WITH_LWIP
#include <lwip/memp.h>
/* no initialization needed with lwip (or, more precisely: lwip must be
* completely initialized anyway by the time coap gets active) */
COAP_STATIC_INLINE void
coap_memory_init(void) {}
/* It would be nice to check that size equals the size given at the memp
* declaration, but i currently don't see a standard way to check that without
* sourcing the custom memp pools and becoming dependent of its syntax
*/
#define coap_malloc_type(type, asize) \
(((asize) <= memp_pools[MEMP_ ## type]->size) ? \
memp_malloc(MEMP_ ## type) : NULL)
#define coap_free_type(type, p) memp_free(MEMP_ ## type, p)
/* As these are fixed size, return value if already defined */
#define coap_realloc_type(type, p, asize) \
((p) ? ((asize) <= memp_pools[MEMP_ ## type]->size) ? (p) : NULL : coap_malloc_type(type, asize))
/* Those are just here to make uri.c happy where string allocation has not been
* made conditional.
*/
COAP_STATIC_INLINE void *
coap_malloc(size_t size) {
(void)size;
LWIP_ASSERT("coap_malloc must not be used in lwIP", 0);
}
COAP_STATIC_INLINE void
coap_free(void *pointer) {
(void)pointer;
LWIP_ASSERT("coap_free must not be used in lwIP", 0);
}
#endif /* WITH_LWIP */
#endif /* COAP_MEM_H_ */
coap_free
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
Definition coap_mem.h:121
coap_malloc
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Definition coap_mem.h:113
coap_memory_init
void coap_memory_init(void)
Initializes libcoap's memory management.
coap_memory_tag_t
coap_memory_tag_t
Type specifiers for coap_malloc_type().
Definition coap_mem.h:37
COAP_DTLS_SESSION
@ COAP_DTLS_SESSION
Definition coap_mem.h:49
COAP_SESSION
@ COAP_SESSION
Definition coap_mem.h:50
COAP_CACHE_KEY
@ COAP_CACHE_KEY
Definition coap_mem.h:52
COAP_DIGEST_CTX
@ COAP_DIGEST_CTX
Definition coap_mem.h:57
COAP_NODE
@ COAP_NODE
Definition coap_mem.h:42
COAP_OSCORE_COM
@ COAP_OSCORE_COM
Definition coap_mem.h:60
COAP_DTLS_CONTEXT
@ COAP_DTLS_CONTEXT
Definition coap_mem.h:59
COAP_OSCORE_EX
@ COAP_OSCORE_EX
Definition coap_mem.h:63
COAP_CACHE_ENTRY
@ COAP_CACHE_ENTRY
Definition coap_mem.h:53
COAP_RESOURCE
@ COAP_RESOURCE
Definition coap_mem.h:47
COAP_RESOURCEATTR
@ COAP_RESOURCEATTR
Definition coap_mem.h:48
COAP_COSE
@ COAP_COSE
Definition coap_mem.h:66
COAP_LG_XMIT
@ COAP_LG_XMIT
Definition coap_mem.h:54
COAP_ATTRIBUTE_VALUE
@ COAP_ATTRIBUTE_VALUE
Definition coap_mem.h:40
COAP_ENDPOINT
@ COAP_ENDPOINT
Definition coap_mem.h:44
COAP_CONTEXT
@ COAP_CONTEXT
Definition coap_mem.h:43
COAP_OPTLIST
@ COAP_OPTLIST
Definition coap_mem.h:51
COAP_PDU
@ COAP_PDU
Definition coap_mem.h:45
COAP_LG_CRCV
@ COAP_LG_CRCV
Definition coap_mem.h:55
COAP_OSCORE_BUF
@ COAP_OSCORE_BUF
Definition coap_mem.h:65
COAP_OSCORE_SEN
@ COAP_OSCORE_SEN
Definition coap_mem.h:61
COAP_OSCORE_REC
@ COAP_OSCORE_REC
Definition coap_mem.h:62
COAP_ATTRIBUTE_NAME
@ COAP_ATTRIBUTE_NAME
Definition coap_mem.h:39
COAP_OSCORE_EP
@ COAP_OSCORE_EP
Definition coap_mem.h:64
COAP_LG_SRCV
@ COAP_LG_SRCV
Definition coap_mem.h:56
COAP_PACKET
@ COAP_PACKET
Definition coap_mem.h:41
COAP_SUBSCRIPTION
@ COAP_SUBSCRIPTION
Definition coap_mem.h:58
COAP_STRING
@ COAP_STRING
Definition coap_mem.h:38
COAP_PDU_BUF
@ COAP_PDU_BUF
Definition coap_mem.h:46
coap_realloc_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...
coap_malloc_type
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.
coap_free_type
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_oscore.h
CoAP OSCORE support.
COAP_STATIC_INLINE
#define COAP_STATIC_INLINE
Definition libcoap.h:53