xref: /btstack/src/btstack_memory.c (revision 798bd46f267607077d84adf48940069241248e5a)
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 
58b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
59b6269742SMatthias Ringwald typedef struct btstack_memory_buffer {
60b6269742SMatthias Ringwald     struct btstack_memory_buffer * next;
61b6269742SMatthias Ringwald     struct btstack_memory_buffer * prev;
62b6269742SMatthias Ringwald } btstack_memory_buffer_t;
63b6269742SMatthias Ringwald 
64*798bd46fSMatthias Ringwald typedef struct {
65*798bd46fSMatthias Ringwald     btstack_memory_buffer_t tracking;
66*798bd46fSMatthias Ringwald     void * pointer;
67*798bd46fSMatthias Ringwald } test_buffer_t;
68*798bd46fSMatthias Ringwald 
69b6269742SMatthias Ringwald static btstack_memory_buffer_t * btstack_memory_malloc_buffers;
7019ef97d2SMatthias Ringwald static uint32_t btstack_memory_malloc_counter;
71b6269742SMatthias Ringwald 
722a95308bSMatthias Ringwald static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){
732a95308bSMatthias Ringwald     btstack_assert(buffer != NULL);
7419ef97d2SMatthias Ringwald     if (btstack_memory_malloc_buffers != NULL) {
7519ef97d2SMatthias Ringwald         // let current first item prev point to new first item
7619ef97d2SMatthias Ringwald         btstack_memory_malloc_buffers->prev = buffer;
7719ef97d2SMatthias Ringwald     }
78b6269742SMatthias Ringwald     buffer->prev = NULL;
79b6269742SMatthias Ringwald     buffer->next = btstack_memory_malloc_buffers;
80b6269742SMatthias Ringwald     btstack_memory_malloc_buffers = buffer;
8119ef97d2SMatthias Ringwald 
8219ef97d2SMatthias Ringwald     btstack_memory_malloc_counter++;
83b6269742SMatthias Ringwald }
84b6269742SMatthias Ringwald 
852a95308bSMatthias Ringwald static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){
862a95308bSMatthias Ringwald     btstack_assert(buffer != NULL);
87b6269742SMatthias Ringwald     if (buffer->prev == NULL){
88b6269742SMatthias Ringwald         // first item
89b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
90b6269742SMatthias Ringwald     } else {
91b6269742SMatthias Ringwald         buffer->prev->next = buffer->next;
92b6269742SMatthias Ringwald     }
93b6269742SMatthias Ringwald     if (buffer->next != NULL){
94b6269742SMatthias Ringwald         buffer->next->prev = buffer->prev;
95b6269742SMatthias Ringwald     }
9619ef97d2SMatthias Ringwald 
9719ef97d2SMatthias Ringwald     btstack_memory_malloc_counter--;
98b6269742SMatthias Ringwald }
99b6269742SMatthias Ringwald #endif
100b6269742SMatthias Ringwald 
101b6269742SMatthias Ringwald void btstack_memory_deinit(void){
102b6269742SMatthias Ringwald #ifdef HAVE_MALLOC
103b6269742SMatthias Ringwald     while (btstack_memory_malloc_buffers != NULL){
104b6269742SMatthias Ringwald         btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers;
105b6269742SMatthias Ringwald         btstack_memory_malloc_buffers = buffer->next;
106b6269742SMatthias Ringwald         free(buffer);
107b6269742SMatthias Ringwald     }
10819ef97d2SMatthias Ringwald     btstack_assert(btstack_memory_malloc_counter == 0);
109b6269742SMatthias Ringwald #endif
110b6269742SMatthias Ringwald }
111a3b02b71Smatthias.ringwald 
1122e97c149S[email protected] 
113a3b02b71Smatthias.ringwald // MARK: hci_connection_t
114a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
115a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
11627faf85aSMilanka 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."
117a265b909SMatthias Ringwald     #else
118a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
119a265b909SMatthias Ringwald     #endif
120a265b909SMatthias Ringwald #endif
121a265b909SMatthias Ringwald 
122a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
123a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
124a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
12529d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
1266527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
127a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
128a2673d88SMatthias Ringwald     if (buffer){
129a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
130a2673d88SMatthias Ringwald     }
131a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
132a3b02b71Smatthias.ringwald }
1336527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
13429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
135a3b02b71Smatthias.ringwald }
136c4d3f927Smatthias.ringwald #else
1376527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
138c4d3f927Smatthias.ringwald     return NULL;
139c4d3f927Smatthias.ringwald }
1406527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
141b6269742SMatthias Ringwald     UNUSED(hci_connection);
142c4d3f927Smatthias.ringwald };
143c4d3f927Smatthias.ringwald #endif
144a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1452a95308bSMatthias Ringwald 
1462a95308bSMatthias Ringwald typedef struct {
1472a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
148*798bd46fSMatthias Ringwald     hci_connection_t data;
1492a95308bSMatthias Ringwald } btstack_memory_hci_connection_t;
1502a95308bSMatthias Ringwald 
1516527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
1522a95308bSMatthias Ringwald     btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t));
153a2673d88SMatthias Ringwald     if (buffer){
154*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_hci_connection_t));
1552a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
1562a95308bSMatthias Ringwald         return &buffer->data;
157b6269742SMatthias Ringwald     } else {
158b6269742SMatthias Ringwald         return NULL;
159a2673d88SMatthias Ringwald     }
160a3b02b71Smatthias.ringwald }
1616527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
162*798bd46fSMatthias Ringwald     // reconstruct buffer start
163*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_connection)[-1];
164*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
165b6269742SMatthias Ringwald     free(buffer);
166a3b02b71Smatthias.ringwald }
167a3b02b71Smatthias.ringwald #endif
168a3b02b71Smatthias.ringwald 
169a3b02b71Smatthias.ringwald 
1702e97c149S[email protected] 
171a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
172a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
173a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
17427faf85aSMilanka 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."
175a265b909SMatthias Ringwald     #else
176a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
177a265b909SMatthias Ringwald     #endif
178a265b909SMatthias Ringwald #endif
179a265b909SMatthias Ringwald 
180a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
181a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
182a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
18329d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1846527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
185a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
186a2673d88SMatthias Ringwald     if (buffer){
187a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
188a2673d88SMatthias Ringwald     }
189a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
190a3b02b71Smatthias.ringwald }
1916527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
19229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
193a3b02b71Smatthias.ringwald }
194c4d3f927Smatthias.ringwald #else
1956527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
196c4d3f927Smatthias.ringwald     return NULL;
197c4d3f927Smatthias.ringwald }
1986527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
199b6269742SMatthias Ringwald     UNUSED(l2cap_service);
200c4d3f927Smatthias.ringwald };
201c4d3f927Smatthias.ringwald #endif
202a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2032a95308bSMatthias Ringwald 
2042a95308bSMatthias Ringwald typedef struct {
2052a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
206*798bd46fSMatthias Ringwald     l2cap_service_t data;
2072a95308bSMatthias Ringwald } btstack_memory_l2cap_service_t;
2082a95308bSMatthias Ringwald 
2096527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
2102a95308bSMatthias Ringwald     btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t));
211a2673d88SMatthias Ringwald     if (buffer){
212*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_l2cap_service_t));
2132a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
2142a95308bSMatthias Ringwald         return &buffer->data;
215b6269742SMatthias Ringwald     } else {
216b6269742SMatthias Ringwald         return NULL;
217a2673d88SMatthias Ringwald     }
218a3b02b71Smatthias.ringwald }
2196527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
220*798bd46fSMatthias Ringwald     // reconstruct buffer start
221*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_service)[-1];
222*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
223b6269742SMatthias Ringwald     free(buffer);
224a3b02b71Smatthias.ringwald }
225a3b02b71Smatthias.ringwald #endif
226a3b02b71Smatthias.ringwald 
227a3b02b71Smatthias.ringwald 
228a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
229a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
230a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
23127faf85aSMilanka 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."
232a265b909SMatthias Ringwald     #else
233a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
234a265b909SMatthias Ringwald     #endif
235a265b909SMatthias Ringwald #endif
236a265b909SMatthias Ringwald 
237a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
238a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
239a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
24029d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
2416527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
242a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
243a2673d88SMatthias Ringwald     if (buffer){
244a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
245a2673d88SMatthias Ringwald     }
246a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
247a3b02b71Smatthias.ringwald }
2486527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
24929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
250a3b02b71Smatthias.ringwald }
251c4d3f927Smatthias.ringwald #else
2526527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
253c4d3f927Smatthias.ringwald     return NULL;
254c4d3f927Smatthias.ringwald }
2556527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
256b6269742SMatthias Ringwald     UNUSED(l2cap_channel);
257c4d3f927Smatthias.ringwald };
258c4d3f927Smatthias.ringwald #endif
259a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2602a95308bSMatthias Ringwald 
2612a95308bSMatthias Ringwald typedef struct {
2622a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
263*798bd46fSMatthias Ringwald     l2cap_channel_t data;
2642a95308bSMatthias Ringwald } btstack_memory_l2cap_channel_t;
2652a95308bSMatthias Ringwald 
2666527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
2672a95308bSMatthias Ringwald     btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t));
268a2673d88SMatthias Ringwald     if (buffer){
269*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_l2cap_channel_t));
2702a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
2712a95308bSMatthias Ringwald         return &buffer->data;
272b6269742SMatthias Ringwald     } else {
273b6269742SMatthias Ringwald         return NULL;
274a2673d88SMatthias Ringwald     }
275a3b02b71Smatthias.ringwald }
2766527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
277*798bd46fSMatthias Ringwald     // reconstruct buffer start
278*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_channel)[-1];
279*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
280b6269742SMatthias Ringwald     free(buffer);
281a3b02b71Smatthias.ringwald }
282a3b02b71Smatthias.ringwald #endif
283a3b02b71Smatthias.ringwald 
284a3b02b71Smatthias.ringwald 
28544c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
2862e97c149S[email protected] 
287a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
288a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
289a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
29027faf85aSMilanka 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."
291a265b909SMatthias Ringwald     #else
292a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
293a265b909SMatthias Ringwald     #endif
294a265b909SMatthias Ringwald #endif
295a265b909SMatthias Ringwald 
296a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
297a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
298a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
29929d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
3006527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
301a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
302a2673d88SMatthias Ringwald     if (buffer){
303a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
304a2673d88SMatthias Ringwald     }
305a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
306a3b02b71Smatthias.ringwald }
3076527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
30829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
309a3b02b71Smatthias.ringwald }
310c4d3f927Smatthias.ringwald #else
3116527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
312c4d3f927Smatthias.ringwald     return NULL;
313c4d3f927Smatthias.ringwald }
3146527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
315b6269742SMatthias Ringwald     UNUSED(rfcomm_multiplexer);
316c4d3f927Smatthias.ringwald };
317c4d3f927Smatthias.ringwald #endif
318a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3192a95308bSMatthias Ringwald 
3202a95308bSMatthias Ringwald typedef struct {
3212a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
322*798bd46fSMatthias Ringwald     rfcomm_multiplexer_t data;
3232a95308bSMatthias Ringwald } btstack_memory_rfcomm_multiplexer_t;
3242a95308bSMatthias Ringwald 
3256527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
3262a95308bSMatthias Ringwald     btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t));
327a2673d88SMatthias Ringwald     if (buffer){
328*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_multiplexer_t));
3292a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
3302a95308bSMatthias Ringwald         return &buffer->data;
331b6269742SMatthias Ringwald     } else {
332b6269742SMatthias Ringwald         return NULL;
333a2673d88SMatthias Ringwald     }
334a3b02b71Smatthias.ringwald }
3356527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
336*798bd46fSMatthias Ringwald     // reconstruct buffer start
337*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_multiplexer)[-1];
338*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
339b6269742SMatthias Ringwald     free(buffer);
340a3b02b71Smatthias.ringwald }
341a3b02b71Smatthias.ringwald #endif
342a3b02b71Smatthias.ringwald 
343a3b02b71Smatthias.ringwald 
344a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
345a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
346a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
34727faf85aSMilanka 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."
348a265b909SMatthias Ringwald     #else
349a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
350a265b909SMatthias Ringwald     #endif
351a265b909SMatthias Ringwald #endif
352a265b909SMatthias Ringwald 
353a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
354a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
355a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
35629d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
3576527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
358a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
359a2673d88SMatthias Ringwald     if (buffer){
360a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
361a2673d88SMatthias Ringwald     }
362a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
363a3b02b71Smatthias.ringwald }
3646527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
36529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
366a3b02b71Smatthias.ringwald }
367c4d3f927Smatthias.ringwald #else
3686527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
369c4d3f927Smatthias.ringwald     return NULL;
370c4d3f927Smatthias.ringwald }
3716527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
372b6269742SMatthias Ringwald     UNUSED(rfcomm_service);
373c4d3f927Smatthias.ringwald };
374c4d3f927Smatthias.ringwald #endif
375a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3762a95308bSMatthias Ringwald 
3772a95308bSMatthias Ringwald typedef struct {
3782a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
379*798bd46fSMatthias Ringwald     rfcomm_service_t data;
3802a95308bSMatthias Ringwald } btstack_memory_rfcomm_service_t;
3812a95308bSMatthias Ringwald 
3826527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
3832a95308bSMatthias Ringwald     btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t));
384a2673d88SMatthias Ringwald     if (buffer){
385*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_service_t));
3862a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
3872a95308bSMatthias Ringwald         return &buffer->data;
388b6269742SMatthias Ringwald     } else {
389b6269742SMatthias Ringwald         return NULL;
390a2673d88SMatthias Ringwald     }
391a3b02b71Smatthias.ringwald }
3926527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
393*798bd46fSMatthias Ringwald     // reconstruct buffer start
394*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_service)[-1];
395*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
396b6269742SMatthias Ringwald     free(buffer);
397a3b02b71Smatthias.ringwald }
398a3b02b71Smatthias.ringwald #endif
399a3b02b71Smatthias.ringwald 
400a3b02b71Smatthias.ringwald 
401a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
402a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
403a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
40427faf85aSMilanka 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."
405a265b909SMatthias Ringwald     #else
406a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
407a265b909SMatthias Ringwald     #endif
408a265b909SMatthias Ringwald #endif
409a265b909SMatthias Ringwald 
410a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
411a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
412a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
41329d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
4146527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
415a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
416a2673d88SMatthias Ringwald     if (buffer){
417a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
418a2673d88SMatthias Ringwald     }
419a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
420a3b02b71Smatthias.ringwald }
4216527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
42229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
423a3b02b71Smatthias.ringwald }
424c4d3f927Smatthias.ringwald #else
4256527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
426c4d3f927Smatthias.ringwald     return NULL;
427c4d3f927Smatthias.ringwald }
4286527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
429b6269742SMatthias Ringwald     UNUSED(rfcomm_channel);
430c4d3f927Smatthias.ringwald };
431c4d3f927Smatthias.ringwald #endif
432a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
4332a95308bSMatthias Ringwald 
4342a95308bSMatthias Ringwald typedef struct {
4352a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
436*798bd46fSMatthias Ringwald     rfcomm_channel_t data;
4372a95308bSMatthias Ringwald } btstack_memory_rfcomm_channel_t;
4382a95308bSMatthias Ringwald 
4396527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
4402a95308bSMatthias Ringwald     btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t));
441a2673d88SMatthias Ringwald     if (buffer){
442*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_rfcomm_channel_t));
4432a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
4442a95308bSMatthias Ringwald         return &buffer->data;
445b6269742SMatthias Ringwald     } else {
446b6269742SMatthias Ringwald         return NULL;
447a2673d88SMatthias Ringwald     }
448a3b02b71Smatthias.ringwald }
4496527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
450*798bd46fSMatthias Ringwald     // reconstruct buffer start
451*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_channel)[-1];
452*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
453b6269742SMatthias Ringwald     free(buffer);
454a3b02b71Smatthias.ringwald }
455a3b02b71Smatthias.ringwald #endif
456a3b02b71Smatthias.ringwald 
457fdb398c2S[email protected] 
458e0e5e285Smatthias.ringwald 
4592c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
460a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
461a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
46227faf85aSMilanka 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."
463a265b909SMatthias Ringwald     #else
464a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
465a265b909SMatthias Ringwald     #endif
466a265b909SMatthias Ringwald #endif
467a265b909SMatthias Ringwald 
468a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
469a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
470a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
4712c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
4722c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
473a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
474a2673d88SMatthias Ringwald     if (buffer){
475a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
476a2673d88SMatthias Ringwald     }
477a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
4781801b596Smatthias.ringwald }
4792c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
4802c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
4811801b596Smatthias.ringwald }
482c4d3f927Smatthias.ringwald #else
4832c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
484c4d3f927Smatthias.ringwald     return NULL;
485c4d3f927Smatthias.ringwald }
4862c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
487b6269742SMatthias Ringwald     UNUSED(btstack_link_key_db_memory_entry);
488c4d3f927Smatthias.ringwald };
489c4d3f927Smatthias.ringwald #endif
4901801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
4912a95308bSMatthias Ringwald 
4922a95308bSMatthias Ringwald typedef struct {
4932a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
494*798bd46fSMatthias Ringwald     btstack_link_key_db_memory_entry_t data;
4952a95308bSMatthias Ringwald } btstack_memory_btstack_link_key_db_memory_entry_t;
4962a95308bSMatthias Ringwald 
4972c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
4982a95308bSMatthias 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));
499a2673d88SMatthias Ringwald     if (buffer){
500*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_btstack_link_key_db_memory_entry_t));
5012a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
5022a95308bSMatthias Ringwald         return &buffer->data;
503b6269742SMatthias Ringwald     } else {
504b6269742SMatthias Ringwald         return NULL;
505a2673d88SMatthias Ringwald     }
5061801b596Smatthias.ringwald }
5072c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
508*798bd46fSMatthias Ringwald     // reconstruct buffer start
509*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) btstack_link_key_db_memory_entry)[-1];
510*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
511b6269742SMatthias Ringwald     free(buffer);
512e0e5e285Smatthias.ringwald }
5131801b596Smatthias.ringwald #endif
5141801b596Smatthias.ringwald 
5152e97c149S[email protected] 
5162e97c149S[email protected] 
5172e97c149S[email protected] // MARK: bnep_service_t
518a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
519a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
52027faf85aSMilanka 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."
521a265b909SMatthias Ringwald     #else
522a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
523a265b909SMatthias Ringwald     #endif
524a265b909SMatthias Ringwald #endif
525a265b909SMatthias Ringwald 
526a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
527a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
528a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
52929d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
5302e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
531a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
532a2673d88SMatthias Ringwald     if (buffer){
533a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
534a2673d88SMatthias Ringwald     }
535a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
5362e97c149S[email protected] }
5372e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
53829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
5392e97c149S[email protected] }
5402e97c149S[email protected] #else
5412e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
5422e97c149S[email protected]     return NULL;
5432e97c149S[email protected] }
5442e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
545b6269742SMatthias Ringwald     UNUSED(bnep_service);
5462e97c149S[email protected] };
5472e97c149S[email protected] #endif
5482e97c149S[email protected] #elif defined(HAVE_MALLOC)
5492a95308bSMatthias Ringwald 
5502a95308bSMatthias Ringwald typedef struct {
5512a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
552*798bd46fSMatthias Ringwald     bnep_service_t data;
5532a95308bSMatthias Ringwald } btstack_memory_bnep_service_t;
5542a95308bSMatthias Ringwald 
5552e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
5562a95308bSMatthias Ringwald     btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t));
557a2673d88SMatthias Ringwald     if (buffer){
558*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_bnep_service_t));
5592a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
5602a95308bSMatthias Ringwald         return &buffer->data;
561b6269742SMatthias Ringwald     } else {
562b6269742SMatthias Ringwald         return NULL;
563a2673d88SMatthias Ringwald     }
5642e97c149S[email protected] }
5652e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
566*798bd46fSMatthias Ringwald     // reconstruct buffer start
567*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_service)[-1];
568*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
569b6269742SMatthias Ringwald     free(buffer);
5702e97c149S[email protected] }
5712e97c149S[email protected] #endif
5722e97c149S[email protected] 
5732e97c149S[email protected] 
5742e97c149S[email protected] // MARK: bnep_channel_t
575a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
576a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
57727faf85aSMilanka 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."
578a265b909SMatthias Ringwald     #else
579a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
580a265b909SMatthias Ringwald     #endif
581a265b909SMatthias Ringwald #endif
582a265b909SMatthias Ringwald 
583a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
584a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
585a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
58629d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
5872e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
588a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
589a2673d88SMatthias Ringwald     if (buffer){
590a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
591a2673d88SMatthias Ringwald     }
592a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
5932e97c149S[email protected] }
5942e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
59529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
5962e97c149S[email protected] }
5972e97c149S[email protected] #else
5982e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
5992e97c149S[email protected]     return NULL;
6002e97c149S[email protected] }
6012e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
602b6269742SMatthias Ringwald     UNUSED(bnep_channel);
6032e97c149S[email protected] };
6042e97c149S[email protected] #endif
6052e97c149S[email protected] #elif defined(HAVE_MALLOC)
6062a95308bSMatthias Ringwald 
6072a95308bSMatthias Ringwald typedef struct {
6082a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
609*798bd46fSMatthias Ringwald     bnep_channel_t data;
6102a95308bSMatthias Ringwald } btstack_memory_bnep_channel_t;
6112a95308bSMatthias Ringwald 
6122e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
6132a95308bSMatthias Ringwald     btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t));
614a2673d88SMatthias Ringwald     if (buffer){
615*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_bnep_channel_t));
6162a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
6172a95308bSMatthias Ringwald         return &buffer->data;
618b6269742SMatthias Ringwald     } else {
619b6269742SMatthias Ringwald         return NULL;
620a2673d88SMatthias Ringwald     }
6212e97c149S[email protected] }
6222e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
623*798bd46fSMatthias Ringwald     // reconstruct buffer start
624*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_channel)[-1];
625*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
626b6269742SMatthias Ringwald     free(buffer);
6272e97c149S[email protected] }
6282e97c149S[email protected] #endif
6292e97c149S[email protected] 
6302e97c149S[email protected] 
631ea5029c9SMilanka Ringwald 
632ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
633a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
634a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
63527faf85aSMilanka 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."
636a265b909SMatthias Ringwald     #else
637a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
638a265b909SMatthias Ringwald     #endif
639a265b909SMatthias Ringwald #endif
640a265b909SMatthias Ringwald 
641a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
642a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
643a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
64429d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
645ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
646a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
647a2673d88SMatthias Ringwald     if (buffer){
648a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
649a2673d88SMatthias Ringwald     }
650a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
651ea5029c9SMilanka Ringwald }
652ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
65329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
654ea5029c9SMilanka Ringwald }
655ea5029c9SMilanka Ringwald #else
656ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
657ea5029c9SMilanka Ringwald     return NULL;
658ea5029c9SMilanka Ringwald }
659ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
660b6269742SMatthias Ringwald     UNUSED(hfp_connection);
661ea5029c9SMilanka Ringwald };
662ea5029c9SMilanka Ringwald #endif
663ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
6642a95308bSMatthias Ringwald 
6652a95308bSMatthias Ringwald typedef struct {
6662a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
667*798bd46fSMatthias Ringwald     hfp_connection_t data;
6682a95308bSMatthias Ringwald } btstack_memory_hfp_connection_t;
6692a95308bSMatthias Ringwald 
670ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
6712a95308bSMatthias Ringwald     btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t));
672a2673d88SMatthias Ringwald     if (buffer){
673*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_hfp_connection_t));
6742a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
6752a95308bSMatthias Ringwald         return &buffer->data;
676b6269742SMatthias Ringwald     } else {
677b6269742SMatthias Ringwald         return NULL;
678a2673d88SMatthias Ringwald     }
679ea5029c9SMilanka Ringwald }
680ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
681*798bd46fSMatthias Ringwald     // reconstruct buffer start
682*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hfp_connection)[-1];
683*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
684b6269742SMatthias Ringwald     free(buffer);
685ea5029c9SMilanka Ringwald }
686ea5029c9SMilanka Ringwald #endif
687ea5029c9SMilanka Ringwald 
688ea5029c9SMilanka Ringwald 
689cd9ee144SMatthias Ringwald 
690cd9ee144SMatthias Ringwald // MARK: service_record_item_t
691a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
692a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
69327faf85aSMilanka 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."
694a265b909SMatthias Ringwald     #else
695a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
696a265b909SMatthias Ringwald     #endif
697a265b909SMatthias Ringwald #endif
698a265b909SMatthias Ringwald 
699a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
700a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
701a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
70229d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
703cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
704a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
705a2673d88SMatthias Ringwald     if (buffer){
706a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
707a2673d88SMatthias Ringwald     }
708a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
709cd9ee144SMatthias Ringwald }
710cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
71129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
712cd9ee144SMatthias Ringwald }
713cd9ee144SMatthias Ringwald #else
714cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
715cd9ee144SMatthias Ringwald     return NULL;
716cd9ee144SMatthias Ringwald }
717cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
718b6269742SMatthias Ringwald     UNUSED(service_record_item);
719cd9ee144SMatthias Ringwald };
720cd9ee144SMatthias Ringwald #endif
721cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
7222a95308bSMatthias Ringwald 
7232a95308bSMatthias Ringwald typedef struct {
7242a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
725*798bd46fSMatthias Ringwald     service_record_item_t data;
7262a95308bSMatthias Ringwald } btstack_memory_service_record_item_t;
7272a95308bSMatthias Ringwald 
728cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
7292a95308bSMatthias Ringwald     btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t));
730a2673d88SMatthias Ringwald     if (buffer){
731*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_service_record_item_t));
7322a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
7332a95308bSMatthias Ringwald         return &buffer->data;
734b6269742SMatthias Ringwald     } else {
735b6269742SMatthias Ringwald         return NULL;
736a2673d88SMatthias Ringwald     }
737cd9ee144SMatthias Ringwald }
738cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
739*798bd46fSMatthias Ringwald     // reconstruct buffer start
740*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) service_record_item)[-1];
741*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
742b6269742SMatthias Ringwald     free(buffer);
743cd9ee144SMatthias Ringwald }
744cd9ee144SMatthias Ringwald #endif
745cd9ee144SMatthias Ringwald 
746cd9ee144SMatthias Ringwald 
74727faf85aSMilanka Ringwald 
7480e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
7490e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
7500e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
7510e826a17SMilanka 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."
75227faf85aSMilanka Ringwald     #else
7530e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
75427faf85aSMilanka Ringwald     #endif
75527faf85aSMilanka Ringwald #endif
75627faf85aSMilanka Ringwald 
7570e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
7580e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
7590e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
7600e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
7610e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
762a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
763a2673d88SMatthias Ringwald     if (buffer){
764a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
765a2673d88SMatthias Ringwald     }
766a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
76727faf85aSMilanka Ringwald }
7680e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
7690e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
77027faf85aSMilanka Ringwald }
77127faf85aSMilanka Ringwald #else
7720e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
77327faf85aSMilanka Ringwald     return NULL;
77427faf85aSMilanka Ringwald }
7750e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
776b6269742SMatthias Ringwald     UNUSED(avdtp_stream_endpoint);
77727faf85aSMilanka Ringwald };
77827faf85aSMilanka Ringwald #endif
77927faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
7802a95308bSMatthias Ringwald 
7812a95308bSMatthias Ringwald typedef struct {
7822a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
783*798bd46fSMatthias Ringwald     avdtp_stream_endpoint_t data;
7842a95308bSMatthias Ringwald } btstack_memory_avdtp_stream_endpoint_t;
7852a95308bSMatthias Ringwald 
7860e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
7872a95308bSMatthias Ringwald     btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t));
788a2673d88SMatthias Ringwald     if (buffer){
789*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avdtp_stream_endpoint_t));
7902a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
7912a95308bSMatthias Ringwald         return &buffer->data;
792b6269742SMatthias Ringwald     } else {
793b6269742SMatthias Ringwald         return NULL;
794a2673d88SMatthias Ringwald     }
79527faf85aSMilanka Ringwald }
7960e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
797*798bd46fSMatthias Ringwald     // reconstruct buffer start
798*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_stream_endpoint)[-1];
799*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
800b6269742SMatthias Ringwald     free(buffer);
80127faf85aSMilanka Ringwald }
80227faf85aSMilanka Ringwald #endif
80327faf85aSMilanka Ringwald 
80427faf85aSMilanka Ringwald 
80512e7f38cSMilanka Ringwald 
80612e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
80712e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
80812e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
80912e7f38cSMilanka 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."
81012e7f38cSMilanka Ringwald     #else
81112e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
81212e7f38cSMilanka Ringwald     #endif
81312e7f38cSMilanka Ringwald #endif
81412e7f38cSMilanka Ringwald 
81512e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
81612e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
81712e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
81812e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
81912e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
820a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
821a2673d88SMatthias Ringwald     if (buffer){
822a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
823a2673d88SMatthias Ringwald     }
824a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
82512e7f38cSMilanka Ringwald }
82612e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
82712e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
82812e7f38cSMilanka Ringwald }
82912e7f38cSMilanka Ringwald #else
83012e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
83112e7f38cSMilanka Ringwald     return NULL;
83212e7f38cSMilanka Ringwald }
83312e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
834b6269742SMatthias Ringwald     UNUSED(avdtp_connection);
83512e7f38cSMilanka Ringwald };
83612e7f38cSMilanka Ringwald #endif
83712e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
8382a95308bSMatthias Ringwald 
8392a95308bSMatthias Ringwald typedef struct {
8402a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
841*798bd46fSMatthias Ringwald     avdtp_connection_t data;
8422a95308bSMatthias Ringwald } btstack_memory_avdtp_connection_t;
8432a95308bSMatthias Ringwald 
84412e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
8452a95308bSMatthias Ringwald     btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t));
846a2673d88SMatthias Ringwald     if (buffer){
847*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avdtp_connection_t));
8482a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
8492a95308bSMatthias Ringwald         return &buffer->data;
850b6269742SMatthias Ringwald     } else {
851b6269742SMatthias Ringwald         return NULL;
852a2673d88SMatthias Ringwald     }
85312e7f38cSMilanka Ringwald }
85412e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
855*798bd46fSMatthias Ringwald     // reconstruct buffer start
856*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_connection)[-1];
857*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
858b6269742SMatthias Ringwald     free(buffer);
85912e7f38cSMilanka Ringwald }
86012e7f38cSMilanka Ringwald #endif
86112e7f38cSMilanka Ringwald 
86212e7f38cSMilanka Ringwald 
86391451a2bSMilanka Ringwald 
86491451a2bSMilanka Ringwald // MARK: avrcp_connection_t
86591451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
86691451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
86791451a2bSMilanka 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."
86891451a2bSMilanka Ringwald     #else
86991451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
87091451a2bSMilanka Ringwald     #endif
87191451a2bSMilanka Ringwald #endif
87291451a2bSMilanka Ringwald 
87391451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
87491451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
87591451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
87691451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
87791451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
878a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
879a2673d88SMatthias Ringwald     if (buffer){
880a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
881a2673d88SMatthias Ringwald     }
882a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
88391451a2bSMilanka Ringwald }
88491451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
88591451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
88691451a2bSMilanka Ringwald }
88791451a2bSMilanka Ringwald #else
88891451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
88991451a2bSMilanka Ringwald     return NULL;
89091451a2bSMilanka Ringwald }
89191451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
892b6269742SMatthias Ringwald     UNUSED(avrcp_connection);
89391451a2bSMilanka Ringwald };
89491451a2bSMilanka Ringwald #endif
89591451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
8962a95308bSMatthias Ringwald 
8972a95308bSMatthias Ringwald typedef struct {
8982a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
899*798bd46fSMatthias Ringwald     avrcp_connection_t data;
9002a95308bSMatthias Ringwald } btstack_memory_avrcp_connection_t;
9012a95308bSMatthias Ringwald 
90291451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
9032a95308bSMatthias Ringwald     btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t));
904a2673d88SMatthias Ringwald     if (buffer){
905*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avrcp_connection_t));
9062a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
9072a95308bSMatthias Ringwald         return &buffer->data;
908b6269742SMatthias Ringwald     } else {
909b6269742SMatthias Ringwald         return NULL;
910a2673d88SMatthias Ringwald     }
91191451a2bSMilanka Ringwald }
91291451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
913*798bd46fSMatthias Ringwald     // reconstruct buffer start
914*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_connection)[-1];
915*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
916b6269742SMatthias Ringwald     free(buffer);
91791451a2bSMilanka Ringwald }
91891451a2bSMilanka Ringwald #endif
91991451a2bSMilanka Ringwald 
92091451a2bSMilanka Ringwald 
921f12a3722SMilanka Ringwald 
922f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
923f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
924f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
925f12a3722SMilanka 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."
926f12a3722SMilanka Ringwald     #else
927f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
928f12a3722SMilanka Ringwald     #endif
929f12a3722SMilanka Ringwald #endif
930f12a3722SMilanka Ringwald 
931f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
932f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
933f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
934f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
935f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
936a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
937a2673d88SMatthias Ringwald     if (buffer){
938a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
939a2673d88SMatthias Ringwald     }
940a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
941f12a3722SMilanka Ringwald }
942f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
943f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
944f12a3722SMilanka Ringwald }
945f12a3722SMilanka Ringwald #else
946f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
947f12a3722SMilanka Ringwald     return NULL;
948f12a3722SMilanka Ringwald }
949f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
950b6269742SMatthias Ringwald     UNUSED(avrcp_browsing_connection);
951f12a3722SMilanka Ringwald };
952f12a3722SMilanka Ringwald #endif
953f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
9542a95308bSMatthias Ringwald 
9552a95308bSMatthias Ringwald typedef struct {
9562a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
957*798bd46fSMatthias Ringwald     avrcp_browsing_connection_t data;
9582a95308bSMatthias Ringwald } btstack_memory_avrcp_browsing_connection_t;
9592a95308bSMatthias Ringwald 
960f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
9612a95308bSMatthias Ringwald     btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t));
962a2673d88SMatthias Ringwald     if (buffer){
963*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_avrcp_browsing_connection_t));
9642a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
9652a95308bSMatthias Ringwald         return &buffer->data;
966b6269742SMatthias Ringwald     } else {
967b6269742SMatthias Ringwald         return NULL;
968a2673d88SMatthias Ringwald     }
969f12a3722SMilanka Ringwald }
970f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
971*798bd46fSMatthias Ringwald     // reconstruct buffer start
972*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_browsing_connection)[-1];
973*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
974b6269742SMatthias Ringwald     free(buffer);
975f12a3722SMilanka Ringwald }
976f12a3722SMilanka Ringwald #endif
977f12a3722SMilanka Ringwald 
978f12a3722SMilanka Ringwald 
97944c5d856SMatthias Ringwald #endif
980a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
9812e97c149S[email protected] 
9822e97c149S[email protected] // MARK: gatt_client_t
983a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
984a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
98527faf85aSMilanka 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."
986a265b909SMatthias Ringwald     #else
987a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
988a265b909SMatthias Ringwald     #endif
989a265b909SMatthias Ringwald #endif
990a265b909SMatthias Ringwald 
991a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
992a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
993a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
99429d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
995d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
996a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
997a2673d88SMatthias Ringwald     if (buffer){
998a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
999a2673d88SMatthias Ringwald     }
1000a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
1001d0fdae3cS[email protected] }
1002d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
100329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
1004d0fdae3cS[email protected] }
1005d0fdae3cS[email protected] #else
1006d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
1007d0fdae3cS[email protected]     return NULL;
1008d0fdae3cS[email protected] }
1009d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
1010b6269742SMatthias Ringwald     UNUSED(gatt_client);
1011d0fdae3cS[email protected] };
1012d0fdae3cS[email protected] #endif
1013d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
10142a95308bSMatthias Ringwald 
10152a95308bSMatthias Ringwald typedef struct {
10162a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1017*798bd46fSMatthias Ringwald     gatt_client_t data;
10182a95308bSMatthias Ringwald } btstack_memory_gatt_client_t;
10192a95308bSMatthias Ringwald 
1020d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
10212a95308bSMatthias Ringwald     btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t));
1022a2673d88SMatthias Ringwald     if (buffer){
1023*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_gatt_client_t));
10242a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
10252a95308bSMatthias Ringwald         return &buffer->data;
1026b6269742SMatthias Ringwald     } else {
1027b6269742SMatthias Ringwald         return NULL;
1028a2673d88SMatthias Ringwald     }
1029d0fdae3cS[email protected] }
1030d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
1031*798bd46fSMatthias Ringwald     // reconstruct buffer start
1032*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) gatt_client)[-1];
1033*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1034b6269742SMatthias Ringwald     free(buffer);
1035d0fdae3cS[email protected] }
1036d0fdae3cS[email protected] #endif
10372e97c149S[email protected] 
10382e97c149S[email protected] 
1039656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
1040a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
1041a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
104227faf85aSMilanka 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."
1043a265b909SMatthias Ringwald     #else
1044a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
1045a265b909SMatthias Ringwald     #endif
1046a265b909SMatthias Ringwald #endif
1047a265b909SMatthias Ringwald 
1048a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
1049a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1050a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
105129d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
1052656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1053a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
1054a2673d88SMatthias Ringwald     if (buffer){
1055a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
1056a2673d88SMatthias Ringwald     }
1057a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
1058656bec4fSMatthias Ringwald }
1059656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
106029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
1061656bec4fSMatthias Ringwald }
1062656bec4fSMatthias Ringwald #else
1063656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1064656bec4fSMatthias Ringwald     return NULL;
1065656bec4fSMatthias Ringwald }
1066656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1067b6269742SMatthias Ringwald     UNUSED(whitelist_entry);
1068656bec4fSMatthias Ringwald };
1069656bec4fSMatthias Ringwald #endif
1070656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
10712a95308bSMatthias Ringwald 
10722a95308bSMatthias Ringwald typedef struct {
10732a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1074*798bd46fSMatthias Ringwald     whitelist_entry_t data;
10752a95308bSMatthias Ringwald } btstack_memory_whitelist_entry_t;
10762a95308bSMatthias Ringwald 
1077656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
10782a95308bSMatthias Ringwald     btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t));
1079a2673d88SMatthias Ringwald     if (buffer){
1080*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_whitelist_entry_t));
10812a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
10822a95308bSMatthias Ringwald         return &buffer->data;
1083b6269742SMatthias Ringwald     } else {
1084b6269742SMatthias Ringwald         return NULL;
1085a2673d88SMatthias Ringwald     }
1086656bec4fSMatthias Ringwald }
1087656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1088*798bd46fSMatthias Ringwald     // reconstruct buffer start
1089*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) whitelist_entry)[-1];
1090*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1091b6269742SMatthias Ringwald     free(buffer);
1092656bec4fSMatthias Ringwald }
1093656bec4fSMatthias Ringwald #endif
1094656bec4fSMatthias Ringwald 
1095656bec4fSMatthias Ringwald 
1096cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
1097a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
1098a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
109927faf85aSMilanka 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."
1100a265b909SMatthias Ringwald     #else
1101a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
1102a265b909SMatthias Ringwald     #endif
1103a265b909SMatthias Ringwald #endif
1104a265b909SMatthias Ringwald 
1105a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
1106a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1107a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
110829d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
1109cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1110a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
1111a2673d88SMatthias Ringwald     if (buffer){
1112a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
1113a2673d88SMatthias Ringwald     }
1114a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
1115cf49570bSMatthias Ringwald }
1116cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
111729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
1118cf49570bSMatthias Ringwald }
1119cf49570bSMatthias Ringwald #else
1120cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1121cf49570bSMatthias Ringwald     return NULL;
1122cf49570bSMatthias Ringwald }
1123cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1124b6269742SMatthias Ringwald     UNUSED(sm_lookup_entry);
1125cf49570bSMatthias Ringwald };
1126cf49570bSMatthias Ringwald #endif
1127cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
11282a95308bSMatthias Ringwald 
11292a95308bSMatthias Ringwald typedef struct {
11302a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1131*798bd46fSMatthias Ringwald     sm_lookup_entry_t data;
11322a95308bSMatthias Ringwald } btstack_memory_sm_lookup_entry_t;
11332a95308bSMatthias Ringwald 
1134cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
11352a95308bSMatthias Ringwald     btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t));
1136a2673d88SMatthias Ringwald     if (buffer){
1137*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_sm_lookup_entry_t));
11382a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
11392a95308bSMatthias Ringwald         return &buffer->data;
1140b6269742SMatthias Ringwald     } else {
1141b6269742SMatthias Ringwald         return NULL;
1142a2673d88SMatthias Ringwald     }
1143cf49570bSMatthias Ringwald }
1144cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1145*798bd46fSMatthias Ringwald     // reconstruct buffer start
1146*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) sm_lookup_entry)[-1];
1147*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1148b6269742SMatthias Ringwald     free(buffer);
1149cf49570bSMatthias Ringwald }
1150cf49570bSMatthias Ringwald #endif
1151cf49570bSMatthias Ringwald 
1152cf49570bSMatthias Ringwald 
115344c5d856SMatthias Ringwald #endif
115444c5d856SMatthias Ringwald #ifdef ENABLE_MESH
1155ebb73e1fSMatthias Ringwald 
1156ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t
1157ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
1158ebb73e1fSMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_PDUS)
1159ebb73e1fSMatthias 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."
1160ebb73e1fSMatthias Ringwald     #else
1161ebb73e1fSMatthias Ringwald         #define MAX_NR_MESH_NETWORK_PDUS 0
1162ebb73e1fSMatthias Ringwald     #endif
1163ebb73e1fSMatthias Ringwald #endif
1164ebb73e1fSMatthias Ringwald 
1165ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
1166ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
1167ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
1168ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool;
1169ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
11701c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
11711c4e8084SMatthias Ringwald     if (buffer){
11721c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_pdu_t));
11731c4e8084SMatthias Ringwald     }
11741c4e8084SMatthias Ringwald     return (mesh_network_pdu_t *) buffer;
1175ebb73e1fSMatthias Ringwald }
1176ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1177ebb73e1fSMatthias Ringwald     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
1178ebb73e1fSMatthias Ringwald }
1179ebb73e1fSMatthias Ringwald #else
1180ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1181ebb73e1fSMatthias Ringwald     return NULL;
1182ebb73e1fSMatthias Ringwald }
1183ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1184b6269742SMatthias Ringwald     UNUSED(mesh_network_pdu);
1185ebb73e1fSMatthias Ringwald };
1186ebb73e1fSMatthias Ringwald #endif
1187ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
11882a95308bSMatthias Ringwald 
11892a95308bSMatthias Ringwald typedef struct {
11902a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1191*798bd46fSMatthias Ringwald     mesh_network_pdu_t data;
11922a95308bSMatthias Ringwald } btstack_memory_mesh_network_pdu_t;
11932a95308bSMatthias Ringwald 
1194ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
11952a95308bSMatthias Ringwald     btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t));
11961c4e8084SMatthias Ringwald     if (buffer){
1197*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_network_pdu_t));
11982a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
11992a95308bSMatthias Ringwald         return &buffer->data;
1200b6269742SMatthias Ringwald     } else {
1201b6269742SMatthias Ringwald         return NULL;
12021c4e8084SMatthias Ringwald     }
1203ebb73e1fSMatthias Ringwald }
1204ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1205*798bd46fSMatthias Ringwald     // reconstruct buffer start
1206*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_pdu)[-1];
1207*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1208b6269742SMatthias Ringwald     free(buffer);
1209ebb73e1fSMatthias Ringwald }
1210ebb73e1fSMatthias Ringwald #endif
1211ebb73e1fSMatthias Ringwald 
1212ebb73e1fSMatthias Ringwald 
1213a4bbc09dSMatthias Ringwald // MARK: mesh_segmented_pdu_t
1214a4bbc09dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS)
1215a4bbc09dSMatthias Ringwald     #if defined(MAX_NO_MESH_SEGMENTED_PDUS)
1216a4bbc09dSMatthias 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."
1217f7434c1fSMatthias Ringwald     #else
1218a4bbc09dSMatthias Ringwald         #define MAX_NR_MESH_SEGMENTED_PDUS 0
1219f7434c1fSMatthias Ringwald     #endif
1220f7434c1fSMatthias Ringwald #endif
1221f7434c1fSMatthias Ringwald 
1222a4bbc09dSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS
1223a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1224a4bbc09dSMatthias Ringwald static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS];
1225a4bbc09dSMatthias Ringwald static btstack_memory_pool_t mesh_segmented_pdu_pool;
1226a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1227a4bbc09dSMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool);
1228f7434c1fSMatthias Ringwald     if (buffer){
1229a4bbc09dSMatthias Ringwald         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1230f7434c1fSMatthias Ringwald     }
1231a4bbc09dSMatthias Ringwald     return (mesh_segmented_pdu_t *) buffer;
1232f7434c1fSMatthias Ringwald }
1233a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1234a4bbc09dSMatthias Ringwald     btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu);
1235f7434c1fSMatthias Ringwald }
1236f7434c1fSMatthias Ringwald #else
1237a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1238f7434c1fSMatthias Ringwald     return NULL;
1239f7434c1fSMatthias Ringwald }
1240a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1241b6269742SMatthias Ringwald     UNUSED(mesh_segmented_pdu);
1242f7434c1fSMatthias Ringwald };
1243f7434c1fSMatthias Ringwald #endif
1244f7434c1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
12452a95308bSMatthias Ringwald 
12462a95308bSMatthias Ringwald typedef struct {
12472a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1248*798bd46fSMatthias Ringwald     mesh_segmented_pdu_t data;
12492a95308bSMatthias Ringwald } btstack_memory_mesh_segmented_pdu_t;
12502a95308bSMatthias Ringwald 
1251a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
12522a95308bSMatthias Ringwald     btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t));
1253f7434c1fSMatthias Ringwald     if (buffer){
1254*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_segmented_pdu_t));
12552a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
12562a95308bSMatthias Ringwald         return &buffer->data;
1257b6269742SMatthias Ringwald     } else {
1258b6269742SMatthias Ringwald         return NULL;
1259f7434c1fSMatthias Ringwald     }
1260f7434c1fSMatthias Ringwald }
1261a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1262*798bd46fSMatthias Ringwald     // reconstruct buffer start
1263*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_segmented_pdu)[-1];
1264*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1265b6269742SMatthias Ringwald     free(buffer);
1266f7434c1fSMatthias Ringwald }
1267f7434c1fSMatthias Ringwald #endif
1268f7434c1fSMatthias Ringwald 
1269f7434c1fSMatthias Ringwald 
1270491f99b3SMatthias Ringwald // MARK: mesh_upper_transport_pdu_t
1271491f99b3SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS)
1272491f99b3SMatthias Ringwald     #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS)
1273491f99b3SMatthias 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."
1274491f99b3SMatthias Ringwald     #else
1275491f99b3SMatthias Ringwald         #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0
1276491f99b3SMatthias Ringwald     #endif
1277491f99b3SMatthias Ringwald #endif
1278491f99b3SMatthias Ringwald 
1279491f99b3SMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
1280491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1281491f99b3SMatthias Ringwald static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS];
1282491f99b3SMatthias Ringwald static btstack_memory_pool_t mesh_upper_transport_pdu_pool;
1283491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1284491f99b3SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool);
1285491f99b3SMatthias Ringwald     if (buffer){
1286491f99b3SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1287491f99b3SMatthias Ringwald     }
1288491f99b3SMatthias Ringwald     return (mesh_upper_transport_pdu_t *) buffer;
1289491f99b3SMatthias Ringwald }
1290491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1291491f99b3SMatthias Ringwald     btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu);
1292491f99b3SMatthias Ringwald }
1293491f99b3SMatthias Ringwald #else
1294491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1295491f99b3SMatthias Ringwald     return NULL;
1296491f99b3SMatthias Ringwald }
1297491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1298b6269742SMatthias Ringwald     UNUSED(mesh_upper_transport_pdu);
1299491f99b3SMatthias Ringwald };
1300491f99b3SMatthias Ringwald #endif
1301491f99b3SMatthias Ringwald #elif defined(HAVE_MALLOC)
13022a95308bSMatthias Ringwald 
13032a95308bSMatthias Ringwald typedef struct {
13042a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1305*798bd46fSMatthias Ringwald     mesh_upper_transport_pdu_t data;
13062a95308bSMatthias Ringwald } btstack_memory_mesh_upper_transport_pdu_t;
13072a95308bSMatthias Ringwald 
1308491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
13092a95308bSMatthias 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));
1310491f99b3SMatthias Ringwald     if (buffer){
1311*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_upper_transport_pdu_t));
13122a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
13132a95308bSMatthias Ringwald         return &buffer->data;
1314b6269742SMatthias Ringwald     } else {
1315b6269742SMatthias Ringwald         return NULL;
1316491f99b3SMatthias Ringwald     }
1317491f99b3SMatthias Ringwald }
1318491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1319*798bd46fSMatthias Ringwald     // reconstruct buffer start
1320*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_upper_transport_pdu)[-1];
1321*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1322b6269742SMatthias Ringwald     free(buffer);
1323491f99b3SMatthias Ringwald }
1324491f99b3SMatthias Ringwald #endif
1325491f99b3SMatthias Ringwald 
1326491f99b3SMatthias Ringwald 
1327c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t
1328c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
1329c0a711d9SMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_KEYS)
1330c0a711d9SMatthias 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."
1331c0a711d9SMatthias Ringwald     #else
1332c0a711d9SMatthias Ringwald         #define MAX_NR_MESH_NETWORK_KEYS 0
1333c0a711d9SMatthias Ringwald     #endif
1334c0a711d9SMatthias Ringwald #endif
1335c0a711d9SMatthias Ringwald 
1336c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
1337c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
1338c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
1339c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool;
1340c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
13411c4e8084SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
13421c4e8084SMatthias Ringwald     if (buffer){
13431c4e8084SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_network_key_t));
13441c4e8084SMatthias Ringwald     }
13451c4e8084SMatthias Ringwald     return (mesh_network_key_t *) buffer;
1346c0a711d9SMatthias Ringwald }
1347c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1348c0a711d9SMatthias Ringwald     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
1349c0a711d9SMatthias Ringwald }
1350c0a711d9SMatthias Ringwald #else
1351c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1352c0a711d9SMatthias Ringwald     return NULL;
1353c0a711d9SMatthias Ringwald }
1354c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1355b6269742SMatthias Ringwald     UNUSED(mesh_network_key);
1356c0a711d9SMatthias Ringwald };
1357c0a711d9SMatthias Ringwald #endif
1358c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC)
13592a95308bSMatthias Ringwald 
13602a95308bSMatthias Ringwald typedef struct {
13612a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1362*798bd46fSMatthias Ringwald     mesh_network_key_t data;
13632a95308bSMatthias Ringwald } btstack_memory_mesh_network_key_t;
13642a95308bSMatthias Ringwald 
1365c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
13662a95308bSMatthias Ringwald     btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t));
13671c4e8084SMatthias Ringwald     if (buffer){
1368*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_network_key_t));
13692a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
13702a95308bSMatthias Ringwald         return &buffer->data;
1371b6269742SMatthias Ringwald     } else {
1372b6269742SMatthias Ringwald         return NULL;
13731c4e8084SMatthias Ringwald     }
1374c0a711d9SMatthias Ringwald }
1375c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1376*798bd46fSMatthias Ringwald     // reconstruct buffer start
1377*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_key)[-1];
1378*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1379b6269742SMatthias Ringwald     free(buffer);
1380c0a711d9SMatthias Ringwald }
1381c0a711d9SMatthias Ringwald #endif
1382c0a711d9SMatthias Ringwald 
1383c0a711d9SMatthias Ringwald 
138401e2bf94SMatthias Ringwald // MARK: mesh_transport_key_t
138501e2bf94SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
138601e2bf94SMatthias Ringwald     #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
138701e2bf94SMatthias 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."
138801e2bf94SMatthias Ringwald     #else
138901e2bf94SMatthias Ringwald         #define MAX_NR_MESH_TRANSPORT_KEYS 0
139001e2bf94SMatthias Ringwald     #endif
139101e2bf94SMatthias Ringwald #endif
139201e2bf94SMatthias Ringwald 
139301e2bf94SMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS
139401e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
139501e2bf94SMatthias Ringwald static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
139601e2bf94SMatthias Ringwald static btstack_memory_pool_t mesh_transport_key_pool;
139701e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
139801e2bf94SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
139901e2bf94SMatthias Ringwald     if (buffer){
140001e2bf94SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_transport_key_t));
140101e2bf94SMatthias Ringwald     }
140201e2bf94SMatthias Ringwald     return (mesh_transport_key_t *) buffer;
140301e2bf94SMatthias Ringwald }
140401e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
140501e2bf94SMatthias Ringwald     btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
140601e2bf94SMatthias Ringwald }
140701e2bf94SMatthias Ringwald #else
140801e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
140901e2bf94SMatthias Ringwald     return NULL;
141001e2bf94SMatthias Ringwald }
141101e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1412b6269742SMatthias Ringwald     UNUSED(mesh_transport_key);
141301e2bf94SMatthias Ringwald };
141401e2bf94SMatthias Ringwald #endif
141501e2bf94SMatthias Ringwald #elif defined(HAVE_MALLOC)
14162a95308bSMatthias Ringwald 
14172a95308bSMatthias Ringwald typedef struct {
14182a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1419*798bd46fSMatthias Ringwald     mesh_transport_key_t data;
14202a95308bSMatthias Ringwald } btstack_memory_mesh_transport_key_t;
14212a95308bSMatthias Ringwald 
142201e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
14232a95308bSMatthias Ringwald     btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t));
142401e2bf94SMatthias Ringwald     if (buffer){
1425*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_transport_key_t));
14262a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
14272a95308bSMatthias Ringwald         return &buffer->data;
1428b6269742SMatthias Ringwald     } else {
1429b6269742SMatthias Ringwald         return NULL;
143001e2bf94SMatthias Ringwald     }
143101e2bf94SMatthias Ringwald }
143201e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1433*798bd46fSMatthias Ringwald     // reconstruct buffer start
1434*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_transport_key)[-1];
1435*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1436b6269742SMatthias Ringwald     free(buffer);
143701e2bf94SMatthias Ringwald }
143801e2bf94SMatthias Ringwald #endif
143901e2bf94SMatthias Ringwald 
144001e2bf94SMatthias Ringwald 
14411f45d603SMatthias Ringwald // MARK: mesh_virtual_address_t
14421f45d603SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
14431f45d603SMatthias Ringwald     #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
14441f45d603SMatthias 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."
14451f45d603SMatthias Ringwald     #else
14461f45d603SMatthias Ringwald         #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
14471f45d603SMatthias Ringwald     #endif
14481f45d603SMatthias Ringwald #endif
14491f45d603SMatthias Ringwald 
14501f45d603SMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
14511f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
14521f45d603SMatthias Ringwald static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
14531f45d603SMatthias Ringwald static btstack_memory_pool_t mesh_virtual_address_pool;
14541f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
14551f45d603SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
14561f45d603SMatthias Ringwald     if (buffer){
14571f45d603SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_virtual_address_t));
14581f45d603SMatthias Ringwald     }
14591f45d603SMatthias Ringwald     return (mesh_virtual_address_t *) buffer;
14601f45d603SMatthias Ringwald }
14611f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
14621f45d603SMatthias Ringwald     btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
14631f45d603SMatthias Ringwald }
14641f45d603SMatthias Ringwald #else
14651f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
14661f45d603SMatthias Ringwald     return NULL;
14671f45d603SMatthias Ringwald }
14681f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1469b6269742SMatthias Ringwald     UNUSED(mesh_virtual_address);
14701f45d603SMatthias Ringwald };
14711f45d603SMatthias Ringwald #endif
14721f45d603SMatthias Ringwald #elif defined(HAVE_MALLOC)
14732a95308bSMatthias Ringwald 
14742a95308bSMatthias Ringwald typedef struct {
14752a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1476*798bd46fSMatthias Ringwald     mesh_virtual_address_t data;
14772a95308bSMatthias Ringwald } btstack_memory_mesh_virtual_address_t;
14782a95308bSMatthias Ringwald 
14791f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
14802a95308bSMatthias Ringwald     btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t));
14811f45d603SMatthias Ringwald     if (buffer){
1482*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_virtual_address_t));
14832a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
14842a95308bSMatthias Ringwald         return &buffer->data;
1485b6269742SMatthias Ringwald     } else {
1486b6269742SMatthias Ringwald         return NULL;
14871f45d603SMatthias Ringwald     }
14881f45d603SMatthias Ringwald }
14891f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1490*798bd46fSMatthias Ringwald     // reconstruct buffer start
1491*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_virtual_address)[-1];
1492*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1493b6269742SMatthias Ringwald     free(buffer);
14941f45d603SMatthias Ringwald }
14951f45d603SMatthias Ringwald #endif
14961f45d603SMatthias Ringwald 
14971f45d603SMatthias Ringwald 
149801122b73SMatthias Ringwald // MARK: mesh_subnet_t
149901122b73SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
150001122b73SMatthias Ringwald     #if defined(MAX_NO_MESH_SUBNETS)
150101122b73SMatthias 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."
150201122b73SMatthias Ringwald     #else
150301122b73SMatthias Ringwald         #define MAX_NR_MESH_SUBNETS 0
150401122b73SMatthias Ringwald     #endif
150501122b73SMatthias Ringwald #endif
150601122b73SMatthias Ringwald 
150701122b73SMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS
150801122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
150901122b73SMatthias Ringwald static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
151001122b73SMatthias Ringwald static btstack_memory_pool_t mesh_subnet_pool;
151101122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
151201122b73SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
151301122b73SMatthias Ringwald     if (buffer){
151401122b73SMatthias Ringwald         memset(buffer, 0, sizeof(mesh_subnet_t));
151501122b73SMatthias Ringwald     }
151601122b73SMatthias Ringwald     return (mesh_subnet_t *) buffer;
151701122b73SMatthias Ringwald }
151801122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
151901122b73SMatthias Ringwald     btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
152001122b73SMatthias Ringwald }
152101122b73SMatthias Ringwald #else
152201122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
152301122b73SMatthias Ringwald     return NULL;
152401122b73SMatthias Ringwald }
152501122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1526b6269742SMatthias Ringwald     UNUSED(mesh_subnet);
152701122b73SMatthias Ringwald };
152801122b73SMatthias Ringwald #endif
152901122b73SMatthias Ringwald #elif defined(HAVE_MALLOC)
15302a95308bSMatthias Ringwald 
15312a95308bSMatthias Ringwald typedef struct {
15322a95308bSMatthias Ringwald     btstack_memory_buffer_t tracking;
1533*798bd46fSMatthias Ringwald     mesh_subnet_t data;
15342a95308bSMatthias Ringwald } btstack_memory_mesh_subnet_t;
15352a95308bSMatthias Ringwald 
153601122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
15372a95308bSMatthias Ringwald     btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t));
153801122b73SMatthias Ringwald     if (buffer){
1539*798bd46fSMatthias Ringwald         memset(buffer, 0, sizeof(btstack_memory_mesh_subnet_t));
15402a95308bSMatthias Ringwald         btstack_memory_tracking_add(&buffer->tracking);
15412a95308bSMatthias Ringwald         return &buffer->data;
1542b6269742SMatthias Ringwald     } else {
1543b6269742SMatthias Ringwald         return NULL;
154401122b73SMatthias Ringwald     }
154501122b73SMatthias Ringwald }
154601122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1547*798bd46fSMatthias Ringwald     // reconstruct buffer start
1548*798bd46fSMatthias Ringwald     btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_subnet)[-1];
1549*798bd46fSMatthias Ringwald     btstack_memory_tracking_remove(buffer);
1550b6269742SMatthias Ringwald     free(buffer);
155101122b73SMatthias Ringwald }
155201122b73SMatthias Ringwald #endif
155301122b73SMatthias Ringwald 
155401122b73SMatthias Ringwald 
15552e97c149S[email protected] #endif
1556*798bd46fSMatthias Ringwald 
1557a3b02b71Smatthias.ringwald // init
1558a3b02b71Smatthias.ringwald void btstack_memory_init(void){
1559*798bd46fSMatthias Ringwald #ifdef HAVE_MALLOC
1560*798bd46fSMatthias Ringwald     // assert that there is no unexpected padding for combined buffer
1561*798bd46fSMatthias Ringwald     btstack_assert(sizeof(test_buffer_t) == sizeof(btstack_memory_buffer_t) + sizeof(void *));
1562*798bd46fSMatthias Ringwald #endif
1563*798bd46fSMatthias Ringwald 
1564a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
1565a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
1566a3b02b71Smatthias.ringwald #endif
1567a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
1568a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
1569a3b02b71Smatthias.ringwald #endif
1570a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
1571a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
1572a3b02b71Smatthias.ringwald #endif
157344c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC
157450dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
157550dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
1576a3b02b71Smatthias.ringwald #endif
157750dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
157850dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
1579a3b02b71Smatthias.ringwald #endif
158050dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
158150dc57fcSMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
158250dc57fcSMatthias Ringwald #endif
158350dc57fcSMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
158450dc57fcSMatthias 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));
158550dc57fcSMatthias Ringwald #endif
158650dc57fcSMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
158750dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
158850dc57fcSMatthias Ringwald #endif
158950dc57fcSMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
159050dc57fcSMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
159150dc57fcSMatthias Ringwald #endif
159250dc57fcSMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
159350dc57fcSMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
159450dc57fcSMatthias Ringwald #endif
159550dc57fcSMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
159650dc57fcSMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
159750dc57fcSMatthias Ringwald #endif
159850dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
159950dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
160050dc57fcSMatthias Ringwald #endif
160150dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
160250dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
160350dc57fcSMatthias Ringwald #endif
160450dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
160550dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
160650dc57fcSMatthias Ringwald #endif
160750dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
160850dc57fcSMatthias Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1609a3b02b71Smatthias.ringwald #endif
1610f12a3722SMilanka Ringwald #endif
1611a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
1612a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
1613a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1614d0fdae3cS[email protected] #endif
1615a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1616a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1617656bec4fSMatthias Ringwald #endif
1618a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1619a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1620cf49570bSMatthias Ringwald #endif
1621ebb73e1fSMatthias Ringwald #endif
162244c5d856SMatthias Ringwald #ifdef ENABLE_MESH
162350dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
162450dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
162544c5d856SMatthias Ringwald #endif
1626a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1627a4bbc09dSMatthias Ringwald     btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t));
1628f7434c1fSMatthias Ringwald #endif
1629491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1630491f99b3SMatthias 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));
1631491f99b3SMatthias Ringwald #endif
163250dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
163350dc57fcSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1634c0a711d9SMatthias Ringwald #endif
163501e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0
163601e2bf94SMatthias Ringwald     btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
163701e2bf94SMatthias Ringwald #endif
16381f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
16391f45d603SMatthias Ringwald     btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
16401f45d603SMatthias Ringwald #endif
164101122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0
164201122b73SMatthias Ringwald     btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
164301122b73SMatthias Ringwald #endif
1644a7d12effS[email protected] #endif
1645a3b02b71Smatthias.ringwald }
1646