1a3b02b71Smatthias.ringwald /* 2a0c35809S[email protected] * Copyright (C) 2014 BlueKitchen GmbH 3a3b02b71Smatthias.ringwald * 4a3b02b71Smatthias.ringwald * Redistribution and use in source and binary forms, with or without 5a3b02b71Smatthias.ringwald * modification, are permitted provided that the following conditions 6a3b02b71Smatthias.ringwald * are met: 7a3b02b71Smatthias.ringwald * 8a3b02b71Smatthias.ringwald * 1. Redistributions of source code must retain the above copyright 9a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer. 10a3b02b71Smatthias.ringwald * 2. Redistributions in binary form must reproduce the above copyright 11a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer in the 12a3b02b71Smatthias.ringwald * documentation and/or other materials provided with the distribution. 13a3b02b71Smatthias.ringwald * 3. Neither the name of the copyright holders nor the names of 14a3b02b71Smatthias.ringwald * contributors may be used to endorse or promote products derived 15a3b02b71Smatthias.ringwald * from this software without specific prior written permission. 166b64433eSmatthias.ringwald * 4. Any redistribution, use, or modification is done solely for 176b64433eSmatthias.ringwald * personal benefit and not for any commercial purpose or for 186b64433eSmatthias.ringwald * monetary gain. 19a3b02b71Smatthias.ringwald * 202e97c149S[email protected] * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21a3b02b71Smatthias.ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22a3b02b71Smatthias.ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25a3b02b71Smatthias.ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26a3b02b71Smatthias.ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27a3b02b71Smatthias.ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28a3b02b71Smatthias.ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29a3b02b71Smatthias.ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30a3b02b71Smatthias.ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31a3b02b71Smatthias.ringwald * SUCH DAMAGE. 32a3b02b71Smatthias.ringwald * 332e97c149S[email protected] * Please inquire about commercial licensing options at 342e97c149S[email protected] * [email protected] 356b64433eSmatthias.ringwald * 36a3b02b71Smatthias.ringwald */ 37a3b02b71Smatthias.ringwald 38f7434c1fSMatthias Ringwald 39e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_memory.c" 40bb2a7656SMatthias Ringwald 41b6269742SMatthias Ringwald 42a3b02b71Smatthias.ringwald /* 43f7434c1fSMatthias Ringwald * btstack_memory.c 44a3b02b71Smatthias.ringwald * 45a3b02b71Smatthias.ringwald * @brief BTstack memory management via configurable memory pools 46a3b02b71Smatthias.ringwald * 47a98592bcSMatthias Ringwald * @note code generated by tool/btstack_memory_generator.py 48a2673d88SMatthias Ringwald * @note returnes buffers are initialized with 0 49a3b02b71Smatthias.ringwald * 50a3b02b71Smatthias.ringwald */ 51a3b02b71Smatthias.ringwald 52a3b02b71Smatthias.ringwald #include "btstack_memory.h" 53d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h" 54b6269742SMatthias Ringwald #include "btstack_debug.h" 55a3b02b71Smatthias.ringwald 56a3b02b71Smatthias.ringwald #include <stdlib.h> 57a3b02b71Smatthias.ringwald 58cf26c8fbSMilanka Ringwald #ifdef ENABLE_MALLOC_TEST 594490dd1dSMatthias Ringwald void * test_malloc(size_t size); 60cf26c8fbSMilanka Ringwald #define malloc test_malloc 61cf26c8fbSMilanka Ringwald #endif 62cf26c8fbSMilanka Ringwald 63b6269742SMatthias Ringwald #ifdef HAVE_MALLOC 64b6269742SMatthias Ringwald typedef struct btstack_memory_buffer { 65b6269742SMatthias Ringwald struct btstack_memory_buffer * next; 66b6269742SMatthias Ringwald struct btstack_memory_buffer * prev; 67b6269742SMatthias Ringwald } btstack_memory_buffer_t; 68b6269742SMatthias Ringwald 69798bd46fSMatthias Ringwald typedef struct { 70798bd46fSMatthias Ringwald btstack_memory_buffer_t tracking; 71798bd46fSMatthias Ringwald void * pointer; 72798bd46fSMatthias Ringwald } test_buffer_t; 73798bd46fSMatthias Ringwald 74b6269742SMatthias Ringwald static btstack_memory_buffer_t * btstack_memory_malloc_buffers; 7519ef97d2SMatthias Ringwald static uint32_t btstack_memory_malloc_counter; 76b6269742SMatthias Ringwald 772a95308bSMatthias Ringwald static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){ 782a95308bSMatthias Ringwald btstack_assert(buffer != NULL); 7919ef97d2SMatthias Ringwald if (btstack_memory_malloc_buffers != NULL) { 8019ef97d2SMatthias Ringwald // let current first item prev point to new first item 8119ef97d2SMatthias Ringwald btstack_memory_malloc_buffers->prev = buffer; 8219ef97d2SMatthias Ringwald } 83b6269742SMatthias Ringwald buffer->prev = NULL; 84b6269742SMatthias Ringwald buffer->next = btstack_memory_malloc_buffers; 85b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer; 8619ef97d2SMatthias Ringwald 8719ef97d2SMatthias Ringwald btstack_memory_malloc_counter++; 88b6269742SMatthias Ringwald } 89b6269742SMatthias Ringwald 902a95308bSMatthias Ringwald static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){ 912a95308bSMatthias Ringwald btstack_assert(buffer != NULL); 92b6269742SMatthias Ringwald if (buffer->prev == NULL){ 93b6269742SMatthias Ringwald // first item 94b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer->next; 95b6269742SMatthias Ringwald } else { 96b6269742SMatthias Ringwald buffer->prev->next = buffer->next; 97b6269742SMatthias Ringwald } 98b6269742SMatthias Ringwald if (buffer->next != NULL){ 99b6269742SMatthias Ringwald buffer->next->prev = buffer->prev; 100b6269742SMatthias Ringwald } 10119ef97d2SMatthias Ringwald 10219ef97d2SMatthias Ringwald btstack_memory_malloc_counter--; 103b6269742SMatthias Ringwald } 104b6269742SMatthias Ringwald #endif 105b6269742SMatthias Ringwald 106b6269742SMatthias Ringwald void btstack_memory_deinit(void){ 107b6269742SMatthias Ringwald #ifdef HAVE_MALLOC 108b6269742SMatthias Ringwald while (btstack_memory_malloc_buffers != NULL){ 109b6269742SMatthias Ringwald btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers; 110b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer->next; 111b6269742SMatthias Ringwald free(buffer); 1120e109a16SMatthias Ringwald btstack_memory_malloc_counter--; 113b6269742SMatthias Ringwald } 11419ef97d2SMatthias Ringwald btstack_assert(btstack_memory_malloc_counter == 0); 115b6269742SMatthias Ringwald #endif 116b6269742SMatthias Ringwald } 117a3b02b71Smatthias.ringwald 1182e97c149S[email protected] 119a3b02b71Smatthias.ringwald // MARK: hci_connection_t 120a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 121a265b909SMatthias Ringwald #if defined(MAX_NO_HCI_CONNECTIONS) 12227faf85aSMilanka Ringwald #error "Deprecated MAX_NO_HCI_CONNECTIONS defined instead of MAX_NR_HCI_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HCI_CONNECTIONS." 123a265b909SMatthias Ringwald #else 124a265b909SMatthias Ringwald #define MAX_NR_HCI_CONNECTIONS 0 125a265b909SMatthias Ringwald #endif 126a265b909SMatthias Ringwald #endif 127a265b909SMatthias Ringwald 128a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS 129a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 130a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 13129d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool; 1326527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 133a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hci_connection_pool); 134a2673d88SMatthias Ringwald if (buffer){ 135a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hci_connection_t)); 136a2673d88SMatthias Ringwald } 137a2673d88SMatthias Ringwald return (hci_connection_t *) buffer; 138a3b02b71Smatthias.ringwald } 1396527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 14029d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hci_connection_pool, hci_connection); 141a3b02b71Smatthias.ringwald } 142c4d3f927Smatthias.ringwald #else 1436527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 144c4d3f927Smatthias.ringwald return NULL; 145c4d3f927Smatthias.ringwald } 1466527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 147b6269742SMatthias Ringwald UNUSED(hci_connection); 148c4d3f927Smatthias.ringwald }; 149c4d3f927Smatthias.ringwald #endif 150a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1512a95308bSMatthias Ringwald 1522a95308bSMatthias Ringwald typedef struct { 1532a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 154798bd46fSMatthias Ringwald hci_connection_t data; 1552a95308bSMatthias Ringwald } btstack_memory_hci_connection_t; 1562a95308bSMatthias Ringwald 1576527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 1582a95308bSMatthias Ringwald btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t)); 159a2673d88SMatthias Ringwald if (buffer){ 160798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_hci_connection_t)); 1612a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 1622a95308bSMatthias Ringwald return &buffer->data; 163b6269742SMatthias Ringwald } else { 164b6269742SMatthias Ringwald return NULL; 165a2673d88SMatthias Ringwald } 166a3b02b71Smatthias.ringwald } 1676527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 168798bd46fSMatthias Ringwald // reconstruct buffer start 169798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_connection)[-1]; 170798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 171b6269742SMatthias Ringwald free(buffer); 172a3b02b71Smatthias.ringwald } 173a3b02b71Smatthias.ringwald #endif 174a3b02b71Smatthias.ringwald 175a3b02b71Smatthias.ringwald 1762e97c149S[email protected] 177a3b02b71Smatthias.ringwald // MARK: l2cap_service_t 178a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 179a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_SERVICES) 18027faf85aSMilanka Ringwald #error "Deprecated MAX_NO_L2CAP_SERVICES defined instead of MAX_NR_L2CAP_SERVICES. Please update your btstack_config.h to use MAX_NR_L2CAP_SERVICES." 181a265b909SMatthias Ringwald #else 182a265b909SMatthias Ringwald #define MAX_NR_L2CAP_SERVICES 0 183a265b909SMatthias Ringwald #endif 184a265b909SMatthias Ringwald #endif 185a265b909SMatthias Ringwald 186a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES 187a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 188a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 18929d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool; 1906527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 191a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_service_pool); 192a2673d88SMatthias Ringwald if (buffer){ 193a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_service_t)); 194a2673d88SMatthias Ringwald } 195a2673d88SMatthias Ringwald return (l2cap_service_t *) buffer; 196a3b02b71Smatthias.ringwald } 1976527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 19829d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 199a3b02b71Smatthias.ringwald } 200c4d3f927Smatthias.ringwald #else 2016527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 202c4d3f927Smatthias.ringwald return NULL; 203c4d3f927Smatthias.ringwald } 2046527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 205b6269742SMatthias Ringwald UNUSED(l2cap_service); 206c4d3f927Smatthias.ringwald }; 207c4d3f927Smatthias.ringwald #endif 208a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2092a95308bSMatthias Ringwald 2102a95308bSMatthias Ringwald typedef struct { 2112a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 212798bd46fSMatthias Ringwald l2cap_service_t data; 2132a95308bSMatthias Ringwald } btstack_memory_l2cap_service_t; 2142a95308bSMatthias Ringwald 2156527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 2162a95308bSMatthias Ringwald btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t)); 217a2673d88SMatthias Ringwald if (buffer){ 218798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_l2cap_service_t)); 2192a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 2202a95308bSMatthias Ringwald return &buffer->data; 221b6269742SMatthias Ringwald } else { 222b6269742SMatthias Ringwald return NULL; 223a2673d88SMatthias Ringwald } 224a3b02b71Smatthias.ringwald } 2256527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 226798bd46fSMatthias Ringwald // reconstruct buffer start 227798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_service)[-1]; 228798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 229b6269742SMatthias Ringwald free(buffer); 230a3b02b71Smatthias.ringwald } 231a3b02b71Smatthias.ringwald #endif 232a3b02b71Smatthias.ringwald 233a3b02b71Smatthias.ringwald 234a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t 235a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 236a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_CHANNELS) 23727faf85aSMilanka Ringwald #error "Deprecated MAX_NO_L2CAP_CHANNELS defined instead of MAX_NR_L2CAP_CHANNELS. Please update your btstack_config.h to use MAX_NR_L2CAP_CHANNELS." 238a265b909SMatthias Ringwald #else 239a265b909SMatthias Ringwald #define MAX_NR_L2CAP_CHANNELS 0 240a265b909SMatthias Ringwald #endif 241a265b909SMatthias Ringwald #endif 242a265b909SMatthias Ringwald 243a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS 244a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 245a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 24629d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool; 2476527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 248a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_channel_pool); 249a2673d88SMatthias Ringwald if (buffer){ 250a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_channel_t)); 251a2673d88SMatthias Ringwald } 252a2673d88SMatthias Ringwald return (l2cap_channel_t *) buffer; 253a3b02b71Smatthias.ringwald } 2546527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 25529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 256a3b02b71Smatthias.ringwald } 257c4d3f927Smatthias.ringwald #else 2586527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 259c4d3f927Smatthias.ringwald return NULL; 260c4d3f927Smatthias.ringwald } 2616527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 262b6269742SMatthias Ringwald UNUSED(l2cap_channel); 263c4d3f927Smatthias.ringwald }; 264c4d3f927Smatthias.ringwald #endif 265a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2662a95308bSMatthias Ringwald 2672a95308bSMatthias Ringwald typedef struct { 2682a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 269798bd46fSMatthias Ringwald l2cap_channel_t data; 2702a95308bSMatthias Ringwald } btstack_memory_l2cap_channel_t; 2712a95308bSMatthias Ringwald 2726527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 2732a95308bSMatthias Ringwald btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t)); 274a2673d88SMatthias Ringwald if (buffer){ 275798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_l2cap_channel_t)); 2762a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 2772a95308bSMatthias Ringwald return &buffer->data; 278b6269742SMatthias Ringwald } else { 279b6269742SMatthias Ringwald return NULL; 280a2673d88SMatthias Ringwald } 281a3b02b71Smatthias.ringwald } 2826527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 283798bd46fSMatthias Ringwald // reconstruct buffer start 284798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_channel)[-1]; 285798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 286b6269742SMatthias Ringwald free(buffer); 287a3b02b71Smatthias.ringwald } 288a3b02b71Smatthias.ringwald #endif 289a3b02b71Smatthias.ringwald 290a3b02b71Smatthias.ringwald 29144c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 2922e97c149S[email protected] 293a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t 294a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 295a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 29627faf85aSMilanka Ringwald #error "Deprecated MAX_NO_RFCOMM_MULTIPLEXERS defined instead of MAX_NR_RFCOMM_MULTIPLEXERS. Please update your btstack_config.h to use MAX_NR_RFCOMM_MULTIPLEXERS." 297a265b909SMatthias Ringwald #else 298a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_MULTIPLEXERS 0 299a265b909SMatthias Ringwald #endif 300a265b909SMatthias Ringwald #endif 301a265b909SMatthias Ringwald 302a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 303a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 304a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 30529d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool; 3066527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 307a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool); 308a2673d88SMatthias Ringwald if (buffer){ 309a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 310a2673d88SMatthias Ringwald } 311a2673d88SMatthias Ringwald return (rfcomm_multiplexer_t *) buffer; 312a3b02b71Smatthias.ringwald } 3136527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 31429d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 315a3b02b71Smatthias.ringwald } 316c4d3f927Smatthias.ringwald #else 3176527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 318c4d3f927Smatthias.ringwald return NULL; 319c4d3f927Smatthias.ringwald } 3206527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 321b6269742SMatthias Ringwald UNUSED(rfcomm_multiplexer); 322c4d3f927Smatthias.ringwald }; 323c4d3f927Smatthias.ringwald #endif 324a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 3252a95308bSMatthias Ringwald 3262a95308bSMatthias Ringwald typedef struct { 3272a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 328798bd46fSMatthias Ringwald rfcomm_multiplexer_t data; 3292a95308bSMatthias Ringwald } btstack_memory_rfcomm_multiplexer_t; 3302a95308bSMatthias Ringwald 3316527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 3322a95308bSMatthias Ringwald btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t)); 333a2673d88SMatthias Ringwald if (buffer){ 334798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_multiplexer_t)); 3352a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 3362a95308bSMatthias Ringwald return &buffer->data; 337b6269742SMatthias Ringwald } else { 338b6269742SMatthias Ringwald return NULL; 339a2673d88SMatthias Ringwald } 340a3b02b71Smatthias.ringwald } 3416527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 342798bd46fSMatthias Ringwald // reconstruct buffer start 343798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_multiplexer)[-1]; 344798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 345b6269742SMatthias Ringwald free(buffer); 346a3b02b71Smatthias.ringwald } 347a3b02b71Smatthias.ringwald #endif 348a3b02b71Smatthias.ringwald 349a3b02b71Smatthias.ringwald 350a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t 351a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 352a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_SERVICES) 35327faf85aSMilanka Ringwald #error "Deprecated MAX_NO_RFCOMM_SERVICES defined instead of MAX_NR_RFCOMM_SERVICES. Please update your btstack_config.h to use MAX_NR_RFCOMM_SERVICES." 354a265b909SMatthias Ringwald #else 355a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_SERVICES 0 356a265b909SMatthias Ringwald #endif 357a265b909SMatthias Ringwald #endif 358a265b909SMatthias Ringwald 359a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES 360a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0 361a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 36229d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool; 3636527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 364a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_service_pool); 365a2673d88SMatthias Ringwald if (buffer){ 366a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_service_t)); 367a2673d88SMatthias Ringwald } 368a2673d88SMatthias Ringwald return (rfcomm_service_t *) buffer; 369a3b02b71Smatthias.ringwald } 3706527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 37129d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 372a3b02b71Smatthias.ringwald } 373c4d3f927Smatthias.ringwald #else 3746527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 375c4d3f927Smatthias.ringwald return NULL; 376c4d3f927Smatthias.ringwald } 3776527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 378b6269742SMatthias Ringwald UNUSED(rfcomm_service); 379c4d3f927Smatthias.ringwald }; 380c4d3f927Smatthias.ringwald #endif 381a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 3822a95308bSMatthias Ringwald 3832a95308bSMatthias Ringwald typedef struct { 3842a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 385798bd46fSMatthias Ringwald rfcomm_service_t data; 3862a95308bSMatthias Ringwald } btstack_memory_rfcomm_service_t; 3872a95308bSMatthias Ringwald 3886527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 3892a95308bSMatthias Ringwald btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t)); 390a2673d88SMatthias Ringwald if (buffer){ 391798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_service_t)); 3922a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 3932a95308bSMatthias Ringwald return &buffer->data; 394b6269742SMatthias Ringwald } else { 395b6269742SMatthias Ringwald return NULL; 396a2673d88SMatthias Ringwald } 397a3b02b71Smatthias.ringwald } 3986527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 399798bd46fSMatthias Ringwald // reconstruct buffer start 400798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_service)[-1]; 401798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 402b6269742SMatthias Ringwald free(buffer); 403a3b02b71Smatthias.ringwald } 404a3b02b71Smatthias.ringwald #endif 405a3b02b71Smatthias.ringwald 406a3b02b71Smatthias.ringwald 407a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t 408a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 409a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_CHANNELS) 41027faf85aSMilanka Ringwald #error "Deprecated MAX_NO_RFCOMM_CHANNELS defined instead of MAX_NR_RFCOMM_CHANNELS. Please update your btstack_config.h to use MAX_NR_RFCOMM_CHANNELS." 411a265b909SMatthias Ringwald #else 412a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_CHANNELS 0 413a265b909SMatthias Ringwald #endif 414a265b909SMatthias Ringwald #endif 415a265b909SMatthias Ringwald 416a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS 417a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0 418a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 41929d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool; 4206527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 421a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool); 422a2673d88SMatthias Ringwald if (buffer){ 423a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_channel_t)); 424a2673d88SMatthias Ringwald } 425a2673d88SMatthias Ringwald return (rfcomm_channel_t *) buffer; 426a3b02b71Smatthias.ringwald } 4276527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 42829d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 429a3b02b71Smatthias.ringwald } 430c4d3f927Smatthias.ringwald #else 4316527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 432c4d3f927Smatthias.ringwald return NULL; 433c4d3f927Smatthias.ringwald } 4346527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 435b6269742SMatthias Ringwald UNUSED(rfcomm_channel); 436c4d3f927Smatthias.ringwald }; 437c4d3f927Smatthias.ringwald #endif 438a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 4392a95308bSMatthias Ringwald 4402a95308bSMatthias Ringwald typedef struct { 4412a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 442798bd46fSMatthias Ringwald rfcomm_channel_t data; 4432a95308bSMatthias Ringwald } btstack_memory_rfcomm_channel_t; 4442a95308bSMatthias Ringwald 4456527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 4462a95308bSMatthias Ringwald btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t)); 447a2673d88SMatthias Ringwald if (buffer){ 448798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_channel_t)); 4492a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 4502a95308bSMatthias Ringwald return &buffer->data; 451b6269742SMatthias Ringwald } else { 452b6269742SMatthias Ringwald return NULL; 453a2673d88SMatthias Ringwald } 454a3b02b71Smatthias.ringwald } 4556527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 456798bd46fSMatthias Ringwald // reconstruct buffer start 457798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_channel)[-1]; 458798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 459b6269742SMatthias Ringwald free(buffer); 460a3b02b71Smatthias.ringwald } 461a3b02b71Smatthias.ringwald #endif 462a3b02b71Smatthias.ringwald 463fdb398c2S[email protected] 464e0e5e285Smatthias.ringwald 4652c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t 466a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 467a265b909SMatthias Ringwald #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 46827faf85aSMilanka Ringwald #error "Deprecated MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES defined instead of MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES. Please update your btstack_config.h to use MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES." 469a265b909SMatthias Ringwald #else 470a265b909SMatthias Ringwald #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 471a265b909SMatthias Ringwald #endif 472a265b909SMatthias Ringwald #endif 473a265b909SMatthias Ringwald 474a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 475a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 476a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 4772c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 4782c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 479a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 480a2673d88SMatthias Ringwald if (buffer){ 481a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 482a2673d88SMatthias Ringwald } 483a2673d88SMatthias Ringwald return (btstack_link_key_db_memory_entry_t *) buffer; 4841801b596Smatthias.ringwald } 4852c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 4862c455dadSMatthias Ringwald btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 4871801b596Smatthias.ringwald } 488c4d3f927Smatthias.ringwald #else 4892c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 490c4d3f927Smatthias.ringwald return NULL; 491c4d3f927Smatthias.ringwald } 4922c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 493b6269742SMatthias Ringwald UNUSED(btstack_link_key_db_memory_entry); 494c4d3f927Smatthias.ringwald }; 495c4d3f927Smatthias.ringwald #endif 4961801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 4972a95308bSMatthias Ringwald 4982a95308bSMatthias Ringwald typedef struct { 4992a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 500798bd46fSMatthias Ringwald btstack_link_key_db_memory_entry_t data; 5012a95308bSMatthias Ringwald } btstack_memory_btstack_link_key_db_memory_entry_t; 5022a95308bSMatthias Ringwald 5032c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 5042a95308bSMatthias Ringwald 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)); 505a2673d88SMatthias Ringwald if (buffer){ 506798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_btstack_link_key_db_memory_entry_t)); 5072a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 5082a95308bSMatthias Ringwald return &buffer->data; 509b6269742SMatthias Ringwald } else { 510b6269742SMatthias Ringwald return NULL; 511a2673d88SMatthias Ringwald } 5121801b596Smatthias.ringwald } 5132c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 514798bd46fSMatthias Ringwald // reconstruct buffer start 515798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) btstack_link_key_db_memory_entry)[-1]; 516798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 517b6269742SMatthias Ringwald free(buffer); 518e0e5e285Smatthias.ringwald } 5191801b596Smatthias.ringwald #endif 5201801b596Smatthias.ringwald 5212e97c149S[email protected] 5222e97c149S[email protected] 5232e97c149S[email protected] // MARK: bnep_service_t 524a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 525a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_SERVICES) 52627faf85aSMilanka Ringwald #error "Deprecated MAX_NO_BNEP_SERVICES defined instead of MAX_NR_BNEP_SERVICES. Please update your btstack_config.h to use MAX_NR_BNEP_SERVICES." 527a265b909SMatthias Ringwald #else 528a265b909SMatthias Ringwald #define MAX_NR_BNEP_SERVICES 0 529a265b909SMatthias Ringwald #endif 530a265b909SMatthias Ringwald #endif 531a265b909SMatthias Ringwald 532a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES 533a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0 534a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 53529d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool; 5362e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 537a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_service_pool); 538a2673d88SMatthias Ringwald if (buffer){ 539a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_service_t)); 540a2673d88SMatthias Ringwald } 541a2673d88SMatthias Ringwald return (bnep_service_t *) buffer; 5422e97c149S[email protected] } 5432e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 54429d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_service_pool, bnep_service); 5452e97c149S[email protected] } 5462e97c149S[email protected] #else 5472e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 5482e97c149S[email protected] return NULL; 5492e97c149S[email protected] } 5502e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 551b6269742SMatthias Ringwald UNUSED(bnep_service); 5522e97c149S[email protected] }; 5532e97c149S[email protected] #endif 5542e97c149S[email protected] #elif defined(HAVE_MALLOC) 5552a95308bSMatthias Ringwald 5562a95308bSMatthias Ringwald typedef struct { 5572a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 558798bd46fSMatthias Ringwald bnep_service_t data; 5592a95308bSMatthias Ringwald } btstack_memory_bnep_service_t; 5602a95308bSMatthias Ringwald 5612e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 5622a95308bSMatthias Ringwald btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t)); 563a2673d88SMatthias Ringwald if (buffer){ 564798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_bnep_service_t)); 5652a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 5662a95308bSMatthias Ringwald return &buffer->data; 567b6269742SMatthias Ringwald } else { 568b6269742SMatthias Ringwald return NULL; 569a2673d88SMatthias Ringwald } 5702e97c149S[email protected] } 5712e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 572798bd46fSMatthias Ringwald // reconstruct buffer start 573798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_service)[-1]; 574798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 575b6269742SMatthias Ringwald free(buffer); 5762e97c149S[email protected] } 5772e97c149S[email protected] #endif 5782e97c149S[email protected] 5792e97c149S[email protected] 5802e97c149S[email protected] // MARK: bnep_channel_t 581a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 582a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_CHANNELS) 58327faf85aSMilanka Ringwald #error "Deprecated MAX_NO_BNEP_CHANNELS defined instead of MAX_NR_BNEP_CHANNELS. Please update your btstack_config.h to use MAX_NR_BNEP_CHANNELS." 584a265b909SMatthias Ringwald #else 585a265b909SMatthias Ringwald #define MAX_NR_BNEP_CHANNELS 0 586a265b909SMatthias Ringwald #endif 587a265b909SMatthias Ringwald #endif 588a265b909SMatthias Ringwald 589a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS 590a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0 591a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 59229d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool; 5932e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 594a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_channel_pool); 595a2673d88SMatthias Ringwald if (buffer){ 596a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_channel_t)); 597a2673d88SMatthias Ringwald } 598a2673d88SMatthias Ringwald return (bnep_channel_t *) buffer; 5992e97c149S[email protected] } 6002e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 60129d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 6022e97c149S[email protected] } 6032e97c149S[email protected] #else 6042e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 6052e97c149S[email protected] return NULL; 6062e97c149S[email protected] } 6072e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 608b6269742SMatthias Ringwald UNUSED(bnep_channel); 6092e97c149S[email protected] }; 6102e97c149S[email protected] #endif 6112e97c149S[email protected] #elif defined(HAVE_MALLOC) 6122a95308bSMatthias Ringwald 6132a95308bSMatthias Ringwald typedef struct { 6142a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 615798bd46fSMatthias Ringwald bnep_channel_t data; 6162a95308bSMatthias Ringwald } btstack_memory_bnep_channel_t; 6172a95308bSMatthias Ringwald 6182e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 6192a95308bSMatthias Ringwald btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t)); 620a2673d88SMatthias Ringwald if (buffer){ 621798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_bnep_channel_t)); 6222a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 6232a95308bSMatthias Ringwald return &buffer->data; 624b6269742SMatthias Ringwald } else { 625b6269742SMatthias Ringwald return NULL; 626a2673d88SMatthias Ringwald } 6272e97c149S[email protected] } 6282e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 629798bd46fSMatthias Ringwald // reconstruct buffer start 630798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_channel)[-1]; 631798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 632b6269742SMatthias Ringwald free(buffer); 6332e97c149S[email protected] } 6342e97c149S[email protected] #endif 6352e97c149S[email protected] 6362e97c149S[email protected] 637ea5029c9SMilanka Ringwald 638ea5029c9SMilanka Ringwald // MARK: hfp_connection_t 639a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 640a265b909SMatthias Ringwald #if defined(MAX_NO_HFP_CONNECTIONS) 64127faf85aSMilanka Ringwald #error "Deprecated MAX_NO_HFP_CONNECTIONS defined instead of MAX_NR_HFP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HFP_CONNECTIONS." 642a265b909SMatthias Ringwald #else 643a265b909SMatthias Ringwald #define MAX_NR_HFP_CONNECTIONS 0 644a265b909SMatthias Ringwald #endif 645a265b909SMatthias Ringwald #endif 646a265b909SMatthias Ringwald 647a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS 648a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0 649a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 65029d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool; 651ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 652a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hfp_connection_pool); 653a2673d88SMatthias Ringwald if (buffer){ 654a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hfp_connection_t)); 655a2673d88SMatthias Ringwald } 656a2673d88SMatthias Ringwald return (hfp_connection_t *) buffer; 657ea5029c9SMilanka Ringwald } 658ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 65929d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 660ea5029c9SMilanka Ringwald } 661ea5029c9SMilanka Ringwald #else 662ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 663ea5029c9SMilanka Ringwald return NULL; 664ea5029c9SMilanka Ringwald } 665ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 666b6269742SMatthias Ringwald UNUSED(hfp_connection); 667ea5029c9SMilanka Ringwald }; 668ea5029c9SMilanka Ringwald #endif 669ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC) 6702a95308bSMatthias Ringwald 6712a95308bSMatthias Ringwald typedef struct { 6722a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 673798bd46fSMatthias Ringwald hfp_connection_t data; 6742a95308bSMatthias Ringwald } btstack_memory_hfp_connection_t; 6752a95308bSMatthias Ringwald 676ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 6772a95308bSMatthias Ringwald btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t)); 678a2673d88SMatthias Ringwald if (buffer){ 679798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_hfp_connection_t)); 6802a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 6812a95308bSMatthias Ringwald return &buffer->data; 682b6269742SMatthias Ringwald } else { 683b6269742SMatthias Ringwald return NULL; 684a2673d88SMatthias Ringwald } 685ea5029c9SMilanka Ringwald } 686ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 687798bd46fSMatthias Ringwald // reconstruct buffer start 688798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hfp_connection)[-1]; 689798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 690b6269742SMatthias Ringwald free(buffer); 691ea5029c9SMilanka Ringwald } 692ea5029c9SMilanka Ringwald #endif 693ea5029c9SMilanka Ringwald 694ea5029c9SMilanka Ringwald 695cd9ee144SMatthias Ringwald 696f399f7fbSMilanka Ringwald // MARK: hid_host_connection_t 697f399f7fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HID_HOST_CONNECTIONS) 698f399f7fbSMilanka Ringwald #if defined(MAX_NO_HID_HOST_CONNECTIONS) 699f399f7fbSMilanka Ringwald #error "Deprecated MAX_NO_HID_HOST_CONNECTIONS defined instead of MAX_NR_HID_HOST_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HID_HOST_CONNECTIONS." 700f399f7fbSMilanka Ringwald #else 701f399f7fbSMilanka Ringwald #define MAX_NR_HID_HOST_CONNECTIONS 0 702f399f7fbSMilanka Ringwald #endif 703f399f7fbSMilanka Ringwald #endif 704f399f7fbSMilanka Ringwald 705f399f7fbSMilanka Ringwald #ifdef MAX_NR_HID_HOST_CONNECTIONS 706f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0 707f399f7fbSMilanka Ringwald static hid_host_connection_t hid_host_connection_storage[MAX_NR_HID_HOST_CONNECTIONS]; 708f399f7fbSMilanka Ringwald static btstack_memory_pool_t hid_host_connection_pool; 709f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 710f399f7fbSMilanka Ringwald void * buffer = btstack_memory_pool_get(&hid_host_connection_pool); 711f399f7fbSMilanka Ringwald if (buffer){ 712f399f7fbSMilanka Ringwald memset(buffer, 0, sizeof(hid_host_connection_t)); 713f399f7fbSMilanka Ringwald } 714f399f7fbSMilanka Ringwald return (hid_host_connection_t *) buffer; 715f399f7fbSMilanka Ringwald } 716f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 717f399f7fbSMilanka Ringwald btstack_memory_pool_free(&hid_host_connection_pool, hid_host_connection); 718f399f7fbSMilanka Ringwald } 719f399f7fbSMilanka Ringwald #else 720f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 721f399f7fbSMilanka Ringwald return NULL; 722f399f7fbSMilanka Ringwald } 723f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 724174a0c1cSMilanka Ringwald UNUSED(hid_host_connection); 725f399f7fbSMilanka Ringwald }; 726f399f7fbSMilanka Ringwald #endif 727f399f7fbSMilanka Ringwald #elif defined(HAVE_MALLOC) 728174a0c1cSMilanka Ringwald 729174a0c1cSMilanka Ringwald typedef struct { 730174a0c1cSMilanka Ringwald btstack_memory_buffer_t tracking; 731174a0c1cSMilanka Ringwald hid_host_connection_t data; 732174a0c1cSMilanka Ringwald } btstack_memory_hid_host_connection_t; 733174a0c1cSMilanka Ringwald 734f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 735174a0c1cSMilanka Ringwald btstack_memory_hid_host_connection_t * buffer = (btstack_memory_hid_host_connection_t *) malloc(sizeof(btstack_memory_hid_host_connection_t)); 736f399f7fbSMilanka Ringwald if (buffer){ 737174a0c1cSMilanka Ringwald memset(buffer, 0, sizeof(btstack_memory_hid_host_connection_t)); 738174a0c1cSMilanka Ringwald btstack_memory_tracking_add(&buffer->tracking); 739174a0c1cSMilanka Ringwald return &buffer->data; 740174a0c1cSMilanka Ringwald } else { 741174a0c1cSMilanka Ringwald return NULL; 742f399f7fbSMilanka Ringwald } 743f399f7fbSMilanka Ringwald } 744f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 745174a0c1cSMilanka Ringwald // reconstruct buffer start 746174a0c1cSMilanka Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hid_host_connection)[-1]; 747174a0c1cSMilanka Ringwald btstack_memory_tracking_remove(buffer); 748174a0c1cSMilanka Ringwald free(buffer); 749f399f7fbSMilanka Ringwald } 750f399f7fbSMilanka Ringwald #endif 751f399f7fbSMilanka Ringwald 752f399f7fbSMilanka Ringwald 753f399f7fbSMilanka Ringwald 754cd9ee144SMatthias Ringwald // MARK: service_record_item_t 755a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 756a265b909SMatthias Ringwald #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 75727faf85aSMilanka Ringwald #error "Deprecated MAX_NO_SERVICE_RECORD_ITEMS defined instead of MAX_NR_SERVICE_RECORD_ITEMS. Please update your btstack_config.h to use MAX_NR_SERVICE_RECORD_ITEMS." 758a265b909SMatthias Ringwald #else 759a265b909SMatthias Ringwald #define MAX_NR_SERVICE_RECORD_ITEMS 0 760a265b909SMatthias Ringwald #endif 761a265b909SMatthias Ringwald #endif 762a265b909SMatthias Ringwald 763a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS 764a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0 765a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 76629d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool; 767cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 768a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&service_record_item_pool); 769a2673d88SMatthias Ringwald if (buffer){ 770a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(service_record_item_t)); 771a2673d88SMatthias Ringwald } 772a2673d88SMatthias Ringwald return (service_record_item_t *) buffer; 773cd9ee144SMatthias Ringwald } 774cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 77529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&service_record_item_pool, service_record_item); 776cd9ee144SMatthias Ringwald } 777cd9ee144SMatthias Ringwald #else 778cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 779cd9ee144SMatthias Ringwald return NULL; 780cd9ee144SMatthias Ringwald } 781cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 782b6269742SMatthias Ringwald UNUSED(service_record_item); 783cd9ee144SMatthias Ringwald }; 784cd9ee144SMatthias Ringwald #endif 785cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC) 7862a95308bSMatthias Ringwald 7872a95308bSMatthias Ringwald typedef struct { 7882a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 789798bd46fSMatthias Ringwald service_record_item_t data; 7902a95308bSMatthias Ringwald } btstack_memory_service_record_item_t; 7912a95308bSMatthias Ringwald 792cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 7932a95308bSMatthias Ringwald btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t)); 794a2673d88SMatthias Ringwald if (buffer){ 795798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_service_record_item_t)); 7962a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 7972a95308bSMatthias Ringwald return &buffer->data; 798b6269742SMatthias Ringwald } else { 799b6269742SMatthias Ringwald return NULL; 800a2673d88SMatthias Ringwald } 801cd9ee144SMatthias Ringwald } 802cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 803798bd46fSMatthias Ringwald // reconstruct buffer start 804798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) service_record_item)[-1]; 805798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 806b6269742SMatthias Ringwald free(buffer); 807cd9ee144SMatthias Ringwald } 808cd9ee144SMatthias Ringwald #endif 809cd9ee144SMatthias Ringwald 810cd9ee144SMatthias Ringwald 81127faf85aSMilanka Ringwald 8120e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t 8130e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 8140e826a17SMilanka Ringwald #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 8150e826a17SMilanka Ringwald #error "Deprecated MAX_NO_AVDTP_STREAM_ENDPOINTS defined instead of MAX_NR_AVDTP_STREAM_ENDPOINTS. Please update your btstack_config.h to use MAX_NR_AVDTP_STREAM_ENDPOINTS." 81627faf85aSMilanka Ringwald #else 8170e826a17SMilanka Ringwald #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 81827faf85aSMilanka Ringwald #endif 81927faf85aSMilanka Ringwald #endif 82027faf85aSMilanka Ringwald 8210e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 8220e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 8230e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 8240e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool; 8250e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 826a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 827a2673d88SMatthias Ringwald if (buffer){ 828a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 829a2673d88SMatthias Ringwald } 830a2673d88SMatthias Ringwald return (avdtp_stream_endpoint_t *) buffer; 83127faf85aSMilanka Ringwald } 8320e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 8330e826a17SMilanka Ringwald btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 83427faf85aSMilanka Ringwald } 83527faf85aSMilanka Ringwald #else 8360e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 83727faf85aSMilanka Ringwald return NULL; 83827faf85aSMilanka Ringwald } 8390e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 840b6269742SMatthias Ringwald UNUSED(avdtp_stream_endpoint); 84127faf85aSMilanka Ringwald }; 84227faf85aSMilanka Ringwald #endif 84327faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC) 8442a95308bSMatthias Ringwald 8452a95308bSMatthias Ringwald typedef struct { 8462a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 847798bd46fSMatthias Ringwald avdtp_stream_endpoint_t data; 8482a95308bSMatthias Ringwald } btstack_memory_avdtp_stream_endpoint_t; 8492a95308bSMatthias Ringwald 8500e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 8512a95308bSMatthias Ringwald btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t)); 852a2673d88SMatthias Ringwald if (buffer){ 853798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avdtp_stream_endpoint_t)); 8542a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 8552a95308bSMatthias Ringwald return &buffer->data; 856b6269742SMatthias Ringwald } else { 857b6269742SMatthias Ringwald return NULL; 858a2673d88SMatthias Ringwald } 85927faf85aSMilanka Ringwald } 8600e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 861798bd46fSMatthias Ringwald // reconstruct buffer start 862798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_stream_endpoint)[-1]; 863798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 864b6269742SMatthias Ringwald free(buffer); 86527faf85aSMilanka Ringwald } 86627faf85aSMilanka Ringwald #endif 86727faf85aSMilanka Ringwald 86827faf85aSMilanka Ringwald 86912e7f38cSMilanka Ringwald 87012e7f38cSMilanka Ringwald // MARK: avdtp_connection_t 87112e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 87212e7f38cSMilanka Ringwald #if defined(MAX_NO_AVDTP_CONNECTIONS) 87312e7f38cSMilanka Ringwald #error "Deprecated MAX_NO_AVDTP_CONNECTIONS defined instead of MAX_NR_AVDTP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVDTP_CONNECTIONS." 87412e7f38cSMilanka Ringwald #else 87512e7f38cSMilanka Ringwald #define MAX_NR_AVDTP_CONNECTIONS 0 87612e7f38cSMilanka Ringwald #endif 87712e7f38cSMilanka Ringwald #endif 87812e7f38cSMilanka Ringwald 87912e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS 88012e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0 88112e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 88212e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool; 88312e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 884a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_connection_pool); 885a2673d88SMatthias Ringwald if (buffer){ 886a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_connection_t)); 887a2673d88SMatthias Ringwald } 888a2673d88SMatthias Ringwald return (avdtp_connection_t *) buffer; 88912e7f38cSMilanka Ringwald } 89012e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 89112e7f38cSMilanka Ringwald btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 89212e7f38cSMilanka Ringwald } 89312e7f38cSMilanka Ringwald #else 89412e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 89512e7f38cSMilanka Ringwald return NULL; 89612e7f38cSMilanka Ringwald } 89712e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 898b6269742SMatthias Ringwald UNUSED(avdtp_connection); 89912e7f38cSMilanka Ringwald }; 90012e7f38cSMilanka Ringwald #endif 90112e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC) 9022a95308bSMatthias Ringwald 9032a95308bSMatthias Ringwald typedef struct { 9042a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 905798bd46fSMatthias Ringwald avdtp_connection_t data; 9062a95308bSMatthias Ringwald } btstack_memory_avdtp_connection_t; 9072a95308bSMatthias Ringwald 90812e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 9092a95308bSMatthias Ringwald btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t)); 910a2673d88SMatthias Ringwald if (buffer){ 911798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avdtp_connection_t)); 9122a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 9132a95308bSMatthias Ringwald return &buffer->data; 914b6269742SMatthias Ringwald } else { 915b6269742SMatthias Ringwald return NULL; 916a2673d88SMatthias Ringwald } 91712e7f38cSMilanka Ringwald } 91812e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 919798bd46fSMatthias Ringwald // reconstruct buffer start 920798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_connection)[-1]; 921798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 922b6269742SMatthias Ringwald free(buffer); 92312e7f38cSMilanka Ringwald } 92412e7f38cSMilanka Ringwald #endif 92512e7f38cSMilanka Ringwald 92612e7f38cSMilanka Ringwald 92791451a2bSMilanka Ringwald 92891451a2bSMilanka Ringwald // MARK: avrcp_connection_t 92991451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 93091451a2bSMilanka Ringwald #if defined(MAX_NO_AVRCP_CONNECTIONS) 93191451a2bSMilanka Ringwald #error "Deprecated MAX_NO_AVRCP_CONNECTIONS defined instead of MAX_NR_AVRCP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_CONNECTIONS." 93291451a2bSMilanka Ringwald #else 93391451a2bSMilanka Ringwald #define MAX_NR_AVRCP_CONNECTIONS 0 93491451a2bSMilanka Ringwald #endif 93591451a2bSMilanka Ringwald #endif 93691451a2bSMilanka Ringwald 93791451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS 93891451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0 93991451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 94091451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool; 94191451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 942a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_connection_pool); 943a2673d88SMatthias Ringwald if (buffer){ 944a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_connection_t)); 945a2673d88SMatthias Ringwald } 946a2673d88SMatthias Ringwald return (avrcp_connection_t *) buffer; 94791451a2bSMilanka Ringwald } 94891451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 94991451a2bSMilanka Ringwald btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 95091451a2bSMilanka Ringwald } 95191451a2bSMilanka Ringwald #else 95291451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 95391451a2bSMilanka Ringwald return NULL; 95491451a2bSMilanka Ringwald } 95591451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 956b6269742SMatthias Ringwald UNUSED(avrcp_connection); 95791451a2bSMilanka Ringwald }; 95891451a2bSMilanka Ringwald #endif 95991451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC) 9602a95308bSMatthias Ringwald 9612a95308bSMatthias Ringwald typedef struct { 9622a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 963798bd46fSMatthias Ringwald avrcp_connection_t data; 9642a95308bSMatthias Ringwald } btstack_memory_avrcp_connection_t; 9652a95308bSMatthias Ringwald 96691451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 9672a95308bSMatthias Ringwald btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t)); 968a2673d88SMatthias Ringwald if (buffer){ 969798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avrcp_connection_t)); 9702a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 9712a95308bSMatthias Ringwald return &buffer->data; 972b6269742SMatthias Ringwald } else { 973b6269742SMatthias Ringwald return NULL; 974a2673d88SMatthias Ringwald } 97591451a2bSMilanka Ringwald } 97691451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 977798bd46fSMatthias Ringwald // reconstruct buffer start 978798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_connection)[-1]; 979798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 980b6269742SMatthias Ringwald free(buffer); 98191451a2bSMilanka Ringwald } 98291451a2bSMilanka Ringwald #endif 98391451a2bSMilanka Ringwald 98491451a2bSMilanka Ringwald 985f12a3722SMilanka Ringwald 986f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t 987f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS) 988f12a3722SMilanka Ringwald #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS) 989f12a3722SMilanka Ringwald #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." 990f12a3722SMilanka Ringwald #else 991f12a3722SMilanka Ringwald #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0 992f12a3722SMilanka Ringwald #endif 993f12a3722SMilanka Ringwald #endif 994f12a3722SMilanka Ringwald 995f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 996f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 997f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS]; 998f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool; 999f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 1000a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool); 1001a2673d88SMatthias Ringwald if (buffer){ 1002a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 1003a2673d88SMatthias Ringwald } 1004a2673d88SMatthias Ringwald return (avrcp_browsing_connection_t *) buffer; 1005f12a3722SMilanka Ringwald } 1006f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1007f12a3722SMilanka Ringwald btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection); 1008f12a3722SMilanka Ringwald } 1009f12a3722SMilanka Ringwald #else 1010f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 1011f12a3722SMilanka Ringwald return NULL; 1012f12a3722SMilanka Ringwald } 1013f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1014b6269742SMatthias Ringwald UNUSED(avrcp_browsing_connection); 1015f12a3722SMilanka Ringwald }; 1016f12a3722SMilanka Ringwald #endif 1017f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC) 10182a95308bSMatthias Ringwald 10192a95308bSMatthias Ringwald typedef struct { 10202a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1021798bd46fSMatthias Ringwald avrcp_browsing_connection_t data; 10222a95308bSMatthias Ringwald } btstack_memory_avrcp_browsing_connection_t; 10232a95308bSMatthias Ringwald 1024f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 10252a95308bSMatthias Ringwald btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t)); 1026a2673d88SMatthias Ringwald if (buffer){ 1027798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avrcp_browsing_connection_t)); 10282a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 10292a95308bSMatthias Ringwald return &buffer->data; 1030b6269742SMatthias Ringwald } else { 1031b6269742SMatthias Ringwald return NULL; 1032a2673d88SMatthias Ringwald } 1033f12a3722SMilanka Ringwald } 1034f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1035798bd46fSMatthias Ringwald // reconstruct buffer start 1036798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_browsing_connection)[-1]; 1037798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1038b6269742SMatthias Ringwald free(buffer); 1039f12a3722SMilanka Ringwald } 1040f12a3722SMilanka Ringwald #endif 1041f12a3722SMilanka Ringwald 1042f12a3722SMilanka Ringwald 104344c5d856SMatthias Ringwald #endif 1044a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 10452e97c149S[email protected] 1046174a0c1cSMilanka Ringwald // MARK: battery_service_client_t 1047174a0c1cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BATTERY_SERVICE_CLIENTS) 1048174a0c1cSMilanka Ringwald #if defined(MAX_NO_BATTERY_SERVICE_CLIENTS) 1049174a0c1cSMilanka Ringwald #error "Deprecated MAX_NO_BATTERY_SERVICE_CLIENTS defined instead of MAX_NR_BATTERY_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_BATTERY_SERVICE_CLIENTS." 1050174a0c1cSMilanka Ringwald #else 1051174a0c1cSMilanka Ringwald #define MAX_NR_BATTERY_SERVICE_CLIENTS 0 1052174a0c1cSMilanka Ringwald #endif 1053174a0c1cSMilanka Ringwald #endif 1054174a0c1cSMilanka Ringwald 1055174a0c1cSMilanka Ringwald #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 1056174a0c1cSMilanka Ringwald #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0 1057174a0c1cSMilanka Ringwald static battery_service_client_t battery_service_client_storage[MAX_NR_BATTERY_SERVICE_CLIENTS]; 1058174a0c1cSMilanka Ringwald static btstack_memory_pool_t battery_service_client_pool; 1059174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1060174a0c1cSMilanka Ringwald void * buffer = btstack_memory_pool_get(&battery_service_client_pool); 1061174a0c1cSMilanka Ringwald if (buffer){ 1062174a0c1cSMilanka Ringwald memset(buffer, 0, sizeof(battery_service_client_t)); 1063174a0c1cSMilanka Ringwald } 1064174a0c1cSMilanka Ringwald return (battery_service_client_t *) buffer; 1065174a0c1cSMilanka Ringwald } 1066174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1067174a0c1cSMilanka Ringwald btstack_memory_pool_free(&battery_service_client_pool, battery_service_client); 1068174a0c1cSMilanka Ringwald } 1069174a0c1cSMilanka Ringwald #else 1070174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1071174a0c1cSMilanka Ringwald return NULL; 1072174a0c1cSMilanka Ringwald } 1073174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1074174a0c1cSMilanka Ringwald UNUSED(battery_service_client); 1075174a0c1cSMilanka Ringwald }; 1076174a0c1cSMilanka Ringwald #endif 1077174a0c1cSMilanka Ringwald #elif defined(HAVE_MALLOC) 1078174a0c1cSMilanka Ringwald 1079174a0c1cSMilanka Ringwald typedef struct { 1080174a0c1cSMilanka Ringwald btstack_memory_buffer_t tracking; 1081174a0c1cSMilanka Ringwald battery_service_client_t data; 1082174a0c1cSMilanka Ringwald } btstack_memory_battery_service_client_t; 1083174a0c1cSMilanka Ringwald 1084174a0c1cSMilanka Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1085174a0c1cSMilanka Ringwald btstack_memory_battery_service_client_t * buffer = (btstack_memory_battery_service_client_t *) malloc(sizeof(btstack_memory_battery_service_client_t)); 1086174a0c1cSMilanka Ringwald if (buffer){ 1087174a0c1cSMilanka Ringwald memset(buffer, 0, sizeof(btstack_memory_battery_service_client_t)); 1088174a0c1cSMilanka Ringwald btstack_memory_tracking_add(&buffer->tracking); 1089174a0c1cSMilanka Ringwald return &buffer->data; 1090174a0c1cSMilanka Ringwald } else { 1091174a0c1cSMilanka Ringwald return NULL; 1092174a0c1cSMilanka Ringwald } 1093174a0c1cSMilanka Ringwald } 1094174a0c1cSMilanka Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1095174a0c1cSMilanka Ringwald // reconstruct buffer start 1096174a0c1cSMilanka Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) battery_service_client)[-1]; 1097174a0c1cSMilanka Ringwald btstack_memory_tracking_remove(buffer); 1098174a0c1cSMilanka Ringwald free(buffer); 1099174a0c1cSMilanka Ringwald } 1100174a0c1cSMilanka Ringwald #endif 1101174a0c1cSMilanka Ringwald 1102174a0c1cSMilanka Ringwald 11032e97c149S[email protected] // MARK: gatt_client_t 1104a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 1105a265b909SMatthias Ringwald #if defined(MAX_NO_GATT_CLIENTS) 110627faf85aSMilanka Ringwald #error "Deprecated MAX_NO_GATT_CLIENTS defined instead of MAX_NR_GATT_CLIENTS. Please update your btstack_config.h to use MAX_NR_GATT_CLIENTS." 1107a265b909SMatthias Ringwald #else 1108a265b909SMatthias Ringwald #define MAX_NR_GATT_CLIENTS 0 1109a265b909SMatthias Ringwald #endif 1110a265b909SMatthias Ringwald #endif 1111a265b909SMatthias Ringwald 1112a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS 1113a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 1114a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 111529d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool; 1116d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 1117a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&gatt_client_pool); 1118a2673d88SMatthias Ringwald if (buffer){ 1119a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(gatt_client_t)); 1120a2673d88SMatthias Ringwald } 1121a2673d88SMatthias Ringwald return (gatt_client_t *) buffer; 1122d0fdae3cS[email protected] } 1123d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 112429d0c4f7SMatthias Ringwald btstack_memory_pool_free(&gatt_client_pool, gatt_client); 1125d0fdae3cS[email protected] } 1126d0fdae3cS[email protected] #else 1127d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 1128d0fdae3cS[email protected] return NULL; 1129d0fdae3cS[email protected] } 1130d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1131b6269742SMatthias Ringwald UNUSED(gatt_client); 1132d0fdae3cS[email protected] }; 1133d0fdae3cS[email protected] #endif 1134d0fdae3cS[email protected] #elif defined(HAVE_MALLOC) 11352a95308bSMatthias Ringwald 11362a95308bSMatthias Ringwald typedef struct { 11372a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1138798bd46fSMatthias Ringwald gatt_client_t data; 11392a95308bSMatthias Ringwald } btstack_memory_gatt_client_t; 11402a95308bSMatthias Ringwald 1141d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 11422a95308bSMatthias Ringwald btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t)); 1143a2673d88SMatthias Ringwald if (buffer){ 1144798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_gatt_client_t)); 11452a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 11462a95308bSMatthias Ringwald return &buffer->data; 1147b6269742SMatthias Ringwald } else { 1148b6269742SMatthias Ringwald return NULL; 1149a2673d88SMatthias Ringwald } 1150d0fdae3cS[email protected] } 1151d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1152798bd46fSMatthias Ringwald // reconstruct buffer start 1153798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) gatt_client)[-1]; 1154798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1155b6269742SMatthias Ringwald free(buffer); 1156d0fdae3cS[email protected] } 1157d0fdae3cS[email protected] #endif 11582e97c149S[email protected] 11592e97c149S[email protected] 1160cf26c8fbSMilanka Ringwald // MARK: hids_client_t 1161cf26c8fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HIDS_CLIENTS) 1162cf26c8fbSMilanka Ringwald #if defined(MAX_NO_HIDS_CLIENTS) 1163cf26c8fbSMilanka Ringwald #error "Deprecated MAX_NO_HIDS_CLIENTS defined instead of MAX_NR_HIDS_CLIENTS. Please update your btstack_config.h to use MAX_NR_HIDS_CLIENTS." 1164cf26c8fbSMilanka Ringwald #else 1165cf26c8fbSMilanka Ringwald #define MAX_NR_HIDS_CLIENTS 0 1166cf26c8fbSMilanka Ringwald #endif 1167cf26c8fbSMilanka Ringwald #endif 1168cf26c8fbSMilanka Ringwald 1169cf26c8fbSMilanka Ringwald #ifdef MAX_NR_HIDS_CLIENTS 1170cf26c8fbSMilanka Ringwald #if MAX_NR_HIDS_CLIENTS > 0 1171cf26c8fbSMilanka Ringwald static hids_client_t hids_client_storage[MAX_NR_HIDS_CLIENTS]; 1172cf26c8fbSMilanka Ringwald static btstack_memory_pool_t hids_client_pool; 1173cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){ 1174cf26c8fbSMilanka Ringwald void * buffer = btstack_memory_pool_get(&hids_client_pool); 1175cf26c8fbSMilanka Ringwald if (buffer){ 1176cf26c8fbSMilanka Ringwald memset(buffer, 0, sizeof(hids_client_t)); 1177cf26c8fbSMilanka Ringwald } 1178cf26c8fbSMilanka Ringwald return (hids_client_t *) buffer; 1179cf26c8fbSMilanka Ringwald } 1180cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1181cf26c8fbSMilanka Ringwald btstack_memory_pool_free(&hids_client_pool, hids_client); 1182cf26c8fbSMilanka Ringwald } 1183cf26c8fbSMilanka Ringwald #else 1184cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){ 1185cf26c8fbSMilanka Ringwald return NULL; 1186cf26c8fbSMilanka Ringwald } 1187cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1188cf26c8fbSMilanka Ringwald UNUSED(hids_client); 1189cf26c8fbSMilanka Ringwald }; 1190cf26c8fbSMilanka Ringwald #endif 1191cf26c8fbSMilanka Ringwald #elif defined(HAVE_MALLOC) 1192cf26c8fbSMilanka Ringwald 1193cf26c8fbSMilanka Ringwald typedef struct { 1194cf26c8fbSMilanka Ringwald btstack_memory_buffer_t tracking; 1195cf26c8fbSMilanka Ringwald hids_client_t data; 1196cf26c8fbSMilanka Ringwald } btstack_memory_hids_client_t; 1197cf26c8fbSMilanka Ringwald 1198cf26c8fbSMilanka Ringwald hids_client_t * btstack_memory_hids_client_get(void){ 1199cf26c8fbSMilanka Ringwald btstack_memory_hids_client_t * buffer = (btstack_memory_hids_client_t *) malloc(sizeof(btstack_memory_hids_client_t)); 1200cf26c8fbSMilanka Ringwald if (buffer){ 1201cf26c8fbSMilanka Ringwald memset(buffer, 0, sizeof(btstack_memory_hids_client_t)); 1202cf26c8fbSMilanka Ringwald btstack_memory_tracking_add(&buffer->tracking); 1203cf26c8fbSMilanka Ringwald return &buffer->data; 1204cf26c8fbSMilanka Ringwald } else { 1205cf26c8fbSMilanka Ringwald return NULL; 1206cf26c8fbSMilanka Ringwald } 1207cf26c8fbSMilanka Ringwald } 1208cf26c8fbSMilanka Ringwald void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1209cf26c8fbSMilanka Ringwald // reconstruct buffer start 1210cf26c8fbSMilanka Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hids_client)[-1]; 1211cf26c8fbSMilanka Ringwald btstack_memory_tracking_remove(buffer); 1212cf26c8fbSMilanka Ringwald free(buffer); 1213cf26c8fbSMilanka Ringwald } 1214cf26c8fbSMilanka Ringwald #endif 1215cf26c8fbSMilanka Ringwald 1216cf26c8fbSMilanka Ringwald 1217cf26c8fbSMilanka Ringwald // MARK: scan_parameters_service_client_t 1218cf26c8fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS) 1219cf26c8fbSMilanka Ringwald #if defined(MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS) 1220cf26c8fbSMilanka Ringwald #error "Deprecated MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS defined instead of MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS." 1221cf26c8fbSMilanka Ringwald #else 1222cf26c8fbSMilanka Ringwald #define MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 0 1223cf26c8fbSMilanka Ringwald #endif 1224cf26c8fbSMilanka Ringwald #endif 1225cf26c8fbSMilanka Ringwald 1226cf26c8fbSMilanka Ringwald #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 1227cf26c8fbSMilanka Ringwald #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0 1228cf26c8fbSMilanka Ringwald static scan_parameters_service_client_t scan_parameters_service_client_storage[MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS]; 1229cf26c8fbSMilanka Ringwald static btstack_memory_pool_t scan_parameters_service_client_pool; 1230cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1231cf26c8fbSMilanka Ringwald void * buffer = btstack_memory_pool_get(&scan_parameters_service_client_pool); 1232cf26c8fbSMilanka Ringwald if (buffer){ 1233cf26c8fbSMilanka Ringwald memset(buffer, 0, sizeof(scan_parameters_service_client_t)); 1234cf26c8fbSMilanka Ringwald } 1235cf26c8fbSMilanka Ringwald return (scan_parameters_service_client_t *) buffer; 1236cf26c8fbSMilanka Ringwald } 1237cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1238cf26c8fbSMilanka Ringwald btstack_memory_pool_free(&scan_parameters_service_client_pool, scan_parameters_service_client); 1239cf26c8fbSMilanka Ringwald } 1240cf26c8fbSMilanka Ringwald #else 1241cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1242cf26c8fbSMilanka Ringwald return NULL; 1243cf26c8fbSMilanka Ringwald } 1244cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1245cf26c8fbSMilanka Ringwald UNUSED(scan_parameters_service_client); 1246cf26c8fbSMilanka Ringwald }; 1247cf26c8fbSMilanka Ringwald #endif 1248cf26c8fbSMilanka Ringwald #elif defined(HAVE_MALLOC) 1249cf26c8fbSMilanka Ringwald 1250cf26c8fbSMilanka Ringwald typedef struct { 1251cf26c8fbSMilanka Ringwald btstack_memory_buffer_t tracking; 1252cf26c8fbSMilanka Ringwald scan_parameters_service_client_t data; 1253cf26c8fbSMilanka Ringwald } btstack_memory_scan_parameters_service_client_t; 1254cf26c8fbSMilanka Ringwald 1255cf26c8fbSMilanka Ringwald scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1256cf26c8fbSMilanka Ringwald btstack_memory_scan_parameters_service_client_t * buffer = (btstack_memory_scan_parameters_service_client_t *) malloc(sizeof(btstack_memory_scan_parameters_service_client_t)); 1257cf26c8fbSMilanka Ringwald if (buffer){ 1258cf26c8fbSMilanka Ringwald memset(buffer, 0, sizeof(btstack_memory_scan_parameters_service_client_t)); 1259cf26c8fbSMilanka Ringwald btstack_memory_tracking_add(&buffer->tracking); 1260cf26c8fbSMilanka Ringwald return &buffer->data; 1261cf26c8fbSMilanka Ringwald } else { 1262cf26c8fbSMilanka Ringwald return NULL; 1263cf26c8fbSMilanka Ringwald } 1264cf26c8fbSMilanka Ringwald } 1265cf26c8fbSMilanka Ringwald void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1266cf26c8fbSMilanka Ringwald // reconstruct buffer start 1267cf26c8fbSMilanka Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) scan_parameters_service_client)[-1]; 1268cf26c8fbSMilanka Ringwald btstack_memory_tracking_remove(buffer); 1269cf26c8fbSMilanka Ringwald free(buffer); 1270cf26c8fbSMilanka Ringwald } 1271cf26c8fbSMilanka Ringwald #endif 1272cf26c8fbSMilanka Ringwald 1273cf26c8fbSMilanka Ringwald 1274cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t 1275a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 1276a265b909SMatthias Ringwald #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 127727faf85aSMilanka Ringwald #error "Deprecated MAX_NO_SM_LOOKUP_ENTRIES defined instead of MAX_NR_SM_LOOKUP_ENTRIES. Please update your btstack_config.h to use MAX_NR_SM_LOOKUP_ENTRIES." 1278a265b909SMatthias Ringwald #else 1279a265b909SMatthias Ringwald #define MAX_NR_SM_LOOKUP_ENTRIES 0 1280a265b909SMatthias Ringwald #endif 1281a265b909SMatthias Ringwald #endif 1282a265b909SMatthias Ringwald 1283a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES 1284a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1285a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 128629d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool; 1287cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1288a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool); 1289a2673d88SMatthias Ringwald if (buffer){ 1290a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(sm_lookup_entry_t)); 1291a2673d88SMatthias Ringwald } 1292a2673d88SMatthias Ringwald return (sm_lookup_entry_t *) buffer; 1293cf49570bSMatthias Ringwald } 1294cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 129529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 1296cf49570bSMatthias Ringwald } 1297cf49570bSMatthias Ringwald #else 1298cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1299cf49570bSMatthias Ringwald return NULL; 1300cf49570bSMatthias Ringwald } 1301cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1302b6269742SMatthias Ringwald UNUSED(sm_lookup_entry); 1303cf49570bSMatthias Ringwald }; 1304cf49570bSMatthias Ringwald #endif 1305cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC) 13062a95308bSMatthias Ringwald 13072a95308bSMatthias Ringwald typedef struct { 13082a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1309798bd46fSMatthias Ringwald sm_lookup_entry_t data; 13102a95308bSMatthias Ringwald } btstack_memory_sm_lookup_entry_t; 13112a95308bSMatthias Ringwald 1312cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 13132a95308bSMatthias Ringwald btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t)); 1314a2673d88SMatthias Ringwald if (buffer){ 1315798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_sm_lookup_entry_t)); 13162a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 13172a95308bSMatthias Ringwald return &buffer->data; 1318b6269742SMatthias Ringwald } else { 1319b6269742SMatthias Ringwald return NULL; 1320a2673d88SMatthias Ringwald } 1321cf49570bSMatthias Ringwald } 1322cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1323798bd46fSMatthias Ringwald // reconstruct buffer start 1324798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) sm_lookup_entry)[-1]; 1325798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1326b6269742SMatthias Ringwald free(buffer); 1327cf49570bSMatthias Ringwald } 1328cf49570bSMatthias Ringwald #endif 1329cf49570bSMatthias Ringwald 1330cf49570bSMatthias Ringwald 1331174a0c1cSMilanka Ringwald // MARK: whitelist_entry_t 1332174a0c1cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 1333174a0c1cSMilanka Ringwald #if defined(MAX_NO_WHITELIST_ENTRIES) 1334174a0c1cSMilanka Ringwald #error "Deprecated MAX_NO_WHITELIST_ENTRIES defined instead of MAX_NR_WHITELIST_ENTRIES. Please update your btstack_config.h to use MAX_NR_WHITELIST_ENTRIES." 1335174a0c1cSMilanka Ringwald #else 1336174a0c1cSMilanka Ringwald #define MAX_NR_WHITELIST_ENTRIES 0 1337174a0c1cSMilanka Ringwald #endif 1338174a0c1cSMilanka Ringwald #endif 1339174a0c1cSMilanka Ringwald 1340174a0c1cSMilanka Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES 1341174a0c1cSMilanka Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 1342174a0c1cSMilanka Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 1343174a0c1cSMilanka Ringwald static btstack_memory_pool_t whitelist_entry_pool; 1344174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1345174a0c1cSMilanka Ringwald void * buffer = btstack_memory_pool_get(&whitelist_entry_pool); 1346174a0c1cSMilanka Ringwald if (buffer){ 1347174a0c1cSMilanka Ringwald memset(buffer, 0, sizeof(whitelist_entry_t)); 1348174a0c1cSMilanka Ringwald } 1349174a0c1cSMilanka Ringwald return (whitelist_entry_t *) buffer; 1350174a0c1cSMilanka Ringwald } 1351174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1352174a0c1cSMilanka Ringwald btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 1353174a0c1cSMilanka Ringwald } 1354174a0c1cSMilanka Ringwald #else 1355174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1356174a0c1cSMilanka Ringwald return NULL; 1357174a0c1cSMilanka Ringwald } 1358174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1359174a0c1cSMilanka Ringwald UNUSED(whitelist_entry); 1360174a0c1cSMilanka Ringwald }; 1361174a0c1cSMilanka Ringwald #endif 1362174a0c1cSMilanka Ringwald #elif defined(HAVE_MALLOC) 1363174a0c1cSMilanka Ringwald 1364174a0c1cSMilanka Ringwald typedef struct { 1365174a0c1cSMilanka Ringwald btstack_memory_buffer_t tracking; 1366174a0c1cSMilanka Ringwald whitelist_entry_t data; 1367174a0c1cSMilanka Ringwald } btstack_memory_whitelist_entry_t; 1368174a0c1cSMilanka Ringwald 1369174a0c1cSMilanka Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1370174a0c1cSMilanka Ringwald btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t)); 1371174a0c1cSMilanka Ringwald if (buffer){ 1372174a0c1cSMilanka Ringwald memset(buffer, 0, sizeof(btstack_memory_whitelist_entry_t)); 1373174a0c1cSMilanka Ringwald btstack_memory_tracking_add(&buffer->tracking); 1374174a0c1cSMilanka Ringwald return &buffer->data; 1375174a0c1cSMilanka Ringwald } else { 1376174a0c1cSMilanka Ringwald return NULL; 1377174a0c1cSMilanka Ringwald } 1378174a0c1cSMilanka Ringwald } 1379174a0c1cSMilanka Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1380174a0c1cSMilanka Ringwald // reconstruct buffer start 1381174a0c1cSMilanka Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) whitelist_entry)[-1]; 1382174a0c1cSMilanka Ringwald btstack_memory_tracking_remove(buffer); 1383174a0c1cSMilanka Ringwald free(buffer); 1384174a0c1cSMilanka Ringwald } 1385174a0c1cSMilanka Ringwald #endif 1386174a0c1cSMilanka Ringwald 1387174a0c1cSMilanka Ringwald 1388*dbca66ffSMatthias Ringwald // MARK: periodic_advertiser_list_entry_t 1389*dbca66ffSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES) 1390*dbca66ffSMatthias Ringwald #if defined(MAX_NO_PERIODIC_ADVERTISER_LIST_ENTRIES) 1391*dbca66ffSMatthias Ringwald #error "Deprecated MAX_NO_PERIODIC_ADVERTISER_LIST_ENTRIES defined instead of MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES. Please update your btstack_config.h to use MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES." 1392*dbca66ffSMatthias Ringwald #else 1393*dbca66ffSMatthias Ringwald #define MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 0 1394*dbca66ffSMatthias Ringwald #endif 1395*dbca66ffSMatthias Ringwald #endif 1396*dbca66ffSMatthias Ringwald 1397*dbca66ffSMatthias Ringwald #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1398*dbca66ffSMatthias Ringwald #if MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES > 0 1399*dbca66ffSMatthias Ringwald static periodic_advertiser_list_entry_t periodic_advertiser_list_entry_storage[MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES]; 1400*dbca66ffSMatthias Ringwald static btstack_memory_pool_t periodic_advertiser_list_entry_pool; 1401*dbca66ffSMatthias Ringwald periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1402*dbca66ffSMatthias Ringwald void * buffer = btstack_memory_pool_get(&periodic_advertiser_list_entry_pool); 1403*dbca66ffSMatthias Ringwald if (buffer){ 1404*dbca66ffSMatthias Ringwald memset(buffer, 0, sizeof(periodic_advertiser_list_entry_t)); 1405*dbca66ffSMatthias Ringwald } 1406*dbca66ffSMatthias Ringwald return (periodic_advertiser_list_entry_t *) buffer; 1407*dbca66ffSMatthias Ringwald } 1408*dbca66ffSMatthias Ringwald void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1409*dbca66ffSMatthias Ringwald btstack_memory_pool_free(&periodic_advertiser_list_entry_pool, periodic_advertiser_list_entry); 1410*dbca66ffSMatthias Ringwald } 1411*dbca66ffSMatthias Ringwald #else 1412*dbca66ffSMatthias Ringwald periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1413*dbca66ffSMatthias Ringwald return NULL; 1414*dbca66ffSMatthias Ringwald } 1415*dbca66ffSMatthias Ringwald void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1416*dbca66ffSMatthias Ringwald UNUSED(periodic_advertiser_list_entry); 1417*dbca66ffSMatthias Ringwald }; 1418*dbca66ffSMatthias Ringwald #endif 1419*dbca66ffSMatthias Ringwald #elif defined(HAVE_MALLOC) 1420*dbca66ffSMatthias Ringwald 1421*dbca66ffSMatthias Ringwald typedef struct { 1422*dbca66ffSMatthias Ringwald btstack_memory_buffer_t tracking; 1423*dbca66ffSMatthias Ringwald periodic_advertiser_list_entry_t data; 1424*dbca66ffSMatthias Ringwald } btstack_memory_periodic_advertiser_list_entry_t; 1425*dbca66ffSMatthias Ringwald 1426*dbca66ffSMatthias Ringwald periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1427*dbca66ffSMatthias Ringwald btstack_memory_periodic_advertiser_list_entry_t * buffer = (btstack_memory_periodic_advertiser_list_entry_t *) malloc(sizeof(btstack_memory_periodic_advertiser_list_entry_t)); 1428*dbca66ffSMatthias Ringwald if (buffer){ 1429*dbca66ffSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_periodic_advertiser_list_entry_t)); 1430*dbca66ffSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 1431*dbca66ffSMatthias Ringwald return &buffer->data; 1432*dbca66ffSMatthias Ringwald } else { 1433*dbca66ffSMatthias Ringwald return NULL; 1434*dbca66ffSMatthias Ringwald } 1435*dbca66ffSMatthias Ringwald } 1436*dbca66ffSMatthias Ringwald void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1437*dbca66ffSMatthias Ringwald // reconstruct buffer start 1438*dbca66ffSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) periodic_advertiser_list_entry)[-1]; 1439*dbca66ffSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1440*dbca66ffSMatthias Ringwald free(buffer); 1441*dbca66ffSMatthias Ringwald } 1442*dbca66ffSMatthias Ringwald #endif 1443*dbca66ffSMatthias Ringwald 1444*dbca66ffSMatthias Ringwald 144544c5d856SMatthias Ringwald #endif 144644c5d856SMatthias Ringwald #ifdef ENABLE_MESH 1447ebb73e1fSMatthias Ringwald 1448ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t 1449ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS) 1450ebb73e1fSMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_PDUS) 1451ebb73e1fSMatthias Ringwald #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." 1452ebb73e1fSMatthias Ringwald #else 1453ebb73e1fSMatthias Ringwald #define MAX_NR_MESH_NETWORK_PDUS 0 1454ebb73e1fSMatthias Ringwald #endif 1455ebb73e1fSMatthias Ringwald #endif 1456ebb73e1fSMatthias Ringwald 1457ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS 1458ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0 1459ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS]; 1460ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool; 1461ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 14621c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool); 14631c4e8084SMatthias Ringwald if (buffer){ 14641c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_pdu_t)); 14651c4e8084SMatthias Ringwald } 14661c4e8084SMatthias Ringwald return (mesh_network_pdu_t *) buffer; 1467ebb73e1fSMatthias Ringwald } 1468ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1469ebb73e1fSMatthias Ringwald btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu); 1470ebb73e1fSMatthias Ringwald } 1471ebb73e1fSMatthias Ringwald #else 1472ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 1473ebb73e1fSMatthias Ringwald return NULL; 1474ebb73e1fSMatthias Ringwald } 1475ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1476b6269742SMatthias Ringwald UNUSED(mesh_network_pdu); 1477ebb73e1fSMatthias Ringwald }; 1478ebb73e1fSMatthias Ringwald #endif 1479ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC) 14802a95308bSMatthias Ringwald 14812a95308bSMatthias Ringwald typedef struct { 14822a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1483798bd46fSMatthias Ringwald mesh_network_pdu_t data; 14842a95308bSMatthias Ringwald } btstack_memory_mesh_network_pdu_t; 14852a95308bSMatthias Ringwald 1486ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 14872a95308bSMatthias Ringwald btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t)); 14881c4e8084SMatthias Ringwald if (buffer){ 1489798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_network_pdu_t)); 14902a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 14912a95308bSMatthias Ringwald return &buffer->data; 1492b6269742SMatthias Ringwald } else { 1493b6269742SMatthias Ringwald return NULL; 14941c4e8084SMatthias Ringwald } 1495ebb73e1fSMatthias Ringwald } 1496ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1497798bd46fSMatthias Ringwald // reconstruct buffer start 1498798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_pdu)[-1]; 1499798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1500b6269742SMatthias Ringwald free(buffer); 1501ebb73e1fSMatthias Ringwald } 1502ebb73e1fSMatthias Ringwald #endif 1503ebb73e1fSMatthias Ringwald 1504ebb73e1fSMatthias Ringwald 1505a4bbc09dSMatthias Ringwald // MARK: mesh_segmented_pdu_t 1506a4bbc09dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS) 1507a4bbc09dSMatthias Ringwald #if defined(MAX_NO_MESH_SEGMENTED_PDUS) 1508a4bbc09dSMatthias Ringwald #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." 1509f7434c1fSMatthias Ringwald #else 1510a4bbc09dSMatthias Ringwald #define MAX_NR_MESH_SEGMENTED_PDUS 0 1511f7434c1fSMatthias Ringwald #endif 1512f7434c1fSMatthias Ringwald #endif 1513f7434c1fSMatthias Ringwald 1514a4bbc09dSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1515a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0 1516a4bbc09dSMatthias Ringwald static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS]; 1517a4bbc09dSMatthias Ringwald static btstack_memory_pool_t mesh_segmented_pdu_pool; 1518a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1519a4bbc09dSMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool); 1520f7434c1fSMatthias Ringwald if (buffer){ 1521a4bbc09dSMatthias Ringwald memset(buffer, 0, sizeof(mesh_segmented_pdu_t)); 1522f7434c1fSMatthias Ringwald } 1523a4bbc09dSMatthias Ringwald return (mesh_segmented_pdu_t *) buffer; 1524f7434c1fSMatthias Ringwald } 1525a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1526a4bbc09dSMatthias Ringwald btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu); 1527f7434c1fSMatthias Ringwald } 1528f7434c1fSMatthias Ringwald #else 1529a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1530f7434c1fSMatthias Ringwald return NULL; 1531f7434c1fSMatthias Ringwald } 1532a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1533b6269742SMatthias Ringwald UNUSED(mesh_segmented_pdu); 1534f7434c1fSMatthias Ringwald }; 1535f7434c1fSMatthias Ringwald #endif 1536f7434c1fSMatthias Ringwald #elif defined(HAVE_MALLOC) 15372a95308bSMatthias Ringwald 15382a95308bSMatthias Ringwald typedef struct { 15392a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1540798bd46fSMatthias Ringwald mesh_segmented_pdu_t data; 15412a95308bSMatthias Ringwald } btstack_memory_mesh_segmented_pdu_t; 15422a95308bSMatthias Ringwald 1543a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 15442a95308bSMatthias Ringwald btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t)); 1545f7434c1fSMatthias Ringwald if (buffer){ 1546798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_segmented_pdu_t)); 15472a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 15482a95308bSMatthias Ringwald return &buffer->data; 1549b6269742SMatthias Ringwald } else { 1550b6269742SMatthias Ringwald return NULL; 1551f7434c1fSMatthias Ringwald } 1552f7434c1fSMatthias Ringwald } 1553a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1554798bd46fSMatthias Ringwald // reconstruct buffer start 1555798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_segmented_pdu)[-1]; 1556798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1557b6269742SMatthias Ringwald free(buffer); 1558f7434c1fSMatthias Ringwald } 1559f7434c1fSMatthias Ringwald #endif 1560f7434c1fSMatthias Ringwald 1561f7434c1fSMatthias Ringwald 1562491f99b3SMatthias Ringwald // MARK: mesh_upper_transport_pdu_t 1563491f99b3SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS) 1564491f99b3SMatthias Ringwald #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS) 1565491f99b3SMatthias Ringwald #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." 1566491f99b3SMatthias Ringwald #else 1567491f99b3SMatthias Ringwald #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0 1568491f99b3SMatthias Ringwald #endif 1569491f99b3SMatthias Ringwald #endif 1570491f99b3SMatthias Ringwald 1571491f99b3SMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1572491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 1573491f99b3SMatthias Ringwald static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS]; 1574491f99b3SMatthias Ringwald static btstack_memory_pool_t mesh_upper_transport_pdu_pool; 1575491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1576491f99b3SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool); 1577491f99b3SMatthias Ringwald if (buffer){ 1578491f99b3SMatthias Ringwald memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t)); 1579491f99b3SMatthias Ringwald } 1580491f99b3SMatthias Ringwald return (mesh_upper_transport_pdu_t *) buffer; 1581491f99b3SMatthias Ringwald } 1582491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1583491f99b3SMatthias Ringwald btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu); 1584491f99b3SMatthias Ringwald } 1585491f99b3SMatthias Ringwald #else 1586491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1587491f99b3SMatthias Ringwald return NULL; 1588491f99b3SMatthias Ringwald } 1589491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1590b6269742SMatthias Ringwald UNUSED(mesh_upper_transport_pdu); 1591491f99b3SMatthias Ringwald }; 1592491f99b3SMatthias Ringwald #endif 1593491f99b3SMatthias Ringwald #elif defined(HAVE_MALLOC) 15942a95308bSMatthias Ringwald 15952a95308bSMatthias Ringwald typedef struct { 15962a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1597798bd46fSMatthias Ringwald mesh_upper_transport_pdu_t data; 15982a95308bSMatthias Ringwald } btstack_memory_mesh_upper_transport_pdu_t; 15992a95308bSMatthias Ringwald 1600491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 16012a95308bSMatthias Ringwald btstack_memory_mesh_upper_transport_pdu_t * buffer = (btstack_memory_mesh_upper_transport_pdu_t *) malloc(sizeof(btstack_memory_mesh_upper_transport_pdu_t)); 1602491f99b3SMatthias Ringwald if (buffer){ 1603798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_upper_transport_pdu_t)); 16042a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 16052a95308bSMatthias Ringwald return &buffer->data; 1606b6269742SMatthias Ringwald } else { 1607b6269742SMatthias Ringwald return NULL; 1608491f99b3SMatthias Ringwald } 1609491f99b3SMatthias Ringwald } 1610491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1611798bd46fSMatthias Ringwald // reconstruct buffer start 1612798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_upper_transport_pdu)[-1]; 1613798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1614b6269742SMatthias Ringwald free(buffer); 1615491f99b3SMatthias Ringwald } 1616491f99b3SMatthias Ringwald #endif 1617491f99b3SMatthias Ringwald 1618491f99b3SMatthias Ringwald 1619c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t 1620c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS) 1621c0a711d9SMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_KEYS) 1622c0a711d9SMatthias Ringwald #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." 1623c0a711d9SMatthias Ringwald #else 1624c0a711d9SMatthias Ringwald #define MAX_NR_MESH_NETWORK_KEYS 0 1625c0a711d9SMatthias Ringwald #endif 1626c0a711d9SMatthias Ringwald #endif 1627c0a711d9SMatthias Ringwald 1628c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS 1629c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0 1630c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS]; 1631c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool; 1632c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 16331c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_key_pool); 16341c4e8084SMatthias Ringwald if (buffer){ 16351c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_key_t)); 16361c4e8084SMatthias Ringwald } 16371c4e8084SMatthias Ringwald return (mesh_network_key_t *) buffer; 1638c0a711d9SMatthias Ringwald } 1639c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1640c0a711d9SMatthias Ringwald btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key); 1641c0a711d9SMatthias Ringwald } 1642c0a711d9SMatthias Ringwald #else 1643c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1644c0a711d9SMatthias Ringwald return NULL; 1645c0a711d9SMatthias Ringwald } 1646c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1647b6269742SMatthias Ringwald UNUSED(mesh_network_key); 1648c0a711d9SMatthias Ringwald }; 1649c0a711d9SMatthias Ringwald #endif 1650c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC) 16512a95308bSMatthias Ringwald 16522a95308bSMatthias Ringwald typedef struct { 16532a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1654798bd46fSMatthias Ringwald mesh_network_key_t data; 16552a95308bSMatthias Ringwald } btstack_memory_mesh_network_key_t; 16562a95308bSMatthias Ringwald 1657c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 16582a95308bSMatthias Ringwald btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t)); 16591c4e8084SMatthias Ringwald if (buffer){ 1660798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_network_key_t)); 16612a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 16622a95308bSMatthias Ringwald return &buffer->data; 1663b6269742SMatthias Ringwald } else { 1664b6269742SMatthias Ringwald return NULL; 16651c4e8084SMatthias Ringwald } 1666c0a711d9SMatthias Ringwald } 1667c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1668798bd46fSMatthias Ringwald // reconstruct buffer start 1669798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_key)[-1]; 1670798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1671b6269742SMatthias Ringwald free(buffer); 1672c0a711d9SMatthias Ringwald } 1673c0a711d9SMatthias Ringwald #endif 1674c0a711d9SMatthias Ringwald 1675c0a711d9SMatthias Ringwald 167601e2bf94SMatthias Ringwald // MARK: mesh_transport_key_t 167701e2bf94SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS) 167801e2bf94SMatthias Ringwald #if defined(MAX_NO_MESH_TRANSPORT_KEYS) 167901e2bf94SMatthias Ringwald #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." 168001e2bf94SMatthias Ringwald #else 168101e2bf94SMatthias Ringwald #define MAX_NR_MESH_TRANSPORT_KEYS 0 168201e2bf94SMatthias Ringwald #endif 168301e2bf94SMatthias Ringwald #endif 168401e2bf94SMatthias Ringwald 168501e2bf94SMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS 168601e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0 168701e2bf94SMatthias Ringwald static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS]; 168801e2bf94SMatthias Ringwald static btstack_memory_pool_t mesh_transport_key_pool; 168901e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 169001e2bf94SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool); 169101e2bf94SMatthias Ringwald if (buffer){ 169201e2bf94SMatthias Ringwald memset(buffer, 0, sizeof(mesh_transport_key_t)); 169301e2bf94SMatthias Ringwald } 169401e2bf94SMatthias Ringwald return (mesh_transport_key_t *) buffer; 169501e2bf94SMatthias Ringwald } 169601e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 169701e2bf94SMatthias Ringwald btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key); 169801e2bf94SMatthias Ringwald } 169901e2bf94SMatthias Ringwald #else 170001e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 170101e2bf94SMatthias Ringwald return NULL; 170201e2bf94SMatthias Ringwald } 170301e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1704b6269742SMatthias Ringwald UNUSED(mesh_transport_key); 170501e2bf94SMatthias Ringwald }; 170601e2bf94SMatthias Ringwald #endif 170701e2bf94SMatthias Ringwald #elif defined(HAVE_MALLOC) 17082a95308bSMatthias Ringwald 17092a95308bSMatthias Ringwald typedef struct { 17102a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1711798bd46fSMatthias Ringwald mesh_transport_key_t data; 17122a95308bSMatthias Ringwald } btstack_memory_mesh_transport_key_t; 17132a95308bSMatthias Ringwald 171401e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 17152a95308bSMatthias Ringwald btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t)); 171601e2bf94SMatthias Ringwald if (buffer){ 1717798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_transport_key_t)); 17182a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 17192a95308bSMatthias Ringwald return &buffer->data; 1720b6269742SMatthias Ringwald } else { 1721b6269742SMatthias Ringwald return NULL; 172201e2bf94SMatthias Ringwald } 172301e2bf94SMatthias Ringwald } 172401e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1725798bd46fSMatthias Ringwald // reconstruct buffer start 1726798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_transport_key)[-1]; 1727798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1728b6269742SMatthias Ringwald free(buffer); 172901e2bf94SMatthias Ringwald } 173001e2bf94SMatthias Ringwald #endif 173101e2bf94SMatthias Ringwald 173201e2bf94SMatthias Ringwald 17331f45d603SMatthias Ringwald // MARK: mesh_virtual_address_t 17341f45d603SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS) 17351f45d603SMatthias Ringwald #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS) 17361f45d603SMatthias Ringwald #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." 17371f45d603SMatthias Ringwald #else 17381f45d603SMatthias Ringwald #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0 17391f45d603SMatthias Ringwald #endif 17401f45d603SMatthias Ringwald #endif 17411f45d603SMatthias Ringwald 17421f45d603SMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 17431f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 17441f45d603SMatthias Ringwald static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS]; 17451f45d603SMatthias Ringwald static btstack_memory_pool_t mesh_virtual_address_pool; 17461f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 17471f45d603SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool); 17481f45d603SMatthias Ringwald if (buffer){ 17491f45d603SMatthias Ringwald memset(buffer, 0, sizeof(mesh_virtual_address_t)); 17501f45d603SMatthias Ringwald } 17511f45d603SMatthias Ringwald return (mesh_virtual_address_t *) buffer; 17521f45d603SMatthias Ringwald } 17531f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 17541f45d603SMatthias Ringwald btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address); 17551f45d603SMatthias Ringwald } 17561f45d603SMatthias Ringwald #else 17571f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 17581f45d603SMatthias Ringwald return NULL; 17591f45d603SMatthias Ringwald } 17601f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1761b6269742SMatthias Ringwald UNUSED(mesh_virtual_address); 17621f45d603SMatthias Ringwald }; 17631f45d603SMatthias Ringwald #endif 17641f45d603SMatthias Ringwald #elif defined(HAVE_MALLOC) 17652a95308bSMatthias Ringwald 17662a95308bSMatthias Ringwald typedef struct { 17672a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1768798bd46fSMatthias Ringwald mesh_virtual_address_t data; 17692a95308bSMatthias Ringwald } btstack_memory_mesh_virtual_address_t; 17702a95308bSMatthias Ringwald 17711f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 17722a95308bSMatthias Ringwald btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t)); 17731f45d603SMatthias Ringwald if (buffer){ 1774798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_virtual_address_t)); 17752a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 17762a95308bSMatthias Ringwald return &buffer->data; 1777b6269742SMatthias Ringwald } else { 1778b6269742SMatthias Ringwald return NULL; 17791f45d603SMatthias Ringwald } 17801f45d603SMatthias Ringwald } 17811f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1782798bd46fSMatthias Ringwald // reconstruct buffer start 1783798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_virtual_address)[-1]; 1784798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1785b6269742SMatthias Ringwald free(buffer); 17861f45d603SMatthias Ringwald } 17871f45d603SMatthias Ringwald #endif 17881f45d603SMatthias Ringwald 17891f45d603SMatthias Ringwald 179001122b73SMatthias Ringwald // MARK: mesh_subnet_t 179101122b73SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS) 179201122b73SMatthias Ringwald #if defined(MAX_NO_MESH_SUBNETS) 179301122b73SMatthias Ringwald #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." 179401122b73SMatthias Ringwald #else 179501122b73SMatthias Ringwald #define MAX_NR_MESH_SUBNETS 0 179601122b73SMatthias Ringwald #endif 179701122b73SMatthias Ringwald #endif 179801122b73SMatthias Ringwald 179901122b73SMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS 180001122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0 180101122b73SMatthias Ringwald static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS]; 180201122b73SMatthias Ringwald static btstack_memory_pool_t mesh_subnet_pool; 180301122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 180401122b73SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_subnet_pool); 180501122b73SMatthias Ringwald if (buffer){ 180601122b73SMatthias Ringwald memset(buffer, 0, sizeof(mesh_subnet_t)); 180701122b73SMatthias Ringwald } 180801122b73SMatthias Ringwald return (mesh_subnet_t *) buffer; 180901122b73SMatthias Ringwald } 181001122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 181101122b73SMatthias Ringwald btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet); 181201122b73SMatthias Ringwald } 181301122b73SMatthias Ringwald #else 181401122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 181501122b73SMatthias Ringwald return NULL; 181601122b73SMatthias Ringwald } 181701122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1818b6269742SMatthias Ringwald UNUSED(mesh_subnet); 181901122b73SMatthias Ringwald }; 182001122b73SMatthias Ringwald #endif 182101122b73SMatthias Ringwald #elif defined(HAVE_MALLOC) 18222a95308bSMatthias Ringwald 18232a95308bSMatthias Ringwald typedef struct { 18242a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1825798bd46fSMatthias Ringwald mesh_subnet_t data; 18262a95308bSMatthias Ringwald } btstack_memory_mesh_subnet_t; 18272a95308bSMatthias Ringwald 182801122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 18292a95308bSMatthias Ringwald btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t)); 183001122b73SMatthias Ringwald if (buffer){ 1831798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_subnet_t)); 18322a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 18332a95308bSMatthias Ringwald return &buffer->data; 1834b6269742SMatthias Ringwald } else { 1835b6269742SMatthias Ringwald return NULL; 183601122b73SMatthias Ringwald } 183701122b73SMatthias Ringwald } 183801122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1839798bd46fSMatthias Ringwald // reconstruct buffer start 1840798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_subnet)[-1]; 1841798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1842b6269742SMatthias Ringwald free(buffer); 184301122b73SMatthias Ringwald } 184401122b73SMatthias Ringwald #endif 184501122b73SMatthias Ringwald 184601122b73SMatthias Ringwald 18472e97c149S[email protected] #endif 1848798bd46fSMatthias Ringwald 1849a3b02b71Smatthias.ringwald // init 1850a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 1851798bd46fSMatthias Ringwald #ifdef HAVE_MALLOC 1852798bd46fSMatthias Ringwald // assert that there is no unexpected padding for combined buffer 1853798bd46fSMatthias Ringwald btstack_assert(sizeof(test_buffer_t) == sizeof(btstack_memory_buffer_t) + sizeof(void *)); 1854798bd46fSMatthias Ringwald #endif 1855798bd46fSMatthias Ringwald 1856a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 1857a265b909SMatthias Ringwald btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 1858a3b02b71Smatthias.ringwald #endif 1859a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 1860a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 1861a3b02b71Smatthias.ringwald #endif 1862a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 1863a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 1864a3b02b71Smatthias.ringwald #endif 186544c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 186650dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 186750dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 1868a3b02b71Smatthias.ringwald #endif 186950dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0 187050dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 1871a3b02b71Smatthias.ringwald #endif 187250dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0 187350dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 187450dc57fcSMatthias Ringwald #endif 187550dc57fcSMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 187650dc57fcSMatthias Ringwald btstack_memory_pool_create(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry_storage, MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES, sizeof(btstack_link_key_db_memory_entry_t)); 187750dc57fcSMatthias Ringwald #endif 187850dc57fcSMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0 187950dc57fcSMatthias Ringwald btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 188050dc57fcSMatthias Ringwald #endif 188150dc57fcSMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0 188250dc57fcSMatthias Ringwald btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 188350dc57fcSMatthias Ringwald #endif 188450dc57fcSMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0 188550dc57fcSMatthias Ringwald btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 188650dc57fcSMatthias Ringwald #endif 1887f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0 1888f399f7fbSMilanka Ringwald btstack_memory_pool_create(&hid_host_connection_pool, hid_host_connection_storage, MAX_NR_HID_HOST_CONNECTIONS, sizeof(hid_host_connection_t)); 1889f399f7fbSMilanka Ringwald #endif 189050dc57fcSMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0 189150dc57fcSMatthias Ringwald btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 189250dc57fcSMatthias Ringwald #endif 189350dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 189450dc57fcSMatthias Ringwald btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t)); 189550dc57fcSMatthias Ringwald #endif 189650dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0 189750dc57fcSMatthias Ringwald btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t)); 189850dc57fcSMatthias Ringwald #endif 189950dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0 190050dc57fcSMatthias Ringwald btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t)); 190150dc57fcSMatthias Ringwald #endif 190250dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 190350dc57fcSMatthias Ringwald btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t)); 1904a3b02b71Smatthias.ringwald #endif 1905f12a3722SMilanka Ringwald #endif 1906a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 1907174a0c1cSMilanka Ringwald #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0 1908174a0c1cSMilanka Ringwald btstack_memory_pool_create(&battery_service_client_pool, battery_service_client_storage, MAX_NR_BATTERY_SERVICE_CLIENTS, sizeof(battery_service_client_t)); 1909174a0c1cSMilanka Ringwald #endif 1910a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 1911a265b909SMatthias Ringwald btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 1912d0fdae3cS[email protected] #endif 1913cf26c8fbSMilanka Ringwald #if MAX_NR_HIDS_CLIENTS > 0 1914cf26c8fbSMilanka Ringwald btstack_memory_pool_create(&hids_client_pool, hids_client_storage, MAX_NR_HIDS_CLIENTS, sizeof(hids_client_t)); 1915cf26c8fbSMilanka Ringwald #endif 1916cf26c8fbSMilanka Ringwald #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0 1917cf26c8fbSMilanka Ringwald btstack_memory_pool_create(&scan_parameters_service_client_pool, scan_parameters_service_client_storage, MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS, sizeof(scan_parameters_service_client_t)); 1918cf26c8fbSMilanka Ringwald #endif 1919a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1920a265b909SMatthias Ringwald btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1921cf49570bSMatthias Ringwald #endif 1922174a0c1cSMilanka Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 1923174a0c1cSMilanka Ringwald btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 1924174a0c1cSMilanka Ringwald #endif 1925*dbca66ffSMatthias Ringwald #if MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES > 0 1926*dbca66ffSMatthias Ringwald btstack_memory_pool_create(&periodic_advertiser_list_entry_pool, periodic_advertiser_list_entry_storage, MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES, sizeof(periodic_advertiser_list_entry_t)); 1927*dbca66ffSMatthias Ringwald #endif 1928ebb73e1fSMatthias Ringwald #endif 192944c5d856SMatthias Ringwald #ifdef ENABLE_MESH 193050dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0 193150dc57fcSMatthias Ringwald btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t)); 193244c5d856SMatthias Ringwald #endif 1933a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0 1934a4bbc09dSMatthias Ringwald btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t)); 1935f7434c1fSMatthias Ringwald #endif 1936491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 1937491f99b3SMatthias Ringwald 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)); 1938491f99b3SMatthias Ringwald #endif 193950dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0 194050dc57fcSMatthias Ringwald btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t)); 1941c0a711d9SMatthias Ringwald #endif 194201e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0 194301e2bf94SMatthias Ringwald btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t)); 194401e2bf94SMatthias Ringwald #endif 19451f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 19461f45d603SMatthias Ringwald btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t)); 19471f45d603SMatthias Ringwald #endif 194801122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0 194901122b73SMatthias Ringwald btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t)); 195001122b73SMatthias Ringwald #endif 1951a7d12effS[email protected] #endif 1952a3b02b71Smatthias.ringwald } 1953