xref: /btstack/src/btstack_memory.c (revision f12a3722fc85b5ee7c999fffc84d872d20325944)
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
45a3b02b71Smatthias.ringwald  *
46a3b02b71Smatthias.ringwald  */
47a3b02b71Smatthias.ringwald 
48a3b02b71Smatthias.ringwald #include "btstack_memory.h"
49d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h"
50a3b02b71Smatthias.ringwald 
51a3b02b71Smatthias.ringwald #include <stdlib.h>
52a3b02b71Smatthias.ringwald 
53a3b02b71Smatthias.ringwald 
542e97c149S[email protected] 
55a3b02b71Smatthias.ringwald // MARK: hci_connection_t
56a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
57a265b909SMatthias Ringwald     #if defined(MAX_NO_HCI_CONNECTIONS)
5827faf85aSMilanka 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."
59a265b909SMatthias Ringwald     #else
60a265b909SMatthias Ringwald         #define MAX_NR_HCI_CONNECTIONS 0
61a265b909SMatthias Ringwald     #endif
62a265b909SMatthias Ringwald #endif
63a265b909SMatthias Ringwald 
64a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
65a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
66a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
6729d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool;
686527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
6929d0c4f7SMatthias Ringwald     return (hci_connection_t *) btstack_memory_pool_get(&hci_connection_pool);
70a3b02b71Smatthias.ringwald }
716527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
7229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
73a3b02b71Smatthias.ringwald }
74c4d3f927Smatthias.ringwald #else
756527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
76c4d3f927Smatthias.ringwald     return NULL;
77c4d3f927Smatthias.ringwald }
786527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
796f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
802e97c149S[email protected]     (void) hci_connection;
81c4d3f927Smatthias.ringwald };
82c4d3f927Smatthias.ringwald #endif
83a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
846527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
856527a633S[email protected]     return (hci_connection_t*) malloc(sizeof(hci_connection_t));
86a3b02b71Smatthias.ringwald }
876527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
88a3b02b71Smatthias.ringwald     free(hci_connection);
89a3b02b71Smatthias.ringwald }
90a3b02b71Smatthias.ringwald #endif
91a3b02b71Smatthias.ringwald 
92a3b02b71Smatthias.ringwald 
932e97c149S[email protected] 
94a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
95a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
96a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_SERVICES)
9727faf85aSMilanka 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."
98a265b909SMatthias Ringwald     #else
99a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_SERVICES 0
100a265b909SMatthias Ringwald     #endif
101a265b909SMatthias Ringwald #endif
102a265b909SMatthias Ringwald 
103a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
104a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
105a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
10629d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool;
1076527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
10829d0c4f7SMatthias Ringwald     return (l2cap_service_t *) btstack_memory_pool_get(&l2cap_service_pool);
109a3b02b71Smatthias.ringwald }
1106527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
11129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
112a3b02b71Smatthias.ringwald }
113c4d3f927Smatthias.ringwald #else
1146527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
115c4d3f927Smatthias.ringwald     return NULL;
116c4d3f927Smatthias.ringwald }
1176527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
1186f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1196f7ecb09S[email protected]     (void) l2cap_service;
120c4d3f927Smatthias.ringwald };
121c4d3f927Smatthias.ringwald #endif
122a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1236527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
1246527a633S[email protected]     return (l2cap_service_t*) malloc(sizeof(l2cap_service_t));
125a3b02b71Smatthias.ringwald }
1266527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
127a3b02b71Smatthias.ringwald     free(l2cap_service);
128a3b02b71Smatthias.ringwald }
129a3b02b71Smatthias.ringwald #endif
130a3b02b71Smatthias.ringwald 
131a3b02b71Smatthias.ringwald 
132a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
133a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
134a265b909SMatthias Ringwald     #if defined(MAX_NO_L2CAP_CHANNELS)
13527faf85aSMilanka 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."
136a265b909SMatthias Ringwald     #else
137a265b909SMatthias Ringwald         #define MAX_NR_L2CAP_CHANNELS 0
138a265b909SMatthias Ringwald     #endif
139a265b909SMatthias Ringwald #endif
140a265b909SMatthias Ringwald 
141a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
142a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
143a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
14429d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool;
1456527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
14629d0c4f7SMatthias Ringwald     return (l2cap_channel_t *) btstack_memory_pool_get(&l2cap_channel_pool);
147a3b02b71Smatthias.ringwald }
1486527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
14929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
150a3b02b71Smatthias.ringwald }
151c4d3f927Smatthias.ringwald #else
1526527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
153c4d3f927Smatthias.ringwald     return NULL;
154c4d3f927Smatthias.ringwald }
1556527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
1566f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1576f7ecb09S[email protected]     (void) l2cap_channel;
158c4d3f927Smatthias.ringwald };
159c4d3f927Smatthias.ringwald #endif
160a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1616527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
1626527a633S[email protected]     return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t));
163a3b02b71Smatthias.ringwald }
1646527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
165a3b02b71Smatthias.ringwald     free(l2cap_channel);
166a3b02b71Smatthias.ringwald }
167a3b02b71Smatthias.ringwald #endif
168a3b02b71Smatthias.ringwald 
169a3b02b71Smatthias.ringwald 
1702e97c149S[email protected] 
171a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
172a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
173a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
17427faf85aSMilanka 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."
175a265b909SMatthias Ringwald     #else
176a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
177a265b909SMatthias Ringwald     #endif
178a265b909SMatthias Ringwald #endif
179a265b909SMatthias Ringwald 
180a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
181a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
182a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
18329d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool;
1846527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
18529d0c4f7SMatthias Ringwald     return (rfcomm_multiplexer_t *) btstack_memory_pool_get(&rfcomm_multiplexer_pool);
186a3b02b71Smatthias.ringwald }
1876527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
18829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
189a3b02b71Smatthias.ringwald }
190c4d3f927Smatthias.ringwald #else
1916527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
192c4d3f927Smatthias.ringwald     return NULL;
193c4d3f927Smatthias.ringwald }
1946527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
1956f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1966f7ecb09S[email protected]     (void) rfcomm_multiplexer;
197c4d3f927Smatthias.ringwald };
198c4d3f927Smatthias.ringwald #endif
199a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2006527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
2016527a633S[email protected]     return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t));
202a3b02b71Smatthias.ringwald }
2036527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
204a3b02b71Smatthias.ringwald     free(rfcomm_multiplexer);
205a3b02b71Smatthias.ringwald }
206a3b02b71Smatthias.ringwald #endif
207a3b02b71Smatthias.ringwald 
208a3b02b71Smatthias.ringwald 
209a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
210a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
211a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_SERVICES)
21227faf85aSMilanka 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."
213a265b909SMatthias Ringwald     #else
214a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_SERVICES 0
215a265b909SMatthias Ringwald     #endif
216a265b909SMatthias Ringwald #endif
217a265b909SMatthias Ringwald 
218a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
219a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
220a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
22129d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool;
2226527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
22329d0c4f7SMatthias Ringwald     return (rfcomm_service_t *) btstack_memory_pool_get(&rfcomm_service_pool);
224a3b02b71Smatthias.ringwald }
2256527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
22629d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
227a3b02b71Smatthias.ringwald }
228c4d3f927Smatthias.ringwald #else
2296527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
230c4d3f927Smatthias.ringwald     return NULL;
231c4d3f927Smatthias.ringwald }
2326527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
2336f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2346f7ecb09S[email protected]     (void) rfcomm_service;
235c4d3f927Smatthias.ringwald };
236c4d3f927Smatthias.ringwald #endif
237a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2386527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
2396527a633S[email protected]     return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t));
240a3b02b71Smatthias.ringwald }
2416527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
242a3b02b71Smatthias.ringwald     free(rfcomm_service);
243a3b02b71Smatthias.ringwald }
244a3b02b71Smatthias.ringwald #endif
245a3b02b71Smatthias.ringwald 
246a3b02b71Smatthias.ringwald 
247a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
248a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
249a265b909SMatthias Ringwald     #if defined(MAX_NO_RFCOMM_CHANNELS)
25027faf85aSMilanka 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."
251a265b909SMatthias Ringwald     #else
252a265b909SMatthias Ringwald         #define MAX_NR_RFCOMM_CHANNELS 0
253a265b909SMatthias Ringwald     #endif
254a265b909SMatthias Ringwald #endif
255a265b909SMatthias Ringwald 
256a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
257a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
258a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
25929d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool;
2606527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
26129d0c4f7SMatthias Ringwald     return (rfcomm_channel_t *) btstack_memory_pool_get(&rfcomm_channel_pool);
262a3b02b71Smatthias.ringwald }
2636527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
26429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
265a3b02b71Smatthias.ringwald }
266c4d3f927Smatthias.ringwald #else
2676527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
268c4d3f927Smatthias.ringwald     return NULL;
269c4d3f927Smatthias.ringwald }
2706527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
2716f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2726f7ecb09S[email protected]     (void) rfcomm_channel;
273c4d3f927Smatthias.ringwald };
274c4d3f927Smatthias.ringwald #endif
275a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2766527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
2776527a633S[email protected]     return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t));
278a3b02b71Smatthias.ringwald }
2796527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
280a3b02b71Smatthias.ringwald     free(rfcomm_channel);
281a3b02b71Smatthias.ringwald }
282a3b02b71Smatthias.ringwald #endif
283a3b02b71Smatthias.ringwald 
284fdb398c2S[email protected] 
285e0e5e285Smatthias.ringwald 
2862c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t
287a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
288a265b909SMatthias Ringwald     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
28927faf85aSMilanka 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."
290a265b909SMatthias Ringwald     #else
291a265b909SMatthias Ringwald         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
292a265b909SMatthias Ringwald     #endif
293a265b909SMatthias Ringwald #endif
294a265b909SMatthias Ringwald 
295a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
296a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
297a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
2982c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
2992c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
3002c455dadSMatthias Ringwald     return (btstack_link_key_db_memory_entry_t *) btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
3011801b596Smatthias.ringwald }
3022c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3032c455dadSMatthias Ringwald     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
3041801b596Smatthias.ringwald }
305c4d3f927Smatthias.ringwald #else
3062c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
307c4d3f927Smatthias.ringwald     return NULL;
308c4d3f927Smatthias.ringwald }
3092c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3106f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3112c455dadSMatthias Ringwald     (void) btstack_link_key_db_memory_entry;
312c4d3f927Smatthias.ringwald };
313c4d3f927Smatthias.ringwald #endif
3141801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3152c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
3162c455dadSMatthias Ringwald     return (btstack_link_key_db_memory_entry_t*) malloc(sizeof(btstack_link_key_db_memory_entry_t));
3171801b596Smatthias.ringwald }
3182c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
3192c455dadSMatthias Ringwald     free(btstack_link_key_db_memory_entry);
320e0e5e285Smatthias.ringwald }
3211801b596Smatthias.ringwald #endif
3221801b596Smatthias.ringwald 
3232e97c149S[email protected] 
3242e97c149S[email protected] 
3252e97c149S[email protected] // MARK: bnep_service_t
326a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
327a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_SERVICES)
32827faf85aSMilanka 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."
329a265b909SMatthias Ringwald     #else
330a265b909SMatthias Ringwald         #define MAX_NR_BNEP_SERVICES 0
331a265b909SMatthias Ringwald     #endif
332a265b909SMatthias Ringwald #endif
333a265b909SMatthias Ringwald 
334a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
335a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
336a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
33729d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool;
3382e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
33929d0c4f7SMatthias Ringwald     return (bnep_service_t *) btstack_memory_pool_get(&bnep_service_pool);
3402e97c149S[email protected] }
3412e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
34229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
3432e97c149S[email protected] }
3442e97c149S[email protected] #else
3452e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
3462e97c149S[email protected]     return NULL;
3472e97c149S[email protected] }
3482e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
3492e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
3502e97c149S[email protected]     (void) bnep_service;
3512e97c149S[email protected] };
3522e97c149S[email protected] #endif
3532e97c149S[email protected] #elif defined(HAVE_MALLOC)
3542e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
3552e97c149S[email protected]     return (bnep_service_t*) malloc(sizeof(bnep_service_t));
3562e97c149S[email protected] }
3572e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
3582e97c149S[email protected]     free(bnep_service);
3592e97c149S[email protected] }
3602e97c149S[email protected] #endif
3612e97c149S[email protected] 
3622e97c149S[email protected] 
3632e97c149S[email protected] // MARK: bnep_channel_t
364a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
365a265b909SMatthias Ringwald     #if defined(MAX_NO_BNEP_CHANNELS)
36627faf85aSMilanka 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."
367a265b909SMatthias Ringwald     #else
368a265b909SMatthias Ringwald         #define MAX_NR_BNEP_CHANNELS 0
369a265b909SMatthias Ringwald     #endif
370a265b909SMatthias Ringwald #endif
371a265b909SMatthias Ringwald 
372a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
373a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
374a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
37529d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool;
3762e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
37729d0c4f7SMatthias Ringwald     return (bnep_channel_t *) btstack_memory_pool_get(&bnep_channel_pool);
3782e97c149S[email protected] }
3792e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
38029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
3812e97c149S[email protected] }
3822e97c149S[email protected] #else
3832e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
3842e97c149S[email protected]     return NULL;
3852e97c149S[email protected] }
3862e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
3872e97c149S[email protected]     // silence compiler warning about unused parameter in a portable way
3882e97c149S[email protected]     (void) bnep_channel;
3892e97c149S[email protected] };
3902e97c149S[email protected] #endif
3912e97c149S[email protected] #elif defined(HAVE_MALLOC)
3922e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
3932e97c149S[email protected]     return (bnep_channel_t*) malloc(sizeof(bnep_channel_t));
3942e97c149S[email protected] }
3952e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
3962e97c149S[email protected]     free(bnep_channel);
3972e97c149S[email protected] }
3982e97c149S[email protected] #endif
3992e97c149S[email protected] 
4002e97c149S[email protected] 
401ea5029c9SMilanka Ringwald 
402ea5029c9SMilanka Ringwald // MARK: hfp_connection_t
403a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
404a265b909SMatthias Ringwald     #if defined(MAX_NO_HFP_CONNECTIONS)
40527faf85aSMilanka 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."
406a265b909SMatthias Ringwald     #else
407a265b909SMatthias Ringwald         #define MAX_NR_HFP_CONNECTIONS 0
408a265b909SMatthias Ringwald     #endif
409a265b909SMatthias Ringwald #endif
410a265b909SMatthias Ringwald 
411a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
412a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
413a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
41429d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool;
415ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
41629d0c4f7SMatthias Ringwald     return (hfp_connection_t *) btstack_memory_pool_get(&hfp_connection_pool);
417ea5029c9SMilanka Ringwald }
418ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
41929d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
420ea5029c9SMilanka Ringwald }
421ea5029c9SMilanka Ringwald #else
422ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
423ea5029c9SMilanka Ringwald     return NULL;
424ea5029c9SMilanka Ringwald }
425ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
426ea5029c9SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
427ea5029c9SMilanka Ringwald     (void) hfp_connection;
428ea5029c9SMilanka Ringwald };
429ea5029c9SMilanka Ringwald #endif
430ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC)
431ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){
432ea5029c9SMilanka Ringwald     return (hfp_connection_t*) malloc(sizeof(hfp_connection_t));
433ea5029c9SMilanka Ringwald }
434ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
435ea5029c9SMilanka Ringwald     free(hfp_connection);
436ea5029c9SMilanka Ringwald }
437ea5029c9SMilanka Ringwald #endif
438ea5029c9SMilanka Ringwald 
439ea5029c9SMilanka Ringwald 
440cd9ee144SMatthias Ringwald 
441cd9ee144SMatthias Ringwald // MARK: service_record_item_t
442a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
443a265b909SMatthias Ringwald     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
44427faf85aSMilanka 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."
445a265b909SMatthias Ringwald     #else
446a265b909SMatthias Ringwald         #define MAX_NR_SERVICE_RECORD_ITEMS 0
447a265b909SMatthias Ringwald     #endif
448a265b909SMatthias Ringwald #endif
449a265b909SMatthias Ringwald 
450a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
451a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
452a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
45329d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool;
454cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
45529d0c4f7SMatthias Ringwald     return (service_record_item_t *) btstack_memory_pool_get(&service_record_item_pool);
456cd9ee144SMatthias Ringwald }
457cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
45829d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
459cd9ee144SMatthias Ringwald }
460cd9ee144SMatthias Ringwald #else
461cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
462cd9ee144SMatthias Ringwald     return NULL;
463cd9ee144SMatthias Ringwald }
464cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
465cd9ee144SMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
466cd9ee144SMatthias Ringwald     (void) service_record_item;
467cd9ee144SMatthias Ringwald };
468cd9ee144SMatthias Ringwald #endif
469cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC)
470cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){
471cd9ee144SMatthias Ringwald     return (service_record_item_t*) malloc(sizeof(service_record_item_t));
472cd9ee144SMatthias Ringwald }
473cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
474cd9ee144SMatthias Ringwald     free(service_record_item);
475cd9ee144SMatthias Ringwald }
476cd9ee144SMatthias Ringwald #endif
477cd9ee144SMatthias Ringwald 
478cd9ee144SMatthias Ringwald 
47927faf85aSMilanka Ringwald 
4800e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t
4810e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
4820e826a17SMilanka Ringwald     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
4830e826a17SMilanka 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."
48427faf85aSMilanka Ringwald     #else
4850e826a17SMilanka Ringwald         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
48627faf85aSMilanka Ringwald     #endif
48727faf85aSMilanka Ringwald #endif
48827faf85aSMilanka Ringwald 
4890e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
4900e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
4910e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
4920e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool;
4930e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
4940e826a17SMilanka Ringwald     return (avdtp_stream_endpoint_t *) btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
49527faf85aSMilanka Ringwald }
4960e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
4970e826a17SMilanka Ringwald     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
49827faf85aSMilanka Ringwald }
49927faf85aSMilanka Ringwald #else
5000e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
50127faf85aSMilanka Ringwald     return NULL;
50227faf85aSMilanka Ringwald }
5030e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
50427faf85aSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
5050e826a17SMilanka Ringwald     (void) avdtp_stream_endpoint;
50627faf85aSMilanka Ringwald };
50727faf85aSMilanka Ringwald #endif
50827faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC)
5090e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
5100e826a17SMilanka Ringwald     return (avdtp_stream_endpoint_t*) malloc(sizeof(avdtp_stream_endpoint_t));
51127faf85aSMilanka Ringwald }
5120e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
5130e826a17SMilanka Ringwald     free(avdtp_stream_endpoint);
51427faf85aSMilanka Ringwald }
51527faf85aSMilanka Ringwald #endif
51627faf85aSMilanka Ringwald 
51727faf85aSMilanka Ringwald 
51812e7f38cSMilanka Ringwald 
51912e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
52012e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
52112e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
52212e7f38cSMilanka 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."
52312e7f38cSMilanka Ringwald     #else
52412e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
52512e7f38cSMilanka Ringwald     #endif
52612e7f38cSMilanka Ringwald #endif
52712e7f38cSMilanka Ringwald 
52812e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
52912e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
53012e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
53112e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
53212e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
53312e7f38cSMilanka Ringwald     return (avdtp_connection_t *) btstack_memory_pool_get(&avdtp_connection_pool);
53412e7f38cSMilanka Ringwald }
53512e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
53612e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
53712e7f38cSMilanka Ringwald }
53812e7f38cSMilanka Ringwald #else
53912e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
54012e7f38cSMilanka Ringwald     return NULL;
54112e7f38cSMilanka Ringwald }
54212e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
54312e7f38cSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
54412e7f38cSMilanka Ringwald     (void) avdtp_connection;
54512e7f38cSMilanka Ringwald };
54612e7f38cSMilanka Ringwald #endif
54712e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
54812e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
54912e7f38cSMilanka Ringwald     return (avdtp_connection_t*) malloc(sizeof(avdtp_connection_t));
55012e7f38cSMilanka Ringwald }
55112e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
55212e7f38cSMilanka Ringwald     free(avdtp_connection);
55312e7f38cSMilanka Ringwald }
55412e7f38cSMilanka Ringwald #endif
55512e7f38cSMilanka Ringwald 
55612e7f38cSMilanka Ringwald 
55791451a2bSMilanka Ringwald 
55891451a2bSMilanka Ringwald // MARK: avrcp_connection_t
55991451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
56091451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
56191451a2bSMilanka 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."
56291451a2bSMilanka Ringwald     #else
56391451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
56491451a2bSMilanka Ringwald     #endif
56591451a2bSMilanka Ringwald #endif
56691451a2bSMilanka Ringwald 
56791451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
56891451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
56991451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
57091451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
57191451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
57291451a2bSMilanka Ringwald     return (avrcp_connection_t *) btstack_memory_pool_get(&avrcp_connection_pool);
57391451a2bSMilanka Ringwald }
57491451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
57591451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
57691451a2bSMilanka Ringwald }
57791451a2bSMilanka Ringwald #else
57891451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
57991451a2bSMilanka Ringwald     return NULL;
58091451a2bSMilanka Ringwald }
58191451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
58291451a2bSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
58391451a2bSMilanka Ringwald     (void) avrcp_connection;
58491451a2bSMilanka Ringwald };
58591451a2bSMilanka Ringwald #endif
58691451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
58791451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
58891451a2bSMilanka Ringwald     return (avrcp_connection_t*) malloc(sizeof(avrcp_connection_t));
58991451a2bSMilanka Ringwald }
59091451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
59191451a2bSMilanka Ringwald     free(avrcp_connection);
59291451a2bSMilanka Ringwald }
59391451a2bSMilanka Ringwald #endif
59491451a2bSMilanka Ringwald 
59591451a2bSMilanka Ringwald 
596*f12a3722SMilanka Ringwald 
597*f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t
598*f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
599*f12a3722SMilanka Ringwald     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
600*f12a3722SMilanka 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."
601*f12a3722SMilanka Ringwald     #else
602*f12a3722SMilanka Ringwald         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
603*f12a3722SMilanka Ringwald     #endif
604*f12a3722SMilanka Ringwald #endif
605*f12a3722SMilanka Ringwald 
606*f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
607*f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
608*f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
609*f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool;
610*f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
611*f12a3722SMilanka Ringwald     return (avrcp_browsing_connection_t *) btstack_memory_pool_get(&avrcp_browsing_connection_pool);
612*f12a3722SMilanka Ringwald }
613*f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
614*f12a3722SMilanka Ringwald     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
615*f12a3722SMilanka Ringwald }
616*f12a3722SMilanka Ringwald #else
617*f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
618*f12a3722SMilanka Ringwald     return NULL;
619*f12a3722SMilanka Ringwald }
620*f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
621*f12a3722SMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
622*f12a3722SMilanka Ringwald     (void) avrcp_browsing_connection;
623*f12a3722SMilanka Ringwald };
624*f12a3722SMilanka Ringwald #endif
625*f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC)
626*f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
627*f12a3722SMilanka Ringwald     return (avrcp_browsing_connection_t*) malloc(sizeof(avrcp_browsing_connection_t));
628*f12a3722SMilanka Ringwald }
629*f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
630*f12a3722SMilanka Ringwald     free(avrcp_browsing_connection);
631*f12a3722SMilanka Ringwald }
632*f12a3722SMilanka Ringwald #endif
633*f12a3722SMilanka Ringwald 
634*f12a3722SMilanka Ringwald 
635a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
6362e97c149S[email protected] 
6372e97c149S[email protected] // MARK: gatt_client_t
638a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
639a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
64027faf85aSMilanka 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."
641a265b909SMatthias Ringwald     #else
642a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
643a265b909SMatthias Ringwald     #endif
644a265b909SMatthias Ringwald #endif
645a265b909SMatthias Ringwald 
646a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
647a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
648a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
64929d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
650d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
65129d0c4f7SMatthias Ringwald     return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool);
652d0fdae3cS[email protected] }
653d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
65429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
655d0fdae3cS[email protected] }
656d0fdae3cS[email protected] #else
657d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
658d0fdae3cS[email protected]     return NULL;
659d0fdae3cS[email protected] }
660d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
6616f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
6626f7ecb09S[email protected]     (void) gatt_client;
663d0fdae3cS[email protected] };
664d0fdae3cS[email protected] #endif
665d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
666d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
667d0fdae3cS[email protected]     return (gatt_client_t*) malloc(sizeof(gatt_client_t));
668d0fdae3cS[email protected] }
669d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
670d0fdae3cS[email protected]     free(gatt_client);
671d0fdae3cS[email protected] }
672d0fdae3cS[email protected] #endif
6732e97c149S[email protected] 
6742e97c149S[email protected] 
675656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
676a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
677a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
67827faf85aSMilanka 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."
679a265b909SMatthias Ringwald     #else
680a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
681a265b909SMatthias Ringwald     #endif
682a265b909SMatthias Ringwald #endif
683a265b909SMatthias Ringwald 
684a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
685a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
686a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
68729d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
688656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
68929d0c4f7SMatthias Ringwald     return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool);
690656bec4fSMatthias Ringwald }
691656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
69229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
693656bec4fSMatthias Ringwald }
694656bec4fSMatthias Ringwald #else
695656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
696656bec4fSMatthias Ringwald     return NULL;
697656bec4fSMatthias Ringwald }
698656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
699656bec4fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
700656bec4fSMatthias Ringwald     (void) whitelist_entry;
701656bec4fSMatthias Ringwald };
702656bec4fSMatthias Ringwald #endif
703656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
704656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
705656bec4fSMatthias Ringwald     return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t));
706656bec4fSMatthias Ringwald }
707656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
708656bec4fSMatthias Ringwald     free(whitelist_entry);
709656bec4fSMatthias Ringwald }
710656bec4fSMatthias Ringwald #endif
711656bec4fSMatthias Ringwald 
712656bec4fSMatthias Ringwald 
713cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
714a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
715a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
71627faf85aSMilanka 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."
717a265b909SMatthias Ringwald     #else
718a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
719a265b909SMatthias Ringwald     #endif
720a265b909SMatthias Ringwald #endif
721a265b909SMatthias Ringwald 
722a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
723a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
724a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
72529d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
726cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
72729d0c4f7SMatthias Ringwald     return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool);
728cf49570bSMatthias Ringwald }
729cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
73029d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
731cf49570bSMatthias Ringwald }
732cf49570bSMatthias Ringwald #else
733cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
734cf49570bSMatthias Ringwald     return NULL;
735cf49570bSMatthias Ringwald }
736cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
737cf49570bSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
738cf49570bSMatthias Ringwald     (void) sm_lookup_entry;
739cf49570bSMatthias Ringwald };
740cf49570bSMatthias Ringwald #endif
741cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
742cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
743cf49570bSMatthias Ringwald     return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t));
744cf49570bSMatthias Ringwald }
745cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
746cf49570bSMatthias Ringwald     free(sm_lookup_entry);
747cf49570bSMatthias Ringwald }
748cf49570bSMatthias Ringwald #endif
749cf49570bSMatthias Ringwald 
750cf49570bSMatthias Ringwald 
7512e97c149S[email protected] #endif
752a3b02b71Smatthias.ringwald // init
753a3b02b71Smatthias.ringwald void btstack_memory_init(void){
754a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
755a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
756a3b02b71Smatthias.ringwald #endif
757a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
758a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
759a3b02b71Smatthias.ringwald #endif
760a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
761a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
762a3b02b71Smatthias.ringwald #endif
763a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
764a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
765a3b02b71Smatthias.ringwald #endif
766a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
767a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
768a3b02b71Smatthias.ringwald #endif
769a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
770a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
771a3b02b71Smatthias.ringwald #endif
772a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
773a265b909SMatthias 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));
7741801b596Smatthias.ringwald #endif
775a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
776a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
7772e97c149S[email protected] #endif
778a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
779a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
7802e97c149S[email protected] #endif
781a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
782a265b909SMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
783ea5029c9SMilanka Ringwald #endif
784a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
785a265b909SMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
786cd9ee144SMatthias Ringwald #endif
7870e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
7880e826a17SMilanka Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
78927faf85aSMilanka Ringwald #endif
79012e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
79112e7f38cSMilanka Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
79212e7f38cSMilanka Ringwald #endif
79391451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
79491451a2bSMilanka Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
79591451a2bSMilanka Ringwald #endif
796*f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
797*f12a3722SMilanka Ringwald     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
798*f12a3722SMilanka Ringwald #endif
799a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
800a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
801a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
802d0fdae3cS[email protected] #endif
803a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
804a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
805656bec4fSMatthias Ringwald #endif
806a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
807a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
808cf49570bSMatthias Ringwald #endif
809a7d12effS[email protected] #endif
810a3b02b71Smatthias.ringwald }
811