xref: /btstack/src/btstack_memory.c (revision fdb398c2d333d32dd9293f9d014bdb0811e3f5ae)
1a3b02b71Smatthias.ringwald /*
26b64433eSmatthias.ringwald  * Copyright (C) 2009-2012 by Matthias Ringwald
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  *
20a3b02b71Smatthias.ringwald  * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD 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  *
336b64433eSmatthias.ringwald  * Please inquire about commercial licensing options at [email protected]
346b64433eSmatthias.ringwald  *
35a3b02b71Smatthias.ringwald  */
36a3b02b71Smatthias.ringwald 
37a3b02b71Smatthias.ringwald /*
38a3b02b71Smatthias.ringwald  *  btstsack_memory.h
39a3b02b71Smatthias.ringwald  *
40a3b02b71Smatthias.ringwald  *  @brief BTstack memory management via configurable memory pools
41a3b02b71Smatthias.ringwald  *
426f7ecb09S[email protected]  *  @note code semi-atuomatically generated by tools/btstack_memory_generator.py
43a3b02b71Smatthias.ringwald  *
44a3b02b71Smatthias.ringwald  */
45a3b02b71Smatthias.ringwald 
46a3b02b71Smatthias.ringwald #include "btstack_memory.h"
47a3b02b71Smatthias.ringwald #include <btstack/memory_pool.h>
48a3b02b71Smatthias.ringwald 
49a3b02b71Smatthias.ringwald #include <stdlib.h>
50a3b02b71Smatthias.ringwald 
51bde315ceS[email protected] #include "btstack-config.h"
52a3b02b71Smatthias.ringwald #include "hci.h"
53a3b02b71Smatthias.ringwald #include "l2cap.h"
54a3b02b71Smatthias.ringwald #include "rfcomm.h"
55a3b02b71Smatthias.ringwald 
56a3b02b71Smatthias.ringwald // MARK: hci_connection_t
57a3b02b71Smatthias.ringwald #ifdef MAX_NO_HCI_CONNECTIONS
58c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0
59a3b02b71Smatthias.ringwald static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS];
60a3b02b71Smatthias.ringwald static memory_pool_t hci_connection_pool;
616527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
62a3b02b71Smatthias.ringwald     return memory_pool_get(&hci_connection_pool);
63a3b02b71Smatthias.ringwald }
646527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
65a3b02b71Smatthias.ringwald     memory_pool_free(&hci_connection_pool, hci_connection);
66a3b02b71Smatthias.ringwald }
67c4d3f927Smatthias.ringwald #else
686527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
69c4d3f927Smatthias.ringwald     return NULL;
70c4d3f927Smatthias.ringwald }
716527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
726f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
736f7ecb09S[email protected]     hci_connection;
74c4d3f927Smatthias.ringwald };
75c4d3f927Smatthias.ringwald #endif
76a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
776527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){
786527a633S[email protected]     return (hci_connection_t*) malloc(sizeof(hci_connection_t));
79a3b02b71Smatthias.ringwald }
806527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
81a3b02b71Smatthias.ringwald     free(hci_connection);
82a3b02b71Smatthias.ringwald }
83e045abdeSmatthias.ringwald #else
846527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS for struct hci_connection is defined. Please, edit the config file."
85a3b02b71Smatthias.ringwald #endif
86a3b02b71Smatthias.ringwald 
87a3b02b71Smatthias.ringwald 
88a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
89a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_SERVICES
90c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0
91a3b02b71Smatthias.ringwald static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES];
92a3b02b71Smatthias.ringwald static memory_pool_t l2cap_service_pool;
936527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
94a3b02b71Smatthias.ringwald     return memory_pool_get(&l2cap_service_pool);
95a3b02b71Smatthias.ringwald }
966527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
97a3b02b71Smatthias.ringwald     memory_pool_free(&l2cap_service_pool, l2cap_service);
98a3b02b71Smatthias.ringwald }
99c4d3f927Smatthias.ringwald #else
1006527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
101c4d3f927Smatthias.ringwald     return NULL;
102c4d3f927Smatthias.ringwald }
1036527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
1046f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1056f7ecb09S[email protected]     (void) l2cap_service;
106c4d3f927Smatthias.ringwald };
107c4d3f927Smatthias.ringwald #endif
108a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1096527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){
1106527a633S[email protected]     return (l2cap_service_t*) malloc(sizeof(l2cap_service_t));
111a3b02b71Smatthias.ringwald }
1126527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
113a3b02b71Smatthias.ringwald     free(l2cap_service);
114a3b02b71Smatthias.ringwald }
115e045abdeSmatthias.ringwald #else
1166527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES for struct l2cap_service is defined. Please, edit the config file."
117a3b02b71Smatthias.ringwald #endif
118a3b02b71Smatthias.ringwald 
119a3b02b71Smatthias.ringwald 
120a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
121a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_CHANNELS
122c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0
123a3b02b71Smatthias.ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS];
124a3b02b71Smatthias.ringwald static memory_pool_t l2cap_channel_pool;
1256527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
126a3b02b71Smatthias.ringwald     return memory_pool_get(&l2cap_channel_pool);
127a3b02b71Smatthias.ringwald }
1286527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
129a3b02b71Smatthias.ringwald     memory_pool_free(&l2cap_channel_pool, l2cap_channel);
130a3b02b71Smatthias.ringwald }
131c4d3f927Smatthias.ringwald #else
1326527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
133c4d3f927Smatthias.ringwald     return NULL;
134c4d3f927Smatthias.ringwald }
1356527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
1366f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1376f7ecb09S[email protected]     (void) l2cap_channel;
138c4d3f927Smatthias.ringwald };
139c4d3f927Smatthias.ringwald #endif
140a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1416527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
1426527a633S[email protected]     return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t));
143a3b02b71Smatthias.ringwald }
1446527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
145a3b02b71Smatthias.ringwald     free(l2cap_channel);
146a3b02b71Smatthias.ringwald }
147e045abdeSmatthias.ringwald #else
1486527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS for struct l2cap_channel is defined. Please, edit the config file."
149a3b02b71Smatthias.ringwald #endif
150a3b02b71Smatthias.ringwald 
151a3b02b71Smatthias.ringwald 
152a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
153a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_MULTIPLEXERS
154c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
155a3b02b71Smatthias.ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS];
156a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_multiplexer_pool;
1576527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
158a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_multiplexer_pool);
159a3b02b71Smatthias.ringwald }
1606527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
161a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
162a3b02b71Smatthias.ringwald }
163c4d3f927Smatthias.ringwald #else
1646527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
165c4d3f927Smatthias.ringwald     return NULL;
166c4d3f927Smatthias.ringwald }
1676527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
1686f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
1696f7ecb09S[email protected]     (void) rfcomm_multiplexer;
170c4d3f927Smatthias.ringwald };
171c4d3f927Smatthias.ringwald #endif
172a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
1736527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
1746527a633S[email protected]     return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t));
175a3b02b71Smatthias.ringwald }
1766527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
177a3b02b71Smatthias.ringwald     free(rfcomm_multiplexer);
178a3b02b71Smatthias.ringwald }
179e045abdeSmatthias.ringwald #else
1806527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS for struct rfcomm_multiplexer is defined. Please, edit the config file."
181a3b02b71Smatthias.ringwald #endif
182a3b02b71Smatthias.ringwald 
183a3b02b71Smatthias.ringwald 
184a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
185a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_SERVICES
186c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0
187a3b02b71Smatthias.ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES];
188a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_service_pool;
1896527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
190a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_service_pool);
191a3b02b71Smatthias.ringwald }
1926527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
193a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_service_pool, rfcomm_service);
194a3b02b71Smatthias.ringwald }
195c4d3f927Smatthias.ringwald #else
1966527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
197c4d3f927Smatthias.ringwald     return NULL;
198c4d3f927Smatthias.ringwald }
1996527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
2006f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2016f7ecb09S[email protected]     (void) rfcomm_service;
202c4d3f927Smatthias.ringwald };
203c4d3f927Smatthias.ringwald #endif
204a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2056527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
2066527a633S[email protected]     return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t));
207a3b02b71Smatthias.ringwald }
2086527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
209a3b02b71Smatthias.ringwald     free(rfcomm_service);
210a3b02b71Smatthias.ringwald }
211e045abdeSmatthias.ringwald #else
2126527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES for struct rfcomm_service is defined. Please, edit the config file."
213a3b02b71Smatthias.ringwald #endif
214a3b02b71Smatthias.ringwald 
215a3b02b71Smatthias.ringwald 
216a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
217a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_CHANNELS
218c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0
219a3b02b71Smatthias.ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS];
220a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_channel_pool;
2216527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
222a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_channel_pool);
223a3b02b71Smatthias.ringwald }
2246527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
225a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
226a3b02b71Smatthias.ringwald }
227c4d3f927Smatthias.ringwald #else
2286527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
229c4d3f927Smatthias.ringwald     return NULL;
230c4d3f927Smatthias.ringwald }
2316527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
2326f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
2336f7ecb09S[email protected]     (void) rfcomm_channel;
234c4d3f927Smatthias.ringwald };
235c4d3f927Smatthias.ringwald #endif
236a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
2376527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
2386527a633S[email protected]     return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t));
239a3b02b71Smatthias.ringwald }
2406527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
241a3b02b71Smatthias.ringwald     free(rfcomm_channel);
242a3b02b71Smatthias.ringwald }
243e045abdeSmatthias.ringwald #else
2446527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file."
245a3b02b71Smatthias.ringwald #endif
246a3b02b71Smatthias.ringwald 
247*fdb398c2S[email protected] // MARK: bnepservice_t
248*fdb398c2S[email protected] #ifdef MAX_NO_BNEP_SERVICES
249*fdb398c2S[email protected] #if MAX_NO_BNEP_SERVICES > 0
250*fdb398c2S[email protected] static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES];
251*fdb398c2S[email protected] static memory_pool_t bnep_service_pool;
252*fdb398c2S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
253*fdb398c2S[email protected]     return memory_pool_get(&bnep_service_pool);
254*fdb398c2S[email protected] }
255*fdb398c2S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
256*fdb398c2S[email protected]     memory_pool_free(&bnep_service_pool, bnep_service);
257*fdb398c2S[email protected] }
258*fdb398c2S[email protected] #else
259*fdb398c2S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
260*fdb398c2S[email protected]     return NULL;
261*fdb398c2S[email protected] }
262*fdb398c2S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
263*fdb398c2S[email protected] };
264*fdb398c2S[email protected] #endif
265*fdb398c2S[email protected] #elif defined(HAVE_MALLOC)
266*fdb398c2S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){
267*fdb398c2S[email protected]     return (bnep_service_t*) malloc(sizeof(bnep_service_t));
268*fdb398c2S[email protected] }
269*fdb398c2S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
270*fdb398c2S[email protected]     free(bnep_service);
271*fdb398c2S[email protected] }
272*fdb398c2S[email protected] #else
273*fdb398c2S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file."
274*fdb398c2S[email protected] #endif
275*fdb398c2S[email protected] 
276*fdb398c2S[email protected] 
277*fdb398c2S[email protected] // MARK: bnep_channel_t
278*fdb398c2S[email protected] #ifdef MAX_NO_BNEP_CHANNELS
279*fdb398c2S[email protected] #if MAX_NO_BNEP_CHANNELS > 0
280*fdb398c2S[email protected] static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS];
281*fdb398c2S[email protected] static memory_pool_t bnep_channel_pool;
282*fdb398c2S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
283*fdb398c2S[email protected]     return memory_pool_get(&bnep_channel_pool);
284*fdb398c2S[email protected] }
285*fdb398c2S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
286*fdb398c2S[email protected]     memory_pool_free(&bnep_channel_pool, bnep_channel);
287*fdb398c2S[email protected] }
288*fdb398c2S[email protected] #else
289*fdb398c2S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
290*fdb398c2S[email protected]     return NULL;
291*fdb398c2S[email protected] }
292*fdb398c2S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
293*fdb398c2S[email protected] };
294*fdb398c2S[email protected] #endif
295*fdb398c2S[email protected] #elif defined(HAVE_MALLOC)
296*fdb398c2S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){
297*fdb398c2S[email protected]     return (bnep_channel_t*) malloc(sizeof(bnep_channel_t));
298*fdb398c2S[email protected] }
299*fdb398c2S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
300*fdb398c2S[email protected]     free(bnep_channel);
301*fdb398c2S[email protected] }
302*fdb398c2S[email protected] #else
303*fdb398c2S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file."
304*fdb398c2S[email protected] #endif
305*fdb398c2S[email protected] 
306e0e5e285Smatthias.ringwald 
307e0e5e285Smatthias.ringwald // MARK: db_mem_device_name_t
308e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_NAMES
309c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
310e0e5e285Smatthias.ringwald static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES];
311e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_name_pool;
3126527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
313e0e5e285Smatthias.ringwald     return memory_pool_get(&db_mem_device_name_pool);
3141801b596Smatthias.ringwald }
3156527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){
316e0e5e285Smatthias.ringwald     memory_pool_free(&db_mem_device_name_pool, db_mem_device_name);
3171801b596Smatthias.ringwald }
318c4d3f927Smatthias.ringwald #else
3196527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
320c4d3f927Smatthias.ringwald     return NULL;
321c4d3f927Smatthias.ringwald }
3226527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t * db_mem_device_name){
3236f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3246f7ecb09S[email protected]     (void) db_mem_device_name;
325c4d3f927Smatthias.ringwald };
326c4d3f927Smatthias.ringwald #endif
3271801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3286527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
3296527a633S[email protected]     return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t));
3301801b596Smatthias.ringwald }
3316527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){
332e0e5e285Smatthias.ringwald     free(db_mem_device_name);
333e0e5e285Smatthias.ringwald }
334e045abdeSmatthias.ringwald #else
3356527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES for struct db_mem_device_name is defined. Please, edit the config file."
336e0e5e285Smatthias.ringwald #endif
337e0e5e285Smatthias.ringwald 
338e0e5e285Smatthias.ringwald 
339e0e5e285Smatthias.ringwald // MARK: db_mem_device_link_key_t
340e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS
341c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
342e0e5e285Smatthias.ringwald static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS];
343e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_link_key_pool;
3446527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
345e0e5e285Smatthias.ringwald     return memory_pool_get(&db_mem_device_link_key_pool);
346e0e5e285Smatthias.ringwald }
3476527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
348e0e5e285Smatthias.ringwald     memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key);
349e0e5e285Smatthias.ringwald }
350c4d3f927Smatthias.ringwald #else
3516527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
352c4d3f927Smatthias.ringwald     return NULL;
353c4d3f927Smatthias.ringwald }
3546527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
3556f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3566f7ecb09S[email protected]     (void) db_mem_device_link_key;
357c4d3f927Smatthias.ringwald };
358c4d3f927Smatthias.ringwald #endif
359e0e5e285Smatthias.ringwald #elif defined(HAVE_MALLOC)
3606527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
3616527a633S[email protected]     return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t));
362e0e5e285Smatthias.ringwald }
3636527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
364e0e5e285Smatthias.ringwald     free(db_mem_device_link_key);
3651801b596Smatthias.ringwald }
366e045abdeSmatthias.ringwald #else
3676527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS for struct db_mem_device_link_key is defined. Please, edit the config file."
3681801b596Smatthias.ringwald #endif
3691801b596Smatthias.ringwald 
3701801b596Smatthias.ringwald 
3711801b596Smatthias.ringwald // MARK: db_mem_service_t
3721801b596Smatthias.ringwald #ifdef MAX_NO_DB_MEM_SERVICES
373c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0
3741801b596Smatthias.ringwald static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES];
3751801b596Smatthias.ringwald static memory_pool_t db_mem_service_pool;
3766527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){
3771801b596Smatthias.ringwald     return memory_pool_get(&db_mem_service_pool);
3781801b596Smatthias.ringwald }
3796527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
3801801b596Smatthias.ringwald     memory_pool_free(&db_mem_service_pool, db_mem_service);
3811801b596Smatthias.ringwald }
382c4d3f927Smatthias.ringwald #else
3836527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){
384c4d3f927Smatthias.ringwald     return NULL;
385c4d3f927Smatthias.ringwald }
3866527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
3876f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
3886f7ecb09S[email protected]     (void) db_mem_service;
389c4d3f927Smatthias.ringwald };
390c4d3f927Smatthias.ringwald #endif
3911801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3926527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){
3936527a633S[email protected]     return (db_mem_service_t*) malloc(sizeof(db_mem_service_t));
3941801b596Smatthias.ringwald }
3956527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
3961801b596Smatthias.ringwald     free(db_mem_service);
3971801b596Smatthias.ringwald }
398e045abdeSmatthias.ringwald #else
3996527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file."
4001801b596Smatthias.ringwald #endif
4011801b596Smatthias.ringwald 
402d0fdae3cS[email protected] // MARK: gatt_client_t
403d0fdae3cS[email protected] #ifdef HAVE_BLE
404d0fdae3cS[email protected] #ifdef MAX_NO_GATT_CLIENTS
405d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0
406d0fdae3cS[email protected] static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS];
407d0fdae3cS[email protected] static memory_pool_t gatt_client_pool;
408d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
409d0fdae3cS[email protected]     return memory_pool_get(&gatt_client_pool);
410d0fdae3cS[email protected] }
411d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
412d0fdae3cS[email protected]     memory_pool_free(&gatt_client_pool, gatt_client);
413d0fdae3cS[email protected] }
414d0fdae3cS[email protected] #else
415d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
416d0fdae3cS[email protected]     return NULL;
417d0fdae3cS[email protected] }
418d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
4196f7ecb09S[email protected]     // silence compiler warning about unused parameter in a portable way
4206f7ecb09S[email protected]     (void) gatt_client;
421d0fdae3cS[email protected] };
422d0fdae3cS[email protected] #endif
423d0fdae3cS[email protected] #elif defined(HAVE_MALLOC)
424d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){
425d0fdae3cS[email protected]     return (gatt_client_t*) malloc(sizeof(gatt_client_t));
426d0fdae3cS[email protected] }
427d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
428d0fdae3cS[email protected]     free(gatt_client);
429d0fdae3cS[email protected] }
430d0fdae3cS[email protected] #else
431d0fdae3cS[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file."
432d0fdae3cS[email protected] #endif
433d0fdae3cS[email protected] #endif
434*fdb398c2S[email protected] 
435a3b02b71Smatthias.ringwald // init
436a3b02b71Smatthias.ringwald void btstack_memory_init(void){
437c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0
438a3b02b71Smatthias.ringwald     memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t));
439a3b02b71Smatthias.ringwald #endif
440c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0
441a3b02b71Smatthias.ringwald     memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t));
442a3b02b71Smatthias.ringwald #endif
443c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0
444a3b02b71Smatthias.ringwald     memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
445a3b02b71Smatthias.ringwald #endif
446c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
447a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
448a3b02b71Smatthias.ringwald #endif
449c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0
450a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
451a3b02b71Smatthias.ringwald #endif
452c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0
453a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
454a3b02b71Smatthias.ringwald #endif
455c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
456e0e5e285Smatthias.ringwald     memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t));
457e0e5e285Smatthias.ringwald #endif
458c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
459e0e5e285Smatthias.ringwald     memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t));
4601801b596Smatthias.ringwald #endif
461c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0
4621801b596Smatthias.ringwald     memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t));
4631801b596Smatthias.ringwald #endif
464a7d12effS[email protected] #ifdef HAVE_BLE
465d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0
466d0fdae3cS[email protected]     memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t));
467d0fdae3cS[email protected] #endif
468a7d12effS[email protected] #endif
469a3b02b71Smatthias.ringwald }
470e045abdeSmatthias.ringwald 
471