xref: /btstack/src/btstack_memory.c (revision c0a711d937540431008924bfa62bfa8a050c681c)
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 
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_memory.c"
39bb2a7656SMatthias Ringwald 
402e97c149S[email protected] 
41a3b02b71Smatthias.ringwald /*
42a98592bcSMatthias Ringwald  *  btstack_memory.h
43a3b02b71Smatthias.ringwald  *
44a3b02b71Smatthias.ringwald  *  @brief BTstack memory management via configurable memory pools
45a3b02b71Smatthias.ringwald  *
46a98592bcSMatthias Ringwald  *  @note code generated by tool/btstack_memory_generator.py
47a2673d88SMatthias Ringwald  *  @note returnes buffers are initialized with 0
48a3b02b71Smatthias.ringwald  *
49a3b02b71Smatthias.ringwald  */
50a3b02b71Smatthias.ringwald 
51a3b02b71Smatthias.ringwald #include "btstack_memory.h"
52d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h"
53a3b02b71Smatthias.ringwald 
54a3b02b71Smatthias.ringwald #include <stdlib.h>
55a3b02b71Smatthias.ringwald 
56a3b02b71Smatthias.ringwald 
572e97c149S[email protected] 
58a3b02b71Smatthias.ringwald // MARK: hci_connection_t
59a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
60a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
6127faf85aSMilanka 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."
62a265b909SMatthias Ringwald     #else
63a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
64a265b909SMatthias Ringwald     #endif
65a265b909SMatthias Ringwald #endif
66a265b909SMatthias Ringwald 
67a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
68a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
69a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
7029d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
716527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
72a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
73a2673d88SMatthias Ringwald     if (buffer){
74a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
75a2673d88SMatthias Ringwald     }
76a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
77a3b02b71Smatthias.ringwald }
786527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
7929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
80a3b02b71Smatthias.ringwald }
81c4d3f927Smatthias.ringwald #else
826527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
83c4d3f927Smatthias.ringwald     return NULL;
84c4d3f927Smatthias.ringwald }
856527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
866f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
872e97c149S[email protected]     (void) hci_connection;
88c4d3f927Smatthias.ringwald };
89c4d3f927Smatthias.ringwald #endif
90a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
916527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
92a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(hci_connection_t));
93a2673d88SMatthias Ringwald     if (buffer){
94a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
95a2673d88SMatthias Ringwald     }
96a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
97a3b02b71Smatthias.ringwald }
986527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
99a3b02b71Smatthias.ringwald     free(hci_connection);
100a3b02b71Smatthias.ringwald }
101a3b02b71Smatthias.ringwald #endif
102a3b02b71Smatthias.ringwald 
103a3b02b71Smatthias.ringwald 
1042e97c149S[email protected] 
105a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
106a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
107a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
10827faf85aSMilanka 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."
109a265b909SMatthias Ringwald     #else
110a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
111a265b909SMatthias Ringwald     #endif
112a265b909SMatthias Ringwald #endif
113a265b909SMatthias Ringwald 
114a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
115a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
116a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
11729d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1186527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
119a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
120a2673d88SMatthias Ringwald     if (buffer){
121a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
122a2673d88SMatthias Ringwald     }
123a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
124a3b02b71Smatthias.ringwald }
1256527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
12629d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
127a3b02b71Smatthias.ringwald }
128c4d3f927Smatthias.ringwald #else
1296527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
130c4d3f927Smatthias.ringwald     return NULL;
131c4d3f927Smatthias.ringwald }
1326527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
1336f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1346f7ecb09S[email protected]     (void) l2cap_service;
135c4d3f927Smatthias.ringwald };
136c4d3f927Smatthias.ringwald #endif
137a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1386527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
139a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_service_t));
140a2673d88SMatthias Ringwald     if (buffer){
141a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
142a2673d88SMatthias Ringwald     }
143a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
144a3b02b71Smatthias.ringwald }
1456527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
146a3b02b71Smatthias.ringwald     free(l2cap_service);
147a3b02b71Smatthias.ringwald }
148a3b02b71Smatthias.ringwald #endif
149a3b02b71Smatthias.ringwald 
150a3b02b71Smatthias.ringwald 
151a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
152a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
153a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
15427faf85aSMilanka 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."
155a265b909SMatthias Ringwald     #else
156a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
157a265b909SMatthias Ringwald     #endif
158a265b909SMatthias Ringwald #endif
159a265b909SMatthias Ringwald 
160a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
161a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
162a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
16329d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
1646527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
165a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
166a2673d88SMatthias Ringwald     if (buffer){
167a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
168a2673d88SMatthias Ringwald     }
169a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
170a3b02b71Smatthias.ringwald }
1716527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
17229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
173a3b02b71Smatthias.ringwald }
174c4d3f927Smatthias.ringwald #else
1756527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
176c4d3f927Smatthias.ringwald     return NULL;
177c4d3f927Smatthias.ringwald }
1786527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
1796f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1806f7ecb09S[email protected]     (void) l2cap_channel;
181c4d3f927Smatthias.ringwald };
182c4d3f927Smatthias.ringwald #endif
183a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1846527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
185a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_channel_t));
186a2673d88SMatthias Ringwald     if (buffer){
187a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
188a2673d88SMatthias Ringwald     }
189a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
190a3b02b71Smatthias.ringwald }
1916527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
192a3b02b71Smatthias.ringwald     free(l2cap_channel);
193a3b02b71Smatthias.ringwald }
194a3b02b71Smatthias.ringwald #endif
195a3b02b71Smatthias.ringwald 
196a3b02b71Smatthias.ringwald 
1972e97c149S[email protected] 
198a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
199a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
200a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
20127faf85aSMilanka 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."
202a265b909SMatthias Ringwald     #else
203a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
204a265b909SMatthias Ringwald     #endif
205a265b909SMatthias Ringwald #endif
206a265b909SMatthias Ringwald 
207a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
208a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
209a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
21029d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
2116527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
212a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
213a2673d88SMatthias Ringwald     if (buffer){
214a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
215a2673d88SMatthias Ringwald     }
216a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
217a3b02b71Smatthias.ringwald }
2186527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
21929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
220a3b02b71Smatthias.ringwald }
221c4d3f927Smatthias.ringwald #else
2226527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
223c4d3f927Smatthias.ringwald     return NULL;
224c4d3f927Smatthias.ringwald }
2256527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
2266f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2276f7ecb09S[email protected]     (void) rfcomm_multiplexer;
228c4d3f927Smatthias.ringwald };
229c4d3f927Smatthias.ringwald #endif
230a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2316527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
232a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_multiplexer_t));
233a2673d88SMatthias Ringwald     if (buffer){
234a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
235a2673d88SMatthias Ringwald     }
236a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
237a3b02b71Smatthias.ringwald }
2386527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
239a3b02b71Smatthias.ringwald     free(rfcomm_multiplexer);
240a3b02b71Smatthias.ringwald }
241a3b02b71Smatthias.ringwald #endif
242a3b02b71Smatthias.ringwald 
243a3b02b71Smatthias.ringwald 
244a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
245a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
246a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
24727faf85aSMilanka 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."
248a265b909SMatthias Ringwald     #else
249a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
250a265b909SMatthias Ringwald     #endif
251a265b909SMatthias Ringwald #endif
252a265b909SMatthias Ringwald 
253a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
254a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
255a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
25629d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
2576527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
258a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
259a2673d88SMatthias Ringwald     if (buffer){
260a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
261a2673d88SMatthias Ringwald     }
262a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
263a3b02b71Smatthias.ringwald }
2646527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
26529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
266a3b02b71Smatthias.ringwald }
267c4d3f927Smatthias.ringwald #else
2686527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
269c4d3f927Smatthias.ringwald     return NULL;
270c4d3f927Smatthias.ringwald }
2716527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
2726f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2736f7ecb09S[email protected]     (void) rfcomm_service;
274c4d3f927Smatthias.ringwald };
275c4d3f927Smatthias.ringwald #endif
276a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2776527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
278a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_service_t));
279a2673d88SMatthias Ringwald     if (buffer){
280a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
281a2673d88SMatthias Ringwald     }
282a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
283a3b02b71Smatthias.ringwald }
2846527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
285a3b02b71Smatthias.ringwald     free(rfcomm_service);
286a3b02b71Smatthias.ringwald }
287a3b02b71Smatthias.ringwald #endif
288a3b02b71Smatthias.ringwald 
289a3b02b71Smatthias.ringwald 
290a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
291a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
292a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
29327faf85aSMilanka 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."
294a265b909SMatthias Ringwald     #else
295a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
296a265b909SMatthias Ringwald     #endif
297a265b909SMatthias Ringwald #endif
298a265b909SMatthias Ringwald 
299a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
300a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
301a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
30229d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
3036527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
304a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
305a2673d88SMatthias Ringwald     if (buffer){
306a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
307a2673d88SMatthias Ringwald     }
308a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
309a3b02b71Smatthias.ringwald }
3106527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
31129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
312a3b02b71Smatthias.ringwald }
313c4d3f927Smatthias.ringwald #else
3146527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
315c4d3f927Smatthias.ringwald     return NULL;
316c4d3f927Smatthias.ringwald }
3176527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
3186f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3196f7ecb09S[email protected]     (void) rfcomm_channel;
320c4d3f927Smatthias.ringwald };
321c4d3f927Smatthias.ringwald #endif
322a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3236527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
324a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_channel_t));
325a2673d88SMatthias Ringwald     if (buffer){
326a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
327a2673d88SMatthias Ringwald     }
328a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
329a3b02b71Smatthias.ringwald }
3306527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
331a3b02b71Smatthias.ringwald     free(rfcomm_channel);
332a3b02b71Smatthias.ringwald }
333a3b02b71Smatthias.ringwald #endif
334a3b02b71Smatthias.ringwald 
335fdb398c2S[email protected] 
336e0e5e285Smatthias.ringwald 
3372c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
338a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
339a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
34027faf85aSMilanka 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."
341a265b909SMatthias Ringwald     #else
342a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
343a265b909SMatthias Ringwald     #endif
344a265b909SMatthias Ringwald #endif
345a265b909SMatthias Ringwald 
346a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
347a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
348a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
3492c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
3502c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
351a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
352a2673d88SMatthias Ringwald     if (buffer){
353a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
354a2673d88SMatthias Ringwald     }
355a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
3561801b596Smatthias.ringwald }
3572c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3582c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
3591801b596Smatthias.ringwald }
360c4d3f927Smatthias.ringwald #else
3612c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
362c4d3f927Smatthias.ringwald     return NULL;
363c4d3f927Smatthias.ringwald }
3642c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3656f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3662c455dadSMatthias Ringwald     (void) btstack_link_key_db_memory_entry;
367c4d3f927Smatthias.ringwald };
368c4d3f927Smatthias.ringwald #endif
3691801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3702c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
371a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t));
372a2673d88SMatthias Ringwald     if (buffer){
373a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
374a2673d88SMatthias Ringwald     }
375a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
3761801b596Smatthias.ringwald }
3772c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3782c455dadSMatthias Ringwald     free(btstack_link_key_db_memory_entry);
379e0e5e285Smatthias.ringwald }
3801801b596Smatthias.ringwald #endif
3811801b596Smatthias.ringwald 
3822e97c149S[email protected] 
3832e97c149S[email protected] 
3842e97c149S[email protected] // MARK: bnep_service_t
385a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
386a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
38727faf85aSMilanka 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."
388a265b909SMatthias Ringwald     #else
389a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
390a265b909SMatthias Ringwald     #endif
391a265b909SMatthias Ringwald #endif
392a265b909SMatthias Ringwald 
393a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
394a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
395a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
39629d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
3972e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
398a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
399a2673d88SMatthias Ringwald     if (buffer){
400a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
401a2673d88SMatthias Ringwald     }
402a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
4032e97c149S[email protected] }
4042e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
40529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
4062e97c149S[email protected] }
4072e97c149S[email protected] #else
4082e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
4092e97c149S[email protected]     return NULL;
4102e97c149S[email protected] }
4112e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
4122e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
4132e97c149S[email protected]     (void) bnep_service;
4142e97c149S[email protected] };
4152e97c149S[email protected] #endif
4162e97c149S[email protected] #elif defined(HAVE_MALLOC)
4172e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
418a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_service_t));
419a2673d88SMatthias Ringwald     if (buffer){
420a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
421a2673d88SMatthias Ringwald     }
422a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
4232e97c149S[email protected] }
4242e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
4252e97c149S[email protected]     free(bnep_service);
4262e97c149S[email protected] }
4272e97c149S[email protected] #endif
4282e97c149S[email protected] 
4292e97c149S[email protected] 
4302e97c149S[email protected] // MARK: bnep_channel_t
431a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
432a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
43327faf85aSMilanka 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."
434a265b909SMatthias Ringwald     #else
435a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
436a265b909SMatthias Ringwald     #endif
437a265b909SMatthias Ringwald #endif
438a265b909SMatthias Ringwald 
439a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
440a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
441a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
44229d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
4432e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
444a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
445a2673d88SMatthias Ringwald     if (buffer){
446a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
447a2673d88SMatthias Ringwald     }
448a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
4492e97c149S[email protected] }
4502e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
45129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
4522e97c149S[email protected] }
4532e97c149S[email protected] #else
4542e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
4552e97c149S[email protected]     return NULL;
4562e97c149S[email protected] }
4572e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
4582e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
4592e97c149S[email protected]     (void) bnep_channel;
4602e97c149S[email protected] };
4612e97c149S[email protected] #endif
4622e97c149S[email protected] #elif defined(HAVE_MALLOC)
4632e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
464a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_channel_t));
465a2673d88SMatthias Ringwald     if (buffer){
466a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
467a2673d88SMatthias Ringwald     }
468a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
4692e97c149S[email protected] }
4702e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
4712e97c149S[email protected]     free(bnep_channel);
4722e97c149S[email protected] }
4732e97c149S[email protected] #endif
4742e97c149S[email protected] 
4752e97c149S[email protected] 
476ea5029c9SMilanka Ringwald 
477ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
478a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
479a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
48027faf85aSMilanka 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."
481a265b909SMatthias Ringwald     #else
482a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
483a265b909SMatthias Ringwald     #endif
484a265b909SMatthias Ringwald #endif
485a265b909SMatthias Ringwald 
486a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
487a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
488a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
48929d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
490ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
491a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
492a2673d88SMatthias Ringwald     if (buffer){
493a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
494a2673d88SMatthias Ringwald     }
495a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
496ea5029c9SMilanka Ringwald }
497ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
49829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
499ea5029c9SMilanka Ringwald }
500ea5029c9SMilanka Ringwald #else
501ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
502ea5029c9SMilanka Ringwald     return NULL;
503ea5029c9SMilanka Ringwald }
504ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
505ea5029c9SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
506ea5029c9SMilanka Ringwald     (void) hfp_connection;
507ea5029c9SMilanka Ringwald };
508ea5029c9SMilanka Ringwald #endif
509ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
510ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
511a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(hfp_connection_t));
512a2673d88SMatthias Ringwald     if (buffer){
513a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
514a2673d88SMatthias Ringwald     }
515a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
516ea5029c9SMilanka Ringwald }
517ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
518ea5029c9SMilanka Ringwald     free(hfp_connection);
519ea5029c9SMilanka Ringwald }
520ea5029c9SMilanka Ringwald #endif
521ea5029c9SMilanka Ringwald 
522ea5029c9SMilanka Ringwald 
523cd9ee144SMatthias Ringwald 
524cd9ee144SMatthias Ringwald // MARK: service_record_item_t
525a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
526a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
52727faf85aSMilanka 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."
528a265b909SMatthias Ringwald     #else
529a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
530a265b909SMatthias Ringwald     #endif
531a265b909SMatthias Ringwald #endif
532a265b909SMatthias Ringwald 
533a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
534a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
535a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
53629d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
537cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
538a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
539a2673d88SMatthias Ringwald     if (buffer){
540a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
541a2673d88SMatthias Ringwald     }
542a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
543cd9ee144SMatthias Ringwald }
544cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
54529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
546cd9ee144SMatthias Ringwald }
547cd9ee144SMatthias Ringwald #else
548cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
549cd9ee144SMatthias Ringwald     return NULL;
550cd9ee144SMatthias Ringwald }
551cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
552cd9ee144SMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
553cd9ee144SMatthias Ringwald     (void) service_record_item;
554cd9ee144SMatthias Ringwald };
555cd9ee144SMatthias Ringwald #endif
556cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
557cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
558a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(service_record_item_t));
559a2673d88SMatthias Ringwald     if (buffer){
560a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
561a2673d88SMatthias Ringwald     }
562a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
563cd9ee144SMatthias Ringwald }
564cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
565cd9ee144SMatthias Ringwald     free(service_record_item);
566cd9ee144SMatthias Ringwald }
567cd9ee144SMatthias Ringwald #endif
568cd9ee144SMatthias Ringwald 
569cd9ee144SMatthias Ringwald 
57027faf85aSMilanka Ringwald 
5710e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
5720e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
5730e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
5740e826a17SMilanka 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."
57527faf85aSMilanka Ringwald     #else
5760e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
57727faf85aSMilanka Ringwald     #endif
57827faf85aSMilanka Ringwald #endif
57927faf85aSMilanka Ringwald 
5800e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
5810e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
5820e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
5830e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
5840e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
585a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
586a2673d88SMatthias Ringwald     if (buffer){
587a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
588a2673d88SMatthias Ringwald     }
589a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
59027faf85aSMilanka Ringwald }
5910e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
5920e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
59327faf85aSMilanka Ringwald }
59427faf85aSMilanka Ringwald #else
5950e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
59627faf85aSMilanka Ringwald     return NULL;
59727faf85aSMilanka Ringwald }
5980e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
59927faf85aSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
6000e826a17SMilanka Ringwald     (void) avdtp_stream_endpoint;
60127faf85aSMilanka Ringwald };
60227faf85aSMilanka Ringwald #endif
60327faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
6040e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
605a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_stream_endpoint_t));
606a2673d88SMatthias Ringwald     if (buffer){
607a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
608a2673d88SMatthias Ringwald     }
609a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
61027faf85aSMilanka Ringwald }
6110e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
6120e826a17SMilanka Ringwald     free(avdtp_stream_endpoint);
61327faf85aSMilanka Ringwald }
61427faf85aSMilanka Ringwald #endif
61527faf85aSMilanka Ringwald 
61627faf85aSMilanka Ringwald 
61712e7f38cSMilanka Ringwald 
61812e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
61912e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
62012e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
62112e7f38cSMilanka 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."
62212e7f38cSMilanka Ringwald     #else
62312e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
62412e7f38cSMilanka Ringwald     #endif
62512e7f38cSMilanka Ringwald #endif
62612e7f38cSMilanka Ringwald 
62712e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
62812e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
62912e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
63012e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
63112e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
632a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
633a2673d88SMatthias Ringwald     if (buffer){
634a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
635a2673d88SMatthias Ringwald     }
636a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
63712e7f38cSMilanka Ringwald }
63812e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
63912e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
64012e7f38cSMilanka Ringwald }
64112e7f38cSMilanka Ringwald #else
64212e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
64312e7f38cSMilanka Ringwald     return NULL;
64412e7f38cSMilanka Ringwald }
64512e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
64612e7f38cSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
64712e7f38cSMilanka Ringwald     (void) avdtp_connection;
64812e7f38cSMilanka Ringwald };
64912e7f38cSMilanka Ringwald #endif
65012e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
65112e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
652a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_connection_t));
653a2673d88SMatthias Ringwald     if (buffer){
654a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
655a2673d88SMatthias Ringwald     }
656a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
65712e7f38cSMilanka Ringwald }
65812e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
65912e7f38cSMilanka Ringwald     free(avdtp_connection);
66012e7f38cSMilanka Ringwald }
66112e7f38cSMilanka Ringwald #endif
66212e7f38cSMilanka Ringwald 
66312e7f38cSMilanka Ringwald 
66491451a2bSMilanka Ringwald 
66591451a2bSMilanka Ringwald // MARK: avrcp_connection_t
66691451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
66791451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
66891451a2bSMilanka 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."
66991451a2bSMilanka Ringwald     #else
67091451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
67191451a2bSMilanka Ringwald     #endif
67291451a2bSMilanka Ringwald #endif
67391451a2bSMilanka Ringwald 
67491451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
67591451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
67691451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
67791451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
67891451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
679a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
680a2673d88SMatthias Ringwald     if (buffer){
681a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
682a2673d88SMatthias Ringwald     }
683a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
68491451a2bSMilanka Ringwald }
68591451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
68691451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
68791451a2bSMilanka Ringwald }
68891451a2bSMilanka Ringwald #else
68991451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
69091451a2bSMilanka Ringwald     return NULL;
69191451a2bSMilanka Ringwald }
69291451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
69391451a2bSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
69491451a2bSMilanka Ringwald     (void) avrcp_connection;
69591451a2bSMilanka Ringwald };
69691451a2bSMilanka Ringwald #endif
69791451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
69891451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
699a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_connection_t));
700a2673d88SMatthias Ringwald     if (buffer){
701a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
702a2673d88SMatthias Ringwald     }
703a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
70491451a2bSMilanka Ringwald }
70591451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
70691451a2bSMilanka Ringwald     free(avrcp_connection);
70791451a2bSMilanka Ringwald }
70891451a2bSMilanka Ringwald #endif
70991451a2bSMilanka Ringwald 
71091451a2bSMilanka Ringwald 
711f12a3722SMilanka Ringwald 
712f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
713f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
714f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
715f12a3722SMilanka 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."
716f12a3722SMilanka Ringwald     #else
717f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
718f12a3722SMilanka Ringwald     #endif
719f12a3722SMilanka Ringwald #endif
720f12a3722SMilanka Ringwald 
721f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
722f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
723f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
724f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
725f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
726a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
727a2673d88SMatthias Ringwald     if (buffer){
728a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
729a2673d88SMatthias Ringwald     }
730a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
731f12a3722SMilanka Ringwald }
732f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
733f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
734f12a3722SMilanka Ringwald }
735f12a3722SMilanka Ringwald #else
736f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
737f12a3722SMilanka Ringwald     return NULL;
738f12a3722SMilanka Ringwald }
739f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
740f12a3722SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
741f12a3722SMilanka Ringwald     (void) avrcp_browsing_connection;
742f12a3722SMilanka Ringwald };
743f12a3722SMilanka Ringwald #endif
744f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
745f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
746a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_browsing_connection_t));
747a2673d88SMatthias Ringwald     if (buffer){
748a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
749a2673d88SMatthias Ringwald     }
750a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
751f12a3722SMilanka Ringwald }
752f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
753f12a3722SMilanka Ringwald     free(avrcp_browsing_connection);
754f12a3722SMilanka Ringwald }
755f12a3722SMilanka Ringwald #endif
756f12a3722SMilanka Ringwald 
757f12a3722SMilanka Ringwald 
758a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
7592e97c149S[email protected] 
7602e97c149S[email protected] // MARK: gatt_client_t
761a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
762a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
76327faf85aSMilanka 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."
764a265b909SMatthias Ringwald     #else
765a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
766a265b909SMatthias Ringwald     #endif
767a265b909SMatthias Ringwald #endif
768a265b909SMatthias Ringwald 
769a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
770a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
771a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
77229d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
773d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
774a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
775a2673d88SMatthias Ringwald     if (buffer){
776a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
777a2673d88SMatthias Ringwald     }
778a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
779d0fdae3cS[email protected] }
780d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
78129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
782d0fdae3cS[email protected] }
783d0fdae3cS[email protected] #else
784d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
785d0fdae3cS[email protected]     return NULL;
786d0fdae3cS[email protected] }
787d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
7886f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
7896f7ecb09S[email protected]     (void) gatt_client;
790d0fdae3cS[email protected] };
791d0fdae3cS[email protected] #endif
792d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
793d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
794a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(gatt_client_t));
795a2673d88SMatthias Ringwald     if (buffer){
796a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
797a2673d88SMatthias Ringwald     }
798a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
799d0fdae3cS[email protected] }
800d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
801d0fdae3cS[email protected]     free(gatt_client);
802d0fdae3cS[email protected] }
803d0fdae3cS[email protected] #endif
8042e97c149S[email protected] 
8052e97c149S[email protected] 
806656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
807a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
808a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
80927faf85aSMilanka 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."
810a265b909SMatthias Ringwald     #else
811a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
812a265b909SMatthias Ringwald     #endif
813a265b909SMatthias Ringwald #endif
814a265b909SMatthias Ringwald 
815a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
816a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
817a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
81829d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
819656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
820a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
821a2673d88SMatthias Ringwald     if (buffer){
822a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
823a2673d88SMatthias Ringwald     }
824a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
825656bec4fSMatthias Ringwald }
826656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
82729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
828656bec4fSMatthias Ringwald }
829656bec4fSMatthias Ringwald #else
830656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
831656bec4fSMatthias Ringwald     return NULL;
832656bec4fSMatthias Ringwald }
833656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
834656bec4fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
835656bec4fSMatthias Ringwald     (void) whitelist_entry;
836656bec4fSMatthias Ringwald };
837656bec4fSMatthias Ringwald #endif
838656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
839656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
840a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(whitelist_entry_t));
841a2673d88SMatthias Ringwald     if (buffer){
842a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
843a2673d88SMatthias Ringwald     }
844a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
845656bec4fSMatthias Ringwald }
846656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
847656bec4fSMatthias Ringwald     free(whitelist_entry);
848656bec4fSMatthias Ringwald }
849656bec4fSMatthias Ringwald #endif
850656bec4fSMatthias Ringwald 
851656bec4fSMatthias Ringwald 
852cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
853a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
854a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
85527faf85aSMilanka 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."
856a265b909SMatthias Ringwald     #else
857a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
858a265b909SMatthias Ringwald     #endif
859a265b909SMatthias Ringwald #endif
860a265b909SMatthias Ringwald 
861a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
862a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
863a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
86429d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
865cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
866a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
867a2673d88SMatthias Ringwald     if (buffer){
868a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
869a2673d88SMatthias Ringwald     }
870a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
871cf49570bSMatthias Ringwald }
872cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
87329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
874cf49570bSMatthias Ringwald }
875cf49570bSMatthias Ringwald #else
876cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
877cf49570bSMatthias Ringwald     return NULL;
878cf49570bSMatthias Ringwald }
879cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
880cf49570bSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
881cf49570bSMatthias Ringwald     (void) sm_lookup_entry;
882cf49570bSMatthias Ringwald };
883cf49570bSMatthias Ringwald #endif
884cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
885cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
886a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(sm_lookup_entry_t));
887a2673d88SMatthias Ringwald     if (buffer){
888a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
889a2673d88SMatthias Ringwald     }
890a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
891cf49570bSMatthias Ringwald }
892cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
893cf49570bSMatthias Ringwald     free(sm_lookup_entry);
894cf49570bSMatthias Ringwald }
895cf49570bSMatthias Ringwald #endif
896cf49570bSMatthias Ringwald 
897cf49570bSMatthias Ringwald 
898ebb73e1fSMatthias Ringwald 
899ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t
900ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
901ebb73e1fSMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_PDUS)
902ebb73e1fSMatthias 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."
903ebb73e1fSMatthias Ringwald     #else
904ebb73e1fSMatthias Ringwald         #define MAX_NR_MESH_NETWORK_PDUS 0
905ebb73e1fSMatthias Ringwald     #endif
906ebb73e1fSMatthias Ringwald #endif
907ebb73e1fSMatthias Ringwald 
908ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
909ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
910ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
911ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool;
912ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
913ebb73e1fSMatthias Ringwald     return (mesh_network_pdu_t *) btstack_memory_pool_get(&mesh_network_pdu_pool);
914ebb73e1fSMatthias Ringwald }
915ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
916ebb73e1fSMatthias Ringwald     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
917ebb73e1fSMatthias Ringwald }
918ebb73e1fSMatthias Ringwald #else
919ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
920ebb73e1fSMatthias Ringwald     return NULL;
921ebb73e1fSMatthias Ringwald }
922ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
923ebb73e1fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
924ebb73e1fSMatthias Ringwald     (void) mesh_network_pdu;
925ebb73e1fSMatthias Ringwald };
926ebb73e1fSMatthias Ringwald #endif
927ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC)
928ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
929ebb73e1fSMatthias Ringwald     return (mesh_network_pdu_t*) malloc(sizeof(mesh_network_pdu_t));
930ebb73e1fSMatthias Ringwald }
931ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
932ebb73e1fSMatthias Ringwald     free(mesh_network_pdu);
933ebb73e1fSMatthias Ringwald }
934ebb73e1fSMatthias Ringwald #endif
935ebb73e1fSMatthias Ringwald 
936ebb73e1fSMatthias Ringwald 
937*c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t
938*c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
939*c0a711d9SMatthias Ringwald     #if defined(MAX_NO_MESH_NETWORK_KEYS)
940*c0a711d9SMatthias 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."
941*c0a711d9SMatthias Ringwald     #else
942*c0a711d9SMatthias Ringwald         #define MAX_NR_MESH_NETWORK_KEYS 0
943*c0a711d9SMatthias Ringwald     #endif
944*c0a711d9SMatthias Ringwald #endif
945*c0a711d9SMatthias Ringwald 
946*c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
947*c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
948*c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
949*c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool;
950*c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
951*c0a711d9SMatthias Ringwald     return (mesh_network_key_t *) btstack_memory_pool_get(&mesh_network_key_pool);
952*c0a711d9SMatthias Ringwald }
953*c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
954*c0a711d9SMatthias Ringwald     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
955*c0a711d9SMatthias Ringwald }
956*c0a711d9SMatthias Ringwald #else
957*c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
958*c0a711d9SMatthias Ringwald     return NULL;
959*c0a711d9SMatthias Ringwald }
960*c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
961*c0a711d9SMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
962*c0a711d9SMatthias Ringwald     (void) mesh_network_key;
963*c0a711d9SMatthias Ringwald };
964*c0a711d9SMatthias Ringwald #endif
965*c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC)
966*c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
967*c0a711d9SMatthias Ringwald     return (mesh_network_key_t*) malloc(sizeof(mesh_network_key_t));
968*c0a711d9SMatthias Ringwald }
969*c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
970*c0a711d9SMatthias Ringwald     free(mesh_network_key);
971*c0a711d9SMatthias Ringwald }
972*c0a711d9SMatthias Ringwald #endif
973*c0a711d9SMatthias Ringwald 
974*c0a711d9SMatthias Ringwald 
9752e97c149S[email protected] #endif
976a3b02b71Smatthias.ringwald // init
977a3b02b71Smatthias.ringwald void btstack_memory_init(void){
978a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
979a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
980a3b02b71Smatthias.ringwald #endif
981a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
982a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
983a3b02b71Smatthias.ringwald #endif
984a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
985a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
986a3b02b71Smatthias.ringwald #endif
987a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
988a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
989a3b02b71Smatthias.ringwald #endif
990a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
991a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
992a3b02b71Smatthias.ringwald #endif
993a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
994a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
995a3b02b71Smatthias.ringwald #endif
996a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
997a265b909SMatthias 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));
9981801b596Smatthias.ringwald #endif
999a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
1000a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
10012e97c149S[email protected] #endif
1002a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
1003a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
10042e97c149S[email protected] #endif
1005a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
1006a265b909SMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
1007ea5029c9SMilanka Ringwald #endif
1008a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
1009a265b909SMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
1010cd9ee144SMatthias Ringwald #endif
10110e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
10120e826a17SMilanka Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
101327faf85aSMilanka Ringwald #endif
101412e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
101512e7f38cSMilanka Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
101612e7f38cSMilanka Ringwald #endif
101791451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
101891451a2bSMilanka Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
101991451a2bSMilanka Ringwald #endif
1020f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
1021f12a3722SMilanka Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1022f12a3722SMilanka Ringwald #endif
1023a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
1024a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
1025a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1026d0fdae3cS[email protected] #endif
1027a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
1028a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1029656bec4fSMatthias Ringwald #endif
1030a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1031a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1032cf49570bSMatthias Ringwald #endif
1033ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0
1034ebb73e1fSMatthias Ringwald     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
1035ebb73e1fSMatthias Ringwald #endif
1036*c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0
1037*c0a711d9SMatthias Ringwald     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1038*c0a711d9SMatthias Ringwald #endif
1039a7d12effS[email protected] #endif
1040a3b02b71Smatthias.ringwald }
1041