xref: /btstack/src/btstack_memory.c (revision b6269742289ca2bcfed3911e19011250886c7ac4)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 
39 #define BTSTACK_FILE__ "btstack_memory.c"
40 
41 
42 /*
43  *  btstack_memory.c
44  *
45  *  @brief BTstack memory management via configurable memory pools
46  *
47  *  @note code generated by tool/btstack_memory_generator.py
48  *  @note returnes buffers are initialized with 0
49  *
50  */
51 
52 #include "btstack_memory.h"
53 #include "btstack_memory_pool.h"
54 #include "btstack_debug.h"
55 
56 #include <stdlib.h>
57 
58 #ifdef HAVE_MALLOC
59 typedef struct btstack_memory_buffer {
60     struct btstack_memory_buffer * next;
61     struct btstack_memory_buffer * prev;
62 } btstack_memory_buffer_t;
63 
64 static btstack_memory_buffer_t * btstack_memory_malloc_buffers;
65 
66 static void btstack_memory_tracking_add(void * raw_buffer){
67     btstack_assert(raw_buffer != NULL);
68     btstack_memory_buffer_t * buffer = (btstack_memory_buffer_t*) raw_buffer;
69     buffer->prev = NULL;
70     buffer->next = btstack_memory_malloc_buffers;
71     if (btstack_memory_malloc_buffers) {
72         btstack_memory_malloc_buffers->prev = buffer;
73     }
74     btstack_memory_malloc_buffers = buffer;
75 }
76 
77 static void btstack_memory_tracking_remove(void * raw_buffer){
78     btstack_assert(raw_buffer != NULL);
79     btstack_memory_buffer_t * buffer = (btstack_memory_buffer_t*) raw_buffer;
80     if (buffer->prev == NULL){
81         // first item
82         btstack_memory_malloc_buffers = buffer->next;
83     } else {
84         buffer->prev->next = buffer->next;
85     }
86     if (buffer->next != NULL){
87         buffer->next->prev = buffer->prev;
88     }
89 }
90 #endif
91 
92 void btstack_memory_deinit(void){
93 #ifdef HAVE_MALLOC
94     while (btstack_memory_malloc_buffers != NULL){
95         btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers;
96         btstack_memory_malloc_buffers = buffer->next;
97         free(buffer);
98     }
99 #endif
100 }
101 
102 
103 // MARK: hci_connection_t
104 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
105     #if defined(MAX_NO_HCI_CONNECTIONS)
106         #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."
107     #else
108         #define MAX_NR_HCI_CONNECTIONS 0
109     #endif
110 #endif
111 
112 #ifdef MAX_NR_HCI_CONNECTIONS
113 #if MAX_NR_HCI_CONNECTIONS > 0
114 static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
115 static btstack_memory_pool_t hci_connection_pool;
116 hci_connection_t * btstack_memory_hci_connection_get(void){
117     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
118     if (buffer){
119         memset(buffer, 0, sizeof(hci_connection_t));
120     }
121     return (hci_connection_t *) buffer;
122 }
123 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
124     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
125 }
126 #else
127 hci_connection_t * btstack_memory_hci_connection_get(void){
128     return NULL;
129 }
130 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
131     UNUSED(hci_connection);
132 };
133 #endif
134 #elif defined(HAVE_MALLOC)
135 hci_connection_t * btstack_memory_hci_connection_get(void){
136     void * buffer = malloc(sizeof(hci_connection_t) + sizeof(btstack_memory_buffer_t));
137     if (buffer){
138         memset(buffer, 0, sizeof(hci_connection_t) + sizeof(btstack_memory_buffer_t));
139         btstack_memory_tracking_add(buffer);
140         return (hci_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
141     } else {
142         return NULL;
143     }
144 }
145 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
146     void * buffer =  ((void *) hci_connection) - sizeof(btstack_memory_buffer_t);
147     btstack_memory_tracking_remove(buffer);
148     free(buffer);
149 }
150 #endif
151 
152 
153 
154 // MARK: l2cap_service_t
155 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
156     #if defined(MAX_NO_L2CAP_SERVICES)
157         #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."
158     #else
159         #define MAX_NR_L2CAP_SERVICES 0
160     #endif
161 #endif
162 
163 #ifdef MAX_NR_L2CAP_SERVICES
164 #if MAX_NR_L2CAP_SERVICES > 0
165 static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
166 static btstack_memory_pool_t l2cap_service_pool;
167 l2cap_service_t * btstack_memory_l2cap_service_get(void){
168     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
169     if (buffer){
170         memset(buffer, 0, sizeof(l2cap_service_t));
171     }
172     return (l2cap_service_t *) buffer;
173 }
174 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
175     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
176 }
177 #else
178 l2cap_service_t * btstack_memory_l2cap_service_get(void){
179     return NULL;
180 }
181 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
182     UNUSED(l2cap_service);
183 };
184 #endif
185 #elif defined(HAVE_MALLOC)
186 l2cap_service_t * btstack_memory_l2cap_service_get(void){
187     void * buffer = malloc(sizeof(l2cap_service_t) + sizeof(btstack_memory_buffer_t));
188     if (buffer){
189         memset(buffer, 0, sizeof(l2cap_service_t) + sizeof(btstack_memory_buffer_t));
190         btstack_memory_tracking_add(buffer);
191         return (l2cap_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
192     } else {
193         return NULL;
194     }
195 }
196 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
197     void * buffer =  ((void *) l2cap_service) - sizeof(btstack_memory_buffer_t);
198     btstack_memory_tracking_remove(buffer);
199     free(buffer);
200 }
201 #endif
202 
203 
204 // MARK: l2cap_channel_t
205 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
206     #if defined(MAX_NO_L2CAP_CHANNELS)
207         #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."
208     #else
209         #define MAX_NR_L2CAP_CHANNELS 0
210     #endif
211 #endif
212 
213 #ifdef MAX_NR_L2CAP_CHANNELS
214 #if MAX_NR_L2CAP_CHANNELS > 0
215 static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
216 static btstack_memory_pool_t l2cap_channel_pool;
217 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
218     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
219     if (buffer){
220         memset(buffer, 0, sizeof(l2cap_channel_t));
221     }
222     return (l2cap_channel_t *) buffer;
223 }
224 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
225     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
226 }
227 #else
228 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
229     return NULL;
230 }
231 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
232     UNUSED(l2cap_channel);
233 };
234 #endif
235 #elif defined(HAVE_MALLOC)
236 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
237     void * buffer = malloc(sizeof(l2cap_channel_t) + sizeof(btstack_memory_buffer_t));
238     if (buffer){
239         memset(buffer, 0, sizeof(l2cap_channel_t) + sizeof(btstack_memory_buffer_t));
240         btstack_memory_tracking_add(buffer);
241         return (l2cap_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
242     } else {
243         return NULL;
244     }
245 }
246 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
247     void * buffer =  ((void *) l2cap_channel) - sizeof(btstack_memory_buffer_t);
248     btstack_memory_tracking_remove(buffer);
249     free(buffer);
250 }
251 #endif
252 
253 
254 #ifdef ENABLE_CLASSIC
255 
256 // MARK: rfcomm_multiplexer_t
257 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
258     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
259         #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."
260     #else
261         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
262     #endif
263 #endif
264 
265 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
266 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
267 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
268 static btstack_memory_pool_t rfcomm_multiplexer_pool;
269 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
270     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
271     if (buffer){
272         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
273     }
274     return (rfcomm_multiplexer_t *) buffer;
275 }
276 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
277     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
278 }
279 #else
280 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
281     return NULL;
282 }
283 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
284     UNUSED(rfcomm_multiplexer);
285 };
286 #endif
287 #elif defined(HAVE_MALLOC)
288 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
289     void * buffer = malloc(sizeof(rfcomm_multiplexer_t) + sizeof(btstack_memory_buffer_t));
290     if (buffer){
291         memset(buffer, 0, sizeof(rfcomm_multiplexer_t) + sizeof(btstack_memory_buffer_t));
292         btstack_memory_tracking_add(buffer);
293         return (rfcomm_multiplexer_t *) (buffer + sizeof(btstack_memory_buffer_t));
294     } else {
295         return NULL;
296     }
297 }
298 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
299     void * buffer =  ((void *) rfcomm_multiplexer) - sizeof(btstack_memory_buffer_t);
300     btstack_memory_tracking_remove(buffer);
301     free(buffer);
302 }
303 #endif
304 
305 
306 // MARK: rfcomm_service_t
307 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
308     #if defined(MAX_NO_RFCOMM_SERVICES)
309         #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."
310     #else
311         #define MAX_NR_RFCOMM_SERVICES 0
312     #endif
313 #endif
314 
315 #ifdef MAX_NR_RFCOMM_SERVICES
316 #if MAX_NR_RFCOMM_SERVICES > 0
317 static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
318 static btstack_memory_pool_t rfcomm_service_pool;
319 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
320     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
321     if (buffer){
322         memset(buffer, 0, sizeof(rfcomm_service_t));
323     }
324     return (rfcomm_service_t *) buffer;
325 }
326 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
327     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
328 }
329 #else
330 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
331     return NULL;
332 }
333 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
334     UNUSED(rfcomm_service);
335 };
336 #endif
337 #elif defined(HAVE_MALLOC)
338 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
339     void * buffer = malloc(sizeof(rfcomm_service_t) + sizeof(btstack_memory_buffer_t));
340     if (buffer){
341         memset(buffer, 0, sizeof(rfcomm_service_t) + sizeof(btstack_memory_buffer_t));
342         btstack_memory_tracking_add(buffer);
343         return (rfcomm_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
344     } else {
345         return NULL;
346     }
347 }
348 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
349     void * buffer =  ((void *) rfcomm_service) - sizeof(btstack_memory_buffer_t);
350     btstack_memory_tracking_remove(buffer);
351     free(buffer);
352 }
353 #endif
354 
355 
356 // MARK: rfcomm_channel_t
357 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
358     #if defined(MAX_NO_RFCOMM_CHANNELS)
359         #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."
360     #else
361         #define MAX_NR_RFCOMM_CHANNELS 0
362     #endif
363 #endif
364 
365 #ifdef MAX_NR_RFCOMM_CHANNELS
366 #if MAX_NR_RFCOMM_CHANNELS > 0
367 static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
368 static btstack_memory_pool_t rfcomm_channel_pool;
369 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
370     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
371     if (buffer){
372         memset(buffer, 0, sizeof(rfcomm_channel_t));
373     }
374     return (rfcomm_channel_t *) buffer;
375 }
376 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
377     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
378 }
379 #else
380 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
381     return NULL;
382 }
383 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
384     UNUSED(rfcomm_channel);
385 };
386 #endif
387 #elif defined(HAVE_MALLOC)
388 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
389     void * buffer = malloc(sizeof(rfcomm_channel_t) + sizeof(btstack_memory_buffer_t));
390     if (buffer){
391         memset(buffer, 0, sizeof(rfcomm_channel_t) + sizeof(btstack_memory_buffer_t));
392         btstack_memory_tracking_add(buffer);
393         return (rfcomm_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
394     } else {
395         return NULL;
396     }
397 }
398 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
399     void * buffer =  ((void *) rfcomm_channel) - sizeof(btstack_memory_buffer_t);
400     btstack_memory_tracking_remove(buffer);
401     free(buffer);
402 }
403 #endif
404 
405 
406 
407 // MARK: btstack_link_key_db_memory_entry_t
408 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
409     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
410         #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."
411     #else
412         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
413     #endif
414 #endif
415 
416 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
417 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
418 static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
419 static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
420 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
421     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
422     if (buffer){
423         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
424     }
425     return (btstack_link_key_db_memory_entry_t *) buffer;
426 }
427 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
428     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
429 }
430 #else
431 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
432     return NULL;
433 }
434 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
435     UNUSED(btstack_link_key_db_memory_entry);
436 };
437 #endif
438 #elif defined(HAVE_MALLOC)
439 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
440     void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t) + sizeof(btstack_memory_buffer_t));
441     if (buffer){
442         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t) + sizeof(btstack_memory_buffer_t));
443         btstack_memory_tracking_add(buffer);
444         return (btstack_link_key_db_memory_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
445     } else {
446         return NULL;
447     }
448 }
449 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
450     void * buffer =  ((void *) btstack_link_key_db_memory_entry) - sizeof(btstack_memory_buffer_t);
451     btstack_memory_tracking_remove(buffer);
452     free(buffer);
453 }
454 #endif
455 
456 
457 
458 // MARK: bnep_service_t
459 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
460     #if defined(MAX_NO_BNEP_SERVICES)
461         #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."
462     #else
463         #define MAX_NR_BNEP_SERVICES 0
464     #endif
465 #endif
466 
467 #ifdef MAX_NR_BNEP_SERVICES
468 #if MAX_NR_BNEP_SERVICES > 0
469 static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
470 static btstack_memory_pool_t bnep_service_pool;
471 bnep_service_t * btstack_memory_bnep_service_get(void){
472     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
473     if (buffer){
474         memset(buffer, 0, sizeof(bnep_service_t));
475     }
476     return (bnep_service_t *) buffer;
477 }
478 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
479     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
480 }
481 #else
482 bnep_service_t * btstack_memory_bnep_service_get(void){
483     return NULL;
484 }
485 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
486     UNUSED(bnep_service);
487 };
488 #endif
489 #elif defined(HAVE_MALLOC)
490 bnep_service_t * btstack_memory_bnep_service_get(void){
491     void * buffer = malloc(sizeof(bnep_service_t) + sizeof(btstack_memory_buffer_t));
492     if (buffer){
493         memset(buffer, 0, sizeof(bnep_service_t) + sizeof(btstack_memory_buffer_t));
494         btstack_memory_tracking_add(buffer);
495         return (bnep_service_t *) (buffer + sizeof(btstack_memory_buffer_t));
496     } else {
497         return NULL;
498     }
499 }
500 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
501     void * buffer =  ((void *) bnep_service) - sizeof(btstack_memory_buffer_t);
502     btstack_memory_tracking_remove(buffer);
503     free(buffer);
504 }
505 #endif
506 
507 
508 // MARK: bnep_channel_t
509 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
510     #if defined(MAX_NO_BNEP_CHANNELS)
511         #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."
512     #else
513         #define MAX_NR_BNEP_CHANNELS 0
514     #endif
515 #endif
516 
517 #ifdef MAX_NR_BNEP_CHANNELS
518 #if MAX_NR_BNEP_CHANNELS > 0
519 static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
520 static btstack_memory_pool_t bnep_channel_pool;
521 bnep_channel_t * btstack_memory_bnep_channel_get(void){
522     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
523     if (buffer){
524         memset(buffer, 0, sizeof(bnep_channel_t));
525     }
526     return (bnep_channel_t *) buffer;
527 }
528 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
529     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
530 }
531 #else
532 bnep_channel_t * btstack_memory_bnep_channel_get(void){
533     return NULL;
534 }
535 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
536     UNUSED(bnep_channel);
537 };
538 #endif
539 #elif defined(HAVE_MALLOC)
540 bnep_channel_t * btstack_memory_bnep_channel_get(void){
541     void * buffer = malloc(sizeof(bnep_channel_t) + sizeof(btstack_memory_buffer_t));
542     if (buffer){
543         memset(buffer, 0, sizeof(bnep_channel_t) + sizeof(btstack_memory_buffer_t));
544         btstack_memory_tracking_add(buffer);
545         return (bnep_channel_t *) (buffer + sizeof(btstack_memory_buffer_t));
546     } else {
547         return NULL;
548     }
549 }
550 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
551     void * buffer =  ((void *) bnep_channel) - sizeof(btstack_memory_buffer_t);
552     btstack_memory_tracking_remove(buffer);
553     free(buffer);
554 }
555 #endif
556 
557 
558 
559 // MARK: hfp_connection_t
560 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
561     #if defined(MAX_NO_HFP_CONNECTIONS)
562         #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."
563     #else
564         #define MAX_NR_HFP_CONNECTIONS 0
565     #endif
566 #endif
567 
568 #ifdef MAX_NR_HFP_CONNECTIONS
569 #if MAX_NR_HFP_CONNECTIONS > 0
570 static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
571 static btstack_memory_pool_t hfp_connection_pool;
572 hfp_connection_t * btstack_memory_hfp_connection_get(void){
573     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
574     if (buffer){
575         memset(buffer, 0, sizeof(hfp_connection_t));
576     }
577     return (hfp_connection_t *) buffer;
578 }
579 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
580     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
581 }
582 #else
583 hfp_connection_t * btstack_memory_hfp_connection_get(void){
584     return NULL;
585 }
586 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
587     UNUSED(hfp_connection);
588 };
589 #endif
590 #elif defined(HAVE_MALLOC)
591 hfp_connection_t * btstack_memory_hfp_connection_get(void){
592     void * buffer = malloc(sizeof(hfp_connection_t) + sizeof(btstack_memory_buffer_t));
593     if (buffer){
594         memset(buffer, 0, sizeof(hfp_connection_t) + sizeof(btstack_memory_buffer_t));
595         btstack_memory_tracking_add(buffer);
596         return (hfp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
597     } else {
598         return NULL;
599     }
600 }
601 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
602     void * buffer =  ((void *) hfp_connection) - sizeof(btstack_memory_buffer_t);
603     btstack_memory_tracking_remove(buffer);
604     free(buffer);
605 }
606 #endif
607 
608 
609 
610 // MARK: service_record_item_t
611 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
612     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
613         #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."
614     #else
615         #define MAX_NR_SERVICE_RECORD_ITEMS 0
616     #endif
617 #endif
618 
619 #ifdef MAX_NR_SERVICE_RECORD_ITEMS
620 #if MAX_NR_SERVICE_RECORD_ITEMS > 0
621 static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
622 static btstack_memory_pool_t service_record_item_pool;
623 service_record_item_t * btstack_memory_service_record_item_get(void){
624     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
625     if (buffer){
626         memset(buffer, 0, sizeof(service_record_item_t));
627     }
628     return (service_record_item_t *) buffer;
629 }
630 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
631     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
632 }
633 #else
634 service_record_item_t * btstack_memory_service_record_item_get(void){
635     return NULL;
636 }
637 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
638     UNUSED(service_record_item);
639 };
640 #endif
641 #elif defined(HAVE_MALLOC)
642 service_record_item_t * btstack_memory_service_record_item_get(void){
643     void * buffer = malloc(sizeof(service_record_item_t) + sizeof(btstack_memory_buffer_t));
644     if (buffer){
645         memset(buffer, 0, sizeof(service_record_item_t) + sizeof(btstack_memory_buffer_t));
646         btstack_memory_tracking_add(buffer);
647         return (service_record_item_t *) (buffer + sizeof(btstack_memory_buffer_t));
648     } else {
649         return NULL;
650     }
651 }
652 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
653     void * buffer =  ((void *) service_record_item) - sizeof(btstack_memory_buffer_t);
654     btstack_memory_tracking_remove(buffer);
655     free(buffer);
656 }
657 #endif
658 
659 
660 
661 // MARK: avdtp_stream_endpoint_t
662 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
663     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
664         #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."
665     #else
666         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
667     #endif
668 #endif
669 
670 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
671 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
672 static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
673 static btstack_memory_pool_t avdtp_stream_endpoint_pool;
674 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
675     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
676     if (buffer){
677         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
678     }
679     return (avdtp_stream_endpoint_t *) buffer;
680 }
681 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
682     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
683 }
684 #else
685 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
686     return NULL;
687 }
688 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
689     UNUSED(avdtp_stream_endpoint);
690 };
691 #endif
692 #elif defined(HAVE_MALLOC)
693 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
694     void * buffer = malloc(sizeof(avdtp_stream_endpoint_t) + sizeof(btstack_memory_buffer_t));
695     if (buffer){
696         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t) + sizeof(btstack_memory_buffer_t));
697         btstack_memory_tracking_add(buffer);
698         return (avdtp_stream_endpoint_t *) (buffer + sizeof(btstack_memory_buffer_t));
699     } else {
700         return NULL;
701     }
702 }
703 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
704     void * buffer =  ((void *) avdtp_stream_endpoint) - sizeof(btstack_memory_buffer_t);
705     btstack_memory_tracking_remove(buffer);
706     free(buffer);
707 }
708 #endif
709 
710 
711 
712 // MARK: avdtp_connection_t
713 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
714     #if defined(MAX_NO_AVDTP_CONNECTIONS)
715         #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."
716     #else
717         #define MAX_NR_AVDTP_CONNECTIONS 0
718     #endif
719 #endif
720 
721 #ifdef MAX_NR_AVDTP_CONNECTIONS
722 #if MAX_NR_AVDTP_CONNECTIONS > 0
723 static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
724 static btstack_memory_pool_t avdtp_connection_pool;
725 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
726     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
727     if (buffer){
728         memset(buffer, 0, sizeof(avdtp_connection_t));
729     }
730     return (avdtp_connection_t *) buffer;
731 }
732 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
733     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
734 }
735 #else
736 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
737     return NULL;
738 }
739 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
740     UNUSED(avdtp_connection);
741 };
742 #endif
743 #elif defined(HAVE_MALLOC)
744 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
745     void * buffer = malloc(sizeof(avdtp_connection_t) + sizeof(btstack_memory_buffer_t));
746     if (buffer){
747         memset(buffer, 0, sizeof(avdtp_connection_t) + sizeof(btstack_memory_buffer_t));
748         btstack_memory_tracking_add(buffer);
749         return (avdtp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
750     } else {
751         return NULL;
752     }
753 }
754 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
755     void * buffer =  ((void *) avdtp_connection) - sizeof(btstack_memory_buffer_t);
756     btstack_memory_tracking_remove(buffer);
757     free(buffer);
758 }
759 #endif
760 
761 
762 
763 // MARK: avrcp_connection_t
764 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
765     #if defined(MAX_NO_AVRCP_CONNECTIONS)
766         #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."
767     #else
768         #define MAX_NR_AVRCP_CONNECTIONS 0
769     #endif
770 #endif
771 
772 #ifdef MAX_NR_AVRCP_CONNECTIONS
773 #if MAX_NR_AVRCP_CONNECTIONS > 0
774 static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
775 static btstack_memory_pool_t avrcp_connection_pool;
776 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
777     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
778     if (buffer){
779         memset(buffer, 0, sizeof(avrcp_connection_t));
780     }
781     return (avrcp_connection_t *) buffer;
782 }
783 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
784     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
785 }
786 #else
787 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
788     return NULL;
789 }
790 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
791     UNUSED(avrcp_connection);
792 };
793 #endif
794 #elif defined(HAVE_MALLOC)
795 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
796     void * buffer = malloc(sizeof(avrcp_connection_t) + sizeof(btstack_memory_buffer_t));
797     if (buffer){
798         memset(buffer, 0, sizeof(avrcp_connection_t) + sizeof(btstack_memory_buffer_t));
799         btstack_memory_tracking_add(buffer);
800         return (avrcp_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
801     } else {
802         return NULL;
803     }
804 }
805 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
806     void * buffer =  ((void *) avrcp_connection) - sizeof(btstack_memory_buffer_t);
807     btstack_memory_tracking_remove(buffer);
808     free(buffer);
809 }
810 #endif
811 
812 
813 
814 // MARK: avrcp_browsing_connection_t
815 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
816     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
817         #error "Deprecated MAX_NO_AVRCP_BROWSING_CONNECTIONS defined instead of MAX_NR_AVRCP_BROWSING_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_BROWSING_CONNECTIONS."
818     #else
819         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
820     #endif
821 #endif
822 
823 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
824 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
825 static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
826 static btstack_memory_pool_t avrcp_browsing_connection_pool;
827 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
828     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
829     if (buffer){
830         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
831     }
832     return (avrcp_browsing_connection_t *) buffer;
833 }
834 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
835     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
836 }
837 #else
838 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
839     return NULL;
840 }
841 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
842     UNUSED(avrcp_browsing_connection);
843 };
844 #endif
845 #elif defined(HAVE_MALLOC)
846 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
847     void * buffer = malloc(sizeof(avrcp_browsing_connection_t) + sizeof(btstack_memory_buffer_t));
848     if (buffer){
849         memset(buffer, 0, sizeof(avrcp_browsing_connection_t) + sizeof(btstack_memory_buffer_t));
850         btstack_memory_tracking_add(buffer);
851         return (avrcp_browsing_connection_t *) (buffer + sizeof(btstack_memory_buffer_t));
852     } else {
853         return NULL;
854     }
855 }
856 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
857     void * buffer =  ((void *) avrcp_browsing_connection) - sizeof(btstack_memory_buffer_t);
858     btstack_memory_tracking_remove(buffer);
859     free(buffer);
860 }
861 #endif
862 
863 
864 #endif
865 #ifdef ENABLE_BLE
866 
867 // MARK: gatt_client_t
868 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
869     #if defined(MAX_NO_GATT_CLIENTS)
870         #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."
871     #else
872         #define MAX_NR_GATT_CLIENTS 0
873     #endif
874 #endif
875 
876 #ifdef MAX_NR_GATT_CLIENTS
877 #if MAX_NR_GATT_CLIENTS > 0
878 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
879 static btstack_memory_pool_t gatt_client_pool;
880 gatt_client_t * btstack_memory_gatt_client_get(void){
881     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
882     if (buffer){
883         memset(buffer, 0, sizeof(gatt_client_t));
884     }
885     return (gatt_client_t *) buffer;
886 }
887 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
888     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
889 }
890 #else
891 gatt_client_t * btstack_memory_gatt_client_get(void){
892     return NULL;
893 }
894 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
895     UNUSED(gatt_client);
896 };
897 #endif
898 #elif defined(HAVE_MALLOC)
899 gatt_client_t * btstack_memory_gatt_client_get(void){
900     void * buffer = malloc(sizeof(gatt_client_t) + sizeof(btstack_memory_buffer_t));
901     if (buffer){
902         memset(buffer, 0, sizeof(gatt_client_t) + sizeof(btstack_memory_buffer_t));
903         btstack_memory_tracking_add(buffer);
904         return (gatt_client_t *) (buffer + sizeof(btstack_memory_buffer_t));
905     } else {
906         return NULL;
907     }
908 }
909 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
910     void * buffer =  ((void *) gatt_client) - sizeof(btstack_memory_buffer_t);
911     btstack_memory_tracking_remove(buffer);
912     free(buffer);
913 }
914 #endif
915 
916 
917 // MARK: whitelist_entry_t
918 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
919     #if defined(MAX_NO_WHITELIST_ENTRIES)
920         #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."
921     #else
922         #define MAX_NR_WHITELIST_ENTRIES 0
923     #endif
924 #endif
925 
926 #ifdef MAX_NR_WHITELIST_ENTRIES
927 #if MAX_NR_WHITELIST_ENTRIES > 0
928 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
929 static btstack_memory_pool_t whitelist_entry_pool;
930 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
931     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
932     if (buffer){
933         memset(buffer, 0, sizeof(whitelist_entry_t));
934     }
935     return (whitelist_entry_t *) buffer;
936 }
937 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
938     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
939 }
940 #else
941 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
942     return NULL;
943 }
944 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
945     UNUSED(whitelist_entry);
946 };
947 #endif
948 #elif defined(HAVE_MALLOC)
949 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
950     void * buffer = malloc(sizeof(whitelist_entry_t) + sizeof(btstack_memory_buffer_t));
951     if (buffer){
952         memset(buffer, 0, sizeof(whitelist_entry_t) + sizeof(btstack_memory_buffer_t));
953         btstack_memory_tracking_add(buffer);
954         return (whitelist_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
955     } else {
956         return NULL;
957     }
958 }
959 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
960     void * buffer =  ((void *) whitelist_entry) - sizeof(btstack_memory_buffer_t);
961     btstack_memory_tracking_remove(buffer);
962     free(buffer);
963 }
964 #endif
965 
966 
967 // MARK: sm_lookup_entry_t
968 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
969     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
970         #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."
971     #else
972         #define MAX_NR_SM_LOOKUP_ENTRIES 0
973     #endif
974 #endif
975 
976 #ifdef MAX_NR_SM_LOOKUP_ENTRIES
977 #if MAX_NR_SM_LOOKUP_ENTRIES > 0
978 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
979 static btstack_memory_pool_t sm_lookup_entry_pool;
980 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
981     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
982     if (buffer){
983         memset(buffer, 0, sizeof(sm_lookup_entry_t));
984     }
985     return (sm_lookup_entry_t *) buffer;
986 }
987 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
988     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
989 }
990 #else
991 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
992     return NULL;
993 }
994 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
995     UNUSED(sm_lookup_entry);
996 };
997 #endif
998 #elif defined(HAVE_MALLOC)
999 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1000     void * buffer = malloc(sizeof(sm_lookup_entry_t) + sizeof(btstack_memory_buffer_t));
1001     if (buffer){
1002         memset(buffer, 0, sizeof(sm_lookup_entry_t) + sizeof(btstack_memory_buffer_t));
1003         btstack_memory_tracking_add(buffer);
1004         return (sm_lookup_entry_t *) (buffer + sizeof(btstack_memory_buffer_t));
1005     } else {
1006         return NULL;
1007     }
1008 }
1009 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1010     void * buffer =  ((void *) sm_lookup_entry) - sizeof(btstack_memory_buffer_t);
1011     btstack_memory_tracking_remove(buffer);
1012     free(buffer);
1013 }
1014 #endif
1015 
1016 
1017 #endif
1018 #ifdef ENABLE_MESH
1019 
1020 // MARK: mesh_network_pdu_t
1021 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
1022     #if defined(MAX_NO_MESH_NETWORK_PDUS)
1023         #error "Deprecated MAX_NO_MESH_NETWORK_PDUS defined instead of MAX_NR_MESH_NETWORK_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_PDUS."
1024     #else
1025         #define MAX_NR_MESH_NETWORK_PDUS 0
1026     #endif
1027 #endif
1028 
1029 #ifdef MAX_NR_MESH_NETWORK_PDUS
1030 #if MAX_NR_MESH_NETWORK_PDUS > 0
1031 static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
1032 static btstack_memory_pool_t mesh_network_pdu_pool;
1033 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1034     void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
1035     if (buffer){
1036         memset(buffer, 0, sizeof(mesh_network_pdu_t));
1037     }
1038     return (mesh_network_pdu_t *) buffer;
1039 }
1040 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1041     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
1042 }
1043 #else
1044 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1045     return NULL;
1046 }
1047 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1048     UNUSED(mesh_network_pdu);
1049 };
1050 #endif
1051 #elif defined(HAVE_MALLOC)
1052 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1053     void * buffer = malloc(sizeof(mesh_network_pdu_t) + sizeof(btstack_memory_buffer_t));
1054     if (buffer){
1055         memset(buffer, 0, sizeof(mesh_network_pdu_t) + sizeof(btstack_memory_buffer_t));
1056         btstack_memory_tracking_add(buffer);
1057         return (mesh_network_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1058     } else {
1059         return NULL;
1060     }
1061 }
1062 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1063     void * buffer =  ((void *) mesh_network_pdu) - sizeof(btstack_memory_buffer_t);
1064     btstack_memory_tracking_remove(buffer);
1065     free(buffer);
1066 }
1067 #endif
1068 
1069 
1070 // MARK: mesh_segmented_pdu_t
1071 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS)
1072     #if defined(MAX_NO_MESH_SEGMENTED_PDUS)
1073         #error "Deprecated MAX_NO_MESH_SEGMENTED_PDUS defined instead of MAX_NR_MESH_SEGMENTED_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_SEGMENTED_PDUS."
1074     #else
1075         #define MAX_NR_MESH_SEGMENTED_PDUS 0
1076     #endif
1077 #endif
1078 
1079 #ifdef MAX_NR_MESH_SEGMENTED_PDUS
1080 #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1081 static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS];
1082 static btstack_memory_pool_t mesh_segmented_pdu_pool;
1083 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1084     void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool);
1085     if (buffer){
1086         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1087     }
1088     return (mesh_segmented_pdu_t *) buffer;
1089 }
1090 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1091     btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu);
1092 }
1093 #else
1094 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1095     return NULL;
1096 }
1097 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1098     UNUSED(mesh_segmented_pdu);
1099 };
1100 #endif
1101 #elif defined(HAVE_MALLOC)
1102 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1103     void * buffer = malloc(sizeof(mesh_segmented_pdu_t) + sizeof(btstack_memory_buffer_t));
1104     if (buffer){
1105         memset(buffer, 0, sizeof(mesh_segmented_pdu_t) + sizeof(btstack_memory_buffer_t));
1106         btstack_memory_tracking_add(buffer);
1107         return (mesh_segmented_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1108     } else {
1109         return NULL;
1110     }
1111 }
1112 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1113     void * buffer =  ((void *) mesh_segmented_pdu) - sizeof(btstack_memory_buffer_t);
1114     btstack_memory_tracking_remove(buffer);
1115     free(buffer);
1116 }
1117 #endif
1118 
1119 
1120 // MARK: mesh_upper_transport_pdu_t
1121 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS)
1122     #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS)
1123         #error "Deprecated MAX_NO_MESH_UPPER_TRANSPORT_PDUS defined instead of MAX_NR_MESH_UPPER_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_UPPER_TRANSPORT_PDUS."
1124     #else
1125         #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0
1126     #endif
1127 #endif
1128 
1129 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
1130 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1131 static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS];
1132 static btstack_memory_pool_t mesh_upper_transport_pdu_pool;
1133 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1134     void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool);
1135     if (buffer){
1136         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1137     }
1138     return (mesh_upper_transport_pdu_t *) buffer;
1139 }
1140 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1141     btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu);
1142 }
1143 #else
1144 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1145     return NULL;
1146 }
1147 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1148     UNUSED(mesh_upper_transport_pdu);
1149 };
1150 #endif
1151 #elif defined(HAVE_MALLOC)
1152 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1153     void * buffer = malloc(sizeof(mesh_upper_transport_pdu_t) + sizeof(btstack_memory_buffer_t));
1154     if (buffer){
1155         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t) + sizeof(btstack_memory_buffer_t));
1156         btstack_memory_tracking_add(buffer);
1157         return (mesh_upper_transport_pdu_t *) (buffer + sizeof(btstack_memory_buffer_t));
1158     } else {
1159         return NULL;
1160     }
1161 }
1162 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1163     void * buffer =  ((void *) mesh_upper_transport_pdu) - sizeof(btstack_memory_buffer_t);
1164     btstack_memory_tracking_remove(buffer);
1165     free(buffer);
1166 }
1167 #endif
1168 
1169 
1170 // MARK: mesh_network_key_t
1171 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
1172     #if defined(MAX_NO_MESH_NETWORK_KEYS)
1173         #error "Deprecated MAX_NO_MESH_NETWORK_KEYS defined instead of MAX_NR_MESH_NETWORK_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_KEYS."
1174     #else
1175         #define MAX_NR_MESH_NETWORK_KEYS 0
1176     #endif
1177 #endif
1178 
1179 #ifdef MAX_NR_MESH_NETWORK_KEYS
1180 #if MAX_NR_MESH_NETWORK_KEYS > 0
1181 static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
1182 static btstack_memory_pool_t mesh_network_key_pool;
1183 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1184     void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
1185     if (buffer){
1186         memset(buffer, 0, sizeof(mesh_network_key_t));
1187     }
1188     return (mesh_network_key_t *) buffer;
1189 }
1190 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1191     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
1192 }
1193 #else
1194 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1195     return NULL;
1196 }
1197 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1198     UNUSED(mesh_network_key);
1199 };
1200 #endif
1201 #elif defined(HAVE_MALLOC)
1202 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1203     void * buffer = malloc(sizeof(mesh_network_key_t) + sizeof(btstack_memory_buffer_t));
1204     if (buffer){
1205         memset(buffer, 0, sizeof(mesh_network_key_t) + sizeof(btstack_memory_buffer_t));
1206         btstack_memory_tracking_add(buffer);
1207         return (mesh_network_key_t *) (buffer + sizeof(btstack_memory_buffer_t));
1208     } else {
1209         return NULL;
1210     }
1211 }
1212 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1213     void * buffer =  ((void *) mesh_network_key) - sizeof(btstack_memory_buffer_t);
1214     btstack_memory_tracking_remove(buffer);
1215     free(buffer);
1216 }
1217 #endif
1218 
1219 
1220 // MARK: mesh_transport_key_t
1221 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
1222     #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
1223         #error "Deprecated MAX_NO_MESH_TRANSPORT_KEYS defined instead of MAX_NR_MESH_TRANSPORT_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_KEYS."
1224     #else
1225         #define MAX_NR_MESH_TRANSPORT_KEYS 0
1226     #endif
1227 #endif
1228 
1229 #ifdef MAX_NR_MESH_TRANSPORT_KEYS
1230 #if MAX_NR_MESH_TRANSPORT_KEYS > 0
1231 static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
1232 static btstack_memory_pool_t mesh_transport_key_pool;
1233 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1234     void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
1235     if (buffer){
1236         memset(buffer, 0, sizeof(mesh_transport_key_t));
1237     }
1238     return (mesh_transport_key_t *) buffer;
1239 }
1240 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1241     btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
1242 }
1243 #else
1244 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1245     return NULL;
1246 }
1247 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1248     UNUSED(mesh_transport_key);
1249 };
1250 #endif
1251 #elif defined(HAVE_MALLOC)
1252 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1253     void * buffer = malloc(sizeof(mesh_transport_key_t) + sizeof(btstack_memory_buffer_t));
1254     if (buffer){
1255         memset(buffer, 0, sizeof(mesh_transport_key_t) + sizeof(btstack_memory_buffer_t));
1256         btstack_memory_tracking_add(buffer);
1257         return (mesh_transport_key_t *) (buffer + sizeof(btstack_memory_buffer_t));
1258     } else {
1259         return NULL;
1260     }
1261 }
1262 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1263     void * buffer =  ((void *) mesh_transport_key) - sizeof(btstack_memory_buffer_t);
1264     btstack_memory_tracking_remove(buffer);
1265     free(buffer);
1266 }
1267 #endif
1268 
1269 
1270 // MARK: mesh_virtual_address_t
1271 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
1272     #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
1273         #error "Deprecated MAX_NO_MESH_VIRTUAL_ADDRESSS defined instead of MAX_NR_MESH_VIRTUAL_ADDRESSS. Please update your btstack_config.h to use MAX_NR_MESH_VIRTUAL_ADDRESSS."
1274     #else
1275         #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
1276     #endif
1277 #endif
1278 
1279 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
1280 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
1281 static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
1282 static btstack_memory_pool_t mesh_virtual_address_pool;
1283 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1284     void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
1285     if (buffer){
1286         memset(buffer, 0, sizeof(mesh_virtual_address_t));
1287     }
1288     return (mesh_virtual_address_t *) buffer;
1289 }
1290 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1291     btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
1292 }
1293 #else
1294 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1295     return NULL;
1296 }
1297 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1298     UNUSED(mesh_virtual_address);
1299 };
1300 #endif
1301 #elif defined(HAVE_MALLOC)
1302 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1303     void * buffer = malloc(sizeof(mesh_virtual_address_t) + sizeof(btstack_memory_buffer_t));
1304     if (buffer){
1305         memset(buffer, 0, sizeof(mesh_virtual_address_t) + sizeof(btstack_memory_buffer_t));
1306         btstack_memory_tracking_add(buffer);
1307         return (mesh_virtual_address_t *) (buffer + sizeof(btstack_memory_buffer_t));
1308     } else {
1309         return NULL;
1310     }
1311 }
1312 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1313     void * buffer =  ((void *) mesh_virtual_address) - sizeof(btstack_memory_buffer_t);
1314     btstack_memory_tracking_remove(buffer);
1315     free(buffer);
1316 }
1317 #endif
1318 
1319 
1320 // MARK: mesh_subnet_t
1321 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
1322     #if defined(MAX_NO_MESH_SUBNETS)
1323         #error "Deprecated MAX_NO_MESH_SUBNETS defined instead of MAX_NR_MESH_SUBNETS. Please update your btstack_config.h to use MAX_NR_MESH_SUBNETS."
1324     #else
1325         #define MAX_NR_MESH_SUBNETS 0
1326     #endif
1327 #endif
1328 
1329 #ifdef MAX_NR_MESH_SUBNETS
1330 #if MAX_NR_MESH_SUBNETS > 0
1331 static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
1332 static btstack_memory_pool_t mesh_subnet_pool;
1333 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1334     void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
1335     if (buffer){
1336         memset(buffer, 0, sizeof(mesh_subnet_t));
1337     }
1338     return (mesh_subnet_t *) buffer;
1339 }
1340 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1341     btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
1342 }
1343 #else
1344 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1345     return NULL;
1346 }
1347 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1348     UNUSED(mesh_subnet);
1349 };
1350 #endif
1351 #elif defined(HAVE_MALLOC)
1352 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1353     void * buffer = malloc(sizeof(mesh_subnet_t) + sizeof(btstack_memory_buffer_t));
1354     if (buffer){
1355         memset(buffer, 0, sizeof(mesh_subnet_t) + sizeof(btstack_memory_buffer_t));
1356         btstack_memory_tracking_add(buffer);
1357         return (mesh_subnet_t *) (buffer + sizeof(btstack_memory_buffer_t));
1358     } else {
1359         return NULL;
1360     }
1361 }
1362 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1363     void * buffer =  ((void *) mesh_subnet) - sizeof(btstack_memory_buffer_t);
1364     btstack_memory_tracking_remove(buffer);
1365     free(buffer);
1366 }
1367 #endif
1368 
1369 
1370 #endif
1371 // init
1372 void btstack_memory_init(void){
1373 #if MAX_NR_HCI_CONNECTIONS > 0
1374     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
1375 #endif
1376 #if MAX_NR_L2CAP_SERVICES > 0
1377     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
1378 #endif
1379 #if MAX_NR_L2CAP_CHANNELS > 0
1380     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
1381 #endif
1382 #ifdef ENABLE_CLASSIC
1383 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
1384     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
1385 #endif
1386 #if MAX_NR_RFCOMM_SERVICES > 0
1387     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
1388 #endif
1389 #if MAX_NR_RFCOMM_CHANNELS > 0
1390     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
1391 #endif
1392 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
1393     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));
1394 #endif
1395 #if MAX_NR_BNEP_SERVICES > 0
1396     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
1397 #endif
1398 #if MAX_NR_BNEP_CHANNELS > 0
1399     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
1400 #endif
1401 #if MAX_NR_HFP_CONNECTIONS > 0
1402     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
1403 #endif
1404 #if MAX_NR_SERVICE_RECORD_ITEMS > 0
1405     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
1406 #endif
1407 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
1408     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
1409 #endif
1410 #if MAX_NR_AVDTP_CONNECTIONS > 0
1411     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
1412 #endif
1413 #if MAX_NR_AVRCP_CONNECTIONS > 0
1414     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
1415 #endif
1416 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
1417     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1418 #endif
1419 #endif
1420 #ifdef ENABLE_BLE
1421 #if MAX_NR_GATT_CLIENTS > 0
1422     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1423 #endif
1424 #if MAX_NR_WHITELIST_ENTRIES > 0
1425     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1426 #endif
1427 #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1428     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1429 #endif
1430 #endif
1431 #ifdef ENABLE_MESH
1432 #if MAX_NR_MESH_NETWORK_PDUS > 0
1433     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
1434 #endif
1435 #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1436     btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t));
1437 #endif
1438 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1439     btstack_memory_pool_create(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu_storage, MAX_NR_MESH_UPPER_TRANSPORT_PDUS, sizeof(mesh_upper_transport_pdu_t));
1440 #endif
1441 #if MAX_NR_MESH_NETWORK_KEYS > 0
1442     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1443 #endif
1444 #if MAX_NR_MESH_TRANSPORT_KEYS > 0
1445     btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
1446 #endif
1447 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
1448     btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
1449 #endif
1450 #if MAX_NR_MESH_SUBNETS > 0
1451     btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
1452 #endif
1453 #endif
1454 }
1455