xref: /btstack/src/btstack_memory.c (revision cf26c8fbbf161f7e5ee9327de39264752c730a34)
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 
41b6269742SMatthias 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"
54b6269742SMatthias Ringwald #include "btstack_debug.h"
55a3b02b71Smatthias.ringwald 
56a3b02b71Smatthias.ringwald #include <stdlib.h>
57a3b02b71Smatthias.ringwald 
58*cf26c8fbSMilanka Ringwald #ifdef ENABLE_MALLOC_TEST
59*cf26c8fbSMilanka Ringwald extern "C" void * test_malloc(size_t size);
60*cf26c8fbSMilanka Ringwald #define malloc test_malloc
61*cf26c8fbSMilanka Ringwald #endif
62*cf26c8fbSMilanka Ringwald 
63b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
64b6269742SMatthias Ringwald typedef struct btstack_memory_buffer {
65b6269742SMatthias Ringwald     struct btstack_memory_buffer * next;
66b6269742SMatthias Ringwald     struct btstack_memory_buffer * prev;
67b6269742SMatthias Ringwald } btstack_memory_buffer_t;
68b6269742SMatthias Ringwald 
69798bd46fSMatthias Ringwald typedef struct {
70798bd46fSMatthias Ringwald     btstack_memory_buffer_t tracking;
71798bd46fSMatthias Ringwald     void * pointer;
72798bd46fSMatthias Ringwald } test_buffer_t;
73798bd46fSMatthias Ringwald 
74b6269742SMatthias Ringwald static btstack_memory_buffer_t * btstack_memory_malloc_buffers;
7519ef97d2SMatthias Ringwald static uint32_t btstack_memory_malloc_counter;
76b6269742SMatthias Ringwald 
772a95308bSMatthias Ringwald static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){
782a95308bSMatthias Ringwald     btstack_assert(buffer != NULL);
7919ef97d2SMatthias Ringwald     if (btstack_memory_malloc_buffers != NULL) {
8019ef97d2SMatthias Ringwald         // let current first item prev point to new first item
8119ef97d2SMatthias Ringwald         btstack_memory_malloc_buffers->prev = buffer;
8219ef97d2SMatthias Ringwald     }
83b6269742SMatthias Ringwald     buffer->prev = NULL;
84b6269742SMatthias Ringwald     buffer->next = btstack_memory_malloc_buffers;
85b6269742SMatthias Ringwald     btstack_memory_malloc_buffers = buffer;
8619ef97d2SMatthias Ringwald 
8719ef97d2SMatthias Ringwald     btstack_memory_malloc_counter++;
88b6269742SMatthias Ringwald }
89b6269742SMatthias Ringwald 
902a95308bSMatthias Ringwald static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){
912a95308bSMatthias Ringwald     btstack_assert(buffer != NULL);
92b6269742SMatthias Ringwald     if (buffer->prev == NULL){
93b6269742SMatthias Ringwald         // first item
94b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
95b6269742SMatthias Ringwald     } else {
96b6269742SMatthias Ringwald         buffer->prev->next = buffer->next;
97b6269742SMatthias Ringwald     }
98b6269742SMatthias Ringwald     if (buffer->next != NULL){
99b6269742SMatthias Ringwald         buffer->next->prev = buffer->prev;
100b6269742SMatthias Ringwald     }
10119ef97d2SMatthias Ringwald 
10219ef97d2SMatthias Ringwald     btstack_memory_malloc_counter--;
103b6269742SMatthias Ringwald }
104b6269742SMatthias Ringwald #endif
105b6269742SMatthias Ringwald 
106b6269742SMatthias Ringwald void btstack_memory_deinit(void){
107b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
108b6269742SMatthias Ringwald     while (btstack_memory_malloc_buffers != NULL){
109b6269742SMatthias Ringwald         btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers;
110b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
111b6269742SMatthias Ringwald         free(buffer);
112b6269742SMatthias Ringwald     }
11319ef97d2SMatthias Ringwald     btstack_assert(btstack_memory_malloc_counter == 0);
114b6269742SMatthias Ringwald #endif
115b6269742SMatthias Ringwald }
116a3b02b71Smatthias.ringwald 
1172e97c149S[email protected] 
118a3b02b71Smatthias.ringwald // MARK: hci_connection_t
119a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
120a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
12127faf85aSMilanka 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."
122a265b909SMatthias Ringwald     #else
123a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
124a265b909SMatthias Ringwald     #endif
125a265b909SMatthias Ringwald #endif
126a265b909SMatthias Ringwald 
127a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
128a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
129a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
13029d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
1316527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
132a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
133a2673d88SMatthias Ringwald     if (buffer){
134a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
135a2673d88SMatthias Ringwald     }
136a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
137a3b02b71Smatthias.ringwald }
1386527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
13929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
140a3b02b71Smatthias.ringwald }
141c4d3f927Smatthias.ringwald #else
1426527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
143c4d3f927Smatthias.ringwald     return NULL;
144c4d3f927Smatthias.ringwald }
1456527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
146b6269742SMatthias Ringwald     UNUSED(hci_connection);
147c4d3f927Smatthias.ringwald };
148c4d3f927Smatthias.ringwald #endif
149a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1502a95308bSMatthias Ringwald 
1512a95308bSMatthias Ringwald typedef struct {
1522a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
153798bd46fSMatthias Ringwald     hci_connection_t data;
1542a95308bSMatthias Ringwald } btstack_memory_hci_connection_t;
1552a95308bSMatthias Ringwald 
1566527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
1572a95308bSMatthias Ringwald     btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t));
158a2673d88SMatthias Ringwald     if (buffer){
159798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_hci_connection_t));
1602a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1612a95308bSMatthias Ringwald         return &buffer->data;
162b6269742SMatthias Ringwald     } else {
163b6269742SMatthias Ringwald         return NULL;
164a2673d88SMatthias Ringwald     }
165a3b02b71Smatthias.ringwald }
1666527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
167798bd46fSMatthias Ringwald     // reconstruct buffer start
168798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_connection)[-1];
169798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
170b6269742SMatthias Ringwald     free(buffer);
171a3b02b71Smatthias.ringwald }
172a3b02b71Smatthias.ringwald #endif
173a3b02b71Smatthias.ringwald 
174a3b02b71Smatthias.ringwald 
1752e97c149S[email protected] 
176a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
177a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
178a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
17927faf85aSMilanka 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."
180a265b909SMatthias Ringwald     #else
181a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
182a265b909SMatthias Ringwald     #endif
183a265b909SMatthias Ringwald #endif
184a265b909SMatthias Ringwald 
185a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
186a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
187a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
18829d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1896527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
190a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
191a2673d88SMatthias Ringwald     if (buffer){
192a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
193a2673d88SMatthias Ringwald     }
194a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
195a3b02b71Smatthias.ringwald }
1966527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
19729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
198a3b02b71Smatthias.ringwald }
199c4d3f927Smatthias.ringwald #else
2006527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
201c4d3f927Smatthias.ringwald     return NULL;
202c4d3f927Smatthias.ringwald }
2036527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
204b6269742SMatthias Ringwald     UNUSED(l2cap_service);
205c4d3f927Smatthias.ringwald };
206c4d3f927Smatthias.ringwald #endif
207a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2082a95308bSMatthias Ringwald 
2092a95308bSMatthias Ringwald typedef struct {
2102a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
211798bd46fSMatthias Ringwald     l2cap_service_t data;
2122a95308bSMatthias Ringwald } btstack_memory_l2cap_service_t;
2132a95308bSMatthias Ringwald 
2146527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
2152a95308bSMatthias Ringwald     btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t));
216a2673d88SMatthias Ringwald     if (buffer){
217798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_l2cap_service_t));
2182a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
2192a95308bSMatthias Ringwald         return &buffer->data;
220b6269742SMatthias Ringwald     } else {
221b6269742SMatthias Ringwald         return NULL;
222a2673d88SMatthias Ringwald     }
223a3b02b71Smatthias.ringwald }
2246527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
225798bd46fSMatthias Ringwald     // reconstruct buffer start
226798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_service)[-1];
227798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
228b6269742SMatthias Ringwald     free(buffer);
229a3b02b71Smatthias.ringwald }
230a3b02b71Smatthias.ringwald #endif
231a3b02b71Smatthias.ringwald 
232a3b02b71Smatthias.ringwald 
233a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
234a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
235a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
23627faf85aSMilanka 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."
237a265b909SMatthias Ringwald     #else
238a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
239a265b909SMatthias Ringwald     #endif
240a265b909SMatthias Ringwald #endif
241a265b909SMatthias Ringwald 
242a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
243a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
244a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
24529d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
2466527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
247a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
248a2673d88SMatthias Ringwald     if (buffer){
249a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
250a2673d88SMatthias Ringwald     }
251a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
252a3b02b71Smatthias.ringwald }
2536527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
25429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
255a3b02b71Smatthias.ringwald }
256c4d3f927Smatthias.ringwald #else
2576527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
258c4d3f927Smatthias.ringwald     return NULL;
259c4d3f927Smatthias.ringwald }
2606527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
261b6269742SMatthias Ringwald     UNUSED(l2cap_channel);
262c4d3f927Smatthias.ringwald };
263c4d3f927Smatthias.ringwald #endif
264a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2652a95308bSMatthias Ringwald 
2662a95308bSMatthias Ringwald typedef struct {
2672a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
268798bd46fSMatthias Ringwald     l2cap_channel_t data;
2692a95308bSMatthias Ringwald } btstack_memory_l2cap_channel_t;
2702a95308bSMatthias Ringwald 
2716527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
2722a95308bSMatthias Ringwald     btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t));
273a2673d88SMatthias Ringwald     if (buffer){
274798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_l2cap_channel_t));
2752a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
2762a95308bSMatthias Ringwald         return &buffer->data;
277b6269742SMatthias Ringwald     } else {
278b6269742SMatthias Ringwald         return NULL;
279a2673d88SMatthias Ringwald     }
280a3b02b71Smatthias.ringwald }
2816527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
282798bd46fSMatthias Ringwald     // reconstruct buffer start
283798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_channel)[-1];
284798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
285b6269742SMatthias Ringwald     free(buffer);
286a3b02b71Smatthias.ringwald }
287a3b02b71Smatthias.ringwald #endif
288a3b02b71Smatthias.ringwald 
289a3b02b71Smatthias.ringwald 
29044c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
2912e97c149S[email protected] 
292a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
293a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
294a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
29527faf85aSMilanka 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."
296a265b909SMatthias Ringwald     #else
297a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
298a265b909SMatthias Ringwald     #endif
299a265b909SMatthias Ringwald #endif
300a265b909SMatthias Ringwald 
301a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
302a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
303a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
30429d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
3056527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
306a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
307a2673d88SMatthias Ringwald     if (buffer){
308a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
309a2673d88SMatthias Ringwald     }
310a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
311a3b02b71Smatthias.ringwald }
3126527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
31329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
314a3b02b71Smatthias.ringwald }
315c4d3f927Smatthias.ringwald #else
3166527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
317c4d3f927Smatthias.ringwald     return NULL;
318c4d3f927Smatthias.ringwald }
3196527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
320b6269742SMatthias Ringwald     UNUSED(rfcomm_multiplexer);
321c4d3f927Smatthias.ringwald };
322c4d3f927Smatthias.ringwald #endif
323a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3242a95308bSMatthias Ringwald 
3252a95308bSMatthias Ringwald typedef struct {
3262a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
327798bd46fSMatthias Ringwald     rfcomm_multiplexer_t data;
3282a95308bSMatthias Ringwald } btstack_memory_rfcomm_multiplexer_t;
3292a95308bSMatthias Ringwald 
3306527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
3312a95308bSMatthias Ringwald     btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t));
332a2673d88SMatthias Ringwald     if (buffer){
333798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_multiplexer_t));
3342a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
3352a95308bSMatthias Ringwald         return &buffer->data;
336b6269742SMatthias Ringwald     } else {
337b6269742SMatthias Ringwald         return NULL;
338a2673d88SMatthias Ringwald     }
339a3b02b71Smatthias.ringwald }
3406527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
341798bd46fSMatthias Ringwald     // reconstruct buffer start
342798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_multiplexer)[-1];
343798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
344b6269742SMatthias Ringwald     free(buffer);
345a3b02b71Smatthias.ringwald }
346a3b02b71Smatthias.ringwald #endif
347a3b02b71Smatthias.ringwald 
348a3b02b71Smatthias.ringwald 
349a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
350a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
351a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
35227faf85aSMilanka 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."
353a265b909SMatthias Ringwald     #else
354a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
355a265b909SMatthias Ringwald     #endif
356a265b909SMatthias Ringwald #endif
357a265b909SMatthias Ringwald 
358a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
359a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
360a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
36129d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
3626527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
363a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
364a2673d88SMatthias Ringwald     if (buffer){
365a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
366a2673d88SMatthias Ringwald     }
367a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
368a3b02b71Smatthias.ringwald }
3696527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
37029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
371a3b02b71Smatthias.ringwald }
372c4d3f927Smatthias.ringwald #else
3736527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
374c4d3f927Smatthias.ringwald     return NULL;
375c4d3f927Smatthias.ringwald }
3766527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
377b6269742SMatthias Ringwald     UNUSED(rfcomm_service);
378c4d3f927Smatthias.ringwald };
379c4d3f927Smatthias.ringwald #endif
380a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3812a95308bSMatthias Ringwald 
3822a95308bSMatthias Ringwald typedef struct {
3832a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
384798bd46fSMatthias Ringwald     rfcomm_service_t data;
3852a95308bSMatthias Ringwald } btstack_memory_rfcomm_service_t;
3862a95308bSMatthias Ringwald 
3876527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
3882a95308bSMatthias Ringwald     btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t));
389a2673d88SMatthias Ringwald     if (buffer){
390798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_service_t));
3912a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
3922a95308bSMatthias Ringwald         return &buffer->data;
393b6269742SMatthias Ringwald     } else {
394b6269742SMatthias Ringwald         return NULL;
395a2673d88SMatthias Ringwald     }
396a3b02b71Smatthias.ringwald }
3976527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
398798bd46fSMatthias Ringwald     // reconstruct buffer start
399798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_service)[-1];
400798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
401b6269742SMatthias Ringwald     free(buffer);
402a3b02b71Smatthias.ringwald }
403a3b02b71Smatthias.ringwald #endif
404a3b02b71Smatthias.ringwald 
405a3b02b71Smatthias.ringwald 
406a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
407a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
408a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
40927faf85aSMilanka 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."
410a265b909SMatthias Ringwald     #else
411a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
412a265b909SMatthias Ringwald     #endif
413a265b909SMatthias Ringwald #endif
414a265b909SMatthias Ringwald 
415a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
416a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
417a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
41829d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
4196527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
420a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
421a2673d88SMatthias Ringwald     if (buffer){
422a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
423a2673d88SMatthias Ringwald     }
424a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
425a3b02b71Smatthias.ringwald }
4266527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
42729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
428a3b02b71Smatthias.ringwald }
429c4d3f927Smatthias.ringwald #else
4306527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
431c4d3f927Smatthias.ringwald     return NULL;
432c4d3f927Smatthias.ringwald }
4336527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
434b6269742SMatthias Ringwald     UNUSED(rfcomm_channel);
435c4d3f927Smatthias.ringwald };
436c4d3f927Smatthias.ringwald #endif
437a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
4382a95308bSMatthias Ringwald 
4392a95308bSMatthias Ringwald typedef struct {
4402a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
441798bd46fSMatthias Ringwald     rfcomm_channel_t data;
4422a95308bSMatthias Ringwald } btstack_memory_rfcomm_channel_t;
4432a95308bSMatthias Ringwald 
4446527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
4452a95308bSMatthias Ringwald     btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t));
446a2673d88SMatthias Ringwald     if (buffer){
447798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_channel_t));
4482a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
4492a95308bSMatthias Ringwald         return &buffer->data;
450b6269742SMatthias Ringwald     } else {
451b6269742SMatthias Ringwald         return NULL;
452a2673d88SMatthias Ringwald     }
453a3b02b71Smatthias.ringwald }
4546527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
455798bd46fSMatthias Ringwald     // reconstruct buffer start
456798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_channel)[-1];
457798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
458b6269742SMatthias Ringwald     free(buffer);
459a3b02b71Smatthias.ringwald }
460a3b02b71Smatthias.ringwald #endif
461a3b02b71Smatthias.ringwald 
462fdb398c2S[email protected] 
463e0e5e285Smatthias.ringwald 
4642c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
465a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
466a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
46727faf85aSMilanka 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."
468a265b909SMatthias Ringwald     #else
469a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
470a265b909SMatthias Ringwald     #endif
471a265b909SMatthias Ringwald #endif
472a265b909SMatthias Ringwald 
473a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
474a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
475a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
4762c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
4772c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
478a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
479a2673d88SMatthias Ringwald     if (buffer){
480a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
481a2673d88SMatthias Ringwald     }
482a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
4831801b596Smatthias.ringwald }
4842c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
4852c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
4861801b596Smatthias.ringwald }
487c4d3f927Smatthias.ringwald #else
4882c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
489c4d3f927Smatthias.ringwald     return NULL;
490c4d3f927Smatthias.ringwald }
4912c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
492b6269742SMatthias Ringwald     UNUSED(btstack_link_key_db_memory_entry);
493c4d3f927Smatthias.ringwald };
494c4d3f927Smatthias.ringwald #endif
4951801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
4962a95308bSMatthias Ringwald 
4972a95308bSMatthias Ringwald typedef struct {
4982a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
499798bd46fSMatthias Ringwald     btstack_link_key_db_memory_entry_t data;
5002a95308bSMatthias Ringwald } btstack_memory_btstack_link_key_db_memory_entry_t;
5012a95308bSMatthias Ringwald 
5022c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
5032a95308bSMatthias Ringwald     btstack_memory_btstack_link_key_db_memory_entry_t * buffer = (btstack_memory_btstack_link_key_db_memory_entry_t *) malloc(sizeof(btstack_memory_btstack_link_key_db_memory_entry_t));
504a2673d88SMatthias Ringwald     if (buffer){
505798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_btstack_link_key_db_memory_entry_t));
5062a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
5072a95308bSMatthias Ringwald         return &buffer->data;
508b6269742SMatthias Ringwald     } else {
509b6269742SMatthias Ringwald         return NULL;
510a2673d88SMatthias Ringwald     }
5111801b596Smatthias.ringwald }
5122c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
513798bd46fSMatthias Ringwald     // reconstruct buffer start
514798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) btstack_link_key_db_memory_entry)[-1];
515798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
516b6269742SMatthias Ringwald     free(buffer);
517e0e5e285Smatthias.ringwald }
5181801b596Smatthias.ringwald #endif
5191801b596Smatthias.ringwald 
5202e97c149S[email protected] 
5212e97c149S[email protected] 
5222e97c149S[email protected] // MARK: bnep_service_t
523a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
524a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
52527faf85aSMilanka 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."
526a265b909SMatthias Ringwald     #else
527a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
528a265b909SMatthias Ringwald     #endif
529a265b909SMatthias Ringwald #endif
530a265b909SMatthias Ringwald 
531a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
532a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
533a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
53429d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
5352e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
536a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
537a2673d88SMatthias Ringwald     if (buffer){
538a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
539a2673d88SMatthias Ringwald     }
540a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
5412e97c149S[email protected] }
5422e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
54329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
5442e97c149S[email protected] }
5452e97c149S[email protected] #else
5462e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
5472e97c149S[email protected]     return NULL;
5482e97c149S[email protected] }
5492e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
550b6269742SMatthias Ringwald     UNUSED(bnep_service);
5512e97c149S[email protected] };
5522e97c149S[email protected] #endif
5532e97c149S[email protected] #elif defined(HAVE_MALLOC)
5542a95308bSMatthias Ringwald 
5552a95308bSMatthias Ringwald typedef struct {
5562a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
557798bd46fSMatthias Ringwald     bnep_service_t data;
5582a95308bSMatthias Ringwald } btstack_memory_bnep_service_t;
5592a95308bSMatthias Ringwald 
5602e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
5612a95308bSMatthias Ringwald     btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t));
562a2673d88SMatthias Ringwald     if (buffer){
563798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_bnep_service_t));
5642a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
5652a95308bSMatthias Ringwald         return &buffer->data;
566b6269742SMatthias Ringwald     } else {
567b6269742SMatthias Ringwald         return NULL;
568a2673d88SMatthias Ringwald     }
5692e97c149S[email protected] }
5702e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
571798bd46fSMatthias Ringwald     // reconstruct buffer start
572798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_service)[-1];
573798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
574b6269742SMatthias Ringwald     free(buffer);
5752e97c149S[email protected] }
5762e97c149S[email protected] #endif
5772e97c149S[email protected] 
5782e97c149S[email protected] 
5792e97c149S[email protected] // MARK: bnep_channel_t
580a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
581a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
58227faf85aSMilanka 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."
583a265b909SMatthias Ringwald     #else
584a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
585a265b909SMatthias Ringwald     #endif
586a265b909SMatthias Ringwald #endif
587a265b909SMatthias Ringwald 
588a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
589a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
590a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
59129d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
5922e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
593a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
594a2673d88SMatthias Ringwald     if (buffer){
595a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
596a2673d88SMatthias Ringwald     }
597a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
5982e97c149S[email protected] }
5992e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
60029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
6012e97c149S[email protected] }
6022e97c149S[email protected] #else
6032e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
6042e97c149S[email protected]     return NULL;
6052e97c149S[email protected] }
6062e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
607b6269742SMatthias Ringwald     UNUSED(bnep_channel);
6082e97c149S[email protected] };
6092e97c149S[email protected] #endif
6102e97c149S[email protected] #elif defined(HAVE_MALLOC)
6112a95308bSMatthias Ringwald 
6122a95308bSMatthias Ringwald typedef struct {
6132a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
614798bd46fSMatthias Ringwald     bnep_channel_t data;
6152a95308bSMatthias Ringwald } btstack_memory_bnep_channel_t;
6162a95308bSMatthias Ringwald 
6172e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
6182a95308bSMatthias Ringwald     btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t));
619a2673d88SMatthias Ringwald     if (buffer){
620798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_bnep_channel_t));
6212a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
6222a95308bSMatthias Ringwald         return &buffer->data;
623b6269742SMatthias Ringwald     } else {
624b6269742SMatthias Ringwald         return NULL;
625a2673d88SMatthias Ringwald     }
6262e97c149S[email protected] }
6272e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
628798bd46fSMatthias Ringwald     // reconstruct buffer start
629798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_channel)[-1];
630798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
631b6269742SMatthias Ringwald     free(buffer);
6322e97c149S[email protected] }
6332e97c149S[email protected] #endif
6342e97c149S[email protected] 
6352e97c149S[email protected] 
636ea5029c9SMilanka Ringwald 
637ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
638a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
639a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
64027faf85aSMilanka 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."
641a265b909SMatthias Ringwald     #else
642a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
643a265b909SMatthias Ringwald     #endif
644a265b909SMatthias Ringwald #endif
645a265b909SMatthias Ringwald 
646a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
647a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
648a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
64929d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
650ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
651a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
652a2673d88SMatthias Ringwald     if (buffer){
653a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
654a2673d88SMatthias Ringwald     }
655a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
656ea5029c9SMilanka Ringwald }
657ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
65829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
659ea5029c9SMilanka Ringwald }
660ea5029c9SMilanka Ringwald #else
661ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
662ea5029c9SMilanka Ringwald     return NULL;
663ea5029c9SMilanka Ringwald }
664ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
665b6269742SMatthias Ringwald     UNUSED(hfp_connection);
666ea5029c9SMilanka Ringwald };
667ea5029c9SMilanka Ringwald #endif
668ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
6692a95308bSMatthias Ringwald 
6702a95308bSMatthias Ringwald typedef struct {
6712a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
672798bd46fSMatthias Ringwald     hfp_connection_t data;
6732a95308bSMatthias Ringwald } btstack_memory_hfp_connection_t;
6742a95308bSMatthias Ringwald 
675ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
6762a95308bSMatthias Ringwald     btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t));
677a2673d88SMatthias Ringwald     if (buffer){
678798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_hfp_connection_t));
6792a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
6802a95308bSMatthias Ringwald         return &buffer->data;
681b6269742SMatthias Ringwald     } else {
682b6269742SMatthias Ringwald         return NULL;
683a2673d88SMatthias Ringwald     }
684ea5029c9SMilanka Ringwald }
685ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
686798bd46fSMatthias Ringwald     // reconstruct buffer start
687798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hfp_connection)[-1];
688798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
689b6269742SMatthias Ringwald     free(buffer);
690ea5029c9SMilanka Ringwald }
691ea5029c9SMilanka Ringwald #endif
692ea5029c9SMilanka Ringwald 
693ea5029c9SMilanka Ringwald 
694cd9ee144SMatthias Ringwald 
695f399f7fbSMilanka Ringwald // MARK: hid_host_connection_t
696f399f7fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HID_HOST_CONNECTIONS)
697f399f7fbSMilanka Ringwald     #if defined(MAX_NO_HID_HOST_CONNECTIONS)
698f399f7fbSMilanka Ringwald         #error "Deprecated MAX_NO_HID_HOST_CONNECTIONS defined instead of MAX_NR_HID_HOST_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HID_HOST_CONNECTIONS."
699f399f7fbSMilanka Ringwald     #else
700f399f7fbSMilanka Ringwald         #define MAX_NR_HID_HOST_CONNECTIONS 0
701f399f7fbSMilanka Ringwald     #endif
702f399f7fbSMilanka Ringwald #endif
703f399f7fbSMilanka Ringwald 
704f399f7fbSMilanka Ringwald #ifdef MAX_NR_HID_HOST_CONNECTIONS
705f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0
706f399f7fbSMilanka Ringwald static hid_host_connection_t hid_host_connection_storage[MAX_NR_HID_HOST_CONNECTIONS];
707f399f7fbSMilanka Ringwald static btstack_memory_pool_t hid_host_connection_pool;
708f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){
709f399f7fbSMilanka Ringwald     void * buffer = btstack_memory_pool_get(&hid_host_connection_pool);
710f399f7fbSMilanka Ringwald     if (buffer){
711f399f7fbSMilanka Ringwald         memset(buffer, 0, sizeof(hid_host_connection_t));
712f399f7fbSMilanka Ringwald     }
713f399f7fbSMilanka Ringwald     return (hid_host_connection_t *) buffer;
714f399f7fbSMilanka Ringwald }
715f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){
716f399f7fbSMilanka Ringwald     btstack_memory_pool_free(&hid_host_connection_pool, hid_host_connection);
717f399f7fbSMilanka Ringwald }
718f399f7fbSMilanka Ringwald #else
719f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){
720f399f7fbSMilanka Ringwald     return NULL;
721f399f7fbSMilanka Ringwald }
722f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){
723174a0c1cSMilanka Ringwald     UNUSED(hid_host_connection);
724f399f7fbSMilanka Ringwald };
725f399f7fbSMilanka Ringwald #endif
726f399f7fbSMilanka Ringwald #elif defined(HAVE_MALLOC)
727174a0c1cSMilanka Ringwald 
728174a0c1cSMilanka Ringwald typedef struct {
729174a0c1cSMilanka Ringwald     btstack_memory_buffer_t tracking;
730174a0c1cSMilanka Ringwald     hid_host_connection_t data;
731174a0c1cSMilanka Ringwald } btstack_memory_hid_host_connection_t;
732174a0c1cSMilanka Ringwald 
733f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){
734174a0c1cSMilanka Ringwald     btstack_memory_hid_host_connection_t * buffer = (btstack_memory_hid_host_connection_t *) malloc(sizeof(btstack_memory_hid_host_connection_t));
735f399f7fbSMilanka Ringwald     if (buffer){
736174a0c1cSMilanka Ringwald         memset(buffer, 0, sizeof(btstack_memory_hid_host_connection_t));
737174a0c1cSMilanka Ringwald         btstack_memory_tracking_add(&buffer->tracking);
738174a0c1cSMilanka Ringwald         return &buffer->data;
739174a0c1cSMilanka Ringwald     } else {
740174a0c1cSMilanka Ringwald         return NULL;
741f399f7fbSMilanka Ringwald     }
742f399f7fbSMilanka Ringwald }
743f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){
744174a0c1cSMilanka Ringwald     // reconstruct buffer start
745174a0c1cSMilanka Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hid_host_connection)[-1];
746174a0c1cSMilanka Ringwald     btstack_memory_tracking_remove(buffer);
747174a0c1cSMilanka Ringwald     free(buffer);
748f399f7fbSMilanka Ringwald }
749f399f7fbSMilanka Ringwald #endif
750f399f7fbSMilanka Ringwald 
751f399f7fbSMilanka Ringwald 
752f399f7fbSMilanka Ringwald 
753cd9ee144SMatthias Ringwald // MARK: service_record_item_t
754a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
755a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
75627faf85aSMilanka 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."
757a265b909SMatthias Ringwald     #else
758a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
759a265b909SMatthias Ringwald     #endif
760a265b909SMatthias Ringwald #endif
761a265b909SMatthias Ringwald 
762a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
763a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
764a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
76529d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
766cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
767a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
768a2673d88SMatthias Ringwald     if (buffer){
769a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
770a2673d88SMatthias Ringwald     }
771a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
772cd9ee144SMatthias Ringwald }
773cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
77429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
775cd9ee144SMatthias Ringwald }
776cd9ee144SMatthias Ringwald #else
777cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
778cd9ee144SMatthias Ringwald     return NULL;
779cd9ee144SMatthias Ringwald }
780cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
781b6269742SMatthias Ringwald     UNUSED(service_record_item);
782cd9ee144SMatthias Ringwald };
783cd9ee144SMatthias Ringwald #endif
784cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
7852a95308bSMatthias Ringwald 
7862a95308bSMatthias Ringwald typedef struct {
7872a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
788798bd46fSMatthias Ringwald     service_record_item_t data;
7892a95308bSMatthias Ringwald } btstack_memory_service_record_item_t;
7902a95308bSMatthias Ringwald 
791cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
7922a95308bSMatthias Ringwald     btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t));
793a2673d88SMatthias Ringwald     if (buffer){
794798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_service_record_item_t));
7952a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
7962a95308bSMatthias Ringwald         return &buffer->data;
797b6269742SMatthias Ringwald     } else {
798b6269742SMatthias Ringwald         return NULL;
799a2673d88SMatthias Ringwald     }
800cd9ee144SMatthias Ringwald }
801cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
802798bd46fSMatthias Ringwald     // reconstruct buffer start
803798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) service_record_item)[-1];
804798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
805b6269742SMatthias Ringwald     free(buffer);
806cd9ee144SMatthias Ringwald }
807cd9ee144SMatthias Ringwald #endif
808cd9ee144SMatthias Ringwald 
809cd9ee144SMatthias Ringwald 
81027faf85aSMilanka Ringwald 
8110e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
8120e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
8130e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
8140e826a17SMilanka 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."
81527faf85aSMilanka Ringwald     #else
8160e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
81727faf85aSMilanka Ringwald     #endif
81827faf85aSMilanka Ringwald #endif
81927faf85aSMilanka Ringwald 
8200e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
8210e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
8220e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
8230e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
8240e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
825a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
826a2673d88SMatthias Ringwald     if (buffer){
827a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
828a2673d88SMatthias Ringwald     }
829a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
83027faf85aSMilanka Ringwald }
8310e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
8320e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
83327faf85aSMilanka Ringwald }
83427faf85aSMilanka Ringwald #else
8350e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
83627faf85aSMilanka Ringwald     return NULL;
83727faf85aSMilanka Ringwald }
8380e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
839b6269742SMatthias Ringwald     UNUSED(avdtp_stream_endpoint);
84027faf85aSMilanka Ringwald };
84127faf85aSMilanka Ringwald #endif
84227faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
8432a95308bSMatthias Ringwald 
8442a95308bSMatthias Ringwald typedef struct {
8452a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
846798bd46fSMatthias Ringwald     avdtp_stream_endpoint_t data;
8472a95308bSMatthias Ringwald } btstack_memory_avdtp_stream_endpoint_t;
8482a95308bSMatthias Ringwald 
8490e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
8502a95308bSMatthias Ringwald     btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t));
851a2673d88SMatthias Ringwald     if (buffer){
852798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avdtp_stream_endpoint_t));
8532a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
8542a95308bSMatthias Ringwald         return &buffer->data;
855b6269742SMatthias Ringwald     } else {
856b6269742SMatthias Ringwald         return NULL;
857a2673d88SMatthias Ringwald     }
85827faf85aSMilanka Ringwald }
8590e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
860798bd46fSMatthias Ringwald     // reconstruct buffer start
861798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_stream_endpoint)[-1];
862798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
863b6269742SMatthias Ringwald     free(buffer);
86427faf85aSMilanka Ringwald }
86527faf85aSMilanka Ringwald #endif
86627faf85aSMilanka Ringwald 
86727faf85aSMilanka Ringwald 
86812e7f38cSMilanka Ringwald 
86912e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
87012e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
87112e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
87212e7f38cSMilanka 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."
87312e7f38cSMilanka Ringwald     #else
87412e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
87512e7f38cSMilanka Ringwald     #endif
87612e7f38cSMilanka Ringwald #endif
87712e7f38cSMilanka Ringwald 
87812e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
87912e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
88012e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
88112e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
88212e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
883a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
884a2673d88SMatthias Ringwald     if (buffer){
885a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
886a2673d88SMatthias Ringwald     }
887a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
88812e7f38cSMilanka Ringwald }
88912e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
89012e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
89112e7f38cSMilanka Ringwald }
89212e7f38cSMilanka Ringwald #else
89312e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
89412e7f38cSMilanka Ringwald     return NULL;
89512e7f38cSMilanka Ringwald }
89612e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
897b6269742SMatthias Ringwald     UNUSED(avdtp_connection);
89812e7f38cSMilanka Ringwald };
89912e7f38cSMilanka Ringwald #endif
90012e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
9012a95308bSMatthias Ringwald 
9022a95308bSMatthias Ringwald typedef struct {
9032a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
904798bd46fSMatthias Ringwald     avdtp_connection_t data;
9052a95308bSMatthias Ringwald } btstack_memory_avdtp_connection_t;
9062a95308bSMatthias Ringwald 
90712e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
9082a95308bSMatthias Ringwald     btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t));
909a2673d88SMatthias Ringwald     if (buffer){
910798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avdtp_connection_t));
9112a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
9122a95308bSMatthias Ringwald         return &buffer->data;
913b6269742SMatthias Ringwald     } else {
914b6269742SMatthias Ringwald         return NULL;
915a2673d88SMatthias Ringwald     }
91612e7f38cSMilanka Ringwald }
91712e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
918798bd46fSMatthias Ringwald     // reconstruct buffer start
919798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_connection)[-1];
920798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
921b6269742SMatthias Ringwald     free(buffer);
92212e7f38cSMilanka Ringwald }
92312e7f38cSMilanka Ringwald #endif
92412e7f38cSMilanka Ringwald 
92512e7f38cSMilanka Ringwald 
92691451a2bSMilanka Ringwald 
92791451a2bSMilanka Ringwald // MARK: avrcp_connection_t
92891451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
92991451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
93091451a2bSMilanka 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."
93191451a2bSMilanka Ringwald     #else
93291451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
93391451a2bSMilanka Ringwald     #endif
93491451a2bSMilanka Ringwald #endif
93591451a2bSMilanka Ringwald 
93691451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
93791451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
93891451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
93991451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
94091451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
941a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
942a2673d88SMatthias Ringwald     if (buffer){
943a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
944a2673d88SMatthias Ringwald     }
945a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
94691451a2bSMilanka Ringwald }
94791451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
94891451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
94991451a2bSMilanka Ringwald }
95091451a2bSMilanka Ringwald #else
95191451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
95291451a2bSMilanka Ringwald     return NULL;
95391451a2bSMilanka Ringwald }
95491451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
955b6269742SMatthias Ringwald     UNUSED(avrcp_connection);
95691451a2bSMilanka Ringwald };
95791451a2bSMilanka Ringwald #endif
95891451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
9592a95308bSMatthias Ringwald 
9602a95308bSMatthias Ringwald typedef struct {
9612a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
962798bd46fSMatthias Ringwald     avrcp_connection_t data;
9632a95308bSMatthias Ringwald } btstack_memory_avrcp_connection_t;
9642a95308bSMatthias Ringwald 
96591451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
9662a95308bSMatthias Ringwald     btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t));
967a2673d88SMatthias Ringwald     if (buffer){
968798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avrcp_connection_t));
9692a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
9702a95308bSMatthias Ringwald         return &buffer->data;
971b6269742SMatthias Ringwald     } else {
972b6269742SMatthias Ringwald         return NULL;
973a2673d88SMatthias Ringwald     }
97491451a2bSMilanka Ringwald }
97591451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
976798bd46fSMatthias Ringwald     // reconstruct buffer start
977798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_connection)[-1];
978798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
979b6269742SMatthias Ringwald     free(buffer);
98091451a2bSMilanka Ringwald }
98191451a2bSMilanka Ringwald #endif
98291451a2bSMilanka Ringwald 
98391451a2bSMilanka Ringwald 
984f12a3722SMilanka Ringwald 
985f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
986f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
987f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
988f12a3722SMilanka 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."
989f12a3722SMilanka Ringwald     #else
990f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
991f12a3722SMilanka Ringwald     #endif
992f12a3722SMilanka Ringwald #endif
993f12a3722SMilanka Ringwald 
994f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
995f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
996f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
997f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
998f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
999a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
1000a2673d88SMatthias Ringwald     if (buffer){
1001a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
1002a2673d88SMatthias Ringwald     }
1003a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
1004f12a3722SMilanka Ringwald }
1005f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
1006f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
1007f12a3722SMilanka Ringwald }
1008f12a3722SMilanka Ringwald #else
1009f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
1010f12a3722SMilanka Ringwald     return NULL;
1011f12a3722SMilanka Ringwald }
1012f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
1013b6269742SMatthias Ringwald     UNUSED(avrcp_browsing_connection);
1014f12a3722SMilanka Ringwald };
1015f12a3722SMilanka Ringwald #endif
1016f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
10172a95308bSMatthias Ringwald 
10182a95308bSMatthias Ringwald typedef struct {
10192a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1020798bd46fSMatthias Ringwald     avrcp_browsing_connection_t data;
10212a95308bSMatthias Ringwald } btstack_memory_avrcp_browsing_connection_t;
10222a95308bSMatthias Ringwald 
1023f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
10242a95308bSMatthias Ringwald     btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t));
1025a2673d88SMatthias Ringwald     if (buffer){
1026798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avrcp_browsing_connection_t));
10272a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
10282a95308bSMatthias Ringwald         return &buffer->data;
1029b6269742SMatthias Ringwald     } else {
1030b6269742SMatthias Ringwald         return NULL;
1031a2673d88SMatthias Ringwald     }
1032f12a3722SMilanka Ringwald }
1033f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
1034798bd46fSMatthias Ringwald     // reconstruct buffer start
1035798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_browsing_connection)[-1];
1036798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1037b6269742SMatthias Ringwald     free(buffer);
1038f12a3722SMilanka Ringwald }
1039f12a3722SMilanka Ringwald #endif
1040f12a3722SMilanka Ringwald 
1041f12a3722SMilanka Ringwald 
104244c5d856SMatthias Ringwald #endif
1043a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
10442e97c149S[email protected] 
1045174a0c1cSMilanka Ringwald // MARK: battery_service_client_t
1046174a0c1cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BATTERY_SERVICE_CLIENTS)
1047174a0c1cSMilanka Ringwald     #if defined(MAX_NO_BATTERY_SERVICE_CLIENTS)
1048174a0c1cSMilanka Ringwald         #error "Deprecated MAX_NO_BATTERY_SERVICE_CLIENTS defined instead of MAX_NR_BATTERY_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_BATTERY_SERVICE_CLIENTS."
1049174a0c1cSMilanka Ringwald     #else
1050174a0c1cSMilanka Ringwald         #define MAX_NR_BATTERY_SERVICE_CLIENTS 0
1051174a0c1cSMilanka Ringwald     #endif
1052174a0c1cSMilanka Ringwald #endif
1053174a0c1cSMilanka Ringwald 
1054174a0c1cSMilanka Ringwald #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS
1055174a0c1cSMilanka Ringwald #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0
1056174a0c1cSMilanka Ringwald static battery_service_client_t battery_service_client_storage[MAX_NR_BATTERY_SERVICE_CLIENTS];
1057174a0c1cSMilanka Ringwald static btstack_memory_pool_t battery_service_client_pool;
1058174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){
1059174a0c1cSMilanka Ringwald     void * buffer = btstack_memory_pool_get(&battery_service_client_pool);
1060174a0c1cSMilanka Ringwald     if (buffer){
1061174a0c1cSMilanka Ringwald         memset(buffer, 0, sizeof(battery_service_client_t));
1062174a0c1cSMilanka Ringwald     }
1063174a0c1cSMilanka Ringwald     return (battery_service_client_t *) buffer;
1064174a0c1cSMilanka Ringwald }
1065174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){
1066174a0c1cSMilanka Ringwald     btstack_memory_pool_free(&battery_service_client_pool, battery_service_client);
1067174a0c1cSMilanka Ringwald }
1068174a0c1cSMilanka Ringwald #else
1069174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){
1070174a0c1cSMilanka Ringwald     return NULL;
1071174a0c1cSMilanka Ringwald }
1072174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){
1073174a0c1cSMilanka Ringwald     UNUSED(battery_service_client);
1074174a0c1cSMilanka Ringwald };
1075174a0c1cSMilanka Ringwald #endif
1076174a0c1cSMilanka Ringwald #elif defined(HAVE_MALLOC)
1077174a0c1cSMilanka Ringwald 
1078174a0c1cSMilanka Ringwald typedef struct {
1079174a0c1cSMilanka Ringwald     btstack_memory_buffer_t tracking;
1080174a0c1cSMilanka Ringwald     battery_service_client_t data;
1081174a0c1cSMilanka Ringwald } btstack_memory_battery_service_client_t;
1082174a0c1cSMilanka Ringwald 
1083174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){
1084174a0c1cSMilanka Ringwald     btstack_memory_battery_service_client_t * buffer = (btstack_memory_battery_service_client_t *) malloc(sizeof(btstack_memory_battery_service_client_t));
1085174a0c1cSMilanka Ringwald     if (buffer){
1086174a0c1cSMilanka Ringwald         memset(buffer, 0, sizeof(btstack_memory_battery_service_client_t));
1087174a0c1cSMilanka Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1088174a0c1cSMilanka Ringwald         return &buffer->data;
1089174a0c1cSMilanka Ringwald     } else {
1090174a0c1cSMilanka Ringwald         return NULL;
1091174a0c1cSMilanka Ringwald     }
1092174a0c1cSMilanka Ringwald }
1093174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){
1094174a0c1cSMilanka Ringwald     // reconstruct buffer start
1095174a0c1cSMilanka Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) battery_service_client)[-1];
1096174a0c1cSMilanka Ringwald     btstack_memory_tracking_remove(buffer);
1097174a0c1cSMilanka Ringwald     free(buffer);
1098174a0c1cSMilanka Ringwald }
1099174a0c1cSMilanka Ringwald #endif
1100174a0c1cSMilanka Ringwald 
1101174a0c1cSMilanka Ringwald 
11022e97c149S[email protected] // MARK: gatt_client_t
1103a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
1104a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
110527faf85aSMilanka 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."
1106a265b909SMatthias Ringwald     #else
1107a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
1108a265b909SMatthias Ringwald     #endif
1109a265b909SMatthias Ringwald #endif
1110a265b909SMatthias Ringwald 
1111a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
1112a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
1113a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
111429d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
1115d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
1116a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
1117a2673d88SMatthias Ringwald     if (buffer){
1118a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
1119a2673d88SMatthias Ringwald     }
1120a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
1121d0fdae3cS[email protected] }
1122d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
112329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
1124d0fdae3cS[email protected] }
1125d0fdae3cS[email protected] #else
1126d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
1127d0fdae3cS[email protected]     return NULL;
1128d0fdae3cS[email protected] }
1129d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
1130b6269742SMatthias Ringwald     UNUSED(gatt_client);
1131d0fdae3cS[email protected] };
1132d0fdae3cS[email protected] #endif
1133d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
11342a95308bSMatthias Ringwald 
11352a95308bSMatthias Ringwald typedef struct {
11362a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1137798bd46fSMatthias Ringwald     gatt_client_t data;
11382a95308bSMatthias Ringwald } btstack_memory_gatt_client_t;
11392a95308bSMatthias Ringwald 
1140d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
11412a95308bSMatthias Ringwald     btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t));
1142a2673d88SMatthias Ringwald     if (buffer){
1143798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_gatt_client_t));
11442a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
11452a95308bSMatthias Ringwald         return &buffer->data;
1146b6269742SMatthias Ringwald     } else {
1147b6269742SMatthias Ringwald         return NULL;
1148a2673d88SMatthias Ringwald     }
1149d0fdae3cS[email protected] }
1150d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
1151798bd46fSMatthias Ringwald     // reconstruct buffer start
1152798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) gatt_client)[-1];
1153798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1154b6269742SMatthias Ringwald     free(buffer);
1155d0fdae3cS[email protected] }
1156d0fdae3cS[email protected] #endif
11572e97c149S[email protected] 
11582e97c149S[email protected] 
1159*cf26c8fbSMilanka Ringwald // MARK: hids_client_t
1160*cf26c8fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HIDS_CLIENTS)
1161*cf26c8fbSMilanka Ringwald     #if defined(MAX_NO_HIDS_CLIENTS)
1162*cf26c8fbSMilanka Ringwald         #error "Deprecated MAX_NO_HIDS_CLIENTS defined instead of MAX_NR_HIDS_CLIENTS. Please update your btstack_config.h to use MAX_NR_HIDS_CLIENTS."
1163*cf26c8fbSMilanka Ringwald     #else
1164*cf26c8fbSMilanka Ringwald         #define MAX_NR_HIDS_CLIENTS 0
1165*cf26c8fbSMilanka Ringwald     #endif
1166*cf26c8fbSMilanka Ringwald #endif
1167*cf26c8fbSMilanka Ringwald 
1168*cf26c8fbSMilanka Ringwald #ifdef MAX_NR_HIDS_CLIENTS
1169*cf26c8fbSMilanka Ringwald #if MAX_NR_HIDS_CLIENTS > 0
1170*cf26c8fbSMilanka Ringwald static hids_client_t hids_client_storage[MAX_NR_HIDS_CLIENTS];
1171*cf26c8fbSMilanka Ringwald static btstack_memory_pool_t hids_client_pool;
1172*cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){
1173*cf26c8fbSMilanka Ringwald     void * buffer = btstack_memory_pool_get(&hids_client_pool);
1174*cf26c8fbSMilanka Ringwald     if (buffer){
1175*cf26c8fbSMilanka Ringwald         memset(buffer, 0, sizeof(hids_client_t));
1176*cf26c8fbSMilanka Ringwald     }
1177*cf26c8fbSMilanka Ringwald     return (hids_client_t *) buffer;
1178*cf26c8fbSMilanka Ringwald }
1179*cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){
1180*cf26c8fbSMilanka Ringwald     btstack_memory_pool_free(&hids_client_pool, hids_client);
1181*cf26c8fbSMilanka Ringwald }
1182*cf26c8fbSMilanka Ringwald #else
1183*cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){
1184*cf26c8fbSMilanka Ringwald     return NULL;
1185*cf26c8fbSMilanka Ringwald }
1186*cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){
1187*cf26c8fbSMilanka Ringwald     UNUSED(hids_client);
1188*cf26c8fbSMilanka Ringwald };
1189*cf26c8fbSMilanka Ringwald #endif
1190*cf26c8fbSMilanka Ringwald #elif defined(HAVE_MALLOC)
1191*cf26c8fbSMilanka Ringwald 
1192*cf26c8fbSMilanka Ringwald typedef struct {
1193*cf26c8fbSMilanka Ringwald     btstack_memory_buffer_t tracking;
1194*cf26c8fbSMilanka Ringwald     hids_client_t data;
1195*cf26c8fbSMilanka Ringwald } btstack_memory_hids_client_t;
1196*cf26c8fbSMilanka Ringwald 
1197*cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){
1198*cf26c8fbSMilanka Ringwald     btstack_memory_hids_client_t * buffer = (btstack_memory_hids_client_t *) malloc(sizeof(btstack_memory_hids_client_t));
1199*cf26c8fbSMilanka Ringwald     if (buffer){
1200*cf26c8fbSMilanka Ringwald         memset(buffer, 0, sizeof(btstack_memory_hids_client_t));
1201*cf26c8fbSMilanka Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1202*cf26c8fbSMilanka Ringwald         return &buffer->data;
1203*cf26c8fbSMilanka Ringwald     } else {
1204*cf26c8fbSMilanka Ringwald         return NULL;
1205*cf26c8fbSMilanka Ringwald     }
1206*cf26c8fbSMilanka Ringwald }
1207*cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){
1208*cf26c8fbSMilanka Ringwald     // reconstruct buffer start
1209*cf26c8fbSMilanka Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hids_client)[-1];
1210*cf26c8fbSMilanka Ringwald     btstack_memory_tracking_remove(buffer);
1211*cf26c8fbSMilanka Ringwald     free(buffer);
1212*cf26c8fbSMilanka Ringwald }
1213*cf26c8fbSMilanka Ringwald #endif
1214*cf26c8fbSMilanka Ringwald 
1215*cf26c8fbSMilanka Ringwald 
1216*cf26c8fbSMilanka Ringwald // MARK: scan_parameters_service_client_t
1217*cf26c8fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS)
1218*cf26c8fbSMilanka Ringwald     #if defined(MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS)
1219*cf26c8fbSMilanka Ringwald         #error "Deprecated MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS defined instead of MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS."
1220*cf26c8fbSMilanka Ringwald     #else
1221*cf26c8fbSMilanka Ringwald         #define MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 0
1222*cf26c8fbSMilanka Ringwald     #endif
1223*cf26c8fbSMilanka Ringwald #endif
1224*cf26c8fbSMilanka Ringwald 
1225*cf26c8fbSMilanka Ringwald #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS
1226*cf26c8fbSMilanka Ringwald #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0
1227*cf26c8fbSMilanka Ringwald static scan_parameters_service_client_t scan_parameters_service_client_storage[MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS];
1228*cf26c8fbSMilanka Ringwald static btstack_memory_pool_t scan_parameters_service_client_pool;
1229*cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){
1230*cf26c8fbSMilanka Ringwald     void * buffer = btstack_memory_pool_get(&scan_parameters_service_client_pool);
1231*cf26c8fbSMilanka Ringwald     if (buffer){
1232*cf26c8fbSMilanka Ringwald         memset(buffer, 0, sizeof(scan_parameters_service_client_t));
1233*cf26c8fbSMilanka Ringwald     }
1234*cf26c8fbSMilanka Ringwald     return (scan_parameters_service_client_t *) buffer;
1235*cf26c8fbSMilanka Ringwald }
1236*cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){
1237*cf26c8fbSMilanka Ringwald     btstack_memory_pool_free(&scan_parameters_service_client_pool, scan_parameters_service_client);
1238*cf26c8fbSMilanka Ringwald }
1239*cf26c8fbSMilanka Ringwald #else
1240*cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){
1241*cf26c8fbSMilanka Ringwald     return NULL;
1242*cf26c8fbSMilanka Ringwald }
1243*cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){
1244*cf26c8fbSMilanka Ringwald     UNUSED(scan_parameters_service_client);
1245*cf26c8fbSMilanka Ringwald };
1246*cf26c8fbSMilanka Ringwald #endif
1247*cf26c8fbSMilanka Ringwald #elif defined(HAVE_MALLOC)
1248*cf26c8fbSMilanka Ringwald 
1249*cf26c8fbSMilanka Ringwald typedef struct {
1250*cf26c8fbSMilanka Ringwald     btstack_memory_buffer_t tracking;
1251*cf26c8fbSMilanka Ringwald     scan_parameters_service_client_t data;
1252*cf26c8fbSMilanka Ringwald } btstack_memory_scan_parameters_service_client_t;
1253*cf26c8fbSMilanka Ringwald 
1254*cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){
1255*cf26c8fbSMilanka Ringwald     btstack_memory_scan_parameters_service_client_t * buffer = (btstack_memory_scan_parameters_service_client_t *) malloc(sizeof(btstack_memory_scan_parameters_service_client_t));
1256*cf26c8fbSMilanka Ringwald     if (buffer){
1257*cf26c8fbSMilanka Ringwald         memset(buffer, 0, sizeof(btstack_memory_scan_parameters_service_client_t));
1258*cf26c8fbSMilanka Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1259*cf26c8fbSMilanka Ringwald         return &buffer->data;
1260*cf26c8fbSMilanka Ringwald     } else {
1261*cf26c8fbSMilanka Ringwald         return NULL;
1262*cf26c8fbSMilanka Ringwald     }
1263*cf26c8fbSMilanka Ringwald }
1264*cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){
1265*cf26c8fbSMilanka Ringwald     // reconstruct buffer start
1266*cf26c8fbSMilanka Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) scan_parameters_service_client)[-1];
1267*cf26c8fbSMilanka Ringwald     btstack_memory_tracking_remove(buffer);
1268*cf26c8fbSMilanka Ringwald     free(buffer);
1269*cf26c8fbSMilanka Ringwald }
1270*cf26c8fbSMilanka Ringwald #endif
1271*cf26c8fbSMilanka Ringwald 
1272*cf26c8fbSMilanka Ringwald 
1273cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
1274a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
1275a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
127627faf85aSMilanka 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."
1277a265b909SMatthias Ringwald     #else
1278a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
1279a265b909SMatthias Ringwald     #endif
1280a265b909SMatthias Ringwald #endif
1281a265b909SMatthias Ringwald 
1282a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
1283a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1284a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
128529d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
1286cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1287a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
1288a2673d88SMatthias Ringwald     if (buffer){
1289a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
1290a2673d88SMatthias Ringwald     }
1291a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
1292cf49570bSMatthias Ringwald }
1293cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
129429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
1295cf49570bSMatthias Ringwald }
1296cf49570bSMatthias Ringwald #else
1297cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1298cf49570bSMatthias Ringwald     return NULL;
1299cf49570bSMatthias Ringwald }
1300cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1301b6269742SMatthias Ringwald     UNUSED(sm_lookup_entry);
1302cf49570bSMatthias Ringwald };
1303cf49570bSMatthias Ringwald #endif
1304cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
13052a95308bSMatthias Ringwald 
13062a95308bSMatthias Ringwald typedef struct {
13072a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1308798bd46fSMatthias Ringwald     sm_lookup_entry_t data;
13092a95308bSMatthias Ringwald } btstack_memory_sm_lookup_entry_t;
13102a95308bSMatthias Ringwald 
1311cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
13122a95308bSMatthias Ringwald     btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t));
1313a2673d88SMatthias Ringwald     if (buffer){
1314798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_sm_lookup_entry_t));
13152a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
13162a95308bSMatthias Ringwald         return &buffer->data;
1317b6269742SMatthias Ringwald     } else {
1318b6269742SMatthias Ringwald         return NULL;
1319a2673d88SMatthias Ringwald     }
1320cf49570bSMatthias Ringwald }
1321cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1322798bd46fSMatthias Ringwald     // reconstruct buffer start
1323798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) sm_lookup_entry)[-1];
1324798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1325b6269742SMatthias Ringwald     free(buffer);
1326cf49570bSMatthias Ringwald }
1327cf49570bSMatthias Ringwald #endif
1328cf49570bSMatthias Ringwald 
1329cf49570bSMatthias Ringwald 
1330174a0c1cSMilanka Ringwald // MARK: whitelist_entry_t
1331174a0c1cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
1332174a0c1cSMilanka Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
1333174a0c1cSMilanka 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."
1334174a0c1cSMilanka Ringwald     #else
1335174a0c1cSMilanka Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
1336174a0c1cSMilanka Ringwald     #endif
1337174a0c1cSMilanka Ringwald #endif
1338174a0c1cSMilanka Ringwald 
1339174a0c1cSMilanka Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
1340174a0c1cSMilanka Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1341174a0c1cSMilanka Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
1342174a0c1cSMilanka Ringwald static btstack_memory_pool_t whitelist_entry_pool;
1343174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1344174a0c1cSMilanka Ringwald     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
1345174a0c1cSMilanka Ringwald     if (buffer){
1346174a0c1cSMilanka Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
1347174a0c1cSMilanka Ringwald     }
1348174a0c1cSMilanka Ringwald     return (whitelist_entry_t *) buffer;
1349174a0c1cSMilanka Ringwald }
1350174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1351174a0c1cSMilanka Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
1352174a0c1cSMilanka Ringwald }
1353174a0c1cSMilanka Ringwald #else
1354174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1355174a0c1cSMilanka Ringwald     return NULL;
1356174a0c1cSMilanka Ringwald }
1357174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1358174a0c1cSMilanka Ringwald     UNUSED(whitelist_entry);
1359174a0c1cSMilanka Ringwald };
1360174a0c1cSMilanka Ringwald #endif
1361174a0c1cSMilanka Ringwald #elif defined(HAVE_MALLOC)
1362174a0c1cSMilanka Ringwald 
1363174a0c1cSMilanka Ringwald typedef struct {
1364174a0c1cSMilanka Ringwald     btstack_memory_buffer_t tracking;
1365174a0c1cSMilanka Ringwald     whitelist_entry_t data;
1366174a0c1cSMilanka Ringwald } btstack_memory_whitelist_entry_t;
1367174a0c1cSMilanka Ringwald 
1368174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1369174a0c1cSMilanka Ringwald     btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t));
1370174a0c1cSMilanka Ringwald     if (buffer){
1371174a0c1cSMilanka Ringwald         memset(buffer, 0, sizeof(btstack_memory_whitelist_entry_t));
1372174a0c1cSMilanka Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1373174a0c1cSMilanka Ringwald         return &buffer->data;
1374174a0c1cSMilanka Ringwald     } else {
1375174a0c1cSMilanka Ringwald         return NULL;
1376174a0c1cSMilanka Ringwald     }
1377174a0c1cSMilanka Ringwald }
1378174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1379174a0c1cSMilanka Ringwald     // reconstruct buffer start
1380174a0c1cSMilanka Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) whitelist_entry)[-1];
1381174a0c1cSMilanka Ringwald     btstack_memory_tracking_remove(buffer);
1382174a0c1cSMilanka Ringwald     free(buffer);
1383174a0c1cSMilanka Ringwald }
1384174a0c1cSMilanka Ringwald #endif
1385174a0c1cSMilanka Ringwald 
1386174a0c1cSMilanka Ringwald 
138744c5d856SMatthias Ringwald #endif
138844c5d856SMatthias Ringwald #ifdef ENABLE_MESH
1389ebb73e1fSMatthias Ringwald 
1390ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t
1391ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
1392ebb73e1fSMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_PDUS)
1393ebb73e1fSMatthias 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."
1394ebb73e1fSMatthias Ringwald     #else
1395ebb73e1fSMatthias Ringwald         #define MAX_NR_MESH_NETWORK_PDUS 0
1396ebb73e1fSMatthias Ringwald     #endif
1397ebb73e1fSMatthias Ringwald #endif
1398ebb73e1fSMatthias Ringwald 
1399ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
1400ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
1401ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
1402ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool;
1403ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
14041c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
14051c4e8084SMatthias Ringwald     if (buffer){
14061c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_pdu_t));
14071c4e8084SMatthias Ringwald     }
14081c4e8084SMatthias Ringwald     return (mesh_network_pdu_t *) buffer;
1409ebb73e1fSMatthias Ringwald }
1410ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1411ebb73e1fSMatthias Ringwald     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
1412ebb73e1fSMatthias Ringwald }
1413ebb73e1fSMatthias Ringwald #else
1414ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1415ebb73e1fSMatthias Ringwald     return NULL;
1416ebb73e1fSMatthias Ringwald }
1417ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1418b6269742SMatthias Ringwald     UNUSED(mesh_network_pdu);
1419ebb73e1fSMatthias Ringwald };
1420ebb73e1fSMatthias Ringwald #endif
1421ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
14222a95308bSMatthias Ringwald 
14232a95308bSMatthias Ringwald typedef struct {
14242a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1425798bd46fSMatthias Ringwald     mesh_network_pdu_t data;
14262a95308bSMatthias Ringwald } btstack_memory_mesh_network_pdu_t;
14272a95308bSMatthias Ringwald 
1428ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
14292a95308bSMatthias Ringwald     btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t));
14301c4e8084SMatthias Ringwald     if (buffer){
1431798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_network_pdu_t));
14322a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
14332a95308bSMatthias Ringwald         return &buffer->data;
1434b6269742SMatthias Ringwald     } else {
1435b6269742SMatthias Ringwald         return NULL;
14361c4e8084SMatthias Ringwald     }
1437ebb73e1fSMatthias Ringwald }
1438ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1439798bd46fSMatthias Ringwald     // reconstruct buffer start
1440798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_pdu)[-1];
1441798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1442b6269742SMatthias Ringwald     free(buffer);
1443ebb73e1fSMatthias Ringwald }
1444ebb73e1fSMatthias Ringwald #endif
1445ebb73e1fSMatthias Ringwald 
1446ebb73e1fSMatthias Ringwald 
1447a4bbc09dSMatthias Ringwald // MARK: mesh_segmented_pdu_t
1448a4bbc09dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS)
1449a4bbc09dSMatthias Ringwald     #if defined(MAX_NO_MESH_SEGMENTED_PDUS)
1450a4bbc09dSMatthias 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."
1451f7434c1fSMatthias Ringwald     #else
1452a4bbc09dSMatthias Ringwald         #define MAX_NR_MESH_SEGMENTED_PDUS 0
1453f7434c1fSMatthias Ringwald     #endif
1454f7434c1fSMatthias Ringwald #endif
1455f7434c1fSMatthias Ringwald 
1456a4bbc09dSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS
1457a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1458a4bbc09dSMatthias Ringwald static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS];
1459a4bbc09dSMatthias Ringwald static btstack_memory_pool_t mesh_segmented_pdu_pool;
1460a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1461a4bbc09dSMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool);
1462f7434c1fSMatthias Ringwald     if (buffer){
1463a4bbc09dSMatthias Ringwald         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1464f7434c1fSMatthias Ringwald     }
1465a4bbc09dSMatthias Ringwald     return (mesh_segmented_pdu_t *) buffer;
1466f7434c1fSMatthias Ringwald }
1467a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1468a4bbc09dSMatthias Ringwald     btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu);
1469f7434c1fSMatthias Ringwald }
1470f7434c1fSMatthias Ringwald #else
1471a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1472f7434c1fSMatthias Ringwald     return NULL;
1473f7434c1fSMatthias Ringwald }
1474a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1475b6269742SMatthias Ringwald     UNUSED(mesh_segmented_pdu);
1476f7434c1fSMatthias Ringwald };
1477f7434c1fSMatthias Ringwald #endif
1478f7434c1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
14792a95308bSMatthias Ringwald 
14802a95308bSMatthias Ringwald typedef struct {
14812a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1482798bd46fSMatthias Ringwald     mesh_segmented_pdu_t data;
14832a95308bSMatthias Ringwald } btstack_memory_mesh_segmented_pdu_t;
14842a95308bSMatthias Ringwald 
1485a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
14862a95308bSMatthias Ringwald     btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t));
1487f7434c1fSMatthias Ringwald     if (buffer){
1488798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_segmented_pdu_t));
14892a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
14902a95308bSMatthias Ringwald         return &buffer->data;
1491b6269742SMatthias Ringwald     } else {
1492b6269742SMatthias Ringwald         return NULL;
1493f7434c1fSMatthias Ringwald     }
1494f7434c1fSMatthias Ringwald }
1495a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1496798bd46fSMatthias Ringwald     // reconstruct buffer start
1497798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_segmented_pdu)[-1];
1498798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1499b6269742SMatthias Ringwald     free(buffer);
1500f7434c1fSMatthias Ringwald }
1501f7434c1fSMatthias Ringwald #endif
1502f7434c1fSMatthias Ringwald 
1503f7434c1fSMatthias Ringwald 
1504491f99b3SMatthias Ringwald // MARK: mesh_upper_transport_pdu_t
1505491f99b3SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS)
1506491f99b3SMatthias Ringwald     #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS)
1507491f99b3SMatthias 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."
1508491f99b3SMatthias Ringwald     #else
1509491f99b3SMatthias Ringwald         #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0
1510491f99b3SMatthias Ringwald     #endif
1511491f99b3SMatthias Ringwald #endif
1512491f99b3SMatthias Ringwald 
1513491f99b3SMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
1514491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1515491f99b3SMatthias Ringwald static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS];
1516491f99b3SMatthias Ringwald static btstack_memory_pool_t mesh_upper_transport_pdu_pool;
1517491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1518491f99b3SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool);
1519491f99b3SMatthias Ringwald     if (buffer){
1520491f99b3SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1521491f99b3SMatthias Ringwald     }
1522491f99b3SMatthias Ringwald     return (mesh_upper_transport_pdu_t *) buffer;
1523491f99b3SMatthias Ringwald }
1524491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1525491f99b3SMatthias Ringwald     btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu);
1526491f99b3SMatthias Ringwald }
1527491f99b3SMatthias Ringwald #else
1528491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1529491f99b3SMatthias Ringwald     return NULL;
1530491f99b3SMatthias Ringwald }
1531491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1532b6269742SMatthias Ringwald     UNUSED(mesh_upper_transport_pdu);
1533491f99b3SMatthias Ringwald };
1534491f99b3SMatthias Ringwald #endif
1535491f99b3SMatthias Ringwald #elif defined(HAVE_MALLOC)
15362a95308bSMatthias Ringwald 
15372a95308bSMatthias Ringwald typedef struct {
15382a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1539798bd46fSMatthias Ringwald     mesh_upper_transport_pdu_t data;
15402a95308bSMatthias Ringwald } btstack_memory_mesh_upper_transport_pdu_t;
15412a95308bSMatthias Ringwald 
1542491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
15432a95308bSMatthias Ringwald     btstack_memory_mesh_upper_transport_pdu_t * buffer = (btstack_memory_mesh_upper_transport_pdu_t *) malloc(sizeof(btstack_memory_mesh_upper_transport_pdu_t));
1544491f99b3SMatthias Ringwald     if (buffer){
1545798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_upper_transport_pdu_t));
15462a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
15472a95308bSMatthias Ringwald         return &buffer->data;
1548b6269742SMatthias Ringwald     } else {
1549b6269742SMatthias Ringwald         return NULL;
1550491f99b3SMatthias Ringwald     }
1551491f99b3SMatthias Ringwald }
1552491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1553798bd46fSMatthias Ringwald     // reconstruct buffer start
1554798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_upper_transport_pdu)[-1];
1555798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1556b6269742SMatthias Ringwald     free(buffer);
1557491f99b3SMatthias Ringwald }
1558491f99b3SMatthias Ringwald #endif
1559491f99b3SMatthias Ringwald 
1560491f99b3SMatthias Ringwald 
1561c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t
1562c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
1563c0a711d9SMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_KEYS)
1564c0a711d9SMatthias 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."
1565c0a711d9SMatthias Ringwald     #else
1566c0a711d9SMatthias Ringwald         #define MAX_NR_MESH_NETWORK_KEYS 0
1567c0a711d9SMatthias Ringwald     #endif
1568c0a711d9SMatthias Ringwald #endif
1569c0a711d9SMatthias Ringwald 
1570c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
1571c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
1572c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
1573c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool;
1574c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
15751c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
15761c4e8084SMatthias Ringwald     if (buffer){
15771c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_key_t));
15781c4e8084SMatthias Ringwald     }
15791c4e8084SMatthias Ringwald     return (mesh_network_key_t *) buffer;
1580c0a711d9SMatthias Ringwald }
1581c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1582c0a711d9SMatthias Ringwald     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
1583c0a711d9SMatthias Ringwald }
1584c0a711d9SMatthias Ringwald #else
1585c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1586c0a711d9SMatthias Ringwald     return NULL;
1587c0a711d9SMatthias Ringwald }
1588c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1589b6269742SMatthias Ringwald     UNUSED(mesh_network_key);
1590c0a711d9SMatthias Ringwald };
1591c0a711d9SMatthias Ringwald #endif
1592c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC)
15932a95308bSMatthias Ringwald 
15942a95308bSMatthias Ringwald typedef struct {
15952a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1596798bd46fSMatthias Ringwald     mesh_network_key_t data;
15972a95308bSMatthias Ringwald } btstack_memory_mesh_network_key_t;
15982a95308bSMatthias Ringwald 
1599c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
16002a95308bSMatthias Ringwald     btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t));
16011c4e8084SMatthias Ringwald     if (buffer){
1602798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_network_key_t));
16032a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
16042a95308bSMatthias Ringwald         return &buffer->data;
1605b6269742SMatthias Ringwald     } else {
1606b6269742SMatthias Ringwald         return NULL;
16071c4e8084SMatthias Ringwald     }
1608c0a711d9SMatthias Ringwald }
1609c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1610798bd46fSMatthias Ringwald     // reconstruct buffer start
1611798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_key)[-1];
1612798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1613b6269742SMatthias Ringwald     free(buffer);
1614c0a711d9SMatthias Ringwald }
1615c0a711d9SMatthias Ringwald #endif
1616c0a711d9SMatthias Ringwald 
1617c0a711d9SMatthias Ringwald 
161801e2bf94SMatthias Ringwald // MARK: mesh_transport_key_t
161901e2bf94SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
162001e2bf94SMatthias Ringwald     #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
162101e2bf94SMatthias 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."
162201e2bf94SMatthias Ringwald     #else
162301e2bf94SMatthias Ringwald         #define MAX_NR_MESH_TRANSPORT_KEYS 0
162401e2bf94SMatthias Ringwald     #endif
162501e2bf94SMatthias Ringwald #endif
162601e2bf94SMatthias Ringwald 
162701e2bf94SMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS
162801e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
162901e2bf94SMatthias Ringwald static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
163001e2bf94SMatthias Ringwald static btstack_memory_pool_t mesh_transport_key_pool;
163101e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
163201e2bf94SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
163301e2bf94SMatthias Ringwald     if (buffer){
163401e2bf94SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_transport_key_t));
163501e2bf94SMatthias Ringwald     }
163601e2bf94SMatthias Ringwald     return (mesh_transport_key_t *) buffer;
163701e2bf94SMatthias Ringwald }
163801e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
163901e2bf94SMatthias Ringwald     btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
164001e2bf94SMatthias Ringwald }
164101e2bf94SMatthias Ringwald #else
164201e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
164301e2bf94SMatthias Ringwald     return NULL;
164401e2bf94SMatthias Ringwald }
164501e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1646b6269742SMatthias Ringwald     UNUSED(mesh_transport_key);
164701e2bf94SMatthias Ringwald };
164801e2bf94SMatthias Ringwald #endif
164901e2bf94SMatthias Ringwald #elif defined(HAVE_MALLOC)
16502a95308bSMatthias Ringwald 
16512a95308bSMatthias Ringwald typedef struct {
16522a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1653798bd46fSMatthias Ringwald     mesh_transport_key_t data;
16542a95308bSMatthias Ringwald } btstack_memory_mesh_transport_key_t;
16552a95308bSMatthias Ringwald 
165601e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
16572a95308bSMatthias Ringwald     btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t));
165801e2bf94SMatthias Ringwald     if (buffer){
1659798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_transport_key_t));
16602a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
16612a95308bSMatthias Ringwald         return &buffer->data;
1662b6269742SMatthias Ringwald     } else {
1663b6269742SMatthias Ringwald         return NULL;
166401e2bf94SMatthias Ringwald     }
166501e2bf94SMatthias Ringwald }
166601e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1667798bd46fSMatthias Ringwald     // reconstruct buffer start
1668798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_transport_key)[-1];
1669798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1670b6269742SMatthias Ringwald     free(buffer);
167101e2bf94SMatthias Ringwald }
167201e2bf94SMatthias Ringwald #endif
167301e2bf94SMatthias Ringwald 
167401e2bf94SMatthias Ringwald 
16751f45d603SMatthias Ringwald // MARK: mesh_virtual_address_t
16761f45d603SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
16771f45d603SMatthias Ringwald     #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
16781f45d603SMatthias 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."
16791f45d603SMatthias Ringwald     #else
16801f45d603SMatthias Ringwald         #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
16811f45d603SMatthias Ringwald     #endif
16821f45d603SMatthias Ringwald #endif
16831f45d603SMatthias Ringwald 
16841f45d603SMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
16851f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
16861f45d603SMatthias Ringwald static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
16871f45d603SMatthias Ringwald static btstack_memory_pool_t mesh_virtual_address_pool;
16881f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
16891f45d603SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
16901f45d603SMatthias Ringwald     if (buffer){
16911f45d603SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_virtual_address_t));
16921f45d603SMatthias Ringwald     }
16931f45d603SMatthias Ringwald     return (mesh_virtual_address_t *) buffer;
16941f45d603SMatthias Ringwald }
16951f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
16961f45d603SMatthias Ringwald     btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
16971f45d603SMatthias Ringwald }
16981f45d603SMatthias Ringwald #else
16991f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
17001f45d603SMatthias Ringwald     return NULL;
17011f45d603SMatthias Ringwald }
17021f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1703b6269742SMatthias Ringwald     UNUSED(mesh_virtual_address);
17041f45d603SMatthias Ringwald };
17051f45d603SMatthias Ringwald #endif
17061f45d603SMatthias Ringwald #elif defined(HAVE_MALLOC)
17072a95308bSMatthias Ringwald 
17082a95308bSMatthias Ringwald typedef struct {
17092a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1710798bd46fSMatthias Ringwald     mesh_virtual_address_t data;
17112a95308bSMatthias Ringwald } btstack_memory_mesh_virtual_address_t;
17122a95308bSMatthias Ringwald 
17131f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
17142a95308bSMatthias Ringwald     btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t));
17151f45d603SMatthias Ringwald     if (buffer){
1716798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_virtual_address_t));
17172a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
17182a95308bSMatthias Ringwald         return &buffer->data;
1719b6269742SMatthias Ringwald     } else {
1720b6269742SMatthias Ringwald         return NULL;
17211f45d603SMatthias Ringwald     }
17221f45d603SMatthias Ringwald }
17231f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1724798bd46fSMatthias Ringwald     // reconstruct buffer start
1725798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_virtual_address)[-1];
1726798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1727b6269742SMatthias Ringwald     free(buffer);
17281f45d603SMatthias Ringwald }
17291f45d603SMatthias Ringwald #endif
17301f45d603SMatthias Ringwald 
17311f45d603SMatthias Ringwald 
173201122b73SMatthias Ringwald // MARK: mesh_subnet_t
173301122b73SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
173401122b73SMatthias Ringwald     #if defined(MAX_NO_MESH_SUBNETS)
173501122b73SMatthias 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."
173601122b73SMatthias Ringwald     #else
173701122b73SMatthias Ringwald         #define MAX_NR_MESH_SUBNETS 0
173801122b73SMatthias Ringwald     #endif
173901122b73SMatthias Ringwald #endif
174001122b73SMatthias Ringwald 
174101122b73SMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS
174201122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
174301122b73SMatthias Ringwald static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
174401122b73SMatthias Ringwald static btstack_memory_pool_t mesh_subnet_pool;
174501122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
174601122b73SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
174701122b73SMatthias Ringwald     if (buffer){
174801122b73SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_subnet_t));
174901122b73SMatthias Ringwald     }
175001122b73SMatthias Ringwald     return (mesh_subnet_t *) buffer;
175101122b73SMatthias Ringwald }
175201122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
175301122b73SMatthias Ringwald     btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
175401122b73SMatthias Ringwald }
175501122b73SMatthias Ringwald #else
175601122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
175701122b73SMatthias Ringwald     return NULL;
175801122b73SMatthias Ringwald }
175901122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1760b6269742SMatthias Ringwald     UNUSED(mesh_subnet);
176101122b73SMatthias Ringwald };
176201122b73SMatthias Ringwald #endif
176301122b73SMatthias Ringwald #elif defined(HAVE_MALLOC)
17642a95308bSMatthias Ringwald 
17652a95308bSMatthias Ringwald typedef struct {
17662a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1767798bd46fSMatthias Ringwald     mesh_subnet_t data;
17682a95308bSMatthias Ringwald } btstack_memory_mesh_subnet_t;
17692a95308bSMatthias Ringwald 
177001122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
17712a95308bSMatthias Ringwald     btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t));
177201122b73SMatthias Ringwald     if (buffer){
1773798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_subnet_t));
17742a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
17752a95308bSMatthias Ringwald         return &buffer->data;
1776b6269742SMatthias Ringwald     } else {
1777b6269742SMatthias Ringwald         return NULL;
177801122b73SMatthias Ringwald     }
177901122b73SMatthias Ringwald }
178001122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1781798bd46fSMatthias Ringwald     // reconstruct buffer start
1782798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_subnet)[-1];
1783798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1784b6269742SMatthias Ringwald     free(buffer);
178501122b73SMatthias Ringwald }
178601122b73SMatthias Ringwald #endif
178701122b73SMatthias Ringwald 
178801122b73SMatthias Ringwald 
17892e97c149S[email protected] #endif
1790798bd46fSMatthias Ringwald 
1791a3b02b71Smatthias.ringwald // init
1792a3b02b71Smatthias.ringwald void btstack_memory_init(void){
1793798bd46fSMatthias Ringwald #ifdef HAVE_MALLOC
1794798bd46fSMatthias Ringwald     // assert that there is no unexpected padding for combined buffer
1795798bd46fSMatthias Ringwald     btstack_assert(sizeof(test_buffer_t) == sizeof(btstack_memory_buffer_t) + sizeof(void *));
1796798bd46fSMatthias Ringwald #endif
1797798bd46fSMatthias Ringwald 
1798a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
1799a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
1800a3b02b71Smatthias.ringwald #endif
1801a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
1802a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
1803a3b02b71Smatthias.ringwald #endif
1804a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
1805a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
1806a3b02b71Smatthias.ringwald #endif
180744c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
180850dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
180950dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
1810a3b02b71Smatthias.ringwald #endif
181150dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
181250dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
1813a3b02b71Smatthias.ringwald #endif
181450dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
181550dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
181650dc57fcSMatthias Ringwald #endif
181750dc57fcSMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
181850dc57fcSMatthias 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));
181950dc57fcSMatthias Ringwald #endif
182050dc57fcSMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
182150dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
182250dc57fcSMatthias Ringwald #endif
182350dc57fcSMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
182450dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
182550dc57fcSMatthias Ringwald #endif
182650dc57fcSMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
182750dc57fcSMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
182850dc57fcSMatthias Ringwald #endif
1829f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0
1830f399f7fbSMilanka Ringwald     btstack_memory_pool_create(&hid_host_connection_pool, hid_host_connection_storage, MAX_NR_HID_HOST_CONNECTIONS, sizeof(hid_host_connection_t));
1831f399f7fbSMilanka Ringwald #endif
183250dc57fcSMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
183350dc57fcSMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
183450dc57fcSMatthias Ringwald #endif
183550dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
183650dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
183750dc57fcSMatthias Ringwald #endif
183850dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
183950dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
184050dc57fcSMatthias Ringwald #endif
184150dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
184250dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
184350dc57fcSMatthias Ringwald #endif
184450dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
184550dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1846a3b02b71Smatthias.ringwald #endif
1847f12a3722SMilanka Ringwald #endif
1848a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
1849174a0c1cSMilanka Ringwald #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0
1850174a0c1cSMilanka Ringwald     btstack_memory_pool_create(&battery_service_client_pool, battery_service_client_storage, MAX_NR_BATTERY_SERVICE_CLIENTS, sizeof(battery_service_client_t));
1851174a0c1cSMilanka Ringwald #endif
1852a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
1853a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1854d0fdae3cS[email protected] #endif
1855*cf26c8fbSMilanka Ringwald #if MAX_NR_HIDS_CLIENTS > 0
1856*cf26c8fbSMilanka Ringwald     btstack_memory_pool_create(&hids_client_pool, hids_client_storage, MAX_NR_HIDS_CLIENTS, sizeof(hids_client_t));
1857*cf26c8fbSMilanka Ringwald #endif
1858*cf26c8fbSMilanka Ringwald #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0
1859*cf26c8fbSMilanka Ringwald     btstack_memory_pool_create(&scan_parameters_service_client_pool, scan_parameters_service_client_storage, MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS, sizeof(scan_parameters_service_client_t));
1860*cf26c8fbSMilanka Ringwald #endif
1861a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1862a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1863cf49570bSMatthias Ringwald #endif
1864174a0c1cSMilanka Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1865174a0c1cSMilanka Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1866174a0c1cSMilanka Ringwald #endif
1867ebb73e1fSMatthias Ringwald #endif
186844c5d856SMatthias Ringwald #ifdef ENABLE_MESH
186950dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
187050dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
187144c5d856SMatthias Ringwald #endif
1872a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1873a4bbc09dSMatthias Ringwald     btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t));
1874f7434c1fSMatthias Ringwald #endif
1875491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1876491f99b3SMatthias 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));
1877491f99b3SMatthias Ringwald #endif
187850dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
187950dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1880c0a711d9SMatthias Ringwald #endif
188101e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
188201e2bf94SMatthias Ringwald     btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
188301e2bf94SMatthias Ringwald #endif
18841f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
18851f45d603SMatthias Ringwald     btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
18861f45d603SMatthias Ringwald #endif
188701122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
188801122b73SMatthias Ringwald     btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
188901122b73SMatthias Ringwald #endif
1890a7d12effS[email protected] #endif
1891a3b02b71Smatthias.ringwald }
1892