xref: /btstack/src/btstack_memory.c (revision 91451a2b33bbb7b067a04097fdeda004573ed67e)
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 
557*91451a2bSMilanka Ringwald 
558*91451a2bSMilanka Ringwald // MARK: avrcp_connection_t
559*91451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
560*91451a2bSMilanka Ringwald     #if defined(MAX_NO_AVRCP_CONNECTIONS)
561*91451a2bSMilanka 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."
562*91451a2bSMilanka Ringwald     #else
563*91451a2bSMilanka Ringwald         #define MAX_NR_AVRCP_CONNECTIONS 0
564*91451a2bSMilanka Ringwald     #endif
565*91451a2bSMilanka Ringwald #endif
566*91451a2bSMilanka Ringwald 
567*91451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
568*91451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
569*91451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
570*91451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool;
571*91451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
572*91451a2bSMilanka Ringwald     return (avrcp_connection_t *) btstack_memory_pool_get(&avrcp_connection_pool);
573*91451a2bSMilanka Ringwald }
574*91451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
575*91451a2bSMilanka Ringwald     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
576*91451a2bSMilanka Ringwald }
577*91451a2bSMilanka Ringwald #else
578*91451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
579*91451a2bSMilanka Ringwald     return NULL;
580*91451a2bSMilanka Ringwald }
581*91451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
582*91451a2bSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
583*91451a2bSMilanka Ringwald     (void) avrcp_connection;
584*91451a2bSMilanka Ringwald };
585*91451a2bSMilanka Ringwald #endif
586*91451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC)
587*91451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
588*91451a2bSMilanka Ringwald     return (avrcp_connection_t*) malloc(sizeof(avrcp_connection_t));
589*91451a2bSMilanka Ringwald }
590*91451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
591*91451a2bSMilanka Ringwald     free(avrcp_connection);
592*91451a2bSMilanka Ringwald }
593*91451a2bSMilanka Ringwald #endif
594*91451a2bSMilanka Ringwald 
595*91451a2bSMilanka Ringwald 
596a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
5972e97c149S[email protected] 
5982e97c149S[email protected] // MARK: gatt_client_t
599a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
600a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
60127faf85aSMilanka 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."
602a265b909SMatthias Ringwald     #else
603a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
604a265b909SMatthias Ringwald     #endif
605a265b909SMatthias Ringwald #endif
606a265b909SMatthias Ringwald 
607a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
608a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
609a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
61029d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
611d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
61229d0c4f7SMatthias Ringwald     return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool);
613d0fdae3cS[email protected] }
614d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
61529d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
616d0fdae3cS[email protected] }
617d0fdae3cS[email protected] #else
618d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
619d0fdae3cS[email protected]     return NULL;
620d0fdae3cS[email protected] }
621d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
6226f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
6236f7ecb09S[email protected]     (void) gatt_client;
624d0fdae3cS[email protected] };
625d0fdae3cS[email protected] #endif
626d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
627d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
628d0fdae3cS[email protected]     return (gatt_client_t*) malloc(sizeof(gatt_client_t));
629d0fdae3cS[email protected] }
630d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
631d0fdae3cS[email protected]     free(gatt_client);
632d0fdae3cS[email protected] }
633d0fdae3cS[email protected] #endif
6342e97c149S[email protected] 
6352e97c149S[email protected] 
636656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
637a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
638a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
63927faf85aSMilanka 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."
640a265b909SMatthias Ringwald     #else
641a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
642a265b909SMatthias Ringwald     #endif
643a265b909SMatthias Ringwald #endif
644a265b909SMatthias Ringwald 
645a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
646a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
647a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
64829d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
649656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
65029d0c4f7SMatthias Ringwald     return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool);
651656bec4fSMatthias Ringwald }
652656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
65329d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
654656bec4fSMatthias Ringwald }
655656bec4fSMatthias Ringwald #else
656656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
657656bec4fSMatthias Ringwald     return NULL;
658656bec4fSMatthias Ringwald }
659656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
660656bec4fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
661656bec4fSMatthias Ringwald     (void) whitelist_entry;
662656bec4fSMatthias Ringwald };
663656bec4fSMatthias Ringwald #endif
664656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
665656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
666656bec4fSMatthias Ringwald     return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t));
667656bec4fSMatthias Ringwald }
668656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
669656bec4fSMatthias Ringwald     free(whitelist_entry);
670656bec4fSMatthias Ringwald }
671656bec4fSMatthias Ringwald #endif
672656bec4fSMatthias Ringwald 
673656bec4fSMatthias Ringwald 
674cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
675a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
676a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
67727faf85aSMilanka 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."
678a265b909SMatthias Ringwald     #else
679a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
680a265b909SMatthias Ringwald     #endif
681a265b909SMatthias Ringwald #endif
682a265b909SMatthias Ringwald 
683a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
684a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
685a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
68629d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
687cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
68829d0c4f7SMatthias Ringwald     return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool);
689cf49570bSMatthias Ringwald }
690cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
69129d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
692cf49570bSMatthias Ringwald }
693cf49570bSMatthias Ringwald #else
694cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
695cf49570bSMatthias Ringwald     return NULL;
696cf49570bSMatthias Ringwald }
697cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
698cf49570bSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
699cf49570bSMatthias Ringwald     (void) sm_lookup_entry;
700cf49570bSMatthias Ringwald };
701cf49570bSMatthias Ringwald #endif
702cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
703cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
704cf49570bSMatthias Ringwald     return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t));
705cf49570bSMatthias Ringwald }
706cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
707cf49570bSMatthias Ringwald     free(sm_lookup_entry);
708cf49570bSMatthias Ringwald }
709cf49570bSMatthias Ringwald #endif
710cf49570bSMatthias Ringwald 
711cf49570bSMatthias Ringwald 
7122e97c149S[email protected] #endif
713a3b02b71Smatthias.ringwald // init
714a3b02b71Smatthias.ringwald void btstack_memory_init(void){
715a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
716a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
717a3b02b71Smatthias.ringwald #endif
718a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
719a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
720a3b02b71Smatthias.ringwald #endif
721a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
722a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
723a3b02b71Smatthias.ringwald #endif
724a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
725a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
726a3b02b71Smatthias.ringwald #endif
727a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
728a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
729a3b02b71Smatthias.ringwald #endif
730a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
731a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
732a3b02b71Smatthias.ringwald #endif
733a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
734a265b909SMatthias 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));
7351801b596Smatthias.ringwald #endif
736a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
737a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
7382e97c149S[email protected] #endif
739a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
740a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
7412e97c149S[email protected] #endif
742a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
743a265b909SMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
744ea5029c9SMilanka Ringwald #endif
745a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
746a265b909SMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
747cd9ee144SMatthias Ringwald #endif
7480e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
7490e826a17SMilanka Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
75027faf85aSMilanka Ringwald #endif
75112e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
75212e7f38cSMilanka Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
75312e7f38cSMilanka Ringwald #endif
754*91451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0
755*91451a2bSMilanka Ringwald     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
756*91451a2bSMilanka Ringwald #endif
757a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
758a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
759a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
760d0fdae3cS[email protected] #endif
761a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
762a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
763656bec4fSMatthias Ringwald #endif
764a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
765a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
766cf49570bSMatthias Ringwald #endif
767a7d12effS[email protected] #endif
768a3b02b71Smatthias.ringwald }
769