xref: /btstack/src/btstack_memory.c (revision 19ef97d232ee437fe9ff38a7e7a560fcf0370b6a)
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 static uint32_t btstack_memory_malloc_counter;
66 
67 static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){
68     btstack_assert(buffer != NULL);
69     if (btstack_memory_malloc_buffers != NULL) {
70         // let current first item prev point to new first item
71         btstack_memory_malloc_buffers->prev = buffer;
72     }
73     buffer->prev = NULL;
74     buffer->next = btstack_memory_malloc_buffers;
75     btstack_memory_malloc_buffers = buffer;
76 
77     btstack_memory_malloc_counter++;
78 }
79 
80 static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){
81     btstack_assert(buffer != NULL);
82     if (buffer->prev == NULL){
83         // first item
84         btstack_memory_malloc_buffers = buffer->next;
85     } else {
86         buffer->prev->next = buffer->next;
87     }
88     if (buffer->next != NULL){
89         buffer->next->prev = buffer->prev;
90     }
91 
92     btstack_memory_malloc_counter--;
93 }
94 #endif
95 
96 void btstack_memory_deinit(void){
97 #ifdef HAVE_MALLOC
98     while (btstack_memory_malloc_buffers != NULL){
99         btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers;
100         btstack_memory_malloc_buffers = buffer->next;
101         free(buffer);
102     }
103     btstack_assert(btstack_memory_malloc_counter == 0);
104 #endif
105 }
106 
107 
108 // MARK: hci_connection_t
109 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
110     #if defined(MAX_NO_HCI_CONNECTIONS)
111         #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."
112     #else
113         #define MAX_NR_HCI_CONNECTIONS 0
114     #endif
115 #endif
116 
117 #ifdef MAX_NR_HCI_CONNECTIONS
118 #if MAX_NR_HCI_CONNECTIONS > 0
119 static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
120 static btstack_memory_pool_t hci_connection_pool;
121 hci_connection_t * btstack_memory_hci_connection_get(void){
122     void * buffer = btstack_memory_pool_get(&hci_connection_pool);
123     if (buffer){
124         memset(buffer, 0, sizeof(hci_connection_t));
125     }
126     return (hci_connection_t *) buffer;
127 }
128 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
129     btstack_memory_pool_free(&hci_connection_pool, hci_connection);
130 }
131 #else
132 hci_connection_t * btstack_memory_hci_connection_get(void){
133     return NULL;
134 }
135 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
136     UNUSED(hci_connection);
137 };
138 #endif
139 #elif defined(HAVE_MALLOC)
140 
141 typedef struct {
142     hci_connection_t data;
143     btstack_memory_buffer_t tracking;
144 } btstack_memory_hci_connection_t;
145 
146 hci_connection_t * btstack_memory_hci_connection_get(void){
147     btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t));
148     if (buffer){
149         memset(buffer, 0, sizeof(hci_connection_t));
150         btstack_memory_tracking_add(&buffer->tracking);
151         return &buffer->data;
152     } else {
153         return NULL;
154     }
155 }
156 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
157     btstack_memory_hci_connection_t * buffer =  (btstack_memory_hci_connection_t *) hci_connection;
158     btstack_memory_tracking_remove(&buffer->tracking);
159     free(buffer);
160 }
161 #endif
162 
163 
164 
165 // MARK: l2cap_service_t
166 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
167     #if defined(MAX_NO_L2CAP_SERVICES)
168         #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."
169     #else
170         #define MAX_NR_L2CAP_SERVICES 0
171     #endif
172 #endif
173 
174 #ifdef MAX_NR_L2CAP_SERVICES
175 #if MAX_NR_L2CAP_SERVICES > 0
176 static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
177 static btstack_memory_pool_t l2cap_service_pool;
178 l2cap_service_t * btstack_memory_l2cap_service_get(void){
179     void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
180     if (buffer){
181         memset(buffer, 0, sizeof(l2cap_service_t));
182     }
183     return (l2cap_service_t *) buffer;
184 }
185 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
186     btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
187 }
188 #else
189 l2cap_service_t * btstack_memory_l2cap_service_get(void){
190     return NULL;
191 }
192 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
193     UNUSED(l2cap_service);
194 };
195 #endif
196 #elif defined(HAVE_MALLOC)
197 
198 typedef struct {
199     l2cap_service_t data;
200     btstack_memory_buffer_t tracking;
201 } btstack_memory_l2cap_service_t;
202 
203 l2cap_service_t * btstack_memory_l2cap_service_get(void){
204     btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t));
205     if (buffer){
206         memset(buffer, 0, sizeof(l2cap_service_t));
207         btstack_memory_tracking_add(&buffer->tracking);
208         return &buffer->data;
209     } else {
210         return NULL;
211     }
212 }
213 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
214     btstack_memory_l2cap_service_t * buffer =  (btstack_memory_l2cap_service_t *) l2cap_service;
215     btstack_memory_tracking_remove(&buffer->tracking);
216     free(buffer);
217 }
218 #endif
219 
220 
221 // MARK: l2cap_channel_t
222 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
223     #if defined(MAX_NO_L2CAP_CHANNELS)
224         #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."
225     #else
226         #define MAX_NR_L2CAP_CHANNELS 0
227     #endif
228 #endif
229 
230 #ifdef MAX_NR_L2CAP_CHANNELS
231 #if MAX_NR_L2CAP_CHANNELS > 0
232 static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
233 static btstack_memory_pool_t l2cap_channel_pool;
234 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
235     void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
236     if (buffer){
237         memset(buffer, 0, sizeof(l2cap_channel_t));
238     }
239     return (l2cap_channel_t *) buffer;
240 }
241 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
242     btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
243 }
244 #else
245 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
246     return NULL;
247 }
248 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
249     UNUSED(l2cap_channel);
250 };
251 #endif
252 #elif defined(HAVE_MALLOC)
253 
254 typedef struct {
255     l2cap_channel_t data;
256     btstack_memory_buffer_t tracking;
257 } btstack_memory_l2cap_channel_t;
258 
259 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
260     btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t));
261     if (buffer){
262         memset(buffer, 0, sizeof(l2cap_channel_t));
263         btstack_memory_tracking_add(&buffer->tracking);
264         return &buffer->data;
265     } else {
266         return NULL;
267     }
268 }
269 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
270     btstack_memory_l2cap_channel_t * buffer =  (btstack_memory_l2cap_channel_t *) l2cap_channel;
271     btstack_memory_tracking_remove(&buffer->tracking);
272     free(buffer);
273 }
274 #endif
275 
276 
277 #ifdef ENABLE_CLASSIC
278 
279 // MARK: rfcomm_multiplexer_t
280 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
281     #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
282         #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."
283     #else
284         #define MAX_NR_RFCOMM_MULTIPLEXERS 0
285     #endif
286 #endif
287 
288 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
289 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
290 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
291 static btstack_memory_pool_t rfcomm_multiplexer_pool;
292 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
293     void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
294     if (buffer){
295         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
296     }
297     return (rfcomm_multiplexer_t *) buffer;
298 }
299 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
300     btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
301 }
302 #else
303 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
304     return NULL;
305 }
306 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
307     UNUSED(rfcomm_multiplexer);
308 };
309 #endif
310 #elif defined(HAVE_MALLOC)
311 
312 typedef struct {
313     rfcomm_multiplexer_t data;
314     btstack_memory_buffer_t tracking;
315 } btstack_memory_rfcomm_multiplexer_t;
316 
317 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
318     btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t));
319     if (buffer){
320         memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
321         btstack_memory_tracking_add(&buffer->tracking);
322         return &buffer->data;
323     } else {
324         return NULL;
325     }
326 }
327 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
328     btstack_memory_rfcomm_multiplexer_t * buffer =  (btstack_memory_rfcomm_multiplexer_t *) rfcomm_multiplexer;
329     btstack_memory_tracking_remove(&buffer->tracking);
330     free(buffer);
331 }
332 #endif
333 
334 
335 // MARK: rfcomm_service_t
336 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
337     #if defined(MAX_NO_RFCOMM_SERVICES)
338         #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."
339     #else
340         #define MAX_NR_RFCOMM_SERVICES 0
341     #endif
342 #endif
343 
344 #ifdef MAX_NR_RFCOMM_SERVICES
345 #if MAX_NR_RFCOMM_SERVICES > 0
346 static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
347 static btstack_memory_pool_t rfcomm_service_pool;
348 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
349     void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
350     if (buffer){
351         memset(buffer, 0, sizeof(rfcomm_service_t));
352     }
353     return (rfcomm_service_t *) buffer;
354 }
355 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
356     btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
357 }
358 #else
359 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
360     return NULL;
361 }
362 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
363     UNUSED(rfcomm_service);
364 };
365 #endif
366 #elif defined(HAVE_MALLOC)
367 
368 typedef struct {
369     rfcomm_service_t data;
370     btstack_memory_buffer_t tracking;
371 } btstack_memory_rfcomm_service_t;
372 
373 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
374     btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t));
375     if (buffer){
376         memset(buffer, 0, sizeof(rfcomm_service_t));
377         btstack_memory_tracking_add(&buffer->tracking);
378         return &buffer->data;
379     } else {
380         return NULL;
381     }
382 }
383 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
384     btstack_memory_rfcomm_service_t * buffer =  (btstack_memory_rfcomm_service_t *) rfcomm_service;
385     btstack_memory_tracking_remove(&buffer->tracking);
386     free(buffer);
387 }
388 #endif
389 
390 
391 // MARK: rfcomm_channel_t
392 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
393     #if defined(MAX_NO_RFCOMM_CHANNELS)
394         #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."
395     #else
396         #define MAX_NR_RFCOMM_CHANNELS 0
397     #endif
398 #endif
399 
400 #ifdef MAX_NR_RFCOMM_CHANNELS
401 #if MAX_NR_RFCOMM_CHANNELS > 0
402 static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
403 static btstack_memory_pool_t rfcomm_channel_pool;
404 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
405     void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
406     if (buffer){
407         memset(buffer, 0, sizeof(rfcomm_channel_t));
408     }
409     return (rfcomm_channel_t *) buffer;
410 }
411 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
412     btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
413 }
414 #else
415 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
416     return NULL;
417 }
418 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
419     UNUSED(rfcomm_channel);
420 };
421 #endif
422 #elif defined(HAVE_MALLOC)
423 
424 typedef struct {
425     rfcomm_channel_t data;
426     btstack_memory_buffer_t tracking;
427 } btstack_memory_rfcomm_channel_t;
428 
429 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
430     btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t));
431     if (buffer){
432         memset(buffer, 0, sizeof(rfcomm_channel_t));
433         btstack_memory_tracking_add(&buffer->tracking);
434         return &buffer->data;
435     } else {
436         return NULL;
437     }
438 }
439 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
440     btstack_memory_rfcomm_channel_t * buffer =  (btstack_memory_rfcomm_channel_t *) rfcomm_channel;
441     btstack_memory_tracking_remove(&buffer->tracking);
442     free(buffer);
443 }
444 #endif
445 
446 
447 
448 // MARK: btstack_link_key_db_memory_entry_t
449 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
450     #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
451         #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."
452     #else
453         #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
454     #endif
455 #endif
456 
457 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
458 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
459 static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
460 static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
461 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
462     void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
463     if (buffer){
464         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
465     }
466     return (btstack_link_key_db_memory_entry_t *) buffer;
467 }
468 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
469     btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
470 }
471 #else
472 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
473     return NULL;
474 }
475 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
476     UNUSED(btstack_link_key_db_memory_entry);
477 };
478 #endif
479 #elif defined(HAVE_MALLOC)
480 
481 typedef struct {
482     btstack_link_key_db_memory_entry_t data;
483     btstack_memory_buffer_t tracking;
484 } btstack_memory_btstack_link_key_db_memory_entry_t;
485 
486 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
487     btstack_memory_btstack_link_key_db_memory_entry_t * buffer = (btstack_memory_btstack_link_key_db_memory_entry_t *) malloc(sizeof(btstack_memory_btstack_link_key_db_memory_entry_t));
488     if (buffer){
489         memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
490         btstack_memory_tracking_add(&buffer->tracking);
491         return &buffer->data;
492     } else {
493         return NULL;
494     }
495 }
496 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
497     btstack_memory_btstack_link_key_db_memory_entry_t * buffer =  (btstack_memory_btstack_link_key_db_memory_entry_t *) btstack_link_key_db_memory_entry;
498     btstack_memory_tracking_remove(&buffer->tracking);
499     free(buffer);
500 }
501 #endif
502 
503 
504 
505 // MARK: bnep_service_t
506 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
507     #if defined(MAX_NO_BNEP_SERVICES)
508         #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."
509     #else
510         #define MAX_NR_BNEP_SERVICES 0
511     #endif
512 #endif
513 
514 #ifdef MAX_NR_BNEP_SERVICES
515 #if MAX_NR_BNEP_SERVICES > 0
516 static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
517 static btstack_memory_pool_t bnep_service_pool;
518 bnep_service_t * btstack_memory_bnep_service_get(void){
519     void * buffer = btstack_memory_pool_get(&bnep_service_pool);
520     if (buffer){
521         memset(buffer, 0, sizeof(bnep_service_t));
522     }
523     return (bnep_service_t *) buffer;
524 }
525 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
526     btstack_memory_pool_free(&bnep_service_pool, bnep_service);
527 }
528 #else
529 bnep_service_t * btstack_memory_bnep_service_get(void){
530     return NULL;
531 }
532 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
533     UNUSED(bnep_service);
534 };
535 #endif
536 #elif defined(HAVE_MALLOC)
537 
538 typedef struct {
539     bnep_service_t data;
540     btstack_memory_buffer_t tracking;
541 } btstack_memory_bnep_service_t;
542 
543 bnep_service_t * btstack_memory_bnep_service_get(void){
544     btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t));
545     if (buffer){
546         memset(buffer, 0, sizeof(bnep_service_t));
547         btstack_memory_tracking_add(&buffer->tracking);
548         return &buffer->data;
549     } else {
550         return NULL;
551     }
552 }
553 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
554     btstack_memory_bnep_service_t * buffer =  (btstack_memory_bnep_service_t *) bnep_service;
555     btstack_memory_tracking_remove(&buffer->tracking);
556     free(buffer);
557 }
558 #endif
559 
560 
561 // MARK: bnep_channel_t
562 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
563     #if defined(MAX_NO_BNEP_CHANNELS)
564         #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."
565     #else
566         #define MAX_NR_BNEP_CHANNELS 0
567     #endif
568 #endif
569 
570 #ifdef MAX_NR_BNEP_CHANNELS
571 #if MAX_NR_BNEP_CHANNELS > 0
572 static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
573 static btstack_memory_pool_t bnep_channel_pool;
574 bnep_channel_t * btstack_memory_bnep_channel_get(void){
575     void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
576     if (buffer){
577         memset(buffer, 0, sizeof(bnep_channel_t));
578     }
579     return (bnep_channel_t *) buffer;
580 }
581 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
582     btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
583 }
584 #else
585 bnep_channel_t * btstack_memory_bnep_channel_get(void){
586     return NULL;
587 }
588 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
589     UNUSED(bnep_channel);
590 };
591 #endif
592 #elif defined(HAVE_MALLOC)
593 
594 typedef struct {
595     bnep_channel_t data;
596     btstack_memory_buffer_t tracking;
597 } btstack_memory_bnep_channel_t;
598 
599 bnep_channel_t * btstack_memory_bnep_channel_get(void){
600     btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t));
601     if (buffer){
602         memset(buffer, 0, sizeof(bnep_channel_t));
603         btstack_memory_tracking_add(&buffer->tracking);
604         return &buffer->data;
605     } else {
606         return NULL;
607     }
608 }
609 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
610     btstack_memory_bnep_channel_t * buffer =  (btstack_memory_bnep_channel_t *) bnep_channel;
611     btstack_memory_tracking_remove(&buffer->tracking);
612     free(buffer);
613 }
614 #endif
615 
616 
617 
618 // MARK: hfp_connection_t
619 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
620     #if defined(MAX_NO_HFP_CONNECTIONS)
621         #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."
622     #else
623         #define MAX_NR_HFP_CONNECTIONS 0
624     #endif
625 #endif
626 
627 #ifdef MAX_NR_HFP_CONNECTIONS
628 #if MAX_NR_HFP_CONNECTIONS > 0
629 static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
630 static btstack_memory_pool_t hfp_connection_pool;
631 hfp_connection_t * btstack_memory_hfp_connection_get(void){
632     void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
633     if (buffer){
634         memset(buffer, 0, sizeof(hfp_connection_t));
635     }
636     return (hfp_connection_t *) buffer;
637 }
638 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
639     btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
640 }
641 #else
642 hfp_connection_t * btstack_memory_hfp_connection_get(void){
643     return NULL;
644 }
645 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
646     UNUSED(hfp_connection);
647 };
648 #endif
649 #elif defined(HAVE_MALLOC)
650 
651 typedef struct {
652     hfp_connection_t data;
653     btstack_memory_buffer_t tracking;
654 } btstack_memory_hfp_connection_t;
655 
656 hfp_connection_t * btstack_memory_hfp_connection_get(void){
657     btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t));
658     if (buffer){
659         memset(buffer, 0, sizeof(hfp_connection_t));
660         btstack_memory_tracking_add(&buffer->tracking);
661         return &buffer->data;
662     } else {
663         return NULL;
664     }
665 }
666 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
667     btstack_memory_hfp_connection_t * buffer =  (btstack_memory_hfp_connection_t *) hfp_connection;
668     btstack_memory_tracking_remove(&buffer->tracking);
669     free(buffer);
670 }
671 #endif
672 
673 
674 
675 // MARK: service_record_item_t
676 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
677     #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
678         #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."
679     #else
680         #define MAX_NR_SERVICE_RECORD_ITEMS 0
681     #endif
682 #endif
683 
684 #ifdef MAX_NR_SERVICE_RECORD_ITEMS
685 #if MAX_NR_SERVICE_RECORD_ITEMS > 0
686 static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
687 static btstack_memory_pool_t service_record_item_pool;
688 service_record_item_t * btstack_memory_service_record_item_get(void){
689     void * buffer = btstack_memory_pool_get(&service_record_item_pool);
690     if (buffer){
691         memset(buffer, 0, sizeof(service_record_item_t));
692     }
693     return (service_record_item_t *) buffer;
694 }
695 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
696     btstack_memory_pool_free(&service_record_item_pool, service_record_item);
697 }
698 #else
699 service_record_item_t * btstack_memory_service_record_item_get(void){
700     return NULL;
701 }
702 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
703     UNUSED(service_record_item);
704 };
705 #endif
706 #elif defined(HAVE_MALLOC)
707 
708 typedef struct {
709     service_record_item_t data;
710     btstack_memory_buffer_t tracking;
711 } btstack_memory_service_record_item_t;
712 
713 service_record_item_t * btstack_memory_service_record_item_get(void){
714     btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t));
715     if (buffer){
716         memset(buffer, 0, sizeof(service_record_item_t));
717         btstack_memory_tracking_add(&buffer->tracking);
718         return &buffer->data;
719     } else {
720         return NULL;
721     }
722 }
723 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
724     btstack_memory_service_record_item_t * buffer =  (btstack_memory_service_record_item_t *) service_record_item;
725     btstack_memory_tracking_remove(&buffer->tracking);
726     free(buffer);
727 }
728 #endif
729 
730 
731 
732 // MARK: avdtp_stream_endpoint_t
733 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
734     #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
735         #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."
736     #else
737         #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
738     #endif
739 #endif
740 
741 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
742 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
743 static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
744 static btstack_memory_pool_t avdtp_stream_endpoint_pool;
745 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
746     void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
747     if (buffer){
748         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
749     }
750     return (avdtp_stream_endpoint_t *) buffer;
751 }
752 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
753     btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
754 }
755 #else
756 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
757     return NULL;
758 }
759 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
760     UNUSED(avdtp_stream_endpoint);
761 };
762 #endif
763 #elif defined(HAVE_MALLOC)
764 
765 typedef struct {
766     avdtp_stream_endpoint_t data;
767     btstack_memory_buffer_t tracking;
768 } btstack_memory_avdtp_stream_endpoint_t;
769 
770 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
771     btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t));
772     if (buffer){
773         memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
774         btstack_memory_tracking_add(&buffer->tracking);
775         return &buffer->data;
776     } else {
777         return NULL;
778     }
779 }
780 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
781     btstack_memory_avdtp_stream_endpoint_t * buffer =  (btstack_memory_avdtp_stream_endpoint_t *) avdtp_stream_endpoint;
782     btstack_memory_tracking_remove(&buffer->tracking);
783     free(buffer);
784 }
785 #endif
786 
787 
788 
789 // MARK: avdtp_connection_t
790 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
791     #if defined(MAX_NO_AVDTP_CONNECTIONS)
792         #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."
793     #else
794         #define MAX_NR_AVDTP_CONNECTIONS 0
795     #endif
796 #endif
797 
798 #ifdef MAX_NR_AVDTP_CONNECTIONS
799 #if MAX_NR_AVDTP_CONNECTIONS > 0
800 static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
801 static btstack_memory_pool_t avdtp_connection_pool;
802 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
803     void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
804     if (buffer){
805         memset(buffer, 0, sizeof(avdtp_connection_t));
806     }
807     return (avdtp_connection_t *) buffer;
808 }
809 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
810     btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
811 }
812 #else
813 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
814     return NULL;
815 }
816 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
817     UNUSED(avdtp_connection);
818 };
819 #endif
820 #elif defined(HAVE_MALLOC)
821 
822 typedef struct {
823     avdtp_connection_t data;
824     btstack_memory_buffer_t tracking;
825 } btstack_memory_avdtp_connection_t;
826 
827 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
828     btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t));
829     if (buffer){
830         memset(buffer, 0, sizeof(avdtp_connection_t));
831         btstack_memory_tracking_add(&buffer->tracking);
832         return &buffer->data;
833     } else {
834         return NULL;
835     }
836 }
837 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
838     btstack_memory_avdtp_connection_t * buffer =  (btstack_memory_avdtp_connection_t *) avdtp_connection;
839     btstack_memory_tracking_remove(&buffer->tracking);
840     free(buffer);
841 }
842 #endif
843 
844 
845 
846 // MARK: avrcp_connection_t
847 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
848     #if defined(MAX_NO_AVRCP_CONNECTIONS)
849         #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."
850     #else
851         #define MAX_NR_AVRCP_CONNECTIONS 0
852     #endif
853 #endif
854 
855 #ifdef MAX_NR_AVRCP_CONNECTIONS
856 #if MAX_NR_AVRCP_CONNECTIONS > 0
857 static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
858 static btstack_memory_pool_t avrcp_connection_pool;
859 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
860     void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
861     if (buffer){
862         memset(buffer, 0, sizeof(avrcp_connection_t));
863     }
864     return (avrcp_connection_t *) buffer;
865 }
866 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
867     btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
868 }
869 #else
870 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
871     return NULL;
872 }
873 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
874     UNUSED(avrcp_connection);
875 };
876 #endif
877 #elif defined(HAVE_MALLOC)
878 
879 typedef struct {
880     avrcp_connection_t data;
881     btstack_memory_buffer_t tracking;
882 } btstack_memory_avrcp_connection_t;
883 
884 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
885     btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t));
886     if (buffer){
887         memset(buffer, 0, sizeof(avrcp_connection_t));
888         btstack_memory_tracking_add(&buffer->tracking);
889         return &buffer->data;
890     } else {
891         return NULL;
892     }
893 }
894 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
895     btstack_memory_avrcp_connection_t * buffer =  (btstack_memory_avrcp_connection_t *) avrcp_connection;
896     btstack_memory_tracking_remove(&buffer->tracking);
897     free(buffer);
898 }
899 #endif
900 
901 
902 
903 // MARK: avrcp_browsing_connection_t
904 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
905     #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
906         #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."
907     #else
908         #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
909     #endif
910 #endif
911 
912 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
913 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
914 static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
915 static btstack_memory_pool_t avrcp_browsing_connection_pool;
916 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
917     void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
918     if (buffer){
919         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
920     }
921     return (avrcp_browsing_connection_t *) buffer;
922 }
923 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
924     btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
925 }
926 #else
927 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
928     return NULL;
929 }
930 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
931     UNUSED(avrcp_browsing_connection);
932 };
933 #endif
934 #elif defined(HAVE_MALLOC)
935 
936 typedef struct {
937     avrcp_browsing_connection_t data;
938     btstack_memory_buffer_t tracking;
939 } btstack_memory_avrcp_browsing_connection_t;
940 
941 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
942     btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t));
943     if (buffer){
944         memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
945         btstack_memory_tracking_add(&buffer->tracking);
946         return &buffer->data;
947     } else {
948         return NULL;
949     }
950 }
951 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
952     btstack_memory_avrcp_browsing_connection_t * buffer =  (btstack_memory_avrcp_browsing_connection_t *) avrcp_browsing_connection;
953     btstack_memory_tracking_remove(&buffer->tracking);
954     free(buffer);
955 }
956 #endif
957 
958 
959 #endif
960 #ifdef ENABLE_BLE
961 
962 // MARK: gatt_client_t
963 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
964     #if defined(MAX_NO_GATT_CLIENTS)
965         #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."
966     #else
967         #define MAX_NR_GATT_CLIENTS 0
968     #endif
969 #endif
970 
971 #ifdef MAX_NR_GATT_CLIENTS
972 #if MAX_NR_GATT_CLIENTS > 0
973 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
974 static btstack_memory_pool_t gatt_client_pool;
975 gatt_client_t * btstack_memory_gatt_client_get(void){
976     void * buffer = btstack_memory_pool_get(&gatt_client_pool);
977     if (buffer){
978         memset(buffer, 0, sizeof(gatt_client_t));
979     }
980     return (gatt_client_t *) buffer;
981 }
982 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
983     btstack_memory_pool_free(&gatt_client_pool, gatt_client);
984 }
985 #else
986 gatt_client_t * btstack_memory_gatt_client_get(void){
987     return NULL;
988 }
989 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
990     UNUSED(gatt_client);
991 };
992 #endif
993 #elif defined(HAVE_MALLOC)
994 
995 typedef struct {
996     gatt_client_t data;
997     btstack_memory_buffer_t tracking;
998 } btstack_memory_gatt_client_t;
999 
1000 gatt_client_t * btstack_memory_gatt_client_get(void){
1001     btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t));
1002     if (buffer){
1003         memset(buffer, 0, sizeof(gatt_client_t));
1004         btstack_memory_tracking_add(&buffer->tracking);
1005         return &buffer->data;
1006     } else {
1007         return NULL;
1008     }
1009 }
1010 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
1011     btstack_memory_gatt_client_t * buffer =  (btstack_memory_gatt_client_t *) gatt_client;
1012     btstack_memory_tracking_remove(&buffer->tracking);
1013     free(buffer);
1014 }
1015 #endif
1016 
1017 
1018 // MARK: whitelist_entry_t
1019 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
1020     #if defined(MAX_NO_WHITELIST_ENTRIES)
1021         #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."
1022     #else
1023         #define MAX_NR_WHITELIST_ENTRIES 0
1024     #endif
1025 #endif
1026 
1027 #ifdef MAX_NR_WHITELIST_ENTRIES
1028 #if MAX_NR_WHITELIST_ENTRIES > 0
1029 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
1030 static btstack_memory_pool_t whitelist_entry_pool;
1031 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1032     void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
1033     if (buffer){
1034         memset(buffer, 0, sizeof(whitelist_entry_t));
1035     }
1036     return (whitelist_entry_t *) buffer;
1037 }
1038 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1039     btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
1040 }
1041 #else
1042 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1043     return NULL;
1044 }
1045 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1046     UNUSED(whitelist_entry);
1047 };
1048 #endif
1049 #elif defined(HAVE_MALLOC)
1050 
1051 typedef struct {
1052     whitelist_entry_t data;
1053     btstack_memory_buffer_t tracking;
1054 } btstack_memory_whitelist_entry_t;
1055 
1056 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
1057     btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t));
1058     if (buffer){
1059         memset(buffer, 0, sizeof(whitelist_entry_t));
1060         btstack_memory_tracking_add(&buffer->tracking);
1061         return &buffer->data;
1062     } else {
1063         return NULL;
1064     }
1065 }
1066 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
1067     btstack_memory_whitelist_entry_t * buffer =  (btstack_memory_whitelist_entry_t *) whitelist_entry;
1068     btstack_memory_tracking_remove(&buffer->tracking);
1069     free(buffer);
1070 }
1071 #endif
1072 
1073 
1074 // MARK: sm_lookup_entry_t
1075 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
1076     #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
1077         #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."
1078     #else
1079         #define MAX_NR_SM_LOOKUP_ENTRIES 0
1080     #endif
1081 #endif
1082 
1083 #ifdef MAX_NR_SM_LOOKUP_ENTRIES
1084 #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1085 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
1086 static btstack_memory_pool_t sm_lookup_entry_pool;
1087 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1088     void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
1089     if (buffer){
1090         memset(buffer, 0, sizeof(sm_lookup_entry_t));
1091     }
1092     return (sm_lookup_entry_t *) buffer;
1093 }
1094 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1095     btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
1096 }
1097 #else
1098 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1099     return NULL;
1100 }
1101 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1102     UNUSED(sm_lookup_entry);
1103 };
1104 #endif
1105 #elif defined(HAVE_MALLOC)
1106 
1107 typedef struct {
1108     sm_lookup_entry_t data;
1109     btstack_memory_buffer_t tracking;
1110 } btstack_memory_sm_lookup_entry_t;
1111 
1112 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
1113     btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t));
1114     if (buffer){
1115         memset(buffer, 0, sizeof(sm_lookup_entry_t));
1116         btstack_memory_tracking_add(&buffer->tracking);
1117         return &buffer->data;
1118     } else {
1119         return NULL;
1120     }
1121 }
1122 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
1123     btstack_memory_sm_lookup_entry_t * buffer =  (btstack_memory_sm_lookup_entry_t *) sm_lookup_entry;
1124     btstack_memory_tracking_remove(&buffer->tracking);
1125     free(buffer);
1126 }
1127 #endif
1128 
1129 
1130 #endif
1131 #ifdef ENABLE_MESH
1132 
1133 // MARK: mesh_network_pdu_t
1134 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
1135     #if defined(MAX_NO_MESH_NETWORK_PDUS)
1136         #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."
1137     #else
1138         #define MAX_NR_MESH_NETWORK_PDUS 0
1139     #endif
1140 #endif
1141 
1142 #ifdef MAX_NR_MESH_NETWORK_PDUS
1143 #if MAX_NR_MESH_NETWORK_PDUS > 0
1144 static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
1145 static btstack_memory_pool_t mesh_network_pdu_pool;
1146 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1147     void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
1148     if (buffer){
1149         memset(buffer, 0, sizeof(mesh_network_pdu_t));
1150     }
1151     return (mesh_network_pdu_t *) buffer;
1152 }
1153 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1154     btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
1155 }
1156 #else
1157 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1158     return NULL;
1159 }
1160 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1161     UNUSED(mesh_network_pdu);
1162 };
1163 #endif
1164 #elif defined(HAVE_MALLOC)
1165 
1166 typedef struct {
1167     mesh_network_pdu_t data;
1168     btstack_memory_buffer_t tracking;
1169 } btstack_memory_mesh_network_pdu_t;
1170 
1171 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
1172     btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t));
1173     if (buffer){
1174         memset(buffer, 0, sizeof(mesh_network_pdu_t));
1175         btstack_memory_tracking_add(&buffer->tracking);
1176         return &buffer->data;
1177     } else {
1178         return NULL;
1179     }
1180 }
1181 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
1182     btstack_memory_mesh_network_pdu_t * buffer =  (btstack_memory_mesh_network_pdu_t *) mesh_network_pdu;
1183     btstack_memory_tracking_remove(&buffer->tracking);
1184     free(buffer);
1185 }
1186 #endif
1187 
1188 
1189 // MARK: mesh_segmented_pdu_t
1190 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS)
1191     #if defined(MAX_NO_MESH_SEGMENTED_PDUS)
1192         #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."
1193     #else
1194         #define MAX_NR_MESH_SEGMENTED_PDUS 0
1195     #endif
1196 #endif
1197 
1198 #ifdef MAX_NR_MESH_SEGMENTED_PDUS
1199 #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1200 static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS];
1201 static btstack_memory_pool_t mesh_segmented_pdu_pool;
1202 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1203     void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool);
1204     if (buffer){
1205         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1206     }
1207     return (mesh_segmented_pdu_t *) buffer;
1208 }
1209 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1210     btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu);
1211 }
1212 #else
1213 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1214     return NULL;
1215 }
1216 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1217     UNUSED(mesh_segmented_pdu);
1218 };
1219 #endif
1220 #elif defined(HAVE_MALLOC)
1221 
1222 typedef struct {
1223     mesh_segmented_pdu_t data;
1224     btstack_memory_buffer_t tracking;
1225 } btstack_memory_mesh_segmented_pdu_t;
1226 
1227 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){
1228     btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t));
1229     if (buffer){
1230         memset(buffer, 0, sizeof(mesh_segmented_pdu_t));
1231         btstack_memory_tracking_add(&buffer->tracking);
1232         return &buffer->data;
1233     } else {
1234         return NULL;
1235     }
1236 }
1237 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){
1238     btstack_memory_mesh_segmented_pdu_t * buffer =  (btstack_memory_mesh_segmented_pdu_t *) mesh_segmented_pdu;
1239     btstack_memory_tracking_remove(&buffer->tracking);
1240     free(buffer);
1241 }
1242 #endif
1243 
1244 
1245 // MARK: mesh_upper_transport_pdu_t
1246 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS)
1247     #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS)
1248         #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."
1249     #else
1250         #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0
1251     #endif
1252 #endif
1253 
1254 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
1255 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1256 static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS];
1257 static btstack_memory_pool_t mesh_upper_transport_pdu_pool;
1258 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1259     void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool);
1260     if (buffer){
1261         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1262     }
1263     return (mesh_upper_transport_pdu_t *) buffer;
1264 }
1265 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1266     btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu);
1267 }
1268 #else
1269 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1270     return NULL;
1271 }
1272 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1273     UNUSED(mesh_upper_transport_pdu);
1274 };
1275 #endif
1276 #elif defined(HAVE_MALLOC)
1277 
1278 typedef struct {
1279     mesh_upper_transport_pdu_t data;
1280     btstack_memory_buffer_t tracking;
1281 } btstack_memory_mesh_upper_transport_pdu_t;
1282 
1283 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){
1284     btstack_memory_mesh_upper_transport_pdu_t * buffer = (btstack_memory_mesh_upper_transport_pdu_t *) malloc(sizeof(btstack_memory_mesh_upper_transport_pdu_t));
1285     if (buffer){
1286         memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t));
1287         btstack_memory_tracking_add(&buffer->tracking);
1288         return &buffer->data;
1289     } else {
1290         return NULL;
1291     }
1292 }
1293 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){
1294     btstack_memory_mesh_upper_transport_pdu_t * buffer =  (btstack_memory_mesh_upper_transport_pdu_t *) mesh_upper_transport_pdu;
1295     btstack_memory_tracking_remove(&buffer->tracking);
1296     free(buffer);
1297 }
1298 #endif
1299 
1300 
1301 // MARK: mesh_network_key_t
1302 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
1303     #if defined(MAX_NO_MESH_NETWORK_KEYS)
1304         #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."
1305     #else
1306         #define MAX_NR_MESH_NETWORK_KEYS 0
1307     #endif
1308 #endif
1309 
1310 #ifdef MAX_NR_MESH_NETWORK_KEYS
1311 #if MAX_NR_MESH_NETWORK_KEYS > 0
1312 static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
1313 static btstack_memory_pool_t mesh_network_key_pool;
1314 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1315     void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
1316     if (buffer){
1317         memset(buffer, 0, sizeof(mesh_network_key_t));
1318     }
1319     return (mesh_network_key_t *) buffer;
1320 }
1321 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1322     btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
1323 }
1324 #else
1325 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1326     return NULL;
1327 }
1328 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1329     UNUSED(mesh_network_key);
1330 };
1331 #endif
1332 #elif defined(HAVE_MALLOC)
1333 
1334 typedef struct {
1335     mesh_network_key_t data;
1336     btstack_memory_buffer_t tracking;
1337 } btstack_memory_mesh_network_key_t;
1338 
1339 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
1340     btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t));
1341     if (buffer){
1342         memset(buffer, 0, sizeof(mesh_network_key_t));
1343         btstack_memory_tracking_add(&buffer->tracking);
1344         return &buffer->data;
1345     } else {
1346         return NULL;
1347     }
1348 }
1349 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
1350     btstack_memory_mesh_network_key_t * buffer =  (btstack_memory_mesh_network_key_t *) mesh_network_key;
1351     btstack_memory_tracking_remove(&buffer->tracking);
1352     free(buffer);
1353 }
1354 #endif
1355 
1356 
1357 // MARK: mesh_transport_key_t
1358 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
1359     #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
1360         #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."
1361     #else
1362         #define MAX_NR_MESH_TRANSPORT_KEYS 0
1363     #endif
1364 #endif
1365 
1366 #ifdef MAX_NR_MESH_TRANSPORT_KEYS
1367 #if MAX_NR_MESH_TRANSPORT_KEYS > 0
1368 static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
1369 static btstack_memory_pool_t mesh_transport_key_pool;
1370 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1371     void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
1372     if (buffer){
1373         memset(buffer, 0, sizeof(mesh_transport_key_t));
1374     }
1375     return (mesh_transport_key_t *) buffer;
1376 }
1377 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1378     btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
1379 }
1380 #else
1381 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1382     return NULL;
1383 }
1384 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1385     UNUSED(mesh_transport_key);
1386 };
1387 #endif
1388 #elif defined(HAVE_MALLOC)
1389 
1390 typedef struct {
1391     mesh_transport_key_t data;
1392     btstack_memory_buffer_t tracking;
1393 } btstack_memory_mesh_transport_key_t;
1394 
1395 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
1396     btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t));
1397     if (buffer){
1398         memset(buffer, 0, sizeof(mesh_transport_key_t));
1399         btstack_memory_tracking_add(&buffer->tracking);
1400         return &buffer->data;
1401     } else {
1402         return NULL;
1403     }
1404 }
1405 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
1406     btstack_memory_mesh_transport_key_t * buffer =  (btstack_memory_mesh_transport_key_t *) mesh_transport_key;
1407     btstack_memory_tracking_remove(&buffer->tracking);
1408     free(buffer);
1409 }
1410 #endif
1411 
1412 
1413 // MARK: mesh_virtual_address_t
1414 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
1415     #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
1416         #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."
1417     #else
1418         #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
1419     #endif
1420 #endif
1421 
1422 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
1423 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
1424 static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
1425 static btstack_memory_pool_t mesh_virtual_address_pool;
1426 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1427     void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
1428     if (buffer){
1429         memset(buffer, 0, sizeof(mesh_virtual_address_t));
1430     }
1431     return (mesh_virtual_address_t *) buffer;
1432 }
1433 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1434     btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
1435 }
1436 #else
1437 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1438     return NULL;
1439 }
1440 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1441     UNUSED(mesh_virtual_address);
1442 };
1443 #endif
1444 #elif defined(HAVE_MALLOC)
1445 
1446 typedef struct {
1447     mesh_virtual_address_t data;
1448     btstack_memory_buffer_t tracking;
1449 } btstack_memory_mesh_virtual_address_t;
1450 
1451 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
1452     btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t));
1453     if (buffer){
1454         memset(buffer, 0, sizeof(mesh_virtual_address_t));
1455         btstack_memory_tracking_add(&buffer->tracking);
1456         return &buffer->data;
1457     } else {
1458         return NULL;
1459     }
1460 }
1461 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
1462     btstack_memory_mesh_virtual_address_t * buffer =  (btstack_memory_mesh_virtual_address_t *) mesh_virtual_address;
1463     btstack_memory_tracking_remove(&buffer->tracking);
1464     free(buffer);
1465 }
1466 #endif
1467 
1468 
1469 // MARK: mesh_subnet_t
1470 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
1471     #if defined(MAX_NO_MESH_SUBNETS)
1472         #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."
1473     #else
1474         #define MAX_NR_MESH_SUBNETS 0
1475     #endif
1476 #endif
1477 
1478 #ifdef MAX_NR_MESH_SUBNETS
1479 #if MAX_NR_MESH_SUBNETS > 0
1480 static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
1481 static btstack_memory_pool_t mesh_subnet_pool;
1482 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1483     void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
1484     if (buffer){
1485         memset(buffer, 0, sizeof(mesh_subnet_t));
1486     }
1487     return (mesh_subnet_t *) buffer;
1488 }
1489 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1490     btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
1491 }
1492 #else
1493 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1494     return NULL;
1495 }
1496 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1497     UNUSED(mesh_subnet);
1498 };
1499 #endif
1500 #elif defined(HAVE_MALLOC)
1501 
1502 typedef struct {
1503     mesh_subnet_t data;
1504     btstack_memory_buffer_t tracking;
1505 } btstack_memory_mesh_subnet_t;
1506 
1507 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
1508     btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t));
1509     if (buffer){
1510         memset(buffer, 0, sizeof(mesh_subnet_t));
1511         btstack_memory_tracking_add(&buffer->tracking);
1512         return &buffer->data;
1513     } else {
1514         return NULL;
1515     }
1516 }
1517 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
1518     btstack_memory_mesh_subnet_t * buffer =  (btstack_memory_mesh_subnet_t *) mesh_subnet;
1519     btstack_memory_tracking_remove(&buffer->tracking);
1520     free(buffer);
1521 }
1522 #endif
1523 
1524 
1525 #endif
1526 // init
1527 void btstack_memory_init(void){
1528 #if MAX_NR_HCI_CONNECTIONS > 0
1529     btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
1530 #endif
1531 #if MAX_NR_L2CAP_SERVICES > 0
1532     btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
1533 #endif
1534 #if MAX_NR_L2CAP_CHANNELS > 0
1535     btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
1536 #endif
1537 #ifdef ENABLE_CLASSIC
1538 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
1539     btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
1540 #endif
1541 #if MAX_NR_RFCOMM_SERVICES > 0
1542     btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
1543 #endif
1544 #if MAX_NR_RFCOMM_CHANNELS > 0
1545     btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
1546 #endif
1547 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
1548     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));
1549 #endif
1550 #if MAX_NR_BNEP_SERVICES > 0
1551     btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
1552 #endif
1553 #if MAX_NR_BNEP_CHANNELS > 0
1554     btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
1555 #endif
1556 #if MAX_NR_HFP_CONNECTIONS > 0
1557     btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
1558 #endif
1559 #if MAX_NR_SERVICE_RECORD_ITEMS > 0
1560     btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
1561 #endif
1562 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
1563     btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
1564 #endif
1565 #if MAX_NR_AVDTP_CONNECTIONS > 0
1566     btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
1567 #endif
1568 #if MAX_NR_AVRCP_CONNECTIONS > 0
1569     btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
1570 #endif
1571 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
1572     btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
1573 #endif
1574 #endif
1575 #ifdef ENABLE_BLE
1576 #if MAX_NR_GATT_CLIENTS > 0
1577     btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
1578 #endif
1579 #if MAX_NR_WHITELIST_ENTRIES > 0
1580     btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
1581 #endif
1582 #if MAX_NR_SM_LOOKUP_ENTRIES > 0
1583     btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
1584 #endif
1585 #endif
1586 #ifdef ENABLE_MESH
1587 #if MAX_NR_MESH_NETWORK_PDUS > 0
1588     btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
1589 #endif
1590 #if MAX_NR_MESH_SEGMENTED_PDUS > 0
1591     btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t));
1592 #endif
1593 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0
1594     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));
1595 #endif
1596 #if MAX_NR_MESH_NETWORK_KEYS > 0
1597     btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
1598 #endif
1599 #if MAX_NR_MESH_TRANSPORT_KEYS > 0
1600     btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
1601 #endif
1602 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
1603     btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
1604 #endif
1605 #if MAX_NR_MESH_SUBNETS > 0
1606     btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
1607 #endif
1608 #endif
1609 }
1610