xref: /btstack/src/btstack_memory.c (revision 12e7f38c5b9c78f7a94f5026e70b1acfa4802a24)
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 
518*12e7f38cSMilanka Ringwald 
519*12e7f38cSMilanka Ringwald // MARK: avdtp_connection_t
520*12e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
521*12e7f38cSMilanka Ringwald     #if defined(MAX_NO_AVDTP_CONNECTIONS)
522*12e7f38cSMilanka 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."
523*12e7f38cSMilanka Ringwald     #else
524*12e7f38cSMilanka Ringwald         #define MAX_NR_AVDTP_CONNECTIONS 0
525*12e7f38cSMilanka Ringwald     #endif
526*12e7f38cSMilanka Ringwald #endif
527*12e7f38cSMilanka Ringwald 
528*12e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
529*12e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
530*12e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
531*12e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool;
532*12e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
533*12e7f38cSMilanka Ringwald     return (avdtp_connection_t *) btstack_memory_pool_get(&avdtp_connection_pool);
534*12e7f38cSMilanka Ringwald }
535*12e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
536*12e7f38cSMilanka Ringwald     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
537*12e7f38cSMilanka Ringwald }
538*12e7f38cSMilanka Ringwald #else
539*12e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
540*12e7f38cSMilanka Ringwald     return NULL;
541*12e7f38cSMilanka Ringwald }
542*12e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
543*12e7f38cSMilanka Ringwald     // silence compiler warning about unused parameter in a portable way
544*12e7f38cSMilanka Ringwald     (void) avdtp_connection;
545*12e7f38cSMilanka Ringwald };
546*12e7f38cSMilanka Ringwald #endif
547*12e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC)
548*12e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
549*12e7f38cSMilanka Ringwald     return (avdtp_connection_t*) malloc(sizeof(avdtp_connection_t));
550*12e7f38cSMilanka Ringwald }
551*12e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
552*12e7f38cSMilanka Ringwald     free(avdtp_connection);
553*12e7f38cSMilanka Ringwald }
554*12e7f38cSMilanka Ringwald #endif
555*12e7f38cSMilanka Ringwald 
556*12e7f38cSMilanka Ringwald 
557a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
5582e97c149S[email protected] 
5592e97c149S[email protected] // MARK: gatt_client_t
560a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
561a265b909SMatthias Ringwald     #if defined(MAX_NO_GATT_CLIENTS)
56227faf85aSMilanka 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."
563a265b909SMatthias Ringwald     #else
564a265b909SMatthias Ringwald         #define MAX_NR_GATT_CLIENTS 0
565a265b909SMatthias Ringwald     #endif
566a265b909SMatthias Ringwald #endif
567a265b909SMatthias Ringwald 
568a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
569a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
570a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
57129d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool;
572d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
57329d0c4f7SMatthias Ringwald     return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool);
574d0fdae3cS[email protected] }
575d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
57629d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
577d0fdae3cS[email protected] }
578d0fdae3cS[email protected] #else
579d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
580d0fdae3cS[email protected]     return NULL;
581d0fdae3cS[email protected] }
582d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
5836f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
5846f7ecb09S[email protected]     (void) gatt_client;
585d0fdae3cS[email protected] };
586d0fdae3cS[email protected] #endif
587d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
588d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
589d0fdae3cS[email protected]     return (gatt_client_t*) malloc(sizeof(gatt_client_t));
590d0fdae3cS[email protected] }
591d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
592d0fdae3cS[email protected]     free(gatt_client);
593d0fdae3cS[email protected] }
594d0fdae3cS[email protected] #endif
5952e97c149S[email protected] 
5962e97c149S[email protected] 
597656bec4fSMatthias Ringwald // MARK: whitelist_entry_t
598a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
599a265b909SMatthias Ringwald     #if defined(MAX_NO_WHITELIST_ENTRIES)
60027faf85aSMilanka 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."
601a265b909SMatthias Ringwald     #else
602a265b909SMatthias Ringwald         #define MAX_NR_WHITELIST_ENTRIES 0
603a265b909SMatthias Ringwald     #endif
604a265b909SMatthias Ringwald #endif
605a265b909SMatthias Ringwald 
606a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
607a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
608a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
60929d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool;
610656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
61129d0c4f7SMatthias Ringwald     return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool);
612656bec4fSMatthias Ringwald }
613656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
61429d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
615656bec4fSMatthias Ringwald }
616656bec4fSMatthias Ringwald #else
617656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
618656bec4fSMatthias Ringwald     return NULL;
619656bec4fSMatthias Ringwald }
620656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
621656bec4fSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
622656bec4fSMatthias Ringwald     (void) whitelist_entry;
623656bec4fSMatthias Ringwald };
624656bec4fSMatthias Ringwald #endif
625656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC)
626656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
627656bec4fSMatthias Ringwald     return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t));
628656bec4fSMatthias Ringwald }
629656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
630656bec4fSMatthias Ringwald     free(whitelist_entry);
631656bec4fSMatthias Ringwald }
632656bec4fSMatthias Ringwald #endif
633656bec4fSMatthias Ringwald 
634656bec4fSMatthias Ringwald 
635cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t
636a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
637a265b909SMatthias Ringwald     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
63827faf85aSMilanka 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."
639a265b909SMatthias Ringwald     #else
640a265b909SMatthias Ringwald         #define MAX_NR_SM_LOOKUP_ENTRIES 0
641a265b909SMatthias Ringwald     #endif
642a265b909SMatthias Ringwald #endif
643a265b909SMatthias Ringwald 
644a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
645a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
646a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
64729d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool;
648cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
64929d0c4f7SMatthias Ringwald     return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool);
650cf49570bSMatthias Ringwald }
651cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
65229d0c4f7SMatthias Ringwald     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
653cf49570bSMatthias Ringwald }
654cf49570bSMatthias Ringwald #else
655cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
656cf49570bSMatthias Ringwald     return NULL;
657cf49570bSMatthias Ringwald }
658cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
659cf49570bSMatthias Ringwald     // silence compiler warning about unused parameter in a portable way
660cf49570bSMatthias Ringwald     (void) sm_lookup_entry;
661cf49570bSMatthias Ringwald };
662cf49570bSMatthias Ringwald #endif
663cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC)
664cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
665cf49570bSMatthias Ringwald     return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t));
666cf49570bSMatthias Ringwald }
667cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
668cf49570bSMatthias Ringwald     free(sm_lookup_entry);
669cf49570bSMatthias Ringwald }
670cf49570bSMatthias Ringwald #endif
671cf49570bSMatthias Ringwald 
672cf49570bSMatthias Ringwald 
6732e97c149S[email protected] #endif
674a3b02b71Smatthias.ringwald // init
675a3b02b71Smatthias.ringwald void btstack_memory_init(void){
676a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0
677a265b909SMatthias Ringwald     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
678a3b02b71Smatthias.ringwald #endif
679a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0
680a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
681a3b02b71Smatthias.ringwald #endif
682a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0
683a265b909SMatthias Ringwald     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
684a3b02b71Smatthias.ringwald #endif
685a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
686a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
687a3b02b71Smatthias.ringwald #endif
688a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0
689a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
690a3b02b71Smatthias.ringwald #endif
691a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0
692a265b909SMatthias Ringwald     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
693a3b02b71Smatthias.ringwald #endif
694a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
695a265b909SMatthias 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));
6961801b596Smatthias.ringwald #endif
697a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0
698a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
6992e97c149S[email protected] #endif
700a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0
701a265b909SMatthias Ringwald     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
7022e97c149S[email protected] #endif
703a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0
704a265b909SMatthias Ringwald     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
705ea5029c9SMilanka Ringwald #endif
706a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0
707a265b909SMatthias Ringwald     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
708cd9ee144SMatthias Ringwald #endif
7090e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
7100e826a17SMilanka Ringwald     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
71127faf85aSMilanka Ringwald #endif
712*12e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0
713*12e7f38cSMilanka Ringwald     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
714*12e7f38cSMilanka Ringwald #endif
715a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE
716a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0
717a265b909SMatthias Ringwald     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
718d0fdae3cS[email protected] #endif
719a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0
720a265b909SMatthias Ringwald     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
721656bec4fSMatthias Ringwald #endif
722a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0
723a265b909SMatthias Ringwald     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
724cf49570bSMatthias Ringwald #endif
725a7d12effS[email protected] #endif
726a3b02b71Smatthias.ringwald }
727