1a3b02b71Smatthias.ringwald /* 2a0c35809S[email protected] * Copyright (C) 2014 BlueKitchen GmbH 3a3b02b71Smatthias.ringwald * 4a3b02b71Smatthias.ringwald * Redistribution and use in source and binary forms, with or without 5a3b02b71Smatthias.ringwald * modification, are permitted provided that the following conditions 6a3b02b71Smatthias.ringwald * are met: 7a3b02b71Smatthias.ringwald * 8a3b02b71Smatthias.ringwald * 1. Redistributions of source code must retain the above copyright 9a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer. 10a3b02b71Smatthias.ringwald * 2. Redistributions in binary form must reproduce the above copyright 11a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer in the 12a3b02b71Smatthias.ringwald * documentation and/or other materials provided with the distribution. 13a3b02b71Smatthias.ringwald * 3. Neither the name of the copyright holders nor the names of 14a3b02b71Smatthias.ringwald * contributors may be used to endorse or promote products derived 15a3b02b71Smatthias.ringwald * from this software without specific prior written permission. 166b64433eSmatthias.ringwald * 4. Any redistribution, use, or modification is done solely for 176b64433eSmatthias.ringwald * personal benefit and not for any commercial purpose or for 186b64433eSmatthias.ringwald * monetary gain. 19a3b02b71Smatthias.ringwald * 202e97c149S[email protected] * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21a3b02b71Smatthias.ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22a3b02b71Smatthias.ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23a3b02b71Smatthias.ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24a3b02b71Smatthias.ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25a3b02b71Smatthias.ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26a3b02b71Smatthias.ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27a3b02b71Smatthias.ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28a3b02b71Smatthias.ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29a3b02b71Smatthias.ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30a3b02b71Smatthias.ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31a3b02b71Smatthias.ringwald * SUCH DAMAGE. 32a3b02b71Smatthias.ringwald * 332e97c149S[email protected] * Please inquire about commercial licensing options at 342e97c149S[email protected] * [email protected] 356b64433eSmatthias.ringwald * 36a3b02b71Smatthias.ringwald */ 37a3b02b71Smatthias.ringwald 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 58b6269742SMatthias Ringwald #ifdef HAVE_MALLOC 59b6269742SMatthias Ringwald typedef struct btstack_memory_buffer { 60b6269742SMatthias Ringwald struct btstack_memory_buffer * next; 61b6269742SMatthias Ringwald struct btstack_memory_buffer * prev; 62b6269742SMatthias Ringwald } btstack_memory_buffer_t; 63b6269742SMatthias Ringwald 64798bd46fSMatthias Ringwald typedef struct { 65798bd46fSMatthias Ringwald btstack_memory_buffer_t tracking; 66798bd46fSMatthias Ringwald void * pointer; 67798bd46fSMatthias Ringwald } test_buffer_t; 68798bd46fSMatthias Ringwald 69b6269742SMatthias Ringwald static btstack_memory_buffer_t * btstack_memory_malloc_buffers; 7019ef97d2SMatthias Ringwald static uint32_t btstack_memory_malloc_counter; 71b6269742SMatthias Ringwald 722a95308bSMatthias Ringwald static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){ 732a95308bSMatthias Ringwald btstack_assert(buffer != NULL); 7419ef97d2SMatthias Ringwald if (btstack_memory_malloc_buffers != NULL) { 7519ef97d2SMatthias Ringwald // let current first item prev point to new first item 7619ef97d2SMatthias Ringwald btstack_memory_malloc_buffers->prev = buffer; 7719ef97d2SMatthias Ringwald } 78b6269742SMatthias Ringwald buffer->prev = NULL; 79b6269742SMatthias Ringwald buffer->next = btstack_memory_malloc_buffers; 80b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer; 8119ef97d2SMatthias Ringwald 8219ef97d2SMatthias Ringwald btstack_memory_malloc_counter++; 83b6269742SMatthias Ringwald } 84b6269742SMatthias Ringwald 852a95308bSMatthias Ringwald static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){ 862a95308bSMatthias Ringwald btstack_assert(buffer != NULL); 87b6269742SMatthias Ringwald if (buffer->prev == NULL){ 88b6269742SMatthias Ringwald // first item 89b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer->next; 90b6269742SMatthias Ringwald } else { 91b6269742SMatthias Ringwald buffer->prev->next = buffer->next; 92b6269742SMatthias Ringwald } 93b6269742SMatthias Ringwald if (buffer->next != NULL){ 94b6269742SMatthias Ringwald buffer->next->prev = buffer->prev; 95b6269742SMatthias Ringwald } 9619ef97d2SMatthias Ringwald 9719ef97d2SMatthias Ringwald btstack_memory_malloc_counter--; 98b6269742SMatthias Ringwald } 99b6269742SMatthias Ringwald #endif 100b6269742SMatthias Ringwald 101b6269742SMatthias Ringwald void btstack_memory_deinit(void){ 102b6269742SMatthias Ringwald #ifdef HAVE_MALLOC 103b6269742SMatthias Ringwald while (btstack_memory_malloc_buffers != NULL){ 104b6269742SMatthias Ringwald btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers; 105b6269742SMatthias Ringwald btstack_memory_malloc_buffers = buffer->next; 106b6269742SMatthias Ringwald free(buffer); 107b6269742SMatthias Ringwald } 10819ef97d2SMatthias Ringwald btstack_assert(btstack_memory_malloc_counter == 0); 109b6269742SMatthias Ringwald #endif 110b6269742SMatthias Ringwald } 111a3b02b71Smatthias.ringwald 1122e97c149S[email protected] 113a3b02b71Smatthias.ringwald // MARK: hci_connection_t 114a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 115a265b909SMatthias Ringwald #if defined(MAX_NO_HCI_CONNECTIONS) 11627faf85aSMilanka 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." 117a265b909SMatthias Ringwald #else 118a265b909SMatthias Ringwald #define MAX_NR_HCI_CONNECTIONS 0 119a265b909SMatthias Ringwald #endif 120a265b909SMatthias Ringwald #endif 121a265b909SMatthias Ringwald 122a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS 123a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 124a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 12529d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool; 1266527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 127a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hci_connection_pool); 128a2673d88SMatthias Ringwald if (buffer){ 129a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hci_connection_t)); 130a2673d88SMatthias Ringwald } 131a2673d88SMatthias Ringwald return (hci_connection_t *) buffer; 132a3b02b71Smatthias.ringwald } 1336527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 13429d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hci_connection_pool, hci_connection); 135a3b02b71Smatthias.ringwald } 136c4d3f927Smatthias.ringwald #else 1376527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 138c4d3f927Smatthias.ringwald return NULL; 139c4d3f927Smatthias.ringwald } 1406527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 141b6269742SMatthias Ringwald UNUSED(hci_connection); 142c4d3f927Smatthias.ringwald }; 143c4d3f927Smatthias.ringwald #endif 144a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1452a95308bSMatthias Ringwald 1462a95308bSMatthias Ringwald typedef struct { 1472a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 148798bd46fSMatthias Ringwald hci_connection_t data; 1492a95308bSMatthias Ringwald } btstack_memory_hci_connection_t; 1502a95308bSMatthias Ringwald 1516527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 1522a95308bSMatthias Ringwald btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t)); 153a2673d88SMatthias Ringwald if (buffer){ 154798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_hci_connection_t)); 1552a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 1562a95308bSMatthias Ringwald return &buffer->data; 157b6269742SMatthias Ringwald } else { 158b6269742SMatthias Ringwald return NULL; 159a2673d88SMatthias Ringwald } 160a3b02b71Smatthias.ringwald } 1616527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 162798bd46fSMatthias Ringwald // reconstruct buffer start 163798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_connection)[-1]; 164798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 165b6269742SMatthias Ringwald free(buffer); 166a3b02b71Smatthias.ringwald } 167a3b02b71Smatthias.ringwald #endif 168a3b02b71Smatthias.ringwald 169a3b02b71Smatthias.ringwald 1702e97c149S[email protected] 171a3b02b71Smatthias.ringwald // MARK: l2cap_service_t 172a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 173a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_SERVICES) 17427faf85aSMilanka 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." 175a265b909SMatthias Ringwald #else 176a265b909SMatthias Ringwald #define MAX_NR_L2CAP_SERVICES 0 177a265b909SMatthias Ringwald #endif 178a265b909SMatthias Ringwald #endif 179a265b909SMatthias Ringwald 180a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES 181a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 182a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 18329d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool; 1846527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 185a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_service_pool); 186a2673d88SMatthias Ringwald if (buffer){ 187a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_service_t)); 188a2673d88SMatthias Ringwald } 189a2673d88SMatthias Ringwald return (l2cap_service_t *) buffer; 190a3b02b71Smatthias.ringwald } 1916527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 19229d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 193a3b02b71Smatthias.ringwald } 194c4d3f927Smatthias.ringwald #else 1956527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 196c4d3f927Smatthias.ringwald return NULL; 197c4d3f927Smatthias.ringwald } 1986527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 199b6269742SMatthias Ringwald UNUSED(l2cap_service); 200c4d3f927Smatthias.ringwald }; 201c4d3f927Smatthias.ringwald #endif 202a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2032a95308bSMatthias Ringwald 2042a95308bSMatthias Ringwald typedef struct { 2052a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 206798bd46fSMatthias Ringwald l2cap_service_t data; 2072a95308bSMatthias Ringwald } btstack_memory_l2cap_service_t; 2082a95308bSMatthias Ringwald 2096527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 2102a95308bSMatthias Ringwald btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t)); 211a2673d88SMatthias Ringwald if (buffer){ 212798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_l2cap_service_t)); 2132a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 2142a95308bSMatthias Ringwald return &buffer->data; 215b6269742SMatthias Ringwald } else { 216b6269742SMatthias Ringwald return NULL; 217a2673d88SMatthias Ringwald } 218a3b02b71Smatthias.ringwald } 2196527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 220798bd46fSMatthias Ringwald // reconstruct buffer start 221798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_service)[-1]; 222798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 223b6269742SMatthias Ringwald free(buffer); 224a3b02b71Smatthias.ringwald } 225a3b02b71Smatthias.ringwald #endif 226a3b02b71Smatthias.ringwald 227a3b02b71Smatthias.ringwald 228a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t 229a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 230a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_CHANNELS) 23127faf85aSMilanka 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." 232a265b909SMatthias Ringwald #else 233a265b909SMatthias Ringwald #define MAX_NR_L2CAP_CHANNELS 0 234a265b909SMatthias Ringwald #endif 235a265b909SMatthias Ringwald #endif 236a265b909SMatthias Ringwald 237a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS 238a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 239a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 24029d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool; 2416527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 242a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_channel_pool); 243a2673d88SMatthias Ringwald if (buffer){ 244a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_channel_t)); 245a2673d88SMatthias Ringwald } 246a2673d88SMatthias Ringwald return (l2cap_channel_t *) buffer; 247a3b02b71Smatthias.ringwald } 2486527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 24929d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 250a3b02b71Smatthias.ringwald } 251c4d3f927Smatthias.ringwald #else 2526527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 253c4d3f927Smatthias.ringwald return NULL; 254c4d3f927Smatthias.ringwald } 2556527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 256b6269742SMatthias Ringwald UNUSED(l2cap_channel); 257c4d3f927Smatthias.ringwald }; 258c4d3f927Smatthias.ringwald #endif 259a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2602a95308bSMatthias Ringwald 2612a95308bSMatthias Ringwald typedef struct { 2622a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 263798bd46fSMatthias Ringwald l2cap_channel_t data; 2642a95308bSMatthias Ringwald } btstack_memory_l2cap_channel_t; 2652a95308bSMatthias Ringwald 2666527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 2672a95308bSMatthias Ringwald btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t)); 268a2673d88SMatthias Ringwald if (buffer){ 269798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_l2cap_channel_t)); 2702a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 2712a95308bSMatthias Ringwald return &buffer->data; 272b6269742SMatthias Ringwald } else { 273b6269742SMatthias Ringwald return NULL; 274a2673d88SMatthias Ringwald } 275a3b02b71Smatthias.ringwald } 2766527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 277798bd46fSMatthias Ringwald // reconstruct buffer start 278798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_channel)[-1]; 279798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 280b6269742SMatthias Ringwald free(buffer); 281a3b02b71Smatthias.ringwald } 282a3b02b71Smatthias.ringwald #endif 283a3b02b71Smatthias.ringwald 284a3b02b71Smatthias.ringwald 28544c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 2862e97c149S[email protected] 287a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t 288a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 289a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 29027faf85aSMilanka 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." 291a265b909SMatthias Ringwald #else 292a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_MULTIPLEXERS 0 293a265b909SMatthias Ringwald #endif 294a265b909SMatthias Ringwald #endif 295a265b909SMatthias Ringwald 296a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 297a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 298a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 29929d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool; 3006527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 301a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool); 302a2673d88SMatthias Ringwald if (buffer){ 303a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 304a2673d88SMatthias Ringwald } 305a2673d88SMatthias Ringwald return (rfcomm_multiplexer_t *) buffer; 306a3b02b71Smatthias.ringwald } 3076527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 30829d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 309a3b02b71Smatthias.ringwald } 310c4d3f927Smatthias.ringwald #else 3116527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 312c4d3f927Smatthias.ringwald return NULL; 313c4d3f927Smatthias.ringwald } 3146527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 315b6269742SMatthias Ringwald UNUSED(rfcomm_multiplexer); 316c4d3f927Smatthias.ringwald }; 317c4d3f927Smatthias.ringwald #endif 318a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 3192a95308bSMatthias Ringwald 3202a95308bSMatthias Ringwald typedef struct { 3212a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 322798bd46fSMatthias Ringwald rfcomm_multiplexer_t data; 3232a95308bSMatthias Ringwald } btstack_memory_rfcomm_multiplexer_t; 3242a95308bSMatthias Ringwald 3256527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 3262a95308bSMatthias Ringwald btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t)); 327a2673d88SMatthias Ringwald if (buffer){ 328798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_multiplexer_t)); 3292a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 3302a95308bSMatthias Ringwald return &buffer->data; 331b6269742SMatthias Ringwald } else { 332b6269742SMatthias Ringwald return NULL; 333a2673d88SMatthias Ringwald } 334a3b02b71Smatthias.ringwald } 3356527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 336798bd46fSMatthias Ringwald // reconstruct buffer start 337798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_multiplexer)[-1]; 338798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 339b6269742SMatthias Ringwald free(buffer); 340a3b02b71Smatthias.ringwald } 341a3b02b71Smatthias.ringwald #endif 342a3b02b71Smatthias.ringwald 343a3b02b71Smatthias.ringwald 344a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t 345a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 346a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_SERVICES) 34727faf85aSMilanka 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." 348a265b909SMatthias Ringwald #else 349a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_SERVICES 0 350a265b909SMatthias Ringwald #endif 351a265b909SMatthias Ringwald #endif 352a265b909SMatthias Ringwald 353a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES 354a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0 355a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 35629d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool; 3576527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 358a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_service_pool); 359a2673d88SMatthias Ringwald if (buffer){ 360a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_service_t)); 361a2673d88SMatthias Ringwald } 362a2673d88SMatthias Ringwald return (rfcomm_service_t *) buffer; 363a3b02b71Smatthias.ringwald } 3646527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 36529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 366a3b02b71Smatthias.ringwald } 367c4d3f927Smatthias.ringwald #else 3686527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 369c4d3f927Smatthias.ringwald return NULL; 370c4d3f927Smatthias.ringwald } 3716527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 372b6269742SMatthias Ringwald UNUSED(rfcomm_service); 373c4d3f927Smatthias.ringwald }; 374c4d3f927Smatthias.ringwald #endif 375a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 3762a95308bSMatthias Ringwald 3772a95308bSMatthias Ringwald typedef struct { 3782a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 379798bd46fSMatthias Ringwald rfcomm_service_t data; 3802a95308bSMatthias Ringwald } btstack_memory_rfcomm_service_t; 3812a95308bSMatthias Ringwald 3826527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 3832a95308bSMatthias Ringwald btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t)); 384a2673d88SMatthias Ringwald if (buffer){ 385798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_service_t)); 3862a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 3872a95308bSMatthias Ringwald return &buffer->data; 388b6269742SMatthias Ringwald } else { 389b6269742SMatthias Ringwald return NULL; 390a2673d88SMatthias Ringwald } 391a3b02b71Smatthias.ringwald } 3926527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 393798bd46fSMatthias Ringwald // reconstruct buffer start 394798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_service)[-1]; 395798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 396b6269742SMatthias Ringwald free(buffer); 397a3b02b71Smatthias.ringwald } 398a3b02b71Smatthias.ringwald #endif 399a3b02b71Smatthias.ringwald 400a3b02b71Smatthias.ringwald 401a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t 402a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 403a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_CHANNELS) 40427faf85aSMilanka 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." 405a265b909SMatthias Ringwald #else 406a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_CHANNELS 0 407a265b909SMatthias Ringwald #endif 408a265b909SMatthias Ringwald #endif 409a265b909SMatthias Ringwald 410a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS 411a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0 412a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 41329d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool; 4146527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 415a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool); 416a2673d88SMatthias Ringwald if (buffer){ 417a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_channel_t)); 418a2673d88SMatthias Ringwald } 419a2673d88SMatthias Ringwald return (rfcomm_channel_t *) buffer; 420a3b02b71Smatthias.ringwald } 4216527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 42229d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 423a3b02b71Smatthias.ringwald } 424c4d3f927Smatthias.ringwald #else 4256527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 426c4d3f927Smatthias.ringwald return NULL; 427c4d3f927Smatthias.ringwald } 4286527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 429b6269742SMatthias Ringwald UNUSED(rfcomm_channel); 430c4d3f927Smatthias.ringwald }; 431c4d3f927Smatthias.ringwald #endif 432a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 4332a95308bSMatthias Ringwald 4342a95308bSMatthias Ringwald typedef struct { 4352a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 436798bd46fSMatthias Ringwald rfcomm_channel_t data; 4372a95308bSMatthias Ringwald } btstack_memory_rfcomm_channel_t; 4382a95308bSMatthias Ringwald 4396527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 4402a95308bSMatthias Ringwald btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t)); 441a2673d88SMatthias Ringwald if (buffer){ 442798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_rfcomm_channel_t)); 4432a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 4442a95308bSMatthias Ringwald return &buffer->data; 445b6269742SMatthias Ringwald } else { 446b6269742SMatthias Ringwald return NULL; 447a2673d88SMatthias Ringwald } 448a3b02b71Smatthias.ringwald } 4496527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 450798bd46fSMatthias Ringwald // reconstruct buffer start 451798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_channel)[-1]; 452798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 453b6269742SMatthias Ringwald free(buffer); 454a3b02b71Smatthias.ringwald } 455a3b02b71Smatthias.ringwald #endif 456a3b02b71Smatthias.ringwald 457fdb398c2S[email protected] 458e0e5e285Smatthias.ringwald 4592c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t 460a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 461a265b909SMatthias Ringwald #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 46227faf85aSMilanka 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." 463a265b909SMatthias Ringwald #else 464a265b909SMatthias Ringwald #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 465a265b909SMatthias Ringwald #endif 466a265b909SMatthias Ringwald #endif 467a265b909SMatthias Ringwald 468a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 469a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 470a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 4712c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 4722c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 473a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 474a2673d88SMatthias Ringwald if (buffer){ 475a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 476a2673d88SMatthias Ringwald } 477a2673d88SMatthias Ringwald return (btstack_link_key_db_memory_entry_t *) buffer; 4781801b596Smatthias.ringwald } 4792c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 4802c455dadSMatthias Ringwald btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 4811801b596Smatthias.ringwald } 482c4d3f927Smatthias.ringwald #else 4832c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 484c4d3f927Smatthias.ringwald return NULL; 485c4d3f927Smatthias.ringwald } 4862c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 487b6269742SMatthias Ringwald UNUSED(btstack_link_key_db_memory_entry); 488c4d3f927Smatthias.ringwald }; 489c4d3f927Smatthias.ringwald #endif 4901801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 4912a95308bSMatthias Ringwald 4922a95308bSMatthias Ringwald typedef struct { 4932a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 494798bd46fSMatthias Ringwald btstack_link_key_db_memory_entry_t data; 4952a95308bSMatthias Ringwald } btstack_memory_btstack_link_key_db_memory_entry_t; 4962a95308bSMatthias Ringwald 4972c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 4982a95308bSMatthias 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)); 499a2673d88SMatthias Ringwald if (buffer){ 500798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_btstack_link_key_db_memory_entry_t)); 5012a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 5022a95308bSMatthias Ringwald return &buffer->data; 503b6269742SMatthias Ringwald } else { 504b6269742SMatthias Ringwald return NULL; 505a2673d88SMatthias Ringwald } 5061801b596Smatthias.ringwald } 5072c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 508798bd46fSMatthias Ringwald // reconstruct buffer start 509798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) btstack_link_key_db_memory_entry)[-1]; 510798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 511b6269742SMatthias Ringwald free(buffer); 512e0e5e285Smatthias.ringwald } 5131801b596Smatthias.ringwald #endif 5141801b596Smatthias.ringwald 5152e97c149S[email protected] 5162e97c149S[email protected] 5172e97c149S[email protected] // MARK: bnep_service_t 518a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 519a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_SERVICES) 52027faf85aSMilanka 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." 521a265b909SMatthias Ringwald #else 522a265b909SMatthias Ringwald #define MAX_NR_BNEP_SERVICES 0 523a265b909SMatthias Ringwald #endif 524a265b909SMatthias Ringwald #endif 525a265b909SMatthias Ringwald 526a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES 527a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0 528a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 52929d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool; 5302e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 531a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_service_pool); 532a2673d88SMatthias Ringwald if (buffer){ 533a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_service_t)); 534a2673d88SMatthias Ringwald } 535a2673d88SMatthias Ringwald return (bnep_service_t *) buffer; 5362e97c149S[email protected] } 5372e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 53829d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_service_pool, bnep_service); 5392e97c149S[email protected] } 5402e97c149S[email protected] #else 5412e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 5422e97c149S[email protected] return NULL; 5432e97c149S[email protected] } 5442e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 545b6269742SMatthias Ringwald UNUSED(bnep_service); 5462e97c149S[email protected] }; 5472e97c149S[email protected] #endif 5482e97c149S[email protected] #elif defined(HAVE_MALLOC) 5492a95308bSMatthias Ringwald 5502a95308bSMatthias Ringwald typedef struct { 5512a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 552798bd46fSMatthias Ringwald bnep_service_t data; 5532a95308bSMatthias Ringwald } btstack_memory_bnep_service_t; 5542a95308bSMatthias Ringwald 5552e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 5562a95308bSMatthias Ringwald btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t)); 557a2673d88SMatthias Ringwald if (buffer){ 558798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_bnep_service_t)); 5592a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 5602a95308bSMatthias Ringwald return &buffer->data; 561b6269742SMatthias Ringwald } else { 562b6269742SMatthias Ringwald return NULL; 563a2673d88SMatthias Ringwald } 5642e97c149S[email protected] } 5652e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 566798bd46fSMatthias Ringwald // reconstruct buffer start 567798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_service)[-1]; 568798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 569b6269742SMatthias Ringwald free(buffer); 5702e97c149S[email protected] } 5712e97c149S[email protected] #endif 5722e97c149S[email protected] 5732e97c149S[email protected] 5742e97c149S[email protected] // MARK: bnep_channel_t 575a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 576a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_CHANNELS) 57727faf85aSMilanka 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." 578a265b909SMatthias Ringwald #else 579a265b909SMatthias Ringwald #define MAX_NR_BNEP_CHANNELS 0 580a265b909SMatthias Ringwald #endif 581a265b909SMatthias Ringwald #endif 582a265b909SMatthias Ringwald 583a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS 584a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0 585a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 58629d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool; 5872e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 588a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_channel_pool); 589a2673d88SMatthias Ringwald if (buffer){ 590a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_channel_t)); 591a2673d88SMatthias Ringwald } 592a2673d88SMatthias Ringwald return (bnep_channel_t *) buffer; 5932e97c149S[email protected] } 5942e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 59529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 5962e97c149S[email protected] } 5972e97c149S[email protected] #else 5982e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 5992e97c149S[email protected] return NULL; 6002e97c149S[email protected] } 6012e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 602b6269742SMatthias Ringwald UNUSED(bnep_channel); 6032e97c149S[email protected] }; 6042e97c149S[email protected] #endif 6052e97c149S[email protected] #elif defined(HAVE_MALLOC) 6062a95308bSMatthias Ringwald 6072a95308bSMatthias Ringwald typedef struct { 6082a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 609798bd46fSMatthias Ringwald bnep_channel_t data; 6102a95308bSMatthias Ringwald } btstack_memory_bnep_channel_t; 6112a95308bSMatthias Ringwald 6122e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 6132a95308bSMatthias Ringwald btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t)); 614a2673d88SMatthias Ringwald if (buffer){ 615798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_bnep_channel_t)); 6162a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 6172a95308bSMatthias Ringwald return &buffer->data; 618b6269742SMatthias Ringwald } else { 619b6269742SMatthias Ringwald return NULL; 620a2673d88SMatthias Ringwald } 6212e97c149S[email protected] } 6222e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 623798bd46fSMatthias Ringwald // reconstruct buffer start 624798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_channel)[-1]; 625798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 626b6269742SMatthias Ringwald free(buffer); 6272e97c149S[email protected] } 6282e97c149S[email protected] #endif 6292e97c149S[email protected] 6302e97c149S[email protected] 631ea5029c9SMilanka Ringwald 632ea5029c9SMilanka Ringwald // MARK: hfp_connection_t 633a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 634a265b909SMatthias Ringwald #if defined(MAX_NO_HFP_CONNECTIONS) 63527faf85aSMilanka 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." 636a265b909SMatthias Ringwald #else 637a265b909SMatthias Ringwald #define MAX_NR_HFP_CONNECTIONS 0 638a265b909SMatthias Ringwald #endif 639a265b909SMatthias Ringwald #endif 640a265b909SMatthias Ringwald 641a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS 642a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0 643a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 64429d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool; 645ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 646a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hfp_connection_pool); 647a2673d88SMatthias Ringwald if (buffer){ 648a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hfp_connection_t)); 649a2673d88SMatthias Ringwald } 650a2673d88SMatthias Ringwald return (hfp_connection_t *) buffer; 651ea5029c9SMilanka Ringwald } 652ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 65329d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 654ea5029c9SMilanka Ringwald } 655ea5029c9SMilanka Ringwald #else 656ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 657ea5029c9SMilanka Ringwald return NULL; 658ea5029c9SMilanka Ringwald } 659ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 660b6269742SMatthias Ringwald UNUSED(hfp_connection); 661ea5029c9SMilanka Ringwald }; 662ea5029c9SMilanka Ringwald #endif 663ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC) 6642a95308bSMatthias Ringwald 6652a95308bSMatthias Ringwald typedef struct { 6662a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 667798bd46fSMatthias Ringwald hfp_connection_t data; 6682a95308bSMatthias Ringwald } btstack_memory_hfp_connection_t; 6692a95308bSMatthias Ringwald 670ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 6712a95308bSMatthias Ringwald btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t)); 672a2673d88SMatthias Ringwald if (buffer){ 673798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_hfp_connection_t)); 6742a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 6752a95308bSMatthias Ringwald return &buffer->data; 676b6269742SMatthias Ringwald } else { 677b6269742SMatthias Ringwald return NULL; 678a2673d88SMatthias Ringwald } 679ea5029c9SMilanka Ringwald } 680ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 681798bd46fSMatthias Ringwald // reconstruct buffer start 682798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hfp_connection)[-1]; 683798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 684b6269742SMatthias Ringwald free(buffer); 685ea5029c9SMilanka Ringwald } 686ea5029c9SMilanka Ringwald #endif 687ea5029c9SMilanka Ringwald 688ea5029c9SMilanka Ringwald 689cd9ee144SMatthias Ringwald 690*f399f7fbSMilanka Ringwald // MARK: hid_host_connection_t 691*f399f7fbSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HID_HOST_CONNECTIONS) 692*f399f7fbSMilanka Ringwald #if defined(MAX_NO_HID_HOST_CONNECTIONS) 693*f399f7fbSMilanka 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." 694*f399f7fbSMilanka Ringwald #else 695*f399f7fbSMilanka Ringwald #define MAX_NR_HID_HOST_CONNECTIONS 0 696*f399f7fbSMilanka Ringwald #endif 697*f399f7fbSMilanka Ringwald #endif 698*f399f7fbSMilanka Ringwald 699*f399f7fbSMilanka Ringwald #ifdef MAX_NR_HID_HOST_CONNECTIONS 700*f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0 701*f399f7fbSMilanka Ringwald static hid_host_connection_t hid_host_connection_storage[MAX_NR_HID_HOST_CONNECTIONS]; 702*f399f7fbSMilanka Ringwald static btstack_memory_pool_t hid_host_connection_pool; 703*f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 704*f399f7fbSMilanka Ringwald void * buffer = btstack_memory_pool_get(&hid_host_connection_pool); 705*f399f7fbSMilanka Ringwald if (buffer){ 706*f399f7fbSMilanka Ringwald memset(buffer, 0, sizeof(hid_host_connection_t)); 707*f399f7fbSMilanka Ringwald } 708*f399f7fbSMilanka Ringwald return (hid_host_connection_t *) buffer; 709*f399f7fbSMilanka Ringwald } 710*f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 711*f399f7fbSMilanka Ringwald btstack_memory_pool_free(&hid_host_connection_pool, hid_host_connection); 712*f399f7fbSMilanka Ringwald } 713*f399f7fbSMilanka Ringwald #else 714*f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 715*f399f7fbSMilanka Ringwald return NULL; 716*f399f7fbSMilanka Ringwald } 717*f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 718*f399f7fbSMilanka Ringwald // silence compiler warning about unused parameter in a portable way 719*f399f7fbSMilanka Ringwald (void) hid_host_connection; 720*f399f7fbSMilanka Ringwald }; 721*f399f7fbSMilanka Ringwald #endif 722*f399f7fbSMilanka Ringwald #elif defined(HAVE_MALLOC) 723*f399f7fbSMilanka Ringwald hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 724*f399f7fbSMilanka Ringwald void * buffer = malloc(sizeof(hid_host_connection_t)); 725*f399f7fbSMilanka Ringwald if (buffer){ 726*f399f7fbSMilanka Ringwald memset(buffer, 0, sizeof(hid_host_connection_t)); 727*f399f7fbSMilanka Ringwald } 728*f399f7fbSMilanka Ringwald return (hid_host_connection_t *) buffer; 729*f399f7fbSMilanka Ringwald } 730*f399f7fbSMilanka Ringwald void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 731*f399f7fbSMilanka Ringwald free(hid_host_connection); 732*f399f7fbSMilanka Ringwald } 733*f399f7fbSMilanka Ringwald #endif 734*f399f7fbSMilanka Ringwald 735*f399f7fbSMilanka Ringwald 736*f399f7fbSMilanka Ringwald 737cd9ee144SMatthias Ringwald // MARK: service_record_item_t 738a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 739a265b909SMatthias Ringwald #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 74027faf85aSMilanka 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." 741a265b909SMatthias Ringwald #else 742a265b909SMatthias Ringwald #define MAX_NR_SERVICE_RECORD_ITEMS 0 743a265b909SMatthias Ringwald #endif 744a265b909SMatthias Ringwald #endif 745a265b909SMatthias Ringwald 746a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS 747a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0 748a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 74929d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool; 750cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 751a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&service_record_item_pool); 752a2673d88SMatthias Ringwald if (buffer){ 753a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(service_record_item_t)); 754a2673d88SMatthias Ringwald } 755a2673d88SMatthias Ringwald return (service_record_item_t *) buffer; 756cd9ee144SMatthias Ringwald } 757cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 75829d0c4f7SMatthias Ringwald btstack_memory_pool_free(&service_record_item_pool, service_record_item); 759cd9ee144SMatthias Ringwald } 760cd9ee144SMatthias Ringwald #else 761cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 762cd9ee144SMatthias Ringwald return NULL; 763cd9ee144SMatthias Ringwald } 764cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 765b6269742SMatthias Ringwald UNUSED(service_record_item); 766cd9ee144SMatthias Ringwald }; 767cd9ee144SMatthias Ringwald #endif 768cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC) 7692a95308bSMatthias Ringwald 7702a95308bSMatthias Ringwald typedef struct { 7712a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 772798bd46fSMatthias Ringwald service_record_item_t data; 7732a95308bSMatthias Ringwald } btstack_memory_service_record_item_t; 7742a95308bSMatthias Ringwald 775cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 7762a95308bSMatthias Ringwald btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t)); 777a2673d88SMatthias Ringwald if (buffer){ 778798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_service_record_item_t)); 7792a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 7802a95308bSMatthias Ringwald return &buffer->data; 781b6269742SMatthias Ringwald } else { 782b6269742SMatthias Ringwald return NULL; 783a2673d88SMatthias Ringwald } 784cd9ee144SMatthias Ringwald } 785cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 786798bd46fSMatthias Ringwald // reconstruct buffer start 787798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) service_record_item)[-1]; 788798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 789b6269742SMatthias Ringwald free(buffer); 790cd9ee144SMatthias Ringwald } 791cd9ee144SMatthias Ringwald #endif 792cd9ee144SMatthias Ringwald 793cd9ee144SMatthias Ringwald 79427faf85aSMilanka Ringwald 7950e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t 7960e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 7970e826a17SMilanka Ringwald #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 7980e826a17SMilanka 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." 79927faf85aSMilanka Ringwald #else 8000e826a17SMilanka Ringwald #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 80127faf85aSMilanka Ringwald #endif 80227faf85aSMilanka Ringwald #endif 80327faf85aSMilanka Ringwald 8040e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 8050e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 8060e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 8070e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool; 8080e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 809a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 810a2673d88SMatthias Ringwald if (buffer){ 811a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 812a2673d88SMatthias Ringwald } 813a2673d88SMatthias Ringwald return (avdtp_stream_endpoint_t *) buffer; 81427faf85aSMilanka Ringwald } 8150e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 8160e826a17SMilanka Ringwald btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 81727faf85aSMilanka Ringwald } 81827faf85aSMilanka Ringwald #else 8190e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 82027faf85aSMilanka Ringwald return NULL; 82127faf85aSMilanka Ringwald } 8220e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 823b6269742SMatthias Ringwald UNUSED(avdtp_stream_endpoint); 82427faf85aSMilanka Ringwald }; 82527faf85aSMilanka Ringwald #endif 82627faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC) 8272a95308bSMatthias Ringwald 8282a95308bSMatthias Ringwald typedef struct { 8292a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 830798bd46fSMatthias Ringwald avdtp_stream_endpoint_t data; 8312a95308bSMatthias Ringwald } btstack_memory_avdtp_stream_endpoint_t; 8322a95308bSMatthias Ringwald 8330e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 8342a95308bSMatthias Ringwald btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t)); 835a2673d88SMatthias Ringwald if (buffer){ 836798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avdtp_stream_endpoint_t)); 8372a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 8382a95308bSMatthias Ringwald return &buffer->data; 839b6269742SMatthias Ringwald } else { 840b6269742SMatthias Ringwald return NULL; 841a2673d88SMatthias Ringwald } 84227faf85aSMilanka Ringwald } 8430e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 844798bd46fSMatthias Ringwald // reconstruct buffer start 845798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_stream_endpoint)[-1]; 846798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 847b6269742SMatthias Ringwald free(buffer); 84827faf85aSMilanka Ringwald } 84927faf85aSMilanka Ringwald #endif 85027faf85aSMilanka Ringwald 85127faf85aSMilanka Ringwald 85212e7f38cSMilanka Ringwald 85312e7f38cSMilanka Ringwald // MARK: avdtp_connection_t 85412e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 85512e7f38cSMilanka Ringwald #if defined(MAX_NO_AVDTP_CONNECTIONS) 85612e7f38cSMilanka 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." 85712e7f38cSMilanka Ringwald #else 85812e7f38cSMilanka Ringwald #define MAX_NR_AVDTP_CONNECTIONS 0 85912e7f38cSMilanka Ringwald #endif 86012e7f38cSMilanka Ringwald #endif 86112e7f38cSMilanka Ringwald 86212e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS 86312e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0 86412e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 86512e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool; 86612e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 867a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_connection_pool); 868a2673d88SMatthias Ringwald if (buffer){ 869a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_connection_t)); 870a2673d88SMatthias Ringwald } 871a2673d88SMatthias Ringwald return (avdtp_connection_t *) buffer; 87212e7f38cSMilanka Ringwald } 87312e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 87412e7f38cSMilanka Ringwald btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 87512e7f38cSMilanka Ringwald } 87612e7f38cSMilanka Ringwald #else 87712e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 87812e7f38cSMilanka Ringwald return NULL; 87912e7f38cSMilanka Ringwald } 88012e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 881b6269742SMatthias Ringwald UNUSED(avdtp_connection); 88212e7f38cSMilanka Ringwald }; 88312e7f38cSMilanka Ringwald #endif 88412e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC) 8852a95308bSMatthias Ringwald 8862a95308bSMatthias Ringwald typedef struct { 8872a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 888798bd46fSMatthias Ringwald avdtp_connection_t data; 8892a95308bSMatthias Ringwald } btstack_memory_avdtp_connection_t; 8902a95308bSMatthias Ringwald 89112e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 8922a95308bSMatthias Ringwald btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t)); 893a2673d88SMatthias Ringwald if (buffer){ 894798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avdtp_connection_t)); 8952a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 8962a95308bSMatthias Ringwald return &buffer->data; 897b6269742SMatthias Ringwald } else { 898b6269742SMatthias Ringwald return NULL; 899a2673d88SMatthias Ringwald } 90012e7f38cSMilanka Ringwald } 90112e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 902798bd46fSMatthias Ringwald // reconstruct buffer start 903798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_connection)[-1]; 904798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 905b6269742SMatthias Ringwald free(buffer); 90612e7f38cSMilanka Ringwald } 90712e7f38cSMilanka Ringwald #endif 90812e7f38cSMilanka Ringwald 90912e7f38cSMilanka Ringwald 91091451a2bSMilanka Ringwald 91191451a2bSMilanka Ringwald // MARK: avrcp_connection_t 91291451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 91391451a2bSMilanka Ringwald #if defined(MAX_NO_AVRCP_CONNECTIONS) 91491451a2bSMilanka 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." 91591451a2bSMilanka Ringwald #else 91691451a2bSMilanka Ringwald #define MAX_NR_AVRCP_CONNECTIONS 0 91791451a2bSMilanka Ringwald #endif 91891451a2bSMilanka Ringwald #endif 91991451a2bSMilanka Ringwald 92091451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS 92191451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0 92291451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 92391451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool; 92491451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 925a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_connection_pool); 926a2673d88SMatthias Ringwald if (buffer){ 927a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_connection_t)); 928a2673d88SMatthias Ringwald } 929a2673d88SMatthias Ringwald return (avrcp_connection_t *) buffer; 93091451a2bSMilanka Ringwald } 93191451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 93291451a2bSMilanka Ringwald btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 93391451a2bSMilanka Ringwald } 93491451a2bSMilanka Ringwald #else 93591451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 93691451a2bSMilanka Ringwald return NULL; 93791451a2bSMilanka Ringwald } 93891451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 939b6269742SMatthias Ringwald UNUSED(avrcp_connection); 94091451a2bSMilanka Ringwald }; 94191451a2bSMilanka Ringwald #endif 94291451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC) 9432a95308bSMatthias Ringwald 9442a95308bSMatthias Ringwald typedef struct { 9452a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 946798bd46fSMatthias Ringwald avrcp_connection_t data; 9472a95308bSMatthias Ringwald } btstack_memory_avrcp_connection_t; 9482a95308bSMatthias Ringwald 94991451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 9502a95308bSMatthias Ringwald btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t)); 951a2673d88SMatthias Ringwald if (buffer){ 952798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avrcp_connection_t)); 9532a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 9542a95308bSMatthias Ringwald return &buffer->data; 955b6269742SMatthias Ringwald } else { 956b6269742SMatthias Ringwald return NULL; 957a2673d88SMatthias Ringwald } 95891451a2bSMilanka Ringwald } 95991451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 960798bd46fSMatthias Ringwald // reconstruct buffer start 961798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_connection)[-1]; 962798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 963b6269742SMatthias Ringwald free(buffer); 96491451a2bSMilanka Ringwald } 96591451a2bSMilanka Ringwald #endif 96691451a2bSMilanka Ringwald 96791451a2bSMilanka Ringwald 968f12a3722SMilanka Ringwald 969f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t 970f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS) 971f12a3722SMilanka Ringwald #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS) 972f12a3722SMilanka 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." 973f12a3722SMilanka Ringwald #else 974f12a3722SMilanka Ringwald #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0 975f12a3722SMilanka Ringwald #endif 976f12a3722SMilanka Ringwald #endif 977f12a3722SMilanka Ringwald 978f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 979f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 980f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS]; 981f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool; 982f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 983a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool); 984a2673d88SMatthias Ringwald if (buffer){ 985a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 986a2673d88SMatthias Ringwald } 987a2673d88SMatthias Ringwald return (avrcp_browsing_connection_t *) buffer; 988f12a3722SMilanka Ringwald } 989f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 990f12a3722SMilanka Ringwald btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection); 991f12a3722SMilanka Ringwald } 992f12a3722SMilanka Ringwald #else 993f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 994f12a3722SMilanka Ringwald return NULL; 995f12a3722SMilanka Ringwald } 996f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 997b6269742SMatthias Ringwald UNUSED(avrcp_browsing_connection); 998f12a3722SMilanka Ringwald }; 999f12a3722SMilanka Ringwald #endif 1000f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC) 10012a95308bSMatthias Ringwald 10022a95308bSMatthias Ringwald typedef struct { 10032a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1004798bd46fSMatthias Ringwald avrcp_browsing_connection_t data; 10052a95308bSMatthias Ringwald } btstack_memory_avrcp_browsing_connection_t; 10062a95308bSMatthias Ringwald 1007f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 10082a95308bSMatthias Ringwald btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t)); 1009a2673d88SMatthias Ringwald if (buffer){ 1010798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_avrcp_browsing_connection_t)); 10112a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 10122a95308bSMatthias Ringwald return &buffer->data; 1013b6269742SMatthias Ringwald } else { 1014b6269742SMatthias Ringwald return NULL; 1015a2673d88SMatthias Ringwald } 1016f12a3722SMilanka Ringwald } 1017f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1018798bd46fSMatthias Ringwald // reconstruct buffer start 1019798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_browsing_connection)[-1]; 1020798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1021b6269742SMatthias Ringwald free(buffer); 1022f12a3722SMilanka Ringwald } 1023f12a3722SMilanka Ringwald #endif 1024f12a3722SMilanka Ringwald 1025f12a3722SMilanka Ringwald 102644c5d856SMatthias Ringwald #endif 1027a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 10282e97c149S[email protected] 10292e97c149S[email protected] // MARK: gatt_client_t 1030a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 1031a265b909SMatthias Ringwald #if defined(MAX_NO_GATT_CLIENTS) 103227faf85aSMilanka 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." 1033a265b909SMatthias Ringwald #else 1034a265b909SMatthias Ringwald #define MAX_NR_GATT_CLIENTS 0 1035a265b909SMatthias Ringwald #endif 1036a265b909SMatthias Ringwald #endif 1037a265b909SMatthias Ringwald 1038a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS 1039a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 1040a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 104129d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool; 1042d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 1043a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&gatt_client_pool); 1044a2673d88SMatthias Ringwald if (buffer){ 1045a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(gatt_client_t)); 1046a2673d88SMatthias Ringwald } 1047a2673d88SMatthias Ringwald return (gatt_client_t *) buffer; 1048d0fdae3cS[email protected] } 1049d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 105029d0c4f7SMatthias Ringwald btstack_memory_pool_free(&gatt_client_pool, gatt_client); 1051d0fdae3cS[email protected] } 1052d0fdae3cS[email protected] #else 1053d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 1054d0fdae3cS[email protected] return NULL; 1055d0fdae3cS[email protected] } 1056d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1057b6269742SMatthias Ringwald UNUSED(gatt_client); 1058d0fdae3cS[email protected] }; 1059d0fdae3cS[email protected] #endif 1060d0fdae3cS[email protected] #elif defined(HAVE_MALLOC) 10612a95308bSMatthias Ringwald 10622a95308bSMatthias Ringwald typedef struct { 10632a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1064798bd46fSMatthias Ringwald gatt_client_t data; 10652a95308bSMatthias Ringwald } btstack_memory_gatt_client_t; 10662a95308bSMatthias Ringwald 1067d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 10682a95308bSMatthias Ringwald btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t)); 1069a2673d88SMatthias Ringwald if (buffer){ 1070798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_gatt_client_t)); 10712a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 10722a95308bSMatthias Ringwald return &buffer->data; 1073b6269742SMatthias Ringwald } else { 1074b6269742SMatthias Ringwald return NULL; 1075a2673d88SMatthias Ringwald } 1076d0fdae3cS[email protected] } 1077d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1078798bd46fSMatthias Ringwald // reconstruct buffer start 1079798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) gatt_client)[-1]; 1080798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1081b6269742SMatthias Ringwald free(buffer); 1082d0fdae3cS[email protected] } 1083d0fdae3cS[email protected] #endif 10842e97c149S[email protected] 10852e97c149S[email protected] 1086656bec4fSMatthias Ringwald // MARK: whitelist_entry_t 1087a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 1088a265b909SMatthias Ringwald #if defined(MAX_NO_WHITELIST_ENTRIES) 108927faf85aSMilanka 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." 1090a265b909SMatthias Ringwald #else 1091a265b909SMatthias Ringwald #define MAX_NR_WHITELIST_ENTRIES 0 1092a265b909SMatthias Ringwald #endif 1093a265b909SMatthias Ringwald #endif 1094a265b909SMatthias Ringwald 1095a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES 1096a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 1097a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 109829d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool; 1099656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1100a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&whitelist_entry_pool); 1101a2673d88SMatthias Ringwald if (buffer){ 1102a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(whitelist_entry_t)); 1103a2673d88SMatthias Ringwald } 1104a2673d88SMatthias Ringwald return (whitelist_entry_t *) buffer; 1105656bec4fSMatthias Ringwald } 1106656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 110729d0c4f7SMatthias Ringwald btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 1108656bec4fSMatthias Ringwald } 1109656bec4fSMatthias Ringwald #else 1110656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1111656bec4fSMatthias Ringwald return NULL; 1112656bec4fSMatthias Ringwald } 1113656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1114b6269742SMatthias Ringwald UNUSED(whitelist_entry); 1115656bec4fSMatthias Ringwald }; 1116656bec4fSMatthias Ringwald #endif 1117656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC) 11182a95308bSMatthias Ringwald 11192a95308bSMatthias Ringwald typedef struct { 11202a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1121798bd46fSMatthias Ringwald whitelist_entry_t data; 11222a95308bSMatthias Ringwald } btstack_memory_whitelist_entry_t; 11232a95308bSMatthias Ringwald 1124656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 11252a95308bSMatthias Ringwald btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t)); 1126a2673d88SMatthias Ringwald if (buffer){ 1127798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_whitelist_entry_t)); 11282a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 11292a95308bSMatthias Ringwald return &buffer->data; 1130b6269742SMatthias Ringwald } else { 1131b6269742SMatthias Ringwald return NULL; 1132a2673d88SMatthias Ringwald } 1133656bec4fSMatthias Ringwald } 1134656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1135798bd46fSMatthias Ringwald // reconstruct buffer start 1136798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) whitelist_entry)[-1]; 1137798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1138b6269742SMatthias Ringwald free(buffer); 1139656bec4fSMatthias Ringwald } 1140656bec4fSMatthias Ringwald #endif 1141656bec4fSMatthias Ringwald 1142656bec4fSMatthias Ringwald 1143cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t 1144a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 1145a265b909SMatthias Ringwald #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 114627faf85aSMilanka 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." 1147a265b909SMatthias Ringwald #else 1148a265b909SMatthias Ringwald #define MAX_NR_SM_LOOKUP_ENTRIES 0 1149a265b909SMatthias Ringwald #endif 1150a265b909SMatthias Ringwald #endif 1151a265b909SMatthias Ringwald 1152a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES 1153a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1154a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 115529d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool; 1156cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1157a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool); 1158a2673d88SMatthias Ringwald if (buffer){ 1159a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(sm_lookup_entry_t)); 1160a2673d88SMatthias Ringwald } 1161a2673d88SMatthias Ringwald return (sm_lookup_entry_t *) buffer; 1162cf49570bSMatthias Ringwald } 1163cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 116429d0c4f7SMatthias Ringwald btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 1165cf49570bSMatthias Ringwald } 1166cf49570bSMatthias Ringwald #else 1167cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1168cf49570bSMatthias Ringwald return NULL; 1169cf49570bSMatthias Ringwald } 1170cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1171b6269742SMatthias Ringwald UNUSED(sm_lookup_entry); 1172cf49570bSMatthias Ringwald }; 1173cf49570bSMatthias Ringwald #endif 1174cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC) 11752a95308bSMatthias Ringwald 11762a95308bSMatthias Ringwald typedef struct { 11772a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1178798bd46fSMatthias Ringwald sm_lookup_entry_t data; 11792a95308bSMatthias Ringwald } btstack_memory_sm_lookup_entry_t; 11802a95308bSMatthias Ringwald 1181cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 11822a95308bSMatthias Ringwald btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t)); 1183a2673d88SMatthias Ringwald if (buffer){ 1184798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_sm_lookup_entry_t)); 11852a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 11862a95308bSMatthias Ringwald return &buffer->data; 1187b6269742SMatthias Ringwald } else { 1188b6269742SMatthias Ringwald return NULL; 1189a2673d88SMatthias Ringwald } 1190cf49570bSMatthias Ringwald } 1191cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1192798bd46fSMatthias Ringwald // reconstruct buffer start 1193798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) sm_lookup_entry)[-1]; 1194798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1195b6269742SMatthias Ringwald free(buffer); 1196cf49570bSMatthias Ringwald } 1197cf49570bSMatthias Ringwald #endif 1198cf49570bSMatthias Ringwald 1199cf49570bSMatthias Ringwald 120044c5d856SMatthias Ringwald #endif 120144c5d856SMatthias Ringwald #ifdef ENABLE_MESH 1202ebb73e1fSMatthias Ringwald 1203ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t 1204ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS) 1205ebb73e1fSMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_PDUS) 1206ebb73e1fSMatthias 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." 1207ebb73e1fSMatthias Ringwald #else 1208ebb73e1fSMatthias Ringwald #define MAX_NR_MESH_NETWORK_PDUS 0 1209ebb73e1fSMatthias Ringwald #endif 1210ebb73e1fSMatthias Ringwald #endif 1211ebb73e1fSMatthias Ringwald 1212ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS 1213ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0 1214ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS]; 1215ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool; 1216ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 12171c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool); 12181c4e8084SMatthias Ringwald if (buffer){ 12191c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_pdu_t)); 12201c4e8084SMatthias Ringwald } 12211c4e8084SMatthias Ringwald return (mesh_network_pdu_t *) buffer; 1222ebb73e1fSMatthias Ringwald } 1223ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1224ebb73e1fSMatthias Ringwald btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu); 1225ebb73e1fSMatthias Ringwald } 1226ebb73e1fSMatthias Ringwald #else 1227ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 1228ebb73e1fSMatthias Ringwald return NULL; 1229ebb73e1fSMatthias Ringwald } 1230ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1231b6269742SMatthias Ringwald UNUSED(mesh_network_pdu); 1232ebb73e1fSMatthias Ringwald }; 1233ebb73e1fSMatthias Ringwald #endif 1234ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC) 12352a95308bSMatthias Ringwald 12362a95308bSMatthias Ringwald typedef struct { 12372a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1238798bd46fSMatthias Ringwald mesh_network_pdu_t data; 12392a95308bSMatthias Ringwald } btstack_memory_mesh_network_pdu_t; 12402a95308bSMatthias Ringwald 1241ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 12422a95308bSMatthias Ringwald btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t)); 12431c4e8084SMatthias Ringwald if (buffer){ 1244798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_network_pdu_t)); 12452a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 12462a95308bSMatthias Ringwald return &buffer->data; 1247b6269742SMatthias Ringwald } else { 1248b6269742SMatthias Ringwald return NULL; 12491c4e8084SMatthias Ringwald } 1250ebb73e1fSMatthias Ringwald } 1251ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1252798bd46fSMatthias Ringwald // reconstruct buffer start 1253798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_pdu)[-1]; 1254798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1255b6269742SMatthias Ringwald free(buffer); 1256ebb73e1fSMatthias Ringwald } 1257ebb73e1fSMatthias Ringwald #endif 1258ebb73e1fSMatthias Ringwald 1259ebb73e1fSMatthias Ringwald 1260a4bbc09dSMatthias Ringwald // MARK: mesh_segmented_pdu_t 1261a4bbc09dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS) 1262a4bbc09dSMatthias Ringwald #if defined(MAX_NO_MESH_SEGMENTED_PDUS) 1263a4bbc09dSMatthias 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." 1264f7434c1fSMatthias Ringwald #else 1265a4bbc09dSMatthias Ringwald #define MAX_NR_MESH_SEGMENTED_PDUS 0 1266f7434c1fSMatthias Ringwald #endif 1267f7434c1fSMatthias Ringwald #endif 1268f7434c1fSMatthias Ringwald 1269a4bbc09dSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1270a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0 1271a4bbc09dSMatthias Ringwald static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS]; 1272a4bbc09dSMatthias Ringwald static btstack_memory_pool_t mesh_segmented_pdu_pool; 1273a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1274a4bbc09dSMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool); 1275f7434c1fSMatthias Ringwald if (buffer){ 1276a4bbc09dSMatthias Ringwald memset(buffer, 0, sizeof(mesh_segmented_pdu_t)); 1277f7434c1fSMatthias Ringwald } 1278a4bbc09dSMatthias Ringwald return (mesh_segmented_pdu_t *) buffer; 1279f7434c1fSMatthias Ringwald } 1280a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1281a4bbc09dSMatthias Ringwald btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu); 1282f7434c1fSMatthias Ringwald } 1283f7434c1fSMatthias Ringwald #else 1284a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1285f7434c1fSMatthias Ringwald return NULL; 1286f7434c1fSMatthias Ringwald } 1287a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1288b6269742SMatthias Ringwald UNUSED(mesh_segmented_pdu); 1289f7434c1fSMatthias Ringwald }; 1290f7434c1fSMatthias Ringwald #endif 1291f7434c1fSMatthias Ringwald #elif defined(HAVE_MALLOC) 12922a95308bSMatthias Ringwald 12932a95308bSMatthias Ringwald typedef struct { 12942a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1295798bd46fSMatthias Ringwald mesh_segmented_pdu_t data; 12962a95308bSMatthias Ringwald } btstack_memory_mesh_segmented_pdu_t; 12972a95308bSMatthias Ringwald 1298a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 12992a95308bSMatthias Ringwald btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t)); 1300f7434c1fSMatthias Ringwald if (buffer){ 1301798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_segmented_pdu_t)); 13022a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 13032a95308bSMatthias Ringwald return &buffer->data; 1304b6269742SMatthias Ringwald } else { 1305b6269742SMatthias Ringwald return NULL; 1306f7434c1fSMatthias Ringwald } 1307f7434c1fSMatthias Ringwald } 1308a4bbc09dSMatthias Ringwald void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1309798bd46fSMatthias Ringwald // reconstruct buffer start 1310798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_segmented_pdu)[-1]; 1311798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1312b6269742SMatthias Ringwald free(buffer); 1313f7434c1fSMatthias Ringwald } 1314f7434c1fSMatthias Ringwald #endif 1315f7434c1fSMatthias Ringwald 1316f7434c1fSMatthias Ringwald 1317491f99b3SMatthias Ringwald // MARK: mesh_upper_transport_pdu_t 1318491f99b3SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS) 1319491f99b3SMatthias Ringwald #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS) 1320491f99b3SMatthias 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." 1321491f99b3SMatthias Ringwald #else 1322491f99b3SMatthias Ringwald #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0 1323491f99b3SMatthias Ringwald #endif 1324491f99b3SMatthias Ringwald #endif 1325491f99b3SMatthias Ringwald 1326491f99b3SMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1327491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 1328491f99b3SMatthias Ringwald static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS]; 1329491f99b3SMatthias Ringwald static btstack_memory_pool_t mesh_upper_transport_pdu_pool; 1330491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1331491f99b3SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool); 1332491f99b3SMatthias Ringwald if (buffer){ 1333491f99b3SMatthias Ringwald memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t)); 1334491f99b3SMatthias Ringwald } 1335491f99b3SMatthias Ringwald return (mesh_upper_transport_pdu_t *) buffer; 1336491f99b3SMatthias Ringwald } 1337491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1338491f99b3SMatthias Ringwald btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu); 1339491f99b3SMatthias Ringwald } 1340491f99b3SMatthias Ringwald #else 1341491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1342491f99b3SMatthias Ringwald return NULL; 1343491f99b3SMatthias Ringwald } 1344491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1345b6269742SMatthias Ringwald UNUSED(mesh_upper_transport_pdu); 1346491f99b3SMatthias Ringwald }; 1347491f99b3SMatthias Ringwald #endif 1348491f99b3SMatthias Ringwald #elif defined(HAVE_MALLOC) 13492a95308bSMatthias Ringwald 13502a95308bSMatthias Ringwald typedef struct { 13512a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1352798bd46fSMatthias Ringwald mesh_upper_transport_pdu_t data; 13532a95308bSMatthias Ringwald } btstack_memory_mesh_upper_transport_pdu_t; 13542a95308bSMatthias Ringwald 1355491f99b3SMatthias Ringwald mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 13562a95308bSMatthias 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)); 1357491f99b3SMatthias Ringwald if (buffer){ 1358798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_upper_transport_pdu_t)); 13592a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 13602a95308bSMatthias Ringwald return &buffer->data; 1361b6269742SMatthias Ringwald } else { 1362b6269742SMatthias Ringwald return NULL; 1363491f99b3SMatthias Ringwald } 1364491f99b3SMatthias Ringwald } 1365491f99b3SMatthias Ringwald void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1366798bd46fSMatthias Ringwald // reconstruct buffer start 1367798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_upper_transport_pdu)[-1]; 1368798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1369b6269742SMatthias Ringwald free(buffer); 1370491f99b3SMatthias Ringwald } 1371491f99b3SMatthias Ringwald #endif 1372491f99b3SMatthias Ringwald 1373491f99b3SMatthias Ringwald 1374c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t 1375c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS) 1376c0a711d9SMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_KEYS) 1377c0a711d9SMatthias 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." 1378c0a711d9SMatthias Ringwald #else 1379c0a711d9SMatthias Ringwald #define MAX_NR_MESH_NETWORK_KEYS 0 1380c0a711d9SMatthias Ringwald #endif 1381c0a711d9SMatthias Ringwald #endif 1382c0a711d9SMatthias Ringwald 1383c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS 1384c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0 1385c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS]; 1386c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool; 1387c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 13881c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_key_pool); 13891c4e8084SMatthias Ringwald if (buffer){ 13901c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_key_t)); 13911c4e8084SMatthias Ringwald } 13921c4e8084SMatthias Ringwald return (mesh_network_key_t *) buffer; 1393c0a711d9SMatthias Ringwald } 1394c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1395c0a711d9SMatthias Ringwald btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key); 1396c0a711d9SMatthias Ringwald } 1397c0a711d9SMatthias Ringwald #else 1398c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1399c0a711d9SMatthias Ringwald return NULL; 1400c0a711d9SMatthias Ringwald } 1401c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1402b6269742SMatthias Ringwald UNUSED(mesh_network_key); 1403c0a711d9SMatthias Ringwald }; 1404c0a711d9SMatthias Ringwald #endif 1405c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC) 14062a95308bSMatthias Ringwald 14072a95308bSMatthias Ringwald typedef struct { 14082a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1409798bd46fSMatthias Ringwald mesh_network_key_t data; 14102a95308bSMatthias Ringwald } btstack_memory_mesh_network_key_t; 14112a95308bSMatthias Ringwald 1412c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 14132a95308bSMatthias Ringwald btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t)); 14141c4e8084SMatthias Ringwald if (buffer){ 1415798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_network_key_t)); 14162a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 14172a95308bSMatthias Ringwald return &buffer->data; 1418b6269742SMatthias Ringwald } else { 1419b6269742SMatthias Ringwald return NULL; 14201c4e8084SMatthias Ringwald } 1421c0a711d9SMatthias Ringwald } 1422c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1423798bd46fSMatthias Ringwald // reconstruct buffer start 1424798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_key)[-1]; 1425798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1426b6269742SMatthias Ringwald free(buffer); 1427c0a711d9SMatthias Ringwald } 1428c0a711d9SMatthias Ringwald #endif 1429c0a711d9SMatthias Ringwald 1430c0a711d9SMatthias Ringwald 143101e2bf94SMatthias Ringwald // MARK: mesh_transport_key_t 143201e2bf94SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS) 143301e2bf94SMatthias Ringwald #if defined(MAX_NO_MESH_TRANSPORT_KEYS) 143401e2bf94SMatthias 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." 143501e2bf94SMatthias Ringwald #else 143601e2bf94SMatthias Ringwald #define MAX_NR_MESH_TRANSPORT_KEYS 0 143701e2bf94SMatthias Ringwald #endif 143801e2bf94SMatthias Ringwald #endif 143901e2bf94SMatthias Ringwald 144001e2bf94SMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS 144101e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0 144201e2bf94SMatthias Ringwald static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS]; 144301e2bf94SMatthias Ringwald static btstack_memory_pool_t mesh_transport_key_pool; 144401e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 144501e2bf94SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool); 144601e2bf94SMatthias Ringwald if (buffer){ 144701e2bf94SMatthias Ringwald memset(buffer, 0, sizeof(mesh_transport_key_t)); 144801e2bf94SMatthias Ringwald } 144901e2bf94SMatthias Ringwald return (mesh_transport_key_t *) buffer; 145001e2bf94SMatthias Ringwald } 145101e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 145201e2bf94SMatthias Ringwald btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key); 145301e2bf94SMatthias Ringwald } 145401e2bf94SMatthias Ringwald #else 145501e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 145601e2bf94SMatthias Ringwald return NULL; 145701e2bf94SMatthias Ringwald } 145801e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1459b6269742SMatthias Ringwald UNUSED(mesh_transport_key); 146001e2bf94SMatthias Ringwald }; 146101e2bf94SMatthias Ringwald #endif 146201e2bf94SMatthias Ringwald #elif defined(HAVE_MALLOC) 14632a95308bSMatthias Ringwald 14642a95308bSMatthias Ringwald typedef struct { 14652a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1466798bd46fSMatthias Ringwald mesh_transport_key_t data; 14672a95308bSMatthias Ringwald } btstack_memory_mesh_transport_key_t; 14682a95308bSMatthias Ringwald 146901e2bf94SMatthias Ringwald mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 14702a95308bSMatthias Ringwald btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t)); 147101e2bf94SMatthias Ringwald if (buffer){ 1472798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_transport_key_t)); 14732a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 14742a95308bSMatthias Ringwald return &buffer->data; 1475b6269742SMatthias Ringwald } else { 1476b6269742SMatthias Ringwald return NULL; 147701e2bf94SMatthias Ringwald } 147801e2bf94SMatthias Ringwald } 147901e2bf94SMatthias Ringwald void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1480798bd46fSMatthias Ringwald // reconstruct buffer start 1481798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_transport_key)[-1]; 1482798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1483b6269742SMatthias Ringwald free(buffer); 148401e2bf94SMatthias Ringwald } 148501e2bf94SMatthias Ringwald #endif 148601e2bf94SMatthias Ringwald 148701e2bf94SMatthias Ringwald 14881f45d603SMatthias Ringwald // MARK: mesh_virtual_address_t 14891f45d603SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS) 14901f45d603SMatthias Ringwald #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS) 14911f45d603SMatthias 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." 14921f45d603SMatthias Ringwald #else 14931f45d603SMatthias Ringwald #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0 14941f45d603SMatthias Ringwald #endif 14951f45d603SMatthias Ringwald #endif 14961f45d603SMatthias Ringwald 14971f45d603SMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 14981f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 14991f45d603SMatthias Ringwald static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS]; 15001f45d603SMatthias Ringwald static btstack_memory_pool_t mesh_virtual_address_pool; 15011f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 15021f45d603SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool); 15031f45d603SMatthias Ringwald if (buffer){ 15041f45d603SMatthias Ringwald memset(buffer, 0, sizeof(mesh_virtual_address_t)); 15051f45d603SMatthias Ringwald } 15061f45d603SMatthias Ringwald return (mesh_virtual_address_t *) buffer; 15071f45d603SMatthias Ringwald } 15081f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 15091f45d603SMatthias Ringwald btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address); 15101f45d603SMatthias Ringwald } 15111f45d603SMatthias Ringwald #else 15121f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 15131f45d603SMatthias Ringwald return NULL; 15141f45d603SMatthias Ringwald } 15151f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1516b6269742SMatthias Ringwald UNUSED(mesh_virtual_address); 15171f45d603SMatthias Ringwald }; 15181f45d603SMatthias Ringwald #endif 15191f45d603SMatthias Ringwald #elif defined(HAVE_MALLOC) 15202a95308bSMatthias Ringwald 15212a95308bSMatthias Ringwald typedef struct { 15222a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1523798bd46fSMatthias Ringwald mesh_virtual_address_t data; 15242a95308bSMatthias Ringwald } btstack_memory_mesh_virtual_address_t; 15252a95308bSMatthias Ringwald 15261f45d603SMatthias Ringwald mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 15272a95308bSMatthias Ringwald btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t)); 15281f45d603SMatthias Ringwald if (buffer){ 1529798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_virtual_address_t)); 15302a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 15312a95308bSMatthias Ringwald return &buffer->data; 1532b6269742SMatthias Ringwald } else { 1533b6269742SMatthias Ringwald return NULL; 15341f45d603SMatthias Ringwald } 15351f45d603SMatthias Ringwald } 15361f45d603SMatthias Ringwald void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1537798bd46fSMatthias Ringwald // reconstruct buffer start 1538798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_virtual_address)[-1]; 1539798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1540b6269742SMatthias Ringwald free(buffer); 15411f45d603SMatthias Ringwald } 15421f45d603SMatthias Ringwald #endif 15431f45d603SMatthias Ringwald 15441f45d603SMatthias Ringwald 154501122b73SMatthias Ringwald // MARK: mesh_subnet_t 154601122b73SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS) 154701122b73SMatthias Ringwald #if defined(MAX_NO_MESH_SUBNETS) 154801122b73SMatthias 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." 154901122b73SMatthias Ringwald #else 155001122b73SMatthias Ringwald #define MAX_NR_MESH_SUBNETS 0 155101122b73SMatthias Ringwald #endif 155201122b73SMatthias Ringwald #endif 155301122b73SMatthias Ringwald 155401122b73SMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS 155501122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0 155601122b73SMatthias Ringwald static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS]; 155701122b73SMatthias Ringwald static btstack_memory_pool_t mesh_subnet_pool; 155801122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 155901122b73SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_subnet_pool); 156001122b73SMatthias Ringwald if (buffer){ 156101122b73SMatthias Ringwald memset(buffer, 0, sizeof(mesh_subnet_t)); 156201122b73SMatthias Ringwald } 156301122b73SMatthias Ringwald return (mesh_subnet_t *) buffer; 156401122b73SMatthias Ringwald } 156501122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 156601122b73SMatthias Ringwald btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet); 156701122b73SMatthias Ringwald } 156801122b73SMatthias Ringwald #else 156901122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 157001122b73SMatthias Ringwald return NULL; 157101122b73SMatthias Ringwald } 157201122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1573b6269742SMatthias Ringwald UNUSED(mesh_subnet); 157401122b73SMatthias Ringwald }; 157501122b73SMatthias Ringwald #endif 157601122b73SMatthias Ringwald #elif defined(HAVE_MALLOC) 15772a95308bSMatthias Ringwald 15782a95308bSMatthias Ringwald typedef struct { 15792a95308bSMatthias Ringwald btstack_memory_buffer_t tracking; 1580798bd46fSMatthias Ringwald mesh_subnet_t data; 15812a95308bSMatthias Ringwald } btstack_memory_mesh_subnet_t; 15822a95308bSMatthias Ringwald 158301122b73SMatthias Ringwald mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 15842a95308bSMatthias Ringwald btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t)); 158501122b73SMatthias Ringwald if (buffer){ 1586798bd46fSMatthias Ringwald memset(buffer, 0, sizeof(btstack_memory_mesh_subnet_t)); 15872a95308bSMatthias Ringwald btstack_memory_tracking_add(&buffer->tracking); 15882a95308bSMatthias Ringwald return &buffer->data; 1589b6269742SMatthias Ringwald } else { 1590b6269742SMatthias Ringwald return NULL; 159101122b73SMatthias Ringwald } 159201122b73SMatthias Ringwald } 159301122b73SMatthias Ringwald void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1594798bd46fSMatthias Ringwald // reconstruct buffer start 1595798bd46fSMatthias Ringwald btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_subnet)[-1]; 1596798bd46fSMatthias Ringwald btstack_memory_tracking_remove(buffer); 1597b6269742SMatthias Ringwald free(buffer); 159801122b73SMatthias Ringwald } 159901122b73SMatthias Ringwald #endif 160001122b73SMatthias Ringwald 160101122b73SMatthias Ringwald 16022e97c149S[email protected] #endif 1603798bd46fSMatthias Ringwald 1604a3b02b71Smatthias.ringwald // init 1605a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 1606798bd46fSMatthias Ringwald #ifdef HAVE_MALLOC 1607798bd46fSMatthias Ringwald // assert that there is no unexpected padding for combined buffer 1608798bd46fSMatthias Ringwald btstack_assert(sizeof(test_buffer_t) == sizeof(btstack_memory_buffer_t) + sizeof(void *)); 1609798bd46fSMatthias Ringwald #endif 1610798bd46fSMatthias Ringwald 1611a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 1612a265b909SMatthias Ringwald btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 1613a3b02b71Smatthias.ringwald #endif 1614a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 1615a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 1616a3b02b71Smatthias.ringwald #endif 1617a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 1618a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 1619a3b02b71Smatthias.ringwald #endif 162044c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 162150dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 162250dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 1623a3b02b71Smatthias.ringwald #endif 162450dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0 162550dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 1626a3b02b71Smatthias.ringwald #endif 162750dc57fcSMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0 162850dc57fcSMatthias Ringwald btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 162950dc57fcSMatthias Ringwald #endif 163050dc57fcSMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 163150dc57fcSMatthias 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)); 163250dc57fcSMatthias Ringwald #endif 163350dc57fcSMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0 163450dc57fcSMatthias Ringwald btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 163550dc57fcSMatthias Ringwald #endif 163650dc57fcSMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0 163750dc57fcSMatthias Ringwald btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 163850dc57fcSMatthias Ringwald #endif 163950dc57fcSMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0 164050dc57fcSMatthias Ringwald btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 164150dc57fcSMatthias Ringwald #endif 1642*f399f7fbSMilanka Ringwald #if MAX_NR_HID_HOST_CONNECTIONS > 0 1643*f399f7fbSMilanka Ringwald btstack_memory_pool_create(&hid_host_connection_pool, hid_host_connection_storage, MAX_NR_HID_HOST_CONNECTIONS, sizeof(hid_host_connection_t)); 1644*f399f7fbSMilanka Ringwald #endif 164550dc57fcSMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0 164650dc57fcSMatthias Ringwald btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 164750dc57fcSMatthias Ringwald #endif 164850dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 164950dc57fcSMatthias Ringwald btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t)); 165050dc57fcSMatthias Ringwald #endif 165150dc57fcSMatthias Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0 165250dc57fcSMatthias Ringwald btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t)); 165350dc57fcSMatthias Ringwald #endif 165450dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0 165550dc57fcSMatthias Ringwald btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t)); 165650dc57fcSMatthias Ringwald #endif 165750dc57fcSMatthias Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 165850dc57fcSMatthias Ringwald btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t)); 1659a3b02b71Smatthias.ringwald #endif 1660f12a3722SMilanka Ringwald #endif 1661a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 1662a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 1663a265b909SMatthias Ringwald btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 1664d0fdae3cS[email protected] #endif 1665a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 1666a265b909SMatthias Ringwald btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 1667656bec4fSMatthias Ringwald #endif 1668a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1669a265b909SMatthias Ringwald btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1670cf49570bSMatthias Ringwald #endif 1671ebb73e1fSMatthias Ringwald #endif 167244c5d856SMatthias Ringwald #ifdef ENABLE_MESH 167350dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0 167450dc57fcSMatthias Ringwald btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t)); 167544c5d856SMatthias Ringwald #endif 1676a4bbc09dSMatthias Ringwald #if MAX_NR_MESH_SEGMENTED_PDUS > 0 1677a4bbc09dSMatthias Ringwald btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t)); 1678f7434c1fSMatthias Ringwald #endif 1679491f99b3SMatthias Ringwald #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 1680491f99b3SMatthias 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)); 1681491f99b3SMatthias Ringwald #endif 168250dc57fcSMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0 168350dc57fcSMatthias Ringwald btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t)); 1684c0a711d9SMatthias Ringwald #endif 168501e2bf94SMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_KEYS > 0 168601e2bf94SMatthias Ringwald btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t)); 168701e2bf94SMatthias Ringwald #endif 16881f45d603SMatthias Ringwald #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 16891f45d603SMatthias Ringwald btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t)); 16901f45d603SMatthias Ringwald #endif 169101122b73SMatthias Ringwald #if MAX_NR_MESH_SUBNETS > 0 169201122b73SMatthias Ringwald btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t)); 169301122b73SMatthias Ringwald #endif 1694a7d12effS[email protected] #endif 1695a3b02b71Smatthias.ringwald } 1696