1 /* 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * This file is part of the CoAP library libcoap. Please see README for terms 5 * of use. 6 */ 7 8 /* Memory pool definitions for the libcoap when used with lwIP (which has its 9 * own mechanism for quickly allocating chunks of data with known sizes). Has 10 * to be findable by lwIP (ie. an #include <lwippools.h> must either directly 11 * include this or include something more generic which includes this), and 12 * MEMP_USE_CUSTOM_POOLS has to be set in lwipopts.h. */ 13 14 #include "coap3/coap_internal.h" 15 #include "coap3/coap_net.h" 16 #include "coap3/coap_resource.h" 17 #include "coap3/coap_subscribe.h" 18 #ifdef COAP_WITH_LIBTINYDTLS 19 #ifndef LWIP_TINYDTLS_LOCAL_FIX 20 #define LWIP_TINYDTLS_LOCAL_FIX 21 #include <lwip/ip_addr.h> 22 /* Local copies of struct to simplify #include nightmare */ 23 typedef struct { 24 unsigned char size; /**< size of session_t::addr */ 25 unsigned short port; /**< transport layer port */ 26 ip_addr_t addr; /**< session IP address */ 27 int ifindex; /**< network interface index */ 28 } l_session_t; 29 30 typedef struct l_coap_tiny_context_t { 31 struct dtls_context_t *dtls_context; 32 coap_context_t *coap_context; 33 coap_dtls_pki_t setup_data; 34 coap_binary_t *priv_key; 35 coap_binary_t *pub_key; 36 } l_coap_tiny_context_t; 37 38 #endif /* LWIP_TINYDTLS_LOCAL_FIX */ 39 #endif /* COAP_WITH_LIBTINYDTLS */ 40 41 #ifndef MEMP_NUM_COAPCONTEXT 42 #define MEMP_NUM_COAPCONTEXT 1 43 #endif 44 45 #ifndef MEMP_NUM_COAPENDPOINT 46 #ifdef COAP_WITH_LIBTINYDTLS 47 #define MEMP_NUM_COAPENDPOINT 2 48 #else /* ! COAP_WITH_LIBTINYDTLS */ 49 #define MEMP_NUM_COAPENDPOINT 1 50 #endif /* ! COAP_WITH_LIBTINYDTLS */ 51 #endif 52 53 /* 1 is sufficient as this is very short-lived */ 54 #ifndef MEMP_NUM_COAPPACKET 55 #define MEMP_NUM_COAPPACKET 1 56 #endif 57 58 #ifndef MEMP_NUM_COAPNODE 59 #define MEMP_NUM_COAPNODE 5 60 #endif 61 62 #ifndef MEMP_NUM_COAPPDU 63 #define MEMP_NUM_COAPPDU MEMP_NUM_COAPNODE 64 #endif 65 66 #ifndef MEMP_NUM_COAPSESSION 67 #define MEMP_NUM_COAPSESSION 2 68 #endif 69 70 #ifndef MEMP_NUM_COAP_SUBSCRIPTION 71 #define MEMP_NUM_COAP_SUBSCRIPTION 4 72 #endif 73 74 #ifndef MEMP_NUM_COAPRESOURCE 75 #define MEMP_NUM_COAPRESOURCE 10 76 #endif 77 78 #ifndef MEMP_NUM_COAPRESOURCEATTR 79 #define MEMP_NUM_COAPRESOURCEATTR 20 80 #endif 81 82 #ifndef MEMP_NUM_COAPOPTLIST 83 #define MEMP_NUM_COAPOPTLIST 5 84 #endif 85 86 #ifndef MEMP_LEN_COAPOPTLIST 87 #define MEMP_LEN_COAPOPTLIST 12 88 #endif 89 90 #ifndef MEMP_NUM_COAPSTRING 91 #define MEMP_NUM_COAPSTRING 10 92 #endif 93 94 #ifndef MEMP_LEN_COAPSTRING 95 #define MEMP_LEN_COAPSTRING 40 96 #endif 97 98 #ifndef MEMP_NUM_COAPCACHE_KEYS 99 #define MEMP_NUM_COAPCACHE_KEYS (2U) 100 #endif /* MEMP_NUM_COAPCACHE_KEYS */ 101 102 #ifndef MEMP_NUM_COAPCACHE_ENTRIES 103 #define MEMP_NUM_COAPCACHE_ENTRIES (2U) 104 #endif /* MEMP_NUM_COAPCACHE_ENTRIES */ 105 106 #ifndef MEMP_NUM_COAPPDUBUF 107 #define MEMP_NUM_COAPPDUBUF 2 108 #endif 109 110 #ifndef MEMP_LEN_COAPPDUBUF 111 #define MEMP_LEN_COAPPDUBUF 400 112 #endif 113 114 #ifndef MEMP_NUM_COAPLGXMIT 115 #define MEMP_NUM_COAPLGXMIT 2 116 #endif 117 118 #ifndef MEMP_NUM_COAPLGCRCV 119 #define MEMP_NUM_COAPLGCRCV 2 120 #endif 121 122 #ifndef MEMP_NUM_COAPLGSRCV 123 #define MEMP_NUM_COAPLGSRCV 2 124 #endif 125 126 #ifndef MEMP_NUM_COAPDIGESTCTX 127 #define MEMP_NUM_COAPDIGESTCTX 4 128 #endif 129 130 #ifndef MEMP_NUM_COAPDTLS_SESSION 131 #define MEMP_NUM_COAPDTLS_SESSION 1 132 #endif 133 134 #ifndef MEMP_NUM_COAPDTLS_CONTEXT 135 #define MEMP_NUM_COAPDTLS_CONTEXT 1 136 #endif 137 138 LWIP_MEMPOOL(COAP_CONTEXT, MEMP_NUM_COAPCONTEXT, sizeof(coap_context_t), "COAP_CONTEXT") 139 #ifdef COAP_SERVER_SUPPORT 140 LWIP_MEMPOOL(COAP_ENDPOINT, MEMP_NUM_COAPENDPOINT, sizeof(coap_endpoint_t), "COAP_ENDPOINT") 141 #endif /* COAP_SERVER_SUPPORT */ 142 LWIP_MEMPOOL(COAP_PACKET, MEMP_NUM_COAPPACKET, sizeof(coap_packet_t), "COAP_PACKET") 143 LWIP_MEMPOOL(COAP_NODE, MEMP_NUM_COAPNODE, sizeof(coap_queue_t), "COAP_NODE") 144 LWIP_MEMPOOL(COAP_PDU, MEMP_NUM_COAPPDU, sizeof(coap_pdu_t), "COAP_PDU") 145 LWIP_MEMPOOL(COAP_SESSION, MEMP_NUM_COAPSESSION, sizeof(coap_session_t), "COAP_SESSION") 146 #ifdef COAP_SERVER_SUPPORT 147 LWIP_MEMPOOL(COAP_SUBSCRIPTION, MEMP_NUM_COAP_SUBSCRIPTION, sizeof(coap_subscription_t), 148 "COAP_SUBSCRIPTION") 149 LWIP_MEMPOOL(COAP_RESOURCE, MEMP_NUM_COAPRESOURCE, sizeof(coap_resource_t), "COAP_RESOURCE") 150 LWIP_MEMPOOL(COAP_RESOURCEATTR, MEMP_NUM_COAPRESOURCEATTR, sizeof(coap_attr_t), "COAP_RESOURCEATTR") 151 #endif /* COAP_SERVER_SUPPORT */ 152 LWIP_MEMPOOL(COAP_OPTLIST, MEMP_NUM_COAPOPTLIST, sizeof(coap_optlist_t)+MEMP_LEN_COAPOPTLIST, 153 "COAP_OPTLIST") 154 LWIP_MEMPOOL(COAP_STRING, MEMP_NUM_COAPSTRING, sizeof(coap_string_t)+MEMP_LEN_COAPSTRING, 155 "COAP_STRING") 156 #ifdef COAP_SERVER_SUPPORT 157 LWIP_MEMPOOL(COAP_CACHE_KEY, MEMP_NUM_COAPCACHE_KEYS, sizeof(coap_cache_key_t), "COAP_CACHE_KEY") 158 LWIP_MEMPOOL(COAP_CACHE_ENTRY, MEMP_NUM_COAPCACHE_ENTRIES, sizeof(coap_cache_entry_t), 159 "COAP_CACHE_ENTRY") 160 #endif /* COAP_SERVER_SUPPORT */ 161 LWIP_MEMPOOL(COAP_PDU_BUF, MEMP_NUM_COAPPDUBUF, MEMP_LEN_COAPPDUBUF, "COAP_PDU_BUF") 162 LWIP_MEMPOOL(COAP_LG_XMIT, MEMP_NUM_COAPLGXMIT, sizeof(coap_lg_xmit_t), "COAP_LG_XMIT") 163 #ifdef COAP_CLIENT_SUPPORT 164 LWIP_MEMPOOL(COAP_LG_CRCV, MEMP_NUM_COAPLGCRCV, sizeof(coap_lg_crcv_t), "COAP_LG_CRCV") 165 #endif /* COAP_CLIENT_SUPPORT */ 166 #ifdef COAP_SERVER_SUPPORT 167 LWIP_MEMPOOL(COAP_LG_SRCV, MEMP_NUM_COAPLGSRCV, sizeof(coap_lg_srcv_t), "COAP_LG_SRCV") 168 LWIP_MEMPOOL(COAP_DIGEST_CTX, MEMP_NUM_COAPDIGESTCTX, sizeof(coap_digest_t) + sizeof(size_t), 169 "COAP_DIGEST_CTX") 170 #endif /* COAP_SERVER_SUPPORT */ 171 #ifdef COAP_WITH_LIBTINYDTLS 172 LWIP_MEMPOOL(COAP_DTLS_SESSION, MEMP_NUM_COAPDTLS_SESSION, sizeof(l_session_t), "COAP_DTLS_SESSION") 173 LWIP_MEMPOOL(COAP_DTLS_CONTEXT, MEMP_NUM_COAPDTLS_CONTEXT, sizeof(l_coap_tiny_context_t), 174 "COAP_DTLS_CONTEXT") 175 #endif /* COAP_WITH_LIBTINYDTLS */ 176