xref: /btstack/src/btstack_memory.c (revision a2673d881087910a9937a97706356e76c5cc5ab6)
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 
382e97c149S[email protected] 
39a3b02b71Smatthias.ringwald /*
40a98592bcSMatthias Ringwald  *  btstack_memory.h
41a3b02b71Smatthias.ringwald  *
42a3b02b71Smatthias.ringwald  *  @brief BTstack memory management via configurable memory pools
43a3b02b71Smatthias.ringwald  *
44a98592bcSMatthias Ringwald  *  @note code generated by tool/btstack_memory_generator.py
45*a2673d88SMatthias Ringwald  *  @note returnes buffers are initialized with 0
46a3b02b71Smatthias.ringwald  *
47a3b02b71Smatthias.ringwald  */
48a3b02b71Smatthias.ringwald 
49a3b02b71Smatthias.ringwald #include "btstack_memory.h"
50d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h"
51a3b02b71Smatthias.ringwald 
52a3b02b71Smatthias.ringwald #include <stdlib.h>
53a3b02b71Smatthias.ringwald 
54a3b02b71Smatthias.ringwald 
552e97c149S[email protected] 
56a3b02b71Smatthias.ringwald // MARK: hci_connection_t
57a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
58a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
5927faf85aSMilanka 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."
60a265b909SMatthias Ringwald     #else
61a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
62a265b909SMatthias Ringwald     #endif
63a265b909SMatthias Ringwald #endif
64a265b909SMatthias Ringwald 
65a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
66a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
67a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
6829d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
696527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
70*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
71*a2673d88SMatthias Ringwald     if (buffer){
72*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
73*a2673d88SMatthias Ringwald     }
74*a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
75a3b02b71Smatthias.ringwald }
766527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
7729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
78a3b02b71Smatthias.ringwald }
79c4d3f927Smatthias.ringwald #else
806527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
81c4d3f927Smatthias.ringwald     return NULL;
82c4d3f927Smatthias.ringwald }
836527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
846f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
852e97c149S[email protected]     (void) hci_connection;
86c4d3f927Smatthias.ringwald };
87c4d3f927Smatthias.ringwald #endif
88a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
896527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
90*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(hci_connection_t));
91*a2673d88SMatthias Ringwald     if (buffer){
92*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hci_connection_t));
93*a2673d88SMatthias Ringwald     }
94*a2673d88SMatthias Ringwald     return (hci_connection_t *) buffer;
95a3b02b71Smatthias.ringwald }
966527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
97a3b02b71Smatthias.ringwald     free(hci_connection);
98a3b02b71Smatthias.ringwald }
99a3b02b71Smatthias.ringwald #endif
100a3b02b71Smatthias.ringwald 
101a3b02b71Smatthias.ringwald 
1022e97c149S[email protected] 
103a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
104a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
105a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
10627faf85aSMilanka 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."
107a265b909SMatthias Ringwald     #else
108a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
109a265b909SMatthias Ringwald     #endif
110a265b909SMatthias Ringwald #endif
111a265b909SMatthias Ringwald 
112a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
113a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
114a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
11529d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1166527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
117*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
118*a2673d88SMatthias Ringwald     if (buffer){
119*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
120*a2673d88SMatthias Ringwald     }
121*a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
122a3b02b71Smatthias.ringwald }
1236527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
12429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
125a3b02b71Smatthias.ringwald }
126c4d3f927Smatthias.ringwald #else
1276527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
128c4d3f927Smatthias.ringwald     return NULL;
129c4d3f927Smatthias.ringwald }
1306527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
1316f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1326f7ecb09S[email protected]     (void) l2cap_service;
133c4d3f927Smatthias.ringwald };
134c4d3f927Smatthias.ringwald #endif
135a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1366527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
137*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_service_t));
138*a2673d88SMatthias Ringwald     if (buffer){
139*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_service_t));
140*a2673d88SMatthias Ringwald     }
141*a2673d88SMatthias Ringwald     return (l2cap_service_t *) buffer;
142a3b02b71Smatthias.ringwald }
1436527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
144a3b02b71Smatthias.ringwald     free(l2cap_service);
145a3b02b71Smatthias.ringwald }
146a3b02b71Smatthias.ringwald #endif
147a3b02b71Smatthias.ringwald 
148a3b02b71Smatthias.ringwald 
149a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
150a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
151a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
15227faf85aSMilanka 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."
153a265b909SMatthias Ringwald     #else
154a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
155a265b909SMatthias Ringwald     #endif
156a265b909SMatthias Ringwald #endif
157a265b909SMatthias Ringwald 
158a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
159a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
160a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
16129d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
1626527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
163*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
164*a2673d88SMatthias Ringwald     if (buffer){
165*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
166*a2673d88SMatthias Ringwald     }
167*a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
168a3b02b71Smatthias.ringwald }
1696527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
17029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
171a3b02b71Smatthias.ringwald }
172c4d3f927Smatthias.ringwald #else
1736527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
174c4d3f927Smatthias.ringwald     return NULL;
175c4d3f927Smatthias.ringwald }
1766527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
1776f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1786f7ecb09S[email protected]     (void) l2cap_channel;
179c4d3f927Smatthias.ringwald };
180c4d3f927Smatthias.ringwald #endif
181a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1826527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
183*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(l2cap_channel_t));
184*a2673d88SMatthias Ringwald     if (buffer){
185*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(l2cap_channel_t));
186*a2673d88SMatthias Ringwald     }
187*a2673d88SMatthias Ringwald     return (l2cap_channel_t *) buffer;
188a3b02b71Smatthias.ringwald }
1896527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
190a3b02b71Smatthias.ringwald     free(l2cap_channel);
191a3b02b71Smatthias.ringwald }
192a3b02b71Smatthias.ringwald #endif
193a3b02b71Smatthias.ringwald 
194a3b02b71Smatthias.ringwald 
1952e97c149S[email protected] 
196a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
197a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
198a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
19927faf85aSMilanka 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."
200a265b909SMatthias Ringwald     #else
201a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
202a265b909SMatthias Ringwald     #endif
203a265b909SMatthias Ringwald #endif
204a265b909SMatthias Ringwald 
205a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
206a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
207a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
20829d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
2096527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
210*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
211*a2673d88SMatthias Ringwald     if (buffer){
212*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
213*a2673d88SMatthias Ringwald     }
214*a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
215a3b02b71Smatthias.ringwald }
2166527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
21729d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
218a3b02b71Smatthias.ringwald }
219c4d3f927Smatthias.ringwald #else
2206527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
221c4d3f927Smatthias.ringwald     return NULL;
222c4d3f927Smatthias.ringwald }
2236527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
2246f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2256f7ecb09S[email protected]     (void) rfcomm_multiplexer;
226c4d3f927Smatthias.ringwald };
227c4d3f927Smatthias.ringwald #endif
228a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2296527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
230*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_multiplexer_t));
231*a2673d88SMatthias Ringwald     if (buffer){
232*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
233*a2673d88SMatthias Ringwald     }
234*a2673d88SMatthias Ringwald     return (rfcomm_multiplexer_t *) buffer;
235a3b02b71Smatthias.ringwald }
2366527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
237a3b02b71Smatthias.ringwald     free(rfcomm_multiplexer);
238a3b02b71Smatthias.ringwald }
239a3b02b71Smatthias.ringwald #endif
240a3b02b71Smatthias.ringwald 
241a3b02b71Smatthias.ringwald 
242a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
243a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
244a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
24527faf85aSMilanka 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."
246a265b909SMatthias Ringwald     #else
247a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
248a265b909SMatthias Ringwald     #endif
249a265b909SMatthias Ringwald #endif
250a265b909SMatthias Ringwald 
251a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
252a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
253a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
25429d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
2556527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
256*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
257*a2673d88SMatthias Ringwald     if (buffer){
258*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
259*a2673d88SMatthias Ringwald     }
260*a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
261a3b02b71Smatthias.ringwald }
2626527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
26329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
264a3b02b71Smatthias.ringwald }
265c4d3f927Smatthias.ringwald #else
2666527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
267c4d3f927Smatthias.ringwald     return NULL;
268c4d3f927Smatthias.ringwald }
2696527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
2706f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2716f7ecb09S[email protected]     (void) rfcomm_service;
272c4d3f927Smatthias.ringwald };
273c4d3f927Smatthias.ringwald #endif
274a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2756527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
276*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_service_t));
277*a2673d88SMatthias Ringwald     if (buffer){
278*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_service_t));
279*a2673d88SMatthias Ringwald     }
280*a2673d88SMatthias Ringwald     return (rfcomm_service_t *) buffer;
281a3b02b71Smatthias.ringwald }
2826527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
283a3b02b71Smatthias.ringwald     free(rfcomm_service);
284a3b02b71Smatthias.ringwald }
285a3b02b71Smatthias.ringwald #endif
286a3b02b71Smatthias.ringwald 
287a3b02b71Smatthias.ringwald 
288a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
289a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
290a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
29127faf85aSMilanka 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."
292a265b909SMatthias Ringwald     #else
293a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
294a265b909SMatthias Ringwald     #endif
295a265b909SMatthias Ringwald #endif
296a265b909SMatthias Ringwald 
297a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
298a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
299a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
30029d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
3016527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
302*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
303*a2673d88SMatthias Ringwald     if (buffer){
304*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
305*a2673d88SMatthias Ringwald     }
306*a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
307a3b02b71Smatthias.ringwald }
3086527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
30929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
310a3b02b71Smatthias.ringwald }
311c4d3f927Smatthias.ringwald #else
3126527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
313c4d3f927Smatthias.ringwald     return NULL;
314c4d3f927Smatthias.ringwald }
3156527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
3166f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3176f7ecb09S[email protected]     (void) rfcomm_channel;
318c4d3f927Smatthias.ringwald };
319c4d3f927Smatthias.ringwald #endif
320a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
3216527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
322*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(rfcomm_channel_t));
323*a2673d88SMatthias Ringwald     if (buffer){
324*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(rfcomm_channel_t));
325*a2673d88SMatthias Ringwald     }
326*a2673d88SMatthias Ringwald     return (rfcomm_channel_t *) buffer;
327a3b02b71Smatthias.ringwald }
3286527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
329a3b02b71Smatthias.ringwald     free(rfcomm_channel);
330a3b02b71Smatthias.ringwald }
331a3b02b71Smatthias.ringwald #endif
332a3b02b71Smatthias.ringwald 
333fdb398c2S[email protected] 
334e0e5e285Smatthias.ringwald 
3352c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
336a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
337a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
33827faf85aSMilanka 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."
339a265b909SMatthias Ringwald     #else
340a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
341a265b909SMatthias Ringwald     #endif
342a265b909SMatthias Ringwald #endif
343a265b909SMatthias Ringwald 
344a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
345a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
346a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
3472c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
3482c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
349*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
350*a2673d88SMatthias Ringwald     if (buffer){
351*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
352*a2673d88SMatthias Ringwald     }
353*a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
3541801b596Smatthias.ringwald }
3552c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3562c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
3571801b596Smatthias.ringwald }
358c4d3f927Smatthias.ringwald #else
3592c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
360c4d3f927Smatthias.ringwald     return NULL;
361c4d3f927Smatthias.ringwald }
3622c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3636f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3642c455dadSMatthias Ringwald     (void) btstack_link_key_db_memory_entry;
365c4d3f927Smatthias.ringwald };
366c4d3f927Smatthias.ringwald #endif
3671801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3682c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
369*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t));
370*a2673d88SMatthias Ringwald     if (buffer){
371*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
372*a2673d88SMatthias Ringwald     }
373*a2673d88SMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) buffer;
3741801b596Smatthias.ringwald }
3752c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3762c455dadSMatthias Ringwald     free(btstack_link_key_db_memory_entry);
377e0e5e285Smatthias.ringwald }
3781801b596Smatthias.ringwald #endif
3791801b596Smatthias.ringwald 
3802e97c149S[email protected] 
3812e97c149S[email protected] 
3822e97c149S[email protected] // MARK: bnep_service_t
383a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
384a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
38527faf85aSMilanka 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."
386a265b909SMatthias Ringwald     #else
387a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
388a265b909SMatthias Ringwald     #endif
389a265b909SMatthias Ringwald #endif
390a265b909SMatthias Ringwald 
391a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
392a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
393a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
39429d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
3952e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
396*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
397*a2673d88SMatthias Ringwald     if (buffer){
398*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
399*a2673d88SMatthias Ringwald     }
400*a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
4012e97c149S[email protected] }
4022e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
40329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
4042e97c149S[email protected] }
4052e97c149S[email protected] #else
4062e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
4072e97c149S[email protected]     return NULL;
4082e97c149S[email protected] }
4092e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
4102e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
4112e97c149S[email protected]     (void) bnep_service;
4122e97c149S[email protected] };
4132e97c149S[email protected] #endif
4142e97c149S[email protected] #elif defined(HAVE_MALLOC)
4152e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
416*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_service_t));
417*a2673d88SMatthias Ringwald     if (buffer){
418*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_service_t));
419*a2673d88SMatthias Ringwald     }
420*a2673d88SMatthias Ringwald     return (bnep_service_t *) buffer;
4212e97c149S[email protected] }
4222e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
4232e97c149S[email protected]     free(bnep_service);
4242e97c149S[email protected] }
4252e97c149S[email protected] #endif
4262e97c149S[email protected] 
4272e97c149S[email protected] 
4282e97c149S[email protected] // MARK: bnep_channel_t
429a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
430a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
43127faf85aSMilanka 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."
432a265b909SMatthias Ringwald     #else
433a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
434a265b909SMatthias Ringwald     #endif
435a265b909SMatthias Ringwald #endif
436a265b909SMatthias Ringwald 
437a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
438a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
439a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
44029d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
4412e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
442*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
443*a2673d88SMatthias Ringwald     if (buffer){
444*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
445*a2673d88SMatthias Ringwald     }
446*a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
4472e97c149S[email protected] }
4482e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
44929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
4502e97c149S[email protected] }
4512e97c149S[email protected] #else
4522e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
4532e97c149S[email protected]     return NULL;
4542e97c149S[email protected] }
4552e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
4562e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
4572e97c149S[email protected]     (void) bnep_channel;
4582e97c149S[email protected] };
4592e97c149S[email protected] #endif
4602e97c149S[email protected] #elif defined(HAVE_MALLOC)
4612e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
462*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(bnep_channel_t));
463*a2673d88SMatthias Ringwald     if (buffer){
464*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(bnep_channel_t));
465*a2673d88SMatthias Ringwald     }
466*a2673d88SMatthias Ringwald     return (bnep_channel_t *) buffer;
4672e97c149S[email protected] }
4682e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
4692e97c149S[email protected]     free(bnep_channel);
4702e97c149S[email protected] }
4712e97c149S[email protected] #endif
4722e97c149S[email protected] 
4732e97c149S[email protected] 
474ea5029c9SMilanka Ringwald 
475ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
476a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
477a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
47827faf85aSMilanka 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."
479a265b909SMatthias Ringwald     #else
480a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
481a265b909SMatthias Ringwald     #endif
482a265b909SMatthias Ringwald #endif
483a265b909SMatthias Ringwald 
484a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
485a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
486a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
48729d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
488ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
489*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
490*a2673d88SMatthias Ringwald     if (buffer){
491*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
492*a2673d88SMatthias Ringwald     }
493*a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
494ea5029c9SMilanka Ringwald }
495ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
49629d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
497ea5029c9SMilanka Ringwald }
498ea5029c9SMilanka Ringwald #else
499ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
500ea5029c9SMilanka Ringwald     return NULL;
501ea5029c9SMilanka Ringwald }
502ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
503ea5029c9SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
504ea5029c9SMilanka Ringwald     (void) hfp_connection;
505ea5029c9SMilanka Ringwald };
506ea5029c9SMilanka Ringwald #endif
507ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
508ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
509*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(hfp_connection_t));
510*a2673d88SMatthias Ringwald     if (buffer){
511*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(hfp_connection_t));
512*a2673d88SMatthias Ringwald     }
513*a2673d88SMatthias Ringwald     return (hfp_connection_t *) buffer;
514ea5029c9SMilanka Ringwald }
515ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
516ea5029c9SMilanka Ringwald     free(hfp_connection);
517ea5029c9SMilanka Ringwald }
518ea5029c9SMilanka Ringwald #endif
519ea5029c9SMilanka Ringwald 
520ea5029c9SMilanka Ringwald 
521cd9ee144SMatthias Ringwald 
522cd9ee144SMatthias Ringwald // MARK: service_record_item_t
523a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
524a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
52527faf85aSMilanka 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."
526a265b909SMatthias Ringwald     #else
527a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
528a265b909SMatthias Ringwald     #endif
529a265b909SMatthias Ringwald #endif
530a265b909SMatthias Ringwald 
531a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
532a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
533a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
53429d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
535cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
536*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
537*a2673d88SMatthias Ringwald     if (buffer){
538*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
539*a2673d88SMatthias Ringwald     }
540*a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
541cd9ee144SMatthias Ringwald }
542cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
54329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
544cd9ee144SMatthias Ringwald }
545cd9ee144SMatthias Ringwald #else
546cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
547cd9ee144SMatthias Ringwald     return NULL;
548cd9ee144SMatthias Ringwald }
549cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
550cd9ee144SMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
551cd9ee144SMatthias Ringwald     (void) service_record_item;
552cd9ee144SMatthias Ringwald };
553cd9ee144SMatthias Ringwald #endif
554cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
555cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
556*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(service_record_item_t));
557*a2673d88SMatthias Ringwald     if (buffer){
558*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(service_record_item_t));
559*a2673d88SMatthias Ringwald     }
560*a2673d88SMatthias Ringwald     return (service_record_item_t *) buffer;
561cd9ee144SMatthias Ringwald }
562cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
563cd9ee144SMatthias Ringwald     free(service_record_item);
564cd9ee144SMatthias Ringwald }
565cd9ee144SMatthias Ringwald #endif
566cd9ee144SMatthias Ringwald 
567cd9ee144SMatthias Ringwald 
56827faf85aSMilanka Ringwald 
5690e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
5700e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
5710e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
5720e826a17SMilanka 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."
57327faf85aSMilanka Ringwald     #else
5740e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
57527faf85aSMilanka Ringwald     #endif
57627faf85aSMilanka Ringwald #endif
57727faf85aSMilanka Ringwald 
5780e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
5790e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
5800e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
5810e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
5820e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
583*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
584*a2673d88SMatthias Ringwald     if (buffer){
585*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
586*a2673d88SMatthias Ringwald     }
587*a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
58827faf85aSMilanka Ringwald }
5890e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
5900e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
59127faf85aSMilanka Ringwald }
59227faf85aSMilanka Ringwald #else
5930e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
59427faf85aSMilanka Ringwald     return NULL;
59527faf85aSMilanka Ringwald }
5960e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
59727faf85aSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
5980e826a17SMilanka Ringwald     (void) avdtp_stream_endpoint;
59927faf85aSMilanka Ringwald };
60027faf85aSMilanka Ringwald #endif
60127faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
6020e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
603*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_stream_endpoint_t));
604*a2673d88SMatthias Ringwald     if (buffer){
605*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
606*a2673d88SMatthias Ringwald     }
607*a2673d88SMatthias Ringwald     return (avdtp_stream_endpoint_t *) buffer;
60827faf85aSMilanka Ringwald }
6090e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
6100e826a17SMilanka Ringwald     free(avdtp_stream_endpoint);
61127faf85aSMilanka Ringwald }
61227faf85aSMilanka Ringwald #endif
61327faf85aSMilanka Ringwald 
61427faf85aSMilanka Ringwald 
61512e7f38cSMilanka Ringwald 
61612e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
61712e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
61812e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
61912e7f38cSMilanka 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."
62012e7f38cSMilanka Ringwald     #else
62112e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
62212e7f38cSMilanka Ringwald     #endif
62312e7f38cSMilanka Ringwald #endif
62412e7f38cSMilanka Ringwald 
62512e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
62612e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
62712e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
62812e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
62912e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
630*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
631*a2673d88SMatthias Ringwald     if (buffer){
632*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
633*a2673d88SMatthias Ringwald     }
634*a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
63512e7f38cSMilanka Ringwald }
63612e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
63712e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
63812e7f38cSMilanka Ringwald }
63912e7f38cSMilanka Ringwald #else
64012e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
64112e7f38cSMilanka Ringwald     return NULL;
64212e7f38cSMilanka Ringwald }
64312e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
64412e7f38cSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
64512e7f38cSMilanka Ringwald     (void) avdtp_connection;
64612e7f38cSMilanka Ringwald };
64712e7f38cSMilanka Ringwald #endif
64812e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
64912e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
650*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avdtp_connection_t));
651*a2673d88SMatthias Ringwald     if (buffer){
652*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avdtp_connection_t));
653*a2673d88SMatthias Ringwald     }
654*a2673d88SMatthias Ringwald     return (avdtp_connection_t *) buffer;
65512e7f38cSMilanka Ringwald }
65612e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
65712e7f38cSMilanka Ringwald     free(avdtp_connection);
65812e7f38cSMilanka Ringwald }
65912e7f38cSMilanka Ringwald #endif
66012e7f38cSMilanka Ringwald 
66112e7f38cSMilanka Ringwald 
66291451a2bSMilanka Ringwald 
66391451a2bSMilanka Ringwald // MARK: avrcp_connection_t
66491451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
66591451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
66691451a2bSMilanka 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."
66791451a2bSMilanka Ringwald     #else
66891451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
66991451a2bSMilanka Ringwald     #endif
67091451a2bSMilanka Ringwald #endif
67191451a2bSMilanka Ringwald 
67291451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
67391451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
67491451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
67591451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
67691451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
677*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
678*a2673d88SMatthias Ringwald     if (buffer){
679*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
680*a2673d88SMatthias Ringwald     }
681*a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
68291451a2bSMilanka Ringwald }
68391451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
68491451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
68591451a2bSMilanka Ringwald }
68691451a2bSMilanka Ringwald #else
68791451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
68891451a2bSMilanka Ringwald     return NULL;
68991451a2bSMilanka Ringwald }
69091451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
69191451a2bSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
69291451a2bSMilanka Ringwald     (void) avrcp_connection;
69391451a2bSMilanka Ringwald };
69491451a2bSMilanka Ringwald #endif
69591451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
69691451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
697*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_connection_t));
698*a2673d88SMatthias Ringwald     if (buffer){
699*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_connection_t));
700*a2673d88SMatthias Ringwald     }
701*a2673d88SMatthias Ringwald     return (avrcp_connection_t *) buffer;
70291451a2bSMilanka Ringwald }
70391451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
70491451a2bSMilanka Ringwald     free(avrcp_connection);
70591451a2bSMilanka Ringwald }
70691451a2bSMilanka Ringwald #endif
70791451a2bSMilanka Ringwald 
70891451a2bSMilanka Ringwald 
709f12a3722SMilanka Ringwald 
710f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
711f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
712f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
713f12a3722SMilanka 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."
714f12a3722SMilanka Ringwald     #else
715f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
716f12a3722SMilanka Ringwald     #endif
717f12a3722SMilanka Ringwald #endif
718f12a3722SMilanka Ringwald 
719f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
720f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
721f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
722f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
723f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
724*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
725*a2673d88SMatthias Ringwald     if (buffer){
726*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
727*a2673d88SMatthias Ringwald     }
728*a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
729f12a3722SMilanka Ringwald }
730f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
731f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
732f12a3722SMilanka Ringwald }
733f12a3722SMilanka Ringwald #else
734f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
735f12a3722SMilanka Ringwald     return NULL;
736f12a3722SMilanka Ringwald }
737f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
738f12a3722SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
739f12a3722SMilanka Ringwald     (void) avrcp_browsing_connection;
740f12a3722SMilanka Ringwald };
741f12a3722SMilanka Ringwald #endif
742f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
743f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
744*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(avrcp_browsing_connection_t));
745*a2673d88SMatthias Ringwald     if (buffer){
746*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
747*a2673d88SMatthias Ringwald     }
748*a2673d88SMatthias Ringwald     return (avrcp_browsing_connection_t *) buffer;
749f12a3722SMilanka Ringwald }
750f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
751f12a3722SMilanka Ringwald     free(avrcp_browsing_connection);
752f12a3722SMilanka Ringwald }
753f12a3722SMilanka Ringwald #endif
754f12a3722SMilanka Ringwald 
755f12a3722SMilanka Ringwald 
756a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
7572e97c149S[email protected] 
7582e97c149S[email protected] // MARK: gatt_client_t
759a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
760a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
76127faf85aSMilanka 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."
762a265b909SMatthias Ringwald     #else
763a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
764a265b909SMatthias Ringwald     #endif
765a265b909SMatthias Ringwald #endif
766a265b909SMatthias Ringwald 
767a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
768a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
769a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
77029d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
771d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
772*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
773*a2673d88SMatthias Ringwald     if (buffer){
774*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
775*a2673d88SMatthias Ringwald     }
776*a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
777d0fdae3cS[email protected] }
778d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
77929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
780d0fdae3cS[email protected] }
781d0fdae3cS[email protected] #else
782d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
783d0fdae3cS[email protected]     return NULL;
784d0fdae3cS[email protected] }
785d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
7866f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
7876f7ecb09S[email protected]     (void) gatt_client;
788d0fdae3cS[email protected] };
789d0fdae3cS[email protected] #endif
790d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
791d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
792*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(gatt_client_t));
793*a2673d88SMatthias Ringwald     if (buffer){
794*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(gatt_client_t));
795*a2673d88SMatthias Ringwald     }
796*a2673d88SMatthias Ringwald     return (gatt_client_t *) buffer;
797d0fdae3cS[email protected] }
798d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
799d0fdae3cS[email protected]     free(gatt_client);
800d0fdae3cS[email protected] }
801d0fdae3cS[email protected] #endif
8022e97c149S[email protected] 
8032e97c149S[email protected] 
804656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
805a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
806a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
80727faf85aSMilanka 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."
808a265b909SMatthias Ringwald     #else
809a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
810a265b909SMatthias Ringwald     #endif
811a265b909SMatthias Ringwald #endif
812a265b909SMatthias Ringwald 
813a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
814a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
815a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
81629d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
817656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
818*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
819*a2673d88SMatthias Ringwald     if (buffer){
820*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
821*a2673d88SMatthias Ringwald     }
822*a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
823656bec4fSMatthias Ringwald }
824656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
82529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
826656bec4fSMatthias Ringwald }
827656bec4fSMatthias Ringwald #else
828656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
829656bec4fSMatthias Ringwald     return NULL;
830656bec4fSMatthias Ringwald }
831656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
832656bec4fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
833656bec4fSMatthias Ringwald     (void) whitelist_entry;
834656bec4fSMatthias Ringwald };
835656bec4fSMatthias Ringwald #endif
836656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
837656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
838*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(whitelist_entry_t));
839*a2673d88SMatthias Ringwald     if (buffer){
840*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(whitelist_entry_t));
841*a2673d88SMatthias Ringwald     }
842*a2673d88SMatthias Ringwald     return (whitelist_entry_t *) buffer;
843656bec4fSMatthias Ringwald }
844656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
845656bec4fSMatthias Ringwald     free(whitelist_entry);
846656bec4fSMatthias Ringwald }
847656bec4fSMatthias Ringwald #endif
848656bec4fSMatthias Ringwald 
849656bec4fSMatthias Ringwald 
850cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
851a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
852a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
85327faf85aSMilanka 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."
854a265b909SMatthias Ringwald     #else
855a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
856a265b909SMatthias Ringwald     #endif
857a265b909SMatthias Ringwald #endif
858a265b909SMatthias Ringwald 
859a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
860a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
861a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
86229d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
863cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
864*a2673d88SMatthias Ringwald     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
865*a2673d88SMatthias Ringwald     if (buffer){
866*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
867*a2673d88SMatthias Ringwald     }
868*a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
869cf49570bSMatthias Ringwald }
870cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
87129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
872cf49570bSMatthias Ringwald }
873cf49570bSMatthias Ringwald #else
874cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
875cf49570bSMatthias Ringwald     return NULL;
876cf49570bSMatthias Ringwald }
877cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
878cf49570bSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
879cf49570bSMatthias Ringwald     (void) sm_lookup_entry;
880cf49570bSMatthias Ringwald };
881cf49570bSMatthias Ringwald #endif
882cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
883cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
884*a2673d88SMatthias Ringwald     void * buffer = malloc(sizeof(sm_lookup_entry_t));
885*a2673d88SMatthias Ringwald     if (buffer){
886*a2673d88SMatthias Ringwald         memset(buffer, 0, sizeof(sm_lookup_entry_t));
887*a2673d88SMatthias Ringwald     }
888*a2673d88SMatthias Ringwald     return (sm_lookup_entry_t *) buffer;
889cf49570bSMatthias Ringwald }
890cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
891cf49570bSMatthias Ringwald     free(sm_lookup_entry);
892cf49570bSMatthias Ringwald }
893cf49570bSMatthias Ringwald #endif
894cf49570bSMatthias Ringwald 
895cf49570bSMatthias Ringwald 
8962e97c149S[email protected] #endif
897a3b02b71Smatthias.ringwald // init
898a3b02b71Smatthias.ringwald void btstack_memory_init(void){
899a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
900a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
901a3b02b71Smatthias.ringwald #endif
902a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
903a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
904a3b02b71Smatthias.ringwald #endif
905a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
906a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
907a3b02b71Smatthias.ringwald #endif
908a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
909a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
910a3b02b71Smatthias.ringwald #endif
911a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
912a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
913a3b02b71Smatthias.ringwald #endif
914a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
915a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
916a3b02b71Smatthias.ringwald #endif
917a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
918a265b909SMatthias 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));
9191801b596Smatthias.ringwald #endif
920a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
921a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
9222e97c149S[email protected] #endif
923a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
924a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
9252e97c149S[email protected] #endif
926a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
927a265b909SMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
928ea5029c9SMilanka Ringwald #endif
929a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
930a265b909SMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
931cd9ee144SMatthias Ringwald #endif
9320e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
9330e826a17SMilanka Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
93427faf85aSMilanka Ringwald #endif
93512e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
93612e7f38cSMilanka Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
93712e7f38cSMilanka Ringwald #endif
93891451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
93991451a2bSMilanka Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
94091451a2bSMilanka Ringwald #endif
941f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
942f12a3722SMilanka Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
943f12a3722SMilanka Ringwald #endif
944a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
945a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
946a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
947d0fdae3cS[email protected] #endif
948a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
949a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
950656bec4fSMatthias Ringwald #endif
951a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
952a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
953cf49570bSMatthias Ringwald #endif
954a7d12effS[email protected] #endif
955a3b02b71Smatthias.ringwald }
956