xref: /btstack/src/btstack_memory.c (revision b6269742289ca2bcfed3911e19011250886c7ac4)
1a3b02b71Smatthias.ringwald /*
2a0c35809S[email protected]  * Copyright (C) 2014 BlueKitchen GmbH
3a3b02b71Smatthias.ringwald  *
4a3b02b71Smatthias.ringwald  * Redistribution and use in source and binary forms, with or without
5a3b02b71Smatthias.ringwald  * modification, are permitted provided that the following conditions
6a3b02b71Smatthias.ringwald  * are met:
7a3b02b71Smatthias.ringwald  *
8a3b02b71Smatthias.ringwald  * 1. Redistributions of source code must retain the above copyright
9a3b02b71Smatthias.ringwald  *    notice, this list of conditions and the following disclaimer.
10a3b02b71Smatthias.ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11a3b02b71Smatthias.ringwald  *    notice, this list of conditions and the following disclaimer in the
12a3b02b71Smatthias.ringwald  *    documentation and/or other materials provided with the distribution.
13a3b02b71Smatthias.ringwald  * 3. Neither the name of the copyright holders nor the names of
14a3b02b71Smatthias.ringwald  *    contributors may be used to endorse or promote products derived
15a3b02b71Smatthias.ringwald  *    from this software without specific prior written permission.
166b64433eSmatthias.ringwald  * 4. Any redistribution, use, or modification is done solely for
176b64433eSmatthias.ringwald  *    personal benefit and not for any commercial purpose or for
186b64433eSmatthias.ringwald  *    monetary gain.
19a3b02b71Smatthias.ringwald  *
202e97c149S[email protected]  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21a3b02b71Smatthias.ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22a3b02b71Smatthias.ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23a3b02b71Smatthias.ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24a3b02b71Smatthias.ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25a3b02b71Smatthias.ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26a3b02b71Smatthias.ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27a3b02b71Smatthias.ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28a3b02b71Smatthias.ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29a3b02b71Smatthias.ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30a3b02b71Smatthias.ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a3b02b71Smatthias.ringwald  * SUCH DAMAGE.
32a3b02b71Smatthias.ringwald  *
332e97c149S[email protected]  * Please inquire about commercial licensing options at
342e97c149S[email protected]  * [email protected]
356b64433eSmatthias.ringwald  *
36a3b02b71Smatthias.ringwald  */
37a3b02b71Smatthias.ringwald 
38f7434c1fSMatthias Ringwald 
39e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_memory.c"
40bb2a7656SMatthias Ringwald 
41*b6269742SMatthias Ringwald 
42a3b02b71Smatthias.ringwald /*
43f7434c1fSMatthias Ringwald  *  btstack_memory.c
44a3b02b71Smatthias.ringwald  *
45a3b02b71Smatthias.ringwald  *  @brief BTstack memory management via configurable memory pools
46a3b02b71Smatthias.ringwald  *
47a98592bcSMatthias Ringwald  *  @note code generated by tool/btstack_memory_generator.py
48a2673d88SMatthias Ringwald  *  @note returnes buffers are initialized with 0
49a3b02b71Smatthias.ringwald  *
50a3b02b71Smatthias.ringwald  */
51a3b02b71Smatthias.ringwald 
52a3b02b71Smatthias.ringwald #include "btstack_memory.h"
53d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h"
54*b6269742SMatthias Ringwald #include "btstack_debug.h"
55a3b02b71Smatthias.ringwald 
56a3b02b71Smatthias.ringwald #include <stdlib.h>
57a3b02b71Smatthias.ringwald 
58*b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
59*b6269742SMatthias Ringwald typedef struct btstack_memory_buffer {
60*b6269742SMatthias Ringwald     struct btstack_memory_buffer * next;
61*b6269742SMatthias Ringwald     struct btstack_memory_buffer * prev;
62*b6269742SMatthias Ringwald } btstack_memory_buffer_t;
63*b6269742SMatthias Ringwald 
64*b6269742SMatthias Ringwald static btstack_memory_buffer_t * btstack_memory_malloc_buffers;
65*b6269742SMatthias Ringwald 
66*b6269742SMatthias Ringwald static void btstack_memory_tracking_add(void * raw_buffer){
67*b6269742SMatthias Ringwald     btstack_assert(raw_buffer != NULL);
68*b6269742SMatthias Ringwald     btstack_memory_buffer_t * buffer = (btstack_memory_buffer_t*) raw_buffer;
69*b6269742SMatthias Ringwald     buffer->prev = NULL;
70*b6269742SMatthias Ringwald     buffer->next = btstack_memory_malloc_buffers;
71*b6269742SMatthias Ringwald     if (btstack_memory_malloc_buffers) {
72*b6269742SMatthias Ringwald         btstack_memory_malloc_buffers->prev = buffer;
73*b6269742SMatthias Ringwald     }
74*b6269742SMatthias Ringwald     btstack_memory_malloc_buffers = buffer;
75*b6269742SMatthias Ringwald }
76*b6269742SMatthias Ringwald 
77*b6269742SMatthias Ringwald static void btstack_memory_tracking_remove(void * raw_buffer){
78*b6269742SMatthias Ringwald     btstack_assert(raw_buffer != NULL);
79*b6269742SMatthias Ringwald     btstack_memory_buffer_t * buffer = (btstack_memory_buffer_t*) raw_buffer;
80*b6269742SMatthias Ringwald     if (buffer->prev == NULL){
81*b6269742SMatthias Ringwald         // first item
82*b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
83*b6269742SMatthias Ringwald     } else {
84*b6269742SMatthias Ringwald         buffer->prev->next = buffer->next;
85*b6269742SMatthias Ringwald     }
86*b6269742SMatthias Ringwald     if (buffer->next != NULL){
87*b6269742SMatthias Ringwald         buffer->next->prev = buffer->prev;
88*b6269742SMatthias Ringwald     }
89*b6269742SMatthias Ringwald }
90*b6269742SMatthias Ringwald #endif
91*b6269742SMatthias Ringwald 
92*b6269742SMatthias Ringwald void btstack_memory_deinit(void){
93*b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
94*b6269742SMatthias Ringwald     while (btstack_memory_malloc_buffers != NULL){
95*b6269742SMatthias Ringwald         btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers;
96*b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
97*b6269742SMatthias Ringwald         free(buffer);
98*b6269742SMatthias Ringwald     }
99*b6269742SMatthias Ringwald #endif
100*b6269742SMatthias Ringwald }
101a3b02b71Smatthias.ringwald 
1022e97c149S[email protected] 
103a3b02b71Smatthias.ringwald // MARK: hci_connection_t
104a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
105a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
10627faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_HCI_CONNECTIONS defined instead of MAX_NR_HCI_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HCI_CONNECTIONS."
107a265b909SMatthias Ringwald     #else
108a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
109a265b909SMatthias Ringwald     #endif
110a265b909SMatthias Ringwald #endif
111a265b909SMatthias Ringwald 
112a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
113a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
114a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
11529d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
1166527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
117a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
118a2673d88SMatthias Ringwald     if (buffer){
119a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
120a2673d88SMatthias Ringwald     }
121a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
122a3b02b71Smatthias.ringwald }
1236527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
12429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
125a3b02b71Smatthias.ringwald }
126c4d3f927Smatthias.ringwald #else
1276527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
128c4d3f927Smatthias.ringwald     return NULL;
129c4d3f927Smatthias.ringwald }
1306527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
131*b6269742SMatthias Ringwald     UNUSED(hci_connection);
132c4d3f927Smatthias.ringwald };
133c4d3f927Smatthias.ringwald #endif
134a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1356527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
136*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(hci_connection_t) + sizeof(btstack_memory_buffer_t));
137a2673d88SMatthias Ringwald     if (buffer){
138*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t) + sizeof(btstack_memory_buffer_t));
139*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
140*b6269742SMatthias Ringwald         return (hci_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
141*b6269742SMatthias Ringwald     } else {
142*b6269742SMatthias Ringwald         return NULL;
143a2673d88SMatthias Ringwald     }
144a3b02b71Smatthias.ringwald }
1456527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
146*b6269742SMatthias Ringwald     void * buffer =  ((void *) hci_connection) - sizeof(btstack_memory_buffer_t);
147*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
148*b6269742SMatthias Ringwald     free(buffer);
149a3b02b71Smatthias.ringwald }
150a3b02b71Smatthias.ringwald #endif
151a3b02b71Smatthias.ringwald 
152a3b02b71Smatthias.ringwald 
1532e97c149S[email protected] 
154a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
155a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
156a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
15727faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_L2CAP_SERVICES defined instead of MAX_NR_L2CAP_SERVICES. Please update your btstack_config.h to use MAX_NR_L2CAP_SERVICES."
158a265b909SMatthias Ringwald     #else
159a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
160a265b909SMatthias Ringwald     #endif
161a265b909SMatthias Ringwald #endif
162a265b909SMatthias Ringwald 
163a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
164a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
165a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
16629d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1676527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
168a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
169a2673d88SMatthias Ringwald     if (buffer){
170a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
171a2673d88SMatthias Ringwald     }
172a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
173a3b02b71Smatthias.ringwald }
1746527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
17529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
176a3b02b71Smatthias.ringwald }
177c4d3f927Smatthias.ringwald #else
1786527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
179c4d3f927Smatthias.ringwald     return NULL;
180c4d3f927Smatthias.ringwald }
1816527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
182*b6269742SMatthias Ringwald     UNUSED(l2cap_service);
183c4d3f927Smatthias.ringwald };
184c4d3f927Smatthias.ringwald #endif
185a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1866527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
187*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_service_t) + sizeof(btstack_memory_buffer_t));
188a2673d88SMatthias Ringwald     if (buffer){
189*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t) + sizeof(btstack_memory_buffer_t));
190*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
191*b6269742SMatthias Ringwald         return (l2cap_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
192*b6269742SMatthias Ringwald     } else {
193*b6269742SMatthias Ringwald         return NULL;
194a2673d88SMatthias Ringwald     }
195a3b02b71Smatthias.ringwald }
1966527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
197*b6269742SMatthias Ringwald     void * buffer =  ((void *) l2cap_service) - sizeof(btstack_memory_buffer_t);
198*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
199*b6269742SMatthias Ringwald     free(buffer);
200a3b02b71Smatthias.ringwald }
201a3b02b71Smatthias.ringwald #endif
202a3b02b71Smatthias.ringwald 
203a3b02b71Smatthias.ringwald 
204a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
205a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
206a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
20727faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_L2CAP_CHANNELS defined instead of MAX_NR_L2CAP_CHANNELS. Please update your btstack_config.h to use MAX_NR_L2CAP_CHANNELS."
208a265b909SMatthias Ringwald     #else
209a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
210a265b909SMatthias Ringwald     #endif
211a265b909SMatthias Ringwald #endif
212a265b909SMatthias Ringwald 
213a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
214a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
215a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
21629d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
2176527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
218a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
219a2673d88SMatthias Ringwald     if (buffer){
220a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
221a2673d88SMatthias Ringwald     }
222a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
223a3b02b71Smatthias.ringwald }
2246527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
22529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
226a3b02b71Smatthias.ringwald }
227c4d3f927Smatthias.ringwald #else
2286527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
229c4d3f927Smatthias.ringwald     return NULL;
230c4d3f927Smatthias.ringwald }
2316527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
232*b6269742SMatthias Ringwald     UNUSED(l2cap_channel);
233c4d3f927Smatthias.ringwald };
234c4d3f927Smatthias.ringwald #endif
235a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2366527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
237*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_channel_t) + sizeof(btstack_memory_buffer_t));
238a2673d88SMatthias Ringwald     if (buffer){
239*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t) + sizeof(btstack_memory_buffer_t));
240*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
241*b6269742SMatthias Ringwald         return (l2cap_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
242*b6269742SMatthias Ringwald     } else {
243*b6269742SMatthias Ringwald         return NULL;
244a2673d88SMatthias Ringwald     }
245a3b02b71Smatthias.ringwald }
2466527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
247*b6269742SMatthias Ringwald     void * buffer =  ((void *) l2cap_channel) - sizeof(btstack_memory_buffer_t);
248*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
249*b6269742SMatthias Ringwald     free(buffer);
250a3b02b71Smatthias.ringwald }
251a3b02b71Smatthias.ringwald #endif
252a3b02b71Smatthias.ringwald 
253a3b02b71Smatthias.ringwald 
25444c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
2552e97c149S[email protected] 
256a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
257a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
258a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
25927faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_RFCOMM_MULTIPLEXERS defined instead of MAX_NR_RFCOMM_MULTIPLEXERS. Please update your btstack_config.h to use MAX_NR_RFCOMM_MULTIPLEXERS."
260a265b909SMatthias Ringwald     #else
261a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
262a265b909SMatthias Ringwald     #endif
263a265b909SMatthias Ringwald #endif
264a265b909SMatthias Ringwald 
265a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
266a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
267a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
26829d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
2696527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
270a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
271a2673d88SMatthias Ringwald     if (buffer){
272a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
273a2673d88SMatthias Ringwald     }
274a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
275a3b02b71Smatthias.ringwald }
2766527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
27729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
278a3b02b71Smatthias.ringwald }
279c4d3f927Smatthias.ringwald #else
2806527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
281c4d3f927Smatthias.ringwald     return NULL;
282c4d3f927Smatthias.ringwald }
2836527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
284*b6269742SMatthias Ringwald     UNUSED(rfcomm_multiplexer);
285c4d3f927Smatthias.ringwald };
286c4d3f927Smatthias.ringwald #endif
287a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2886527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
289*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_multiplexer_t) + sizeof(btstack_memory_buffer_t));
290a2673d88SMatthias Ringwald     if (buffer){
291*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t) + sizeof(btstack_memory_buffer_t));
292*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
293*b6269742SMatthias Ringwald         return (rfcomm_multiplexer_t *) (buffer + sizeof(btstack_memory_buffer_t));
294*b6269742SMatthias Ringwald     } else {
295*b6269742SMatthias Ringwald         return NULL;
296a2673d88SMatthias Ringwald     }
297a3b02b71Smatthias.ringwald }
2986527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
299*b6269742SMatthias Ringwald     void * buffer =  ((void *) rfcomm_multiplexer) - sizeof(btstack_memory_buffer_t);
300*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
301*b6269742SMatthias Ringwald     free(buffer);
302a3b02b71Smatthias.ringwald }
303a3b02b71Smatthias.ringwald #endif
304a3b02b71Smatthias.ringwald 
305a3b02b71Smatthias.ringwald 
306a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
307a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
308a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
30927faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_RFCOMM_SERVICES defined instead of MAX_NR_RFCOMM_SERVICES. Please update your btstack_config.h to use MAX_NR_RFCOMM_SERVICES."
310a265b909SMatthias Ringwald     #else
311a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
312a265b909SMatthias Ringwald     #endif
313a265b909SMatthias Ringwald #endif
314a265b909SMatthias Ringwald 
315a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
316a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
317a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
31829d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
3196527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
320a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
321a2673d88SMatthias Ringwald     if (buffer){
322a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
323a2673d88SMatthias Ringwald     }
324a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
325a3b02b71Smatthias.ringwald }
3266527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
32729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
328a3b02b71Smatthias.ringwald }
329c4d3f927Smatthias.ringwald #else
3306527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
331c4d3f927Smatthias.ringwald     return NULL;
332c4d3f927Smatthias.ringwald }
3336527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
334*b6269742SMatthias Ringwald     UNUSED(rfcomm_service);
335c4d3f927Smatthias.ringwald };
336c4d3f927Smatthias.ringwald #endif
337a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3386527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
339*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_service_t) + sizeof(btstack_memory_buffer_t));
340a2673d88SMatthias Ringwald     if (buffer){
341*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t) + sizeof(btstack_memory_buffer_t));
342*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
343*b6269742SMatthias Ringwald         return (rfcomm_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
344*b6269742SMatthias Ringwald     } else {
345*b6269742SMatthias Ringwald         return NULL;
346a2673d88SMatthias Ringwald     }
347a3b02b71Smatthias.ringwald }
3486527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
349*b6269742SMatthias Ringwald     void * buffer =  ((void *) rfcomm_service) - sizeof(btstack_memory_buffer_t);
350*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
351*b6269742SMatthias Ringwald     free(buffer);
352a3b02b71Smatthias.ringwald }
353a3b02b71Smatthias.ringwald #endif
354a3b02b71Smatthias.ringwald 
355a3b02b71Smatthias.ringwald 
356a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
357a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
358a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
35927faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_RFCOMM_CHANNELS defined instead of MAX_NR_RFCOMM_CHANNELS. Please update your btstack_config.h to use MAX_NR_RFCOMM_CHANNELS."
360a265b909SMatthias Ringwald     #else
361a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
362a265b909SMatthias Ringwald     #endif
363a265b909SMatthias Ringwald #endif
364a265b909SMatthias Ringwald 
365a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
366a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
367a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
36829d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
3696527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
370a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
371a2673d88SMatthias Ringwald     if (buffer){
372a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
373a2673d88SMatthias Ringwald     }
374a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
375a3b02b71Smatthias.ringwald }
3766527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
37729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
378a3b02b71Smatthias.ringwald }
379c4d3f927Smatthias.ringwald #else
3806527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
381c4d3f927Smatthias.ringwald     return NULL;
382c4d3f927Smatthias.ringwald }
3836527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
384*b6269742SMatthias Ringwald     UNUSED(rfcomm_channel);
385c4d3f927Smatthias.ringwald };
386c4d3f927Smatthias.ringwald #endif
387a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3886527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
389*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_channel_t) + sizeof(btstack_memory_buffer_t));
390a2673d88SMatthias Ringwald     if (buffer){
391*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t) + sizeof(btstack_memory_buffer_t));
392*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
393*b6269742SMatthias Ringwald         return (rfcomm_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
394*b6269742SMatthias Ringwald     } else {
395*b6269742SMatthias Ringwald         return NULL;
396a2673d88SMatthias Ringwald     }
397a3b02b71Smatthias.ringwald }
3986527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
399*b6269742SMatthias Ringwald     void * buffer =  ((void *) rfcomm_channel) - sizeof(btstack_memory_buffer_t);
400*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
401*b6269742SMatthias Ringwald     free(buffer);
402a3b02b71Smatthias.ringwald }
403a3b02b71Smatthias.ringwald #endif
404a3b02b71Smatthias.ringwald 
405fdb398c2S[email protected] 
406e0e5e285Smatthias.ringwald 
4072c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
408a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
409a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
41027faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES defined instead of MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES. Please update your btstack_config.h to use MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES."
411a265b909SMatthias Ringwald     #else
412a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
413a265b909SMatthias Ringwald     #endif
414a265b909SMatthias Ringwald #endif
415a265b909SMatthias Ringwald 
416a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
417a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
418a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
4192c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
4202c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
421a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
422a2673d88SMatthias Ringwald     if (buffer){
423a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
424a2673d88SMatthias Ringwald     }
425a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
4261801b596Smatthias.ringwald }
4272c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
4282c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
4291801b596Smatthias.ringwald }
430c4d3f927Smatthias.ringwald #else
4312c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
432c4d3f927Smatthias.ringwald     return NULL;
433c4d3f927Smatthias.ringwald }
4342c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
435*b6269742SMatthias Ringwald     UNUSED(btstack_link_key_db_memory_entry);
436c4d3f927Smatthias.ringwald };
437c4d3f927Smatthias.ringwald #endif
4381801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
4392c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
440*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t) + sizeof(btstack_memory_buffer_t));
441a2673d88SMatthias Ringwald     if (buffer){
442*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t) + sizeof(btstack_memory_buffer_t));
443*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
444*b6269742SMatthias Ringwald         return (btstack_link_key_db_memory_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
445*b6269742SMatthias Ringwald     } else {
446*b6269742SMatthias Ringwald         return NULL;
447a2673d88SMatthias Ringwald     }
4481801b596Smatthias.ringwald }
4492c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
450*b6269742SMatthias Ringwald     void * buffer =  ((void *) btstack_link_key_db_memory_entry) - sizeof(btstack_memory_buffer_t);
451*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
452*b6269742SMatthias Ringwald     free(buffer);
453e0e5e285Smatthias.ringwald }
4541801b596Smatthias.ringwald #endif
4551801b596Smatthias.ringwald 
4562e97c149S[email protected] 
4572e97c149S[email protected] 
4582e97c149S[email protected] // MARK: bnep_service_t
459a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
460a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
46127faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_BNEP_SERVICES defined instead of MAX_NR_BNEP_SERVICES. Please update your btstack_config.h to use MAX_NR_BNEP_SERVICES."
462a265b909SMatthias Ringwald     #else
463a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
464a265b909SMatthias Ringwald     #endif
465a265b909SMatthias Ringwald #endif
466a265b909SMatthias Ringwald 
467a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
468a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
469a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
47029d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
4712e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
472a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
473a2673d88SMatthias Ringwald     if (buffer){
474a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
475a2673d88SMatthias Ringwald     }
476a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
4772e97c149S[email protected] }
4782e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
47929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
4802e97c149S[email protected] }
4812e97c149S[email protected] #else
4822e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
4832e97c149S[email protected]     return NULL;
4842e97c149S[email protected] }
4852e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
486*b6269742SMatthias Ringwald     UNUSED(bnep_service);
4872e97c149S[email protected] };
4882e97c149S[email protected] #endif
4892e97c149S[email protected] #elif defined(HAVE_MALLOC)
4902e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
491*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_service_t) + sizeof(btstack_memory_buffer_t));
492a2673d88SMatthias Ringwald     if (buffer){
493*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t) + sizeof(btstack_memory_buffer_t));
494*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
495*b6269742SMatthias Ringwald         return (bnep_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
496*b6269742SMatthias Ringwald     } else {
497*b6269742SMatthias Ringwald         return NULL;
498a2673d88SMatthias Ringwald     }
4992e97c149S[email protected] }
5002e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
501*b6269742SMatthias Ringwald     void * buffer =  ((void *) bnep_service) - sizeof(btstack_memory_buffer_t);
502*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
503*b6269742SMatthias Ringwald     free(buffer);
5042e97c149S[email protected] }
5052e97c149S[email protected] #endif
5062e97c149S[email protected] 
5072e97c149S[email protected] 
5082e97c149S[email protected] // MARK: bnep_channel_t
509a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
510a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
51127faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_BNEP_CHANNELS defined instead of MAX_NR_BNEP_CHANNELS. Please update your btstack_config.h to use MAX_NR_BNEP_CHANNELS."
512a265b909SMatthias Ringwald     #else
513a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
514a265b909SMatthias Ringwald     #endif
515a265b909SMatthias Ringwald #endif
516a265b909SMatthias Ringwald 
517a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
518a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
519a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
52029d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
5212e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
522a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
523a2673d88SMatthias Ringwald     if (buffer){
524a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
525a2673d88SMatthias Ringwald     }
526a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
5272e97c149S[email protected] }
5282e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
52929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
5302e97c149S[email protected] }
5312e97c149S[email protected] #else
5322e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
5332e97c149S[email protected]     return NULL;
5342e97c149S[email protected] }
5352e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
536*b6269742SMatthias Ringwald     UNUSED(bnep_channel);
5372e97c149S[email protected] };
5382e97c149S[email protected] #endif
5392e97c149S[email protected] #elif defined(HAVE_MALLOC)
5402e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
541*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_channel_t) + sizeof(btstack_memory_buffer_t));
542a2673d88SMatthias Ringwald     if (buffer){
543*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t) + sizeof(btstack_memory_buffer_t));
544*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
545*b6269742SMatthias Ringwald         return (bnep_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
546*b6269742SMatthias Ringwald     } else {
547*b6269742SMatthias Ringwald         return NULL;
548a2673d88SMatthias Ringwald     }
5492e97c149S[email protected] }
5502e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
551*b6269742SMatthias Ringwald     void * buffer =  ((void *) bnep_channel) - sizeof(btstack_memory_buffer_t);
552*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
553*b6269742SMatthias Ringwald     free(buffer);
5542e97c149S[email protected] }
5552e97c149S[email protected] #endif
5562e97c149S[email protected] 
5572e97c149S[email protected] 
558ea5029c9SMilanka Ringwald 
559ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
560a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
561a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
56227faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_HFP_CONNECTIONS defined instead of MAX_NR_HFP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HFP_CONNECTIONS."
563a265b909SMatthias Ringwald     #else
564a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
565a265b909SMatthias Ringwald     #endif
566a265b909SMatthias Ringwald #endif
567a265b909SMatthias Ringwald 
568a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
569a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
570a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
57129d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
572ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
573a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
574a2673d88SMatthias Ringwald     if (buffer){
575a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
576a2673d88SMatthias Ringwald     }
577a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
578ea5029c9SMilanka Ringwald }
579ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
58029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
581ea5029c9SMilanka Ringwald }
582ea5029c9SMilanka Ringwald #else
583ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
584ea5029c9SMilanka Ringwald     return NULL;
585ea5029c9SMilanka Ringwald }
586ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
587*b6269742SMatthias Ringwald     UNUSED(hfp_connection);
588ea5029c9SMilanka Ringwald };
589ea5029c9SMilanka Ringwald #endif
590ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
591ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
592*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(hfp_connection_t) + sizeof(btstack_memory_buffer_t));
593a2673d88SMatthias Ringwald     if (buffer){
594*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t) + sizeof(btstack_memory_buffer_t));
595*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
596*b6269742SMatthias Ringwald         return (hfp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
597*b6269742SMatthias Ringwald     } else {
598*b6269742SMatthias Ringwald         return NULL;
599a2673d88SMatthias Ringwald     }
600ea5029c9SMilanka Ringwald }
601ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
602*b6269742SMatthias Ringwald     void * buffer =  ((void *) hfp_connection) - sizeof(btstack_memory_buffer_t);
603*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
604*b6269742SMatthias Ringwald     free(buffer);
605ea5029c9SMilanka Ringwald }
606ea5029c9SMilanka Ringwald #endif
607ea5029c9SMilanka Ringwald 
608ea5029c9SMilanka Ringwald 
609cd9ee144SMatthias Ringwald 
610cd9ee144SMatthias Ringwald // MARK: service_record_item_t
611a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
612a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
61327faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_SERVICE_RECORD_ITEMS defined instead of MAX_NR_SERVICE_RECORD_ITEMS. Please update your btstack_config.h to use MAX_NR_SERVICE_RECORD_ITEMS."
614a265b909SMatthias Ringwald     #else
615a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
616a265b909SMatthias Ringwald     #endif
617a265b909SMatthias Ringwald #endif
618a265b909SMatthias Ringwald 
619a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
620a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
621a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
62229d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
623cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
624a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
625a2673d88SMatthias Ringwald     if (buffer){
626a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
627a2673d88SMatthias Ringwald     }
628a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
629cd9ee144SMatthias Ringwald }
630cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
63129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
632cd9ee144SMatthias Ringwald }
633cd9ee144SMatthias Ringwald #else
634cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
635cd9ee144SMatthias Ringwald     return NULL;
636cd9ee144SMatthias Ringwald }
637cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
638*b6269742SMatthias Ringwald     UNUSED(service_record_item);
639cd9ee144SMatthias Ringwald };
640cd9ee144SMatthias Ringwald #endif
641cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
642cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
643*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(service_record_item_t) + sizeof(btstack_memory_buffer_t));
644a2673d88SMatthias Ringwald     if (buffer){
645*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t) + sizeof(btstack_memory_buffer_t));
646*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
647*b6269742SMatthias Ringwald         return (service_record_item_t *) (buffer + sizeof(btstack_memory_buffer_t));
648*b6269742SMatthias Ringwald     } else {
649*b6269742SMatthias Ringwald         return NULL;
650a2673d88SMatthias Ringwald     }
651cd9ee144SMatthias Ringwald }
652cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
653*b6269742SMatthias Ringwald     void * buffer =  ((void *) service_record_item) - sizeof(btstack_memory_buffer_t);
654*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
655*b6269742SMatthias Ringwald     free(buffer);
656cd9ee144SMatthias Ringwald }
657cd9ee144SMatthias Ringwald #endif
658cd9ee144SMatthias Ringwald 
659cd9ee144SMatthias Ringwald 
66027faf85aSMilanka Ringwald 
6610e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
6620e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
6630e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
6640e826a17SMilanka Ringwald         #error "Deprecated MAX_NO_AVDTP_STREAM_ENDPOINTS defined instead of MAX_NR_AVDTP_STREAM_ENDPOINTS. Please update your btstack_config.h to use MAX_NR_AVDTP_STREAM_ENDPOINTS."
66527faf85aSMilanka Ringwald     #else
6660e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
66727faf85aSMilanka Ringwald     #endif
66827faf85aSMilanka Ringwald #endif
66927faf85aSMilanka Ringwald 
6700e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
6710e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
6720e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
6730e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
6740e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
675a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
676a2673d88SMatthias Ringwald     if (buffer){
677a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
678a2673d88SMatthias Ringwald     }
679a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
68027faf85aSMilanka Ringwald }
6810e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
6820e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
68327faf85aSMilanka Ringwald }
68427faf85aSMilanka Ringwald #else
6850e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
68627faf85aSMilanka Ringwald     return NULL;
68727faf85aSMilanka Ringwald }
6880e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
689*b6269742SMatthias Ringwald     UNUSED(avdtp_stream_endpoint);
69027faf85aSMilanka Ringwald };
69127faf85aSMilanka Ringwald #endif
69227faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
6930e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
694*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_stream_endpoint_t) + sizeof(btstack_memory_buffer_t));
695a2673d88SMatthias Ringwald     if (buffer){
696*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t) + sizeof(btstack_memory_buffer_t));
697*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
698*b6269742SMatthias Ringwald         return (avdtp_stream_endpoint_t *) (buffer + sizeof(btstack_memory_buffer_t));
699*b6269742SMatthias Ringwald     } else {
700*b6269742SMatthias Ringwald         return NULL;
701a2673d88SMatthias Ringwald     }
70227faf85aSMilanka Ringwald }
7030e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
704*b6269742SMatthias Ringwald     void * buffer =  ((void *) avdtp_stream_endpoint) - sizeof(btstack_memory_buffer_t);
705*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
706*b6269742SMatthias Ringwald     free(buffer);
70727faf85aSMilanka Ringwald }
70827faf85aSMilanka Ringwald #endif
70927faf85aSMilanka Ringwald 
71027faf85aSMilanka Ringwald 
71112e7f38cSMilanka Ringwald 
71212e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
71312e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
71412e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
71512e7f38cSMilanka Ringwald         #error "Deprecated MAX_NO_AVDTP_CONNECTIONS defined instead of MAX_NR_AVDTP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVDTP_CONNECTIONS."
71612e7f38cSMilanka Ringwald     #else
71712e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
71812e7f38cSMilanka Ringwald     #endif
71912e7f38cSMilanka Ringwald #endif
72012e7f38cSMilanka Ringwald 
72112e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
72212e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
72312e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
72412e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
72512e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
726a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
727a2673d88SMatthias Ringwald     if (buffer){
728a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
729a2673d88SMatthias Ringwald     }
730a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
73112e7f38cSMilanka Ringwald }
73212e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
73312e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
73412e7f38cSMilanka Ringwald }
73512e7f38cSMilanka Ringwald #else
73612e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
73712e7f38cSMilanka Ringwald     return NULL;
73812e7f38cSMilanka Ringwald }
73912e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
740*b6269742SMatthias Ringwald     UNUSED(avdtp_connection);
74112e7f38cSMilanka Ringwald };
74212e7f38cSMilanka Ringwald #endif
74312e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
74412e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
745*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_connection_t) + sizeof(btstack_memory_buffer_t));
746a2673d88SMatthias Ringwald     if (buffer){
747*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t) + sizeof(btstack_memory_buffer_t));
748*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
749*b6269742SMatthias Ringwald         return (avdtp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
750*b6269742SMatthias Ringwald     } else {
751*b6269742SMatthias Ringwald         return NULL;
752a2673d88SMatthias Ringwald     }
75312e7f38cSMilanka Ringwald }
75412e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
755*b6269742SMatthias Ringwald     void * buffer =  ((void *) avdtp_connection) - sizeof(btstack_memory_buffer_t);
756*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
757*b6269742SMatthias Ringwald     free(buffer);
75812e7f38cSMilanka Ringwald }
75912e7f38cSMilanka Ringwald #endif
76012e7f38cSMilanka Ringwald 
76112e7f38cSMilanka Ringwald 
76291451a2bSMilanka Ringwald 
76391451a2bSMilanka Ringwald // MARK: avrcp_connection_t
76491451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
76591451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
76691451a2bSMilanka Ringwald         #error "Deprecated MAX_NO_AVRCP_CONNECTIONS defined instead of MAX_NR_AVRCP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_CONNECTIONS."
76791451a2bSMilanka Ringwald     #else
76891451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
76991451a2bSMilanka Ringwald     #endif
77091451a2bSMilanka Ringwald #endif
77191451a2bSMilanka Ringwald 
77291451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
77391451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
77491451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
77591451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
77691451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
777a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
778a2673d88SMatthias Ringwald     if (buffer){
779a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
780a2673d88SMatthias Ringwald     }
781a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
78291451a2bSMilanka Ringwald }
78391451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
78491451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
78591451a2bSMilanka Ringwald }
78691451a2bSMilanka Ringwald #else
78791451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
78891451a2bSMilanka Ringwald     return NULL;
78991451a2bSMilanka Ringwald }
79091451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
791*b6269742SMatthias Ringwald     UNUSED(avrcp_connection);
79291451a2bSMilanka Ringwald };
79391451a2bSMilanka Ringwald #endif
79491451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
79591451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
796*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_connection_t) + sizeof(btstack_memory_buffer_t));
797a2673d88SMatthias Ringwald     if (buffer){
798*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t) + sizeof(btstack_memory_buffer_t));
799*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
800*b6269742SMatthias Ringwald         return (avrcp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
801*b6269742SMatthias Ringwald     } else {
802*b6269742SMatthias Ringwald         return NULL;
803a2673d88SMatthias Ringwald     }
80491451a2bSMilanka Ringwald }
80591451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
806*b6269742SMatthias Ringwald     void * buffer =  ((void *) avrcp_connection) - sizeof(btstack_memory_buffer_t);
807*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
808*b6269742SMatthias Ringwald     free(buffer);
80991451a2bSMilanka Ringwald }
81091451a2bSMilanka Ringwald #endif
81191451a2bSMilanka Ringwald 
81291451a2bSMilanka Ringwald 
813f12a3722SMilanka Ringwald 
814f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
815f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
816f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
817f12a3722SMilanka Ringwald         #error "Deprecated MAX_NO_AVRCP_BROWSING_CONNECTIONS defined instead of MAX_NR_AVRCP_BROWSING_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_BROWSING_CONNECTIONS."
818f12a3722SMilanka Ringwald     #else
819f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
820f12a3722SMilanka Ringwald     #endif
821f12a3722SMilanka Ringwald #endif
822f12a3722SMilanka Ringwald 
823f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
824f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
825f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
826f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
827f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
828a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
829a2673d88SMatthias Ringwald     if (buffer){
830a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
831a2673d88SMatthias Ringwald     }
832a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
833f12a3722SMilanka Ringwald }
834f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
835f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
836f12a3722SMilanka Ringwald }
837f12a3722SMilanka Ringwald #else
838f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
839f12a3722SMilanka Ringwald     return NULL;
840f12a3722SMilanka Ringwald }
841f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
842*b6269742SMatthias Ringwald     UNUSED(avrcp_browsing_connection);
843f12a3722SMilanka Ringwald };
844f12a3722SMilanka Ringwald #endif
845f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
846f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
847*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_browsing_connection_t) + sizeof(btstack_memory_buffer_t));
848a2673d88SMatthias Ringwald     if (buffer){
849*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t) + sizeof(btstack_memory_buffer_t));
850*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
851*b6269742SMatthias Ringwald         return (avrcp_browsing_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
852*b6269742SMatthias Ringwald     } else {
853*b6269742SMatthias Ringwald         return NULL;
854a2673d88SMatthias Ringwald     }
855f12a3722SMilanka Ringwald }
856f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
857*b6269742SMatthias Ringwald     void * buffer =  ((void *) avrcp_browsing_connection) - sizeof(btstack_memory_buffer_t);
858*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
859*b6269742SMatthias Ringwald     free(buffer);
860f12a3722SMilanka Ringwald }
861f12a3722SMilanka Ringwald #endif
862f12a3722SMilanka Ringwald 
863f12a3722SMilanka Ringwald 
86444c5d856SMatthias Ringwald #endif
865a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
8662e97c149S[email protected] 
8672e97c149S[email protected] // MARK: gatt_client_t
868a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
869a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
87027faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_GATT_CLIENTS defined instead of MAX_NR_GATT_CLIENTS. Please update your btstack_config.h to use MAX_NR_GATT_CLIENTS."
871a265b909SMatthias Ringwald     #else
872a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
873a265b909SMatthias Ringwald     #endif
874a265b909SMatthias Ringwald #endif
875a265b909SMatthias Ringwald 
876a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
877a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
878a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
87929d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
880d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
881a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
882a2673d88SMatthias Ringwald     if (buffer){
883a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
884a2673d88SMatthias Ringwald     }
885a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
886d0fdae3cS[email protected] }
887d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
88829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
889d0fdae3cS[email protected] }
890d0fdae3cS[email protected] #else
891d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
892d0fdae3cS[email protected]     return NULL;
893d0fdae3cS[email protected] }
894d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
895*b6269742SMatthias Ringwald     UNUSED(gatt_client);
896d0fdae3cS[email protected] };
897d0fdae3cS[email protected] #endif
898d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
899d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
900*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(gatt_client_t) + sizeof(btstack_memory_buffer_t));
901a2673d88SMatthias Ringwald     if (buffer){
902*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t) + sizeof(btstack_memory_buffer_t));
903*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
904*b6269742SMatthias Ringwald         return (gatt_client_t *) (buffer + sizeof(btstack_memory_buffer_t));
905*b6269742SMatthias Ringwald     } else {
906*b6269742SMatthias Ringwald         return NULL;
907a2673d88SMatthias Ringwald     }
908d0fdae3cS[email protected] }
909d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
910*b6269742SMatthias Ringwald     void * buffer =  ((void *) gatt_client) - sizeof(btstack_memory_buffer_t);
911*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
912*b6269742SMatthias Ringwald     free(buffer);
913d0fdae3cS[email protected] }
914d0fdae3cS[email protected] #endif
9152e97c149S[email protected] 
9162e97c149S[email protected] 
917656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
918a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
919a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
92027faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_WHITELIST_ENTRIES defined instead of MAX_NR_WHITELIST_ENTRIES. Please update your btstack_config.h to use MAX_NR_WHITELIST_ENTRIES."
921a265b909SMatthias Ringwald     #else
922a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
923a265b909SMatthias Ringwald     #endif
924a265b909SMatthias Ringwald #endif
925a265b909SMatthias Ringwald 
926a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
927a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
928a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
92929d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
930656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
931a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
932a2673d88SMatthias Ringwald     if (buffer){
933a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
934a2673d88SMatthias Ringwald     }
935a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
936656bec4fSMatthias Ringwald }
937656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
93829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
939656bec4fSMatthias Ringwald }
940656bec4fSMatthias Ringwald #else
941656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
942656bec4fSMatthias Ringwald     return NULL;
943656bec4fSMatthias Ringwald }
944656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
945*b6269742SMatthias Ringwald     UNUSED(whitelist_entry);
946656bec4fSMatthias Ringwald };
947656bec4fSMatthias Ringwald #endif
948656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
949656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
950*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(whitelist_entry_t) + sizeof(btstack_memory_buffer_t));
951a2673d88SMatthias Ringwald     if (buffer){
952*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t) + sizeof(btstack_memory_buffer_t));
953*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
954*b6269742SMatthias Ringwald         return (whitelist_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
955*b6269742SMatthias Ringwald     } else {
956*b6269742SMatthias Ringwald         return NULL;
957a2673d88SMatthias Ringwald     }
958656bec4fSMatthias Ringwald }
959656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
960*b6269742SMatthias Ringwald     void * buffer =  ((void *) whitelist_entry) - sizeof(btstack_memory_buffer_t);
961*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
962*b6269742SMatthias Ringwald     free(buffer);
963656bec4fSMatthias Ringwald }
964656bec4fSMatthias Ringwald #endif
965656bec4fSMatthias Ringwald 
966656bec4fSMatthias Ringwald 
967cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
968a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
969a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
97027faf85aSMilanka Ringwald         #error "Deprecated MAX_NO_SM_LOOKUP_ENTRIES defined instead of MAX_NR_SM_LOOKUP_ENTRIES. Please update your btstack_config.h to use MAX_NR_SM_LOOKUP_ENTRIES."
971a265b909SMatthias Ringwald     #else
972a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
973a265b909SMatthias Ringwald     #endif
974a265b909SMatthias Ringwald #endif
975a265b909SMatthias Ringwald 
976a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
977a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
978a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
97929d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
980cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
981a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
982a2673d88SMatthias Ringwald     if (buffer){
983a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
984a2673d88SMatthias Ringwald     }
985a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
986cf49570bSMatthias Ringwald }
987cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
98829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
989cf49570bSMatthias Ringwald }
990cf49570bSMatthias Ringwald #else
991cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
992cf49570bSMatthias Ringwald     return NULL;
993cf49570bSMatthias Ringwald }
994cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
995*b6269742SMatthias Ringwald     UNUSED(sm_lookup_entry);
996cf49570bSMatthias Ringwald };
997cf49570bSMatthias Ringwald #endif
998cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
999cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1000*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(sm_lookup_entry_t) + sizeof(btstack_memory_buffer_t));
1001a2673d88SMatthias Ringwald     if (buffer){
1002*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t) + sizeof(btstack_memory_buffer_t));
1003*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1004*b6269742SMatthias Ringwald         return (sm_lookup_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
1005*b6269742SMatthias Ringwald     } else {
1006*b6269742SMatthias Ringwald         return NULL;
1007a2673d88SMatthias Ringwald     }
1008cf49570bSMatthias Ringwald }
1009cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1010*b6269742SMatthias Ringwald     void * buffer =  ((void *) sm_lookup_entry) - sizeof(btstack_memory_buffer_t);
1011*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1012*b6269742SMatthias Ringwald     free(buffer);
1013cf49570bSMatthias Ringwald }
1014cf49570bSMatthias Ringwald #endif
1015cf49570bSMatthias Ringwald 
1016cf49570bSMatthias Ringwald 
101744c5d856SMatthias Ringwald #endif
101844c5d856SMatthias Ringwald #ifdef ENABLE_MESH
1019ebb73e1fSMatthias Ringwald 
1020ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t
1021ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
1022ebb73e1fSMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_PDUS)
1023ebb73e1fSMatthias Ringwald         #error "Deprecated MAX_NO_MESH_NETWORK_PDUS defined instead of MAX_NR_MESH_NETWORK_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_PDUS."
1024ebb73e1fSMatthias Ringwald     #else
1025ebb73e1fSMatthias Ringwald         #define MAX_NR_MESH_NETWORK_PDUS 0
1026ebb73e1fSMatthias Ringwald     #endif
1027ebb73e1fSMatthias Ringwald #endif
1028ebb73e1fSMatthias Ringwald 
1029ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
1030ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
1031ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
1032ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool;
1033ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
10341c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
10351c4e8084SMatthias Ringwald     if (buffer){
10361c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_pdu_t));
10371c4e8084SMatthias Ringwald     }
10381c4e8084SMatthias Ringwald     return (mesh_network_pdu_t *) buffer;
1039ebb73e1fSMatthias Ringwald }
1040ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1041ebb73e1fSMatthias Ringwald     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
1042ebb73e1fSMatthias Ringwald }
1043ebb73e1fSMatthias Ringwald #else
1044ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1045ebb73e1fSMatthias Ringwald     return NULL;
1046ebb73e1fSMatthias Ringwald }
1047ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1048*b6269742SMatthias Ringwald     UNUSED(mesh_network_pdu);
1049ebb73e1fSMatthias Ringwald };
1050ebb73e1fSMatthias Ringwald #endif
1051ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
1052ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1053*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_network_pdu_t) + sizeof(btstack_memory_buffer_t));
10541c4e8084SMatthias Ringwald     if (buffer){
1055*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_pdu_t) + sizeof(btstack_memory_buffer_t));
1056*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1057*b6269742SMatthias Ringwald         return (mesh_network_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1058*b6269742SMatthias Ringwald     } else {
1059*b6269742SMatthias Ringwald         return NULL;
10601c4e8084SMatthias Ringwald     }
1061ebb73e1fSMatthias Ringwald }
1062ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1063*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_network_pdu) - sizeof(btstack_memory_buffer_t);
1064*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1065*b6269742SMatthias Ringwald     free(buffer);
1066ebb73e1fSMatthias Ringwald }
1067ebb73e1fSMatthias Ringwald #endif
1068ebb73e1fSMatthias Ringwald 
1069ebb73e1fSMatthias Ringwald 
1070a4bbc09dSMatthias Ringwald // MARK: mesh_segmented_pdu_t
1071a4bbc09dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS)
1072a4bbc09dSMatthias Ringwald     #if defined(MAX_NO_MESH_SEGMENTED_PDUS)
1073a4bbc09dSMatthias Ringwald         #error "Deprecated MAX_NO_MESH_SEGMENTED_PDUS defined instead of MAX_NR_MESH_SEGMENTED_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_SEGMENTED_PDUS."
1074f7434c1fSMatthias Ringwald     #else
1075a4bbc09dSMatthias Ringwald         #define MAX_NR_MESH_SEGMENTED_PDUS 0
1076f7434c1fSMatthias Ringwald     #endif
1077f7434c1fSMatthias Ringwald #endif
1078f7434c1fSMatthias Ringwald 
1079a4bbc09dSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS
1080a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1081a4bbc09dSMatthias Ringwald static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS];
1082a4bbc09dSMatthias Ringwald static btstack_memory_pool_t mesh_segmented_pdu_pool;
1083a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1084a4bbc09dSMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool);
1085f7434c1fSMatthias Ringwald     if (buffer){
1086a4bbc09dSMatthias Ringwald         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1087f7434c1fSMatthias Ringwald     }
1088a4bbc09dSMatthias Ringwald     return (mesh_segmented_pdu_t *) buffer;
1089f7434c1fSMatthias Ringwald }
1090a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1091a4bbc09dSMatthias Ringwald     btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu);
1092f7434c1fSMatthias Ringwald }
1093f7434c1fSMatthias Ringwald #else
1094a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1095f7434c1fSMatthias Ringwald     return NULL;
1096f7434c1fSMatthias Ringwald }
1097a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1098*b6269742SMatthias Ringwald     UNUSED(mesh_segmented_pdu);
1099f7434c1fSMatthias Ringwald };
1100f7434c1fSMatthias Ringwald #endif
1101f7434c1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
1102a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1103*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_segmented_pdu_t) + sizeof(btstack_memory_buffer_t));
1104f7434c1fSMatthias Ringwald     if (buffer){
1105*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_segmented_pdu_t) + sizeof(btstack_memory_buffer_t));
1106*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1107*b6269742SMatthias Ringwald         return (mesh_segmented_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1108*b6269742SMatthias Ringwald     } else {
1109*b6269742SMatthias Ringwald         return NULL;
1110f7434c1fSMatthias Ringwald     }
1111f7434c1fSMatthias Ringwald }
1112a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1113*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_segmented_pdu) - sizeof(btstack_memory_buffer_t);
1114*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1115*b6269742SMatthias Ringwald     free(buffer);
1116f7434c1fSMatthias Ringwald }
1117f7434c1fSMatthias Ringwald #endif
1118f7434c1fSMatthias Ringwald 
1119f7434c1fSMatthias Ringwald 
1120491f99b3SMatthias Ringwald // MARK: mesh_upper_transport_pdu_t
1121491f99b3SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS)
1122491f99b3SMatthias Ringwald     #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS)
1123491f99b3SMatthias Ringwald         #error "Deprecated MAX_NO_MESH_UPPER_TRANSPORT_PDUS defined instead of MAX_NR_MESH_UPPER_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_UPPER_TRANSPORT_PDUS."
1124491f99b3SMatthias Ringwald     #else
1125491f99b3SMatthias Ringwald         #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0
1126491f99b3SMatthias Ringwald     #endif
1127491f99b3SMatthias Ringwald #endif
1128491f99b3SMatthias Ringwald 
1129491f99b3SMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
1130491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1131491f99b3SMatthias Ringwald static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS];
1132491f99b3SMatthias Ringwald static btstack_memory_pool_t mesh_upper_transport_pdu_pool;
1133491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1134491f99b3SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool);
1135491f99b3SMatthias Ringwald     if (buffer){
1136491f99b3SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1137491f99b3SMatthias Ringwald     }
1138491f99b3SMatthias Ringwald     return (mesh_upper_transport_pdu_t *) buffer;
1139491f99b3SMatthias Ringwald }
1140491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1141491f99b3SMatthias Ringwald     btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu);
1142491f99b3SMatthias Ringwald }
1143491f99b3SMatthias Ringwald #else
1144491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1145491f99b3SMatthias Ringwald     return NULL;
1146491f99b3SMatthias Ringwald }
1147491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1148*b6269742SMatthias Ringwald     UNUSED(mesh_upper_transport_pdu);
1149491f99b3SMatthias Ringwald };
1150491f99b3SMatthias Ringwald #endif
1151491f99b3SMatthias Ringwald #elif defined(HAVE_MALLOC)
1152491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1153*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_upper_transport_pdu_t) + sizeof(btstack_memory_buffer_t));
1154491f99b3SMatthias Ringwald     if (buffer){
1155*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t) + sizeof(btstack_memory_buffer_t));
1156*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1157*b6269742SMatthias Ringwald         return (mesh_upper_transport_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1158*b6269742SMatthias Ringwald     } else {
1159*b6269742SMatthias Ringwald         return NULL;
1160491f99b3SMatthias Ringwald     }
1161491f99b3SMatthias Ringwald }
1162491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1163*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_upper_transport_pdu) - sizeof(btstack_memory_buffer_t);
1164*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1165*b6269742SMatthias Ringwald     free(buffer);
1166491f99b3SMatthias Ringwald }
1167491f99b3SMatthias Ringwald #endif
1168491f99b3SMatthias Ringwald 
1169491f99b3SMatthias Ringwald 
1170c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t
1171c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
1172c0a711d9SMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_KEYS)
1173c0a711d9SMatthias Ringwald         #error "Deprecated MAX_NO_MESH_NETWORK_KEYS defined instead of MAX_NR_MESH_NETWORK_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_KEYS."
1174c0a711d9SMatthias Ringwald     #else
1175c0a711d9SMatthias Ringwald         #define MAX_NR_MESH_NETWORK_KEYS 0
1176c0a711d9SMatthias Ringwald     #endif
1177c0a711d9SMatthias Ringwald #endif
1178c0a711d9SMatthias Ringwald 
1179c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
1180c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
1181c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
1182c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool;
1183c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
11841c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
11851c4e8084SMatthias Ringwald     if (buffer){
11861c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_key_t));
11871c4e8084SMatthias Ringwald     }
11881c4e8084SMatthias Ringwald     return (mesh_network_key_t *) buffer;
1189c0a711d9SMatthias Ringwald }
1190c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1191c0a711d9SMatthias Ringwald     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
1192c0a711d9SMatthias Ringwald }
1193c0a711d9SMatthias Ringwald #else
1194c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1195c0a711d9SMatthias Ringwald     return NULL;
1196c0a711d9SMatthias Ringwald }
1197c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1198*b6269742SMatthias Ringwald     UNUSED(mesh_network_key);
1199c0a711d9SMatthias Ringwald };
1200c0a711d9SMatthias Ringwald #endif
1201c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC)
1202c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1203*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_network_key_t) + sizeof(btstack_memory_buffer_t));
12041c4e8084SMatthias Ringwald     if (buffer){
1205*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_key_t) + sizeof(btstack_memory_buffer_t));
1206*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1207*b6269742SMatthias Ringwald         return (mesh_network_key_t *) (buffer + sizeof(btstack_memory_buffer_t));
1208*b6269742SMatthias Ringwald     } else {
1209*b6269742SMatthias Ringwald         return NULL;
12101c4e8084SMatthias Ringwald     }
1211c0a711d9SMatthias Ringwald }
1212c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1213*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_network_key) - sizeof(btstack_memory_buffer_t);
1214*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1215*b6269742SMatthias Ringwald     free(buffer);
1216c0a711d9SMatthias Ringwald }
1217c0a711d9SMatthias Ringwald #endif
1218c0a711d9SMatthias Ringwald 
1219c0a711d9SMatthias Ringwald 
122001e2bf94SMatthias Ringwald // MARK: mesh_transport_key_t
122101e2bf94SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
122201e2bf94SMatthias Ringwald     #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
122301e2bf94SMatthias Ringwald         #error "Deprecated MAX_NO_MESH_TRANSPORT_KEYS defined instead of MAX_NR_MESH_TRANSPORT_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_KEYS."
122401e2bf94SMatthias Ringwald     #else
122501e2bf94SMatthias Ringwald         #define MAX_NR_MESH_TRANSPORT_KEYS 0
122601e2bf94SMatthias Ringwald     #endif
122701e2bf94SMatthias Ringwald #endif
122801e2bf94SMatthias Ringwald 
122901e2bf94SMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS
123001e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
123101e2bf94SMatthias Ringwald static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
123201e2bf94SMatthias Ringwald static btstack_memory_pool_t mesh_transport_key_pool;
123301e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
123401e2bf94SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
123501e2bf94SMatthias Ringwald     if (buffer){
123601e2bf94SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_transport_key_t));
123701e2bf94SMatthias Ringwald     }
123801e2bf94SMatthias Ringwald     return (mesh_transport_key_t *) buffer;
123901e2bf94SMatthias Ringwald }
124001e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
124101e2bf94SMatthias Ringwald     btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
124201e2bf94SMatthias Ringwald }
124301e2bf94SMatthias Ringwald #else
124401e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
124501e2bf94SMatthias Ringwald     return NULL;
124601e2bf94SMatthias Ringwald }
124701e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1248*b6269742SMatthias Ringwald     UNUSED(mesh_transport_key);
124901e2bf94SMatthias Ringwald };
125001e2bf94SMatthias Ringwald #endif
125101e2bf94SMatthias Ringwald #elif defined(HAVE_MALLOC)
125201e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1253*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_transport_key_t) + sizeof(btstack_memory_buffer_t));
125401e2bf94SMatthias Ringwald     if (buffer){
1255*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_transport_key_t) + sizeof(btstack_memory_buffer_t));
1256*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1257*b6269742SMatthias Ringwald         return (mesh_transport_key_t *) (buffer + sizeof(btstack_memory_buffer_t));
1258*b6269742SMatthias Ringwald     } else {
1259*b6269742SMatthias Ringwald         return NULL;
126001e2bf94SMatthias Ringwald     }
126101e2bf94SMatthias Ringwald }
126201e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1263*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_transport_key) - sizeof(btstack_memory_buffer_t);
1264*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1265*b6269742SMatthias Ringwald     free(buffer);
126601e2bf94SMatthias Ringwald }
126701e2bf94SMatthias Ringwald #endif
126801e2bf94SMatthias Ringwald 
126901e2bf94SMatthias Ringwald 
12701f45d603SMatthias Ringwald // MARK: mesh_virtual_address_t
12711f45d603SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
12721f45d603SMatthias Ringwald     #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
12731f45d603SMatthias Ringwald         #error "Deprecated MAX_NO_MESH_VIRTUAL_ADDRESSS defined instead of MAX_NR_MESH_VIRTUAL_ADDRESSS. Please update your btstack_config.h to use MAX_NR_MESH_VIRTUAL_ADDRESSS."
12741f45d603SMatthias Ringwald     #else
12751f45d603SMatthias Ringwald         #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
12761f45d603SMatthias Ringwald     #endif
12771f45d603SMatthias Ringwald #endif
12781f45d603SMatthias Ringwald 
12791f45d603SMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
12801f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
12811f45d603SMatthias Ringwald static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
12821f45d603SMatthias Ringwald static btstack_memory_pool_t mesh_virtual_address_pool;
12831f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
12841f45d603SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
12851f45d603SMatthias Ringwald     if (buffer){
12861f45d603SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_virtual_address_t));
12871f45d603SMatthias Ringwald     }
12881f45d603SMatthias Ringwald     return (mesh_virtual_address_t *) buffer;
12891f45d603SMatthias Ringwald }
12901f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
12911f45d603SMatthias Ringwald     btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
12921f45d603SMatthias Ringwald }
12931f45d603SMatthias Ringwald #else
12941f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
12951f45d603SMatthias Ringwald     return NULL;
12961f45d603SMatthias Ringwald }
12971f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1298*b6269742SMatthias Ringwald     UNUSED(mesh_virtual_address);
12991f45d603SMatthias Ringwald };
13001f45d603SMatthias Ringwald #endif
13011f45d603SMatthias Ringwald #elif defined(HAVE_MALLOC)
13021f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1303*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_virtual_address_t) + sizeof(btstack_memory_buffer_t));
13041f45d603SMatthias Ringwald     if (buffer){
1305*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_virtual_address_t) + sizeof(btstack_memory_buffer_t));
1306*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1307*b6269742SMatthias Ringwald         return (mesh_virtual_address_t *) (buffer + sizeof(btstack_memory_buffer_t));
1308*b6269742SMatthias Ringwald     } else {
1309*b6269742SMatthias Ringwald         return NULL;
13101f45d603SMatthias Ringwald     }
13111f45d603SMatthias Ringwald }
13121f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1313*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_virtual_address) - sizeof(btstack_memory_buffer_t);
1314*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1315*b6269742SMatthias Ringwald     free(buffer);
13161f45d603SMatthias Ringwald }
13171f45d603SMatthias Ringwald #endif
13181f45d603SMatthias Ringwald 
13191f45d603SMatthias Ringwald 
132001122b73SMatthias Ringwald // MARK: mesh_subnet_t
132101122b73SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
132201122b73SMatthias Ringwald     #if defined(MAX_NO_MESH_SUBNETS)
132301122b73SMatthias Ringwald         #error "Deprecated MAX_NO_MESH_SUBNETS defined instead of MAX_NR_MESH_SUBNETS. Please update your btstack_config.h to use MAX_NR_MESH_SUBNETS."
132401122b73SMatthias Ringwald     #else
132501122b73SMatthias Ringwald         #define MAX_NR_MESH_SUBNETS 0
132601122b73SMatthias Ringwald     #endif
132701122b73SMatthias Ringwald #endif
132801122b73SMatthias Ringwald 
132901122b73SMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS
133001122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
133101122b73SMatthias Ringwald static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
133201122b73SMatthias Ringwald static btstack_memory_pool_t mesh_subnet_pool;
133301122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
133401122b73SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
133501122b73SMatthias Ringwald     if (buffer){
133601122b73SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_subnet_t));
133701122b73SMatthias Ringwald     }
133801122b73SMatthias Ringwald     return (mesh_subnet_t *) buffer;
133901122b73SMatthias Ringwald }
134001122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
134101122b73SMatthias Ringwald     btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
134201122b73SMatthias Ringwald }
134301122b73SMatthias Ringwald #else
134401122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
134501122b73SMatthias Ringwald     return NULL;
134601122b73SMatthias Ringwald }
134701122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1348*b6269742SMatthias Ringwald     UNUSED(mesh_subnet);
134901122b73SMatthias Ringwald };
135001122b73SMatthias Ringwald #endif
135101122b73SMatthias Ringwald #elif defined(HAVE_MALLOC)
135201122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1353*b6269742SMatthias Ringwald     void * buffer = malloc(sizeof(mesh_subnet_t) + sizeof(btstack_memory_buffer_t));
135401122b73SMatthias Ringwald     if (buffer){
1355*b6269742SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_subnet_t) + sizeof(btstack_memory_buffer_t));
1356*b6269742SMatthias Ringwald         btstack_memory_tracking_add(buffer);
1357*b6269742SMatthias Ringwald         return (mesh_subnet_t *) (buffer + sizeof(btstack_memory_buffer_t));
1358*b6269742SMatthias Ringwald     } else {
1359*b6269742SMatthias Ringwald         return NULL;
136001122b73SMatthias Ringwald     }
136101122b73SMatthias Ringwald }
136201122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1363*b6269742SMatthias Ringwald     void * buffer =  ((void *) mesh_subnet) - sizeof(btstack_memory_buffer_t);
1364*b6269742SMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1365*b6269742SMatthias Ringwald     free(buffer);
136601122b73SMatthias Ringwald }
136701122b73SMatthias Ringwald #endif
136801122b73SMatthias Ringwald 
136901122b73SMatthias Ringwald 
13702e97c149S[email protected] #endif
1371a3b02b71Smatthias.ringwald // init
1372a3b02b71Smatthias.ringwald void btstack_memory_init(void){
1373a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
1374a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
1375a3b02b71Smatthias.ringwald #endif
1376a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
1377a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
1378a3b02b71Smatthias.ringwald #endif
1379a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
1380a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
1381a3b02b71Smatthias.ringwald #endif
138244c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
138350dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
138450dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
1385a3b02b71Smatthias.ringwald #endif
138650dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
138750dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
1388a3b02b71Smatthias.ringwald #endif
138950dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
139050dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
139150dc57fcSMatthias Ringwald #endif
139250dc57fcSMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
139350dc57fcSMatthias Ringwald     btstack_memory_pool_create(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry_storage, MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES, sizeof(btstack_link_key_db_memory_entry_t));
139450dc57fcSMatthias Ringwald #endif
139550dc57fcSMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
139650dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
139750dc57fcSMatthias Ringwald #endif
139850dc57fcSMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
139950dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
140050dc57fcSMatthias Ringwald #endif
140150dc57fcSMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
140250dc57fcSMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
140350dc57fcSMatthias Ringwald #endif
140450dc57fcSMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
140550dc57fcSMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
140650dc57fcSMatthias Ringwald #endif
140750dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
140850dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
140950dc57fcSMatthias Ringwald #endif
141050dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
141150dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
141250dc57fcSMatthias Ringwald #endif
141350dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
141450dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
141550dc57fcSMatthias Ringwald #endif
141650dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
141750dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1418a3b02b71Smatthias.ringwald #endif
1419f12a3722SMilanka Ringwald #endif
1420a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
1421a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
1422a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1423d0fdae3cS[email protected] #endif
1424a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1425a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1426656bec4fSMatthias Ringwald #endif
1427a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1428a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1429cf49570bSMatthias Ringwald #endif
1430ebb73e1fSMatthias Ringwald #endif
143144c5d856SMatthias Ringwald #ifdef ENABLE_MESH
143250dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
143350dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
143444c5d856SMatthias Ringwald #endif
1435a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1436a4bbc09dSMatthias Ringwald     btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t));
1437f7434c1fSMatthias Ringwald #endif
1438491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1439491f99b3SMatthias Ringwald     btstack_memory_pool_create(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu_storage, MAX_NR_MESH_UPPER_TRANSPORT_PDUS, sizeof(mesh_upper_transport_pdu_t));
1440491f99b3SMatthias Ringwald #endif
144150dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
144250dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1443c0a711d9SMatthias Ringwald #endif
144401e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
144501e2bf94SMatthias Ringwald     btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
144601e2bf94SMatthias Ringwald #endif
14471f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
14481f45d603SMatthias Ringwald     btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
14491f45d603SMatthias Ringwald #endif
145001122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
145101122b73SMatthias Ringwald     btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
145201122b73SMatthias Ringwald #endif
1453a7d12effS[email protected] #endif
1454a3b02b71Smatthias.ringwald }
1455