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 38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_memory.c" 39bb2a7656SMatthias Ringwald 402e97c149S[email protected] 41a3b02b71Smatthias.ringwald /* 42a98592bcSMatthias Ringwald * btstack_memory.h 43a3b02b71Smatthias.ringwald * 44a3b02b71Smatthias.ringwald * @brief BTstack memory management via configurable memory pools 45a3b02b71Smatthias.ringwald * 46a98592bcSMatthias Ringwald * @note code generated by tool/btstack_memory_generator.py 47a2673d88SMatthias Ringwald * @note returnes buffers are initialized with 0 48a3b02b71Smatthias.ringwald * 49a3b02b71Smatthias.ringwald */ 50a3b02b71Smatthias.ringwald 51a3b02b71Smatthias.ringwald #include "btstack_memory.h" 52d2e6c4b7SMatthias Ringwald #include "btstack_memory_pool.h" 53a3b02b71Smatthias.ringwald 54a3b02b71Smatthias.ringwald #include <stdlib.h> 55a3b02b71Smatthias.ringwald 56a3b02b71Smatthias.ringwald 572e97c149S[email protected] 58a3b02b71Smatthias.ringwald // MARK: hci_connection_t 59a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 60a265b909SMatthias Ringwald #if defined(MAX_NO_HCI_CONNECTIONS) 6127faf85aSMilanka 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." 62a265b909SMatthias Ringwald #else 63a265b909SMatthias Ringwald #define MAX_NR_HCI_CONNECTIONS 0 64a265b909SMatthias Ringwald #endif 65a265b909SMatthias Ringwald #endif 66a265b909SMatthias Ringwald 67a265b909SMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS 68a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 69a265b909SMatthias Ringwald static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 7029d0c4f7SMatthias Ringwald static btstack_memory_pool_t hci_connection_pool; 716527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 72a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hci_connection_pool); 73a2673d88SMatthias Ringwald if (buffer){ 74a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hci_connection_t)); 75a2673d88SMatthias Ringwald } 76a2673d88SMatthias Ringwald return (hci_connection_t *) buffer; 77a3b02b71Smatthias.ringwald } 786527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 7929d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hci_connection_pool, hci_connection); 80a3b02b71Smatthias.ringwald } 81c4d3f927Smatthias.ringwald #else 826527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 83c4d3f927Smatthias.ringwald return NULL; 84c4d3f927Smatthias.ringwald } 856527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 866f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 872e97c149S[email protected] (void) hci_connection; 88c4d3f927Smatthias.ringwald }; 89c4d3f927Smatthias.ringwald #endif 90a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 916527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 92a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(hci_connection_t)); 93a2673d88SMatthias Ringwald if (buffer){ 94a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hci_connection_t)); 95a2673d88SMatthias Ringwald } 96a2673d88SMatthias Ringwald return (hci_connection_t *) buffer; 97a3b02b71Smatthias.ringwald } 986527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 99a3b02b71Smatthias.ringwald free(hci_connection); 100a3b02b71Smatthias.ringwald } 101a3b02b71Smatthias.ringwald #endif 102a3b02b71Smatthias.ringwald 103a3b02b71Smatthias.ringwald 1042e97c149S[email protected] 105a3b02b71Smatthias.ringwald // MARK: l2cap_service_t 106a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 107a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_SERVICES) 10827faf85aSMilanka 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." 109a265b909SMatthias Ringwald #else 110a265b909SMatthias Ringwald #define MAX_NR_L2CAP_SERVICES 0 111a265b909SMatthias Ringwald #endif 112a265b909SMatthias Ringwald #endif 113a265b909SMatthias Ringwald 114a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES 115a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 116a265b909SMatthias Ringwald static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 11729d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_service_pool; 1186527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 119a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_service_pool); 120a2673d88SMatthias Ringwald if (buffer){ 121a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_service_t)); 122a2673d88SMatthias Ringwald } 123a2673d88SMatthias Ringwald return (l2cap_service_t *) buffer; 124a3b02b71Smatthias.ringwald } 1256527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 12629d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 127a3b02b71Smatthias.ringwald } 128c4d3f927Smatthias.ringwald #else 1296527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 130c4d3f927Smatthias.ringwald return NULL; 131c4d3f927Smatthias.ringwald } 1326527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 1336f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 1346f7ecb09S[email protected] (void) l2cap_service; 135c4d3f927Smatthias.ringwald }; 136c4d3f927Smatthias.ringwald #endif 137a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1386527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 139a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(l2cap_service_t)); 140a2673d88SMatthias Ringwald if (buffer){ 141a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_service_t)); 142a2673d88SMatthias Ringwald } 143a2673d88SMatthias Ringwald return (l2cap_service_t *) buffer; 144a3b02b71Smatthias.ringwald } 1456527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 146a3b02b71Smatthias.ringwald free(l2cap_service); 147a3b02b71Smatthias.ringwald } 148a3b02b71Smatthias.ringwald #endif 149a3b02b71Smatthias.ringwald 150a3b02b71Smatthias.ringwald 151a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t 152a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 153a265b909SMatthias Ringwald #if defined(MAX_NO_L2CAP_CHANNELS) 15427faf85aSMilanka 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." 155a265b909SMatthias Ringwald #else 156a265b909SMatthias Ringwald #define MAX_NR_L2CAP_CHANNELS 0 157a265b909SMatthias Ringwald #endif 158a265b909SMatthias Ringwald #endif 159a265b909SMatthias Ringwald 160a265b909SMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS 161a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 162a265b909SMatthias Ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 16329d0c4f7SMatthias Ringwald static btstack_memory_pool_t l2cap_channel_pool; 1646527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 165a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&l2cap_channel_pool); 166a2673d88SMatthias Ringwald if (buffer){ 167a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_channel_t)); 168a2673d88SMatthias Ringwald } 169a2673d88SMatthias Ringwald return (l2cap_channel_t *) buffer; 170a3b02b71Smatthias.ringwald } 1716527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 17229d0c4f7SMatthias Ringwald btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 173a3b02b71Smatthias.ringwald } 174c4d3f927Smatthias.ringwald #else 1756527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 176c4d3f927Smatthias.ringwald return NULL; 177c4d3f927Smatthias.ringwald } 1786527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 1796f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 1806f7ecb09S[email protected] (void) l2cap_channel; 181c4d3f927Smatthias.ringwald }; 182c4d3f927Smatthias.ringwald #endif 183a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1846527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 185a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(l2cap_channel_t)); 186a2673d88SMatthias Ringwald if (buffer){ 187a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(l2cap_channel_t)); 188a2673d88SMatthias Ringwald } 189a2673d88SMatthias Ringwald return (l2cap_channel_t *) buffer; 190a3b02b71Smatthias.ringwald } 1916527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 192a3b02b71Smatthias.ringwald free(l2cap_channel); 193a3b02b71Smatthias.ringwald } 194a3b02b71Smatthias.ringwald #endif 195a3b02b71Smatthias.ringwald 196a3b02b71Smatthias.ringwald 19744c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 1982e97c149S[email protected] 199a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t 200a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 201a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 20227faf85aSMilanka 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." 203a265b909SMatthias Ringwald #else 204a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_MULTIPLEXERS 0 205a265b909SMatthias Ringwald #endif 206a265b909SMatthias Ringwald #endif 207a265b909SMatthias Ringwald 208a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 209a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 210a265b909SMatthias Ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 21129d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_multiplexer_pool; 2126527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 213a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool); 214a2673d88SMatthias Ringwald if (buffer){ 215a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 216a2673d88SMatthias Ringwald } 217a2673d88SMatthias Ringwald return (rfcomm_multiplexer_t *) buffer; 218a3b02b71Smatthias.ringwald } 2196527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 22029d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 221a3b02b71Smatthias.ringwald } 222c4d3f927Smatthias.ringwald #else 2236527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 224c4d3f927Smatthias.ringwald return NULL; 225c4d3f927Smatthias.ringwald } 2266527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 2276f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 2286f7ecb09S[email protected] (void) rfcomm_multiplexer; 229c4d3f927Smatthias.ringwald }; 230c4d3f927Smatthias.ringwald #endif 231a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2326527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 233a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(rfcomm_multiplexer_t)); 234a2673d88SMatthias Ringwald if (buffer){ 235a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 236a2673d88SMatthias Ringwald } 237a2673d88SMatthias Ringwald return (rfcomm_multiplexer_t *) buffer; 238a3b02b71Smatthias.ringwald } 2396527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 240a3b02b71Smatthias.ringwald free(rfcomm_multiplexer); 241a3b02b71Smatthias.ringwald } 242a3b02b71Smatthias.ringwald #endif 243a3b02b71Smatthias.ringwald 244a3b02b71Smatthias.ringwald 245a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t 246a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 247a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_SERVICES) 24827faf85aSMilanka 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." 249a265b909SMatthias Ringwald #else 250a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_SERVICES 0 251a265b909SMatthias Ringwald #endif 252a265b909SMatthias Ringwald #endif 253a265b909SMatthias Ringwald 254a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES 255a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_SERVICES > 0 256a265b909SMatthias Ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 25729d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_service_pool; 2586527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 259a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_service_pool); 260a2673d88SMatthias Ringwald if (buffer){ 261a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_service_t)); 262a2673d88SMatthias Ringwald } 263a2673d88SMatthias Ringwald return (rfcomm_service_t *) buffer; 264a3b02b71Smatthias.ringwald } 2656527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 26629d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 267a3b02b71Smatthias.ringwald } 268c4d3f927Smatthias.ringwald #else 2696527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 270c4d3f927Smatthias.ringwald return NULL; 271c4d3f927Smatthias.ringwald } 2726527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 2736f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 2746f7ecb09S[email protected] (void) rfcomm_service; 275c4d3f927Smatthias.ringwald }; 276c4d3f927Smatthias.ringwald #endif 277a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2786527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 279a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(rfcomm_service_t)); 280a2673d88SMatthias Ringwald if (buffer){ 281a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_service_t)); 282a2673d88SMatthias Ringwald } 283a2673d88SMatthias Ringwald return (rfcomm_service_t *) buffer; 284a3b02b71Smatthias.ringwald } 2856527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 286a3b02b71Smatthias.ringwald free(rfcomm_service); 287a3b02b71Smatthias.ringwald } 288a3b02b71Smatthias.ringwald #endif 289a3b02b71Smatthias.ringwald 290a3b02b71Smatthias.ringwald 291a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t 292a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 293a265b909SMatthias Ringwald #if defined(MAX_NO_RFCOMM_CHANNELS) 29427faf85aSMilanka 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." 295a265b909SMatthias Ringwald #else 296a265b909SMatthias Ringwald #define MAX_NR_RFCOMM_CHANNELS 0 297a265b909SMatthias Ringwald #endif 298a265b909SMatthias Ringwald #endif 299a265b909SMatthias Ringwald 300a265b909SMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS 301a265b909SMatthias Ringwald #if MAX_NR_RFCOMM_CHANNELS > 0 302a265b909SMatthias Ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 30329d0c4f7SMatthias Ringwald static btstack_memory_pool_t rfcomm_channel_pool; 3046527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 305a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool); 306a2673d88SMatthias Ringwald if (buffer){ 307a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_channel_t)); 308a2673d88SMatthias Ringwald } 309a2673d88SMatthias Ringwald return (rfcomm_channel_t *) buffer; 310a3b02b71Smatthias.ringwald } 3116527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 31229d0c4f7SMatthias Ringwald btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 313a3b02b71Smatthias.ringwald } 314c4d3f927Smatthias.ringwald #else 3156527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 316c4d3f927Smatthias.ringwald return NULL; 317c4d3f927Smatthias.ringwald } 3186527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 3196f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 3206f7ecb09S[email protected] (void) rfcomm_channel; 321c4d3f927Smatthias.ringwald }; 322c4d3f927Smatthias.ringwald #endif 323a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 3246527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 325a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(rfcomm_channel_t)); 326a2673d88SMatthias Ringwald if (buffer){ 327a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(rfcomm_channel_t)); 328a2673d88SMatthias Ringwald } 329a2673d88SMatthias Ringwald return (rfcomm_channel_t *) buffer; 330a3b02b71Smatthias.ringwald } 3316527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 332a3b02b71Smatthias.ringwald free(rfcomm_channel); 333a3b02b71Smatthias.ringwald } 334a3b02b71Smatthias.ringwald #endif 335a3b02b71Smatthias.ringwald 336fdb398c2S[email protected] 337e0e5e285Smatthias.ringwald 3382c455dadSMatthias Ringwald // MARK: btstack_link_key_db_memory_entry_t 339a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 340a265b909SMatthias Ringwald #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 34127faf85aSMilanka 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." 342a265b909SMatthias Ringwald #else 343a265b909SMatthias Ringwald #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 344a265b909SMatthias Ringwald #endif 345a265b909SMatthias Ringwald #endif 346a265b909SMatthias Ringwald 347a265b909SMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 348a265b909SMatthias Ringwald #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 349a265b909SMatthias Ringwald static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 3502c455dadSMatthias Ringwald static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 3512c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 352a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 353a2673d88SMatthias Ringwald if (buffer){ 354a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 355a2673d88SMatthias Ringwald } 356a2673d88SMatthias Ringwald return (btstack_link_key_db_memory_entry_t *) buffer; 3571801b596Smatthias.ringwald } 3582c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 3592c455dadSMatthias Ringwald btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 3601801b596Smatthias.ringwald } 361c4d3f927Smatthias.ringwald #else 3622c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 363c4d3f927Smatthias.ringwald return NULL; 364c4d3f927Smatthias.ringwald } 3652c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 3666f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 3672c455dadSMatthias Ringwald (void) btstack_link_key_db_memory_entry; 368c4d3f927Smatthias.ringwald }; 369c4d3f927Smatthias.ringwald #endif 3701801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 3712c455dadSMatthias Ringwald btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 372a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t)); 373a2673d88SMatthias Ringwald if (buffer){ 374a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 375a2673d88SMatthias Ringwald } 376a2673d88SMatthias Ringwald return (btstack_link_key_db_memory_entry_t *) buffer; 3771801b596Smatthias.ringwald } 3782c455dadSMatthias Ringwald void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 3792c455dadSMatthias Ringwald free(btstack_link_key_db_memory_entry); 380e0e5e285Smatthias.ringwald } 3811801b596Smatthias.ringwald #endif 3821801b596Smatthias.ringwald 3832e97c149S[email protected] 3842e97c149S[email protected] 3852e97c149S[email protected] // MARK: bnep_service_t 386a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 387a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_SERVICES) 38827faf85aSMilanka 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." 389a265b909SMatthias Ringwald #else 390a265b909SMatthias Ringwald #define MAX_NR_BNEP_SERVICES 0 391a265b909SMatthias Ringwald #endif 392a265b909SMatthias Ringwald #endif 393a265b909SMatthias Ringwald 394a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES 395a265b909SMatthias Ringwald #if MAX_NR_BNEP_SERVICES > 0 396a265b909SMatthias Ringwald static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 39729d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_service_pool; 3982e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 399a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_service_pool); 400a2673d88SMatthias Ringwald if (buffer){ 401a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_service_t)); 402a2673d88SMatthias Ringwald } 403a2673d88SMatthias Ringwald return (bnep_service_t *) buffer; 4042e97c149S[email protected] } 4052e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 40629d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_service_pool, bnep_service); 4072e97c149S[email protected] } 4082e97c149S[email protected] #else 4092e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 4102e97c149S[email protected] return NULL; 4112e97c149S[email protected] } 4122e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 4132e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 4142e97c149S[email protected] (void) bnep_service; 4152e97c149S[email protected] }; 4162e97c149S[email protected] #endif 4172e97c149S[email protected] #elif defined(HAVE_MALLOC) 4182e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 419a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(bnep_service_t)); 420a2673d88SMatthias Ringwald if (buffer){ 421a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_service_t)); 422a2673d88SMatthias Ringwald } 423a2673d88SMatthias Ringwald return (bnep_service_t *) buffer; 4242e97c149S[email protected] } 4252e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 4262e97c149S[email protected] free(bnep_service); 4272e97c149S[email protected] } 4282e97c149S[email protected] #endif 4292e97c149S[email protected] 4302e97c149S[email protected] 4312e97c149S[email protected] // MARK: bnep_channel_t 432a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 433a265b909SMatthias Ringwald #if defined(MAX_NO_BNEP_CHANNELS) 43427faf85aSMilanka 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." 435a265b909SMatthias Ringwald #else 436a265b909SMatthias Ringwald #define MAX_NR_BNEP_CHANNELS 0 437a265b909SMatthias Ringwald #endif 438a265b909SMatthias Ringwald #endif 439a265b909SMatthias Ringwald 440a265b909SMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS 441a265b909SMatthias Ringwald #if MAX_NR_BNEP_CHANNELS > 0 442a265b909SMatthias Ringwald static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 44329d0c4f7SMatthias Ringwald static btstack_memory_pool_t bnep_channel_pool; 4442e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 445a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&bnep_channel_pool); 446a2673d88SMatthias Ringwald if (buffer){ 447a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_channel_t)); 448a2673d88SMatthias Ringwald } 449a2673d88SMatthias Ringwald return (bnep_channel_t *) buffer; 4502e97c149S[email protected] } 4512e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 45229d0c4f7SMatthias Ringwald btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 4532e97c149S[email protected] } 4542e97c149S[email protected] #else 4552e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 4562e97c149S[email protected] return NULL; 4572e97c149S[email protected] } 4582e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 4592e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 4602e97c149S[email protected] (void) bnep_channel; 4612e97c149S[email protected] }; 4622e97c149S[email protected] #endif 4632e97c149S[email protected] #elif defined(HAVE_MALLOC) 4642e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 465a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(bnep_channel_t)); 466a2673d88SMatthias Ringwald if (buffer){ 467a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(bnep_channel_t)); 468a2673d88SMatthias Ringwald } 469a2673d88SMatthias Ringwald return (bnep_channel_t *) buffer; 4702e97c149S[email protected] } 4712e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 4722e97c149S[email protected] free(bnep_channel); 4732e97c149S[email protected] } 4742e97c149S[email protected] #endif 4752e97c149S[email protected] 4762e97c149S[email protected] 477ea5029c9SMilanka Ringwald 478ea5029c9SMilanka Ringwald // MARK: hfp_connection_t 479a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 480a265b909SMatthias Ringwald #if defined(MAX_NO_HFP_CONNECTIONS) 48127faf85aSMilanka 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." 482a265b909SMatthias Ringwald #else 483a265b909SMatthias Ringwald #define MAX_NR_HFP_CONNECTIONS 0 484a265b909SMatthias Ringwald #endif 485a265b909SMatthias Ringwald #endif 486a265b909SMatthias Ringwald 487a265b909SMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS 488a265b909SMatthias Ringwald #if MAX_NR_HFP_CONNECTIONS > 0 489a265b909SMatthias Ringwald static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 49029d0c4f7SMatthias Ringwald static btstack_memory_pool_t hfp_connection_pool; 491ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 492a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&hfp_connection_pool); 493a2673d88SMatthias Ringwald if (buffer){ 494a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hfp_connection_t)); 495a2673d88SMatthias Ringwald } 496a2673d88SMatthias Ringwald return (hfp_connection_t *) buffer; 497ea5029c9SMilanka Ringwald } 498ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 49929d0c4f7SMatthias Ringwald btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 500ea5029c9SMilanka Ringwald } 501ea5029c9SMilanka Ringwald #else 502ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 503ea5029c9SMilanka Ringwald return NULL; 504ea5029c9SMilanka Ringwald } 505ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 506ea5029c9SMilanka Ringwald // silence compiler warning about unused parameter in a portable way 507ea5029c9SMilanka Ringwald (void) hfp_connection; 508ea5029c9SMilanka Ringwald }; 509ea5029c9SMilanka Ringwald #endif 510ea5029c9SMilanka Ringwald #elif defined(HAVE_MALLOC) 511ea5029c9SMilanka Ringwald hfp_connection_t * btstack_memory_hfp_connection_get(void){ 512a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(hfp_connection_t)); 513a2673d88SMatthias Ringwald if (buffer){ 514a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(hfp_connection_t)); 515a2673d88SMatthias Ringwald } 516a2673d88SMatthias Ringwald return (hfp_connection_t *) buffer; 517ea5029c9SMilanka Ringwald } 518ea5029c9SMilanka Ringwald void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 519ea5029c9SMilanka Ringwald free(hfp_connection); 520ea5029c9SMilanka Ringwald } 521ea5029c9SMilanka Ringwald #endif 522ea5029c9SMilanka Ringwald 523ea5029c9SMilanka Ringwald 524cd9ee144SMatthias Ringwald 525cd9ee144SMatthias Ringwald // MARK: service_record_item_t 526a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 527a265b909SMatthias Ringwald #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 52827faf85aSMilanka 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." 529a265b909SMatthias Ringwald #else 530a265b909SMatthias Ringwald #define MAX_NR_SERVICE_RECORD_ITEMS 0 531a265b909SMatthias Ringwald #endif 532a265b909SMatthias Ringwald #endif 533a265b909SMatthias Ringwald 534a265b909SMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS 535a265b909SMatthias Ringwald #if MAX_NR_SERVICE_RECORD_ITEMS > 0 536a265b909SMatthias Ringwald static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 53729d0c4f7SMatthias Ringwald static btstack_memory_pool_t service_record_item_pool; 538cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 539a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&service_record_item_pool); 540a2673d88SMatthias Ringwald if (buffer){ 541a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(service_record_item_t)); 542a2673d88SMatthias Ringwald } 543a2673d88SMatthias Ringwald return (service_record_item_t *) buffer; 544cd9ee144SMatthias Ringwald } 545cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 54629d0c4f7SMatthias Ringwald btstack_memory_pool_free(&service_record_item_pool, service_record_item); 547cd9ee144SMatthias Ringwald } 548cd9ee144SMatthias Ringwald #else 549cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 550cd9ee144SMatthias Ringwald return NULL; 551cd9ee144SMatthias Ringwald } 552cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 553cd9ee144SMatthias Ringwald // silence compiler warning about unused parameter in a portable way 554cd9ee144SMatthias Ringwald (void) service_record_item; 555cd9ee144SMatthias Ringwald }; 556cd9ee144SMatthias Ringwald #endif 557cd9ee144SMatthias Ringwald #elif defined(HAVE_MALLOC) 558cd9ee144SMatthias Ringwald service_record_item_t * btstack_memory_service_record_item_get(void){ 559a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(service_record_item_t)); 560a2673d88SMatthias Ringwald if (buffer){ 561a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(service_record_item_t)); 562a2673d88SMatthias Ringwald } 563a2673d88SMatthias Ringwald return (service_record_item_t *) buffer; 564cd9ee144SMatthias Ringwald } 565cd9ee144SMatthias Ringwald void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 566cd9ee144SMatthias Ringwald free(service_record_item); 567cd9ee144SMatthias Ringwald } 568cd9ee144SMatthias Ringwald #endif 569cd9ee144SMatthias Ringwald 570cd9ee144SMatthias Ringwald 57127faf85aSMilanka Ringwald 5720e826a17SMilanka Ringwald // MARK: avdtp_stream_endpoint_t 5730e826a17SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 5740e826a17SMilanka Ringwald #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 5750e826a17SMilanka 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." 57627faf85aSMilanka Ringwald #else 5770e826a17SMilanka Ringwald #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 57827faf85aSMilanka Ringwald #endif 57927faf85aSMilanka Ringwald #endif 58027faf85aSMilanka Ringwald 5810e826a17SMilanka Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 5820e826a17SMilanka Ringwald #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 5830e826a17SMilanka Ringwald static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 5840e826a17SMilanka Ringwald static btstack_memory_pool_t avdtp_stream_endpoint_pool; 5850e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 586a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 587a2673d88SMatthias Ringwald if (buffer){ 588a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 589a2673d88SMatthias Ringwald } 590a2673d88SMatthias Ringwald return (avdtp_stream_endpoint_t *) buffer; 59127faf85aSMilanka Ringwald } 5920e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 5930e826a17SMilanka Ringwald btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 59427faf85aSMilanka Ringwald } 59527faf85aSMilanka Ringwald #else 5960e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 59727faf85aSMilanka Ringwald return NULL; 59827faf85aSMilanka Ringwald } 5990e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 60027faf85aSMilanka Ringwald // silence compiler warning about unused parameter in a portable way 6010e826a17SMilanka Ringwald (void) avdtp_stream_endpoint; 60227faf85aSMilanka Ringwald }; 60327faf85aSMilanka Ringwald #endif 60427faf85aSMilanka Ringwald #elif defined(HAVE_MALLOC) 6050e826a17SMilanka Ringwald avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 606a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(avdtp_stream_endpoint_t)); 607a2673d88SMatthias Ringwald if (buffer){ 608a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 609a2673d88SMatthias Ringwald } 610a2673d88SMatthias Ringwald return (avdtp_stream_endpoint_t *) buffer; 61127faf85aSMilanka Ringwald } 6120e826a17SMilanka Ringwald void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 6130e826a17SMilanka Ringwald free(avdtp_stream_endpoint); 61427faf85aSMilanka Ringwald } 61527faf85aSMilanka Ringwald #endif 61627faf85aSMilanka Ringwald 61727faf85aSMilanka Ringwald 61812e7f38cSMilanka Ringwald 61912e7f38cSMilanka Ringwald // MARK: avdtp_connection_t 62012e7f38cSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 62112e7f38cSMilanka Ringwald #if defined(MAX_NO_AVDTP_CONNECTIONS) 62212e7f38cSMilanka 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." 62312e7f38cSMilanka Ringwald #else 62412e7f38cSMilanka Ringwald #define MAX_NR_AVDTP_CONNECTIONS 0 62512e7f38cSMilanka Ringwald #endif 62612e7f38cSMilanka Ringwald #endif 62712e7f38cSMilanka Ringwald 62812e7f38cSMilanka Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS 62912e7f38cSMilanka Ringwald #if MAX_NR_AVDTP_CONNECTIONS > 0 63012e7f38cSMilanka Ringwald static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 63112e7f38cSMilanka Ringwald static btstack_memory_pool_t avdtp_connection_pool; 63212e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 633a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avdtp_connection_pool); 634a2673d88SMatthias Ringwald if (buffer){ 635a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_connection_t)); 636a2673d88SMatthias Ringwald } 637a2673d88SMatthias Ringwald return (avdtp_connection_t *) buffer; 63812e7f38cSMilanka Ringwald } 63912e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 64012e7f38cSMilanka Ringwald btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 64112e7f38cSMilanka Ringwald } 64212e7f38cSMilanka Ringwald #else 64312e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 64412e7f38cSMilanka Ringwald return NULL; 64512e7f38cSMilanka Ringwald } 64612e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 64712e7f38cSMilanka Ringwald // silence compiler warning about unused parameter in a portable way 64812e7f38cSMilanka Ringwald (void) avdtp_connection; 64912e7f38cSMilanka Ringwald }; 65012e7f38cSMilanka Ringwald #endif 65112e7f38cSMilanka Ringwald #elif defined(HAVE_MALLOC) 65212e7f38cSMilanka Ringwald avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 653a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(avdtp_connection_t)); 654a2673d88SMatthias Ringwald if (buffer){ 655a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avdtp_connection_t)); 656a2673d88SMatthias Ringwald } 657a2673d88SMatthias Ringwald return (avdtp_connection_t *) buffer; 65812e7f38cSMilanka Ringwald } 65912e7f38cSMilanka Ringwald void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 66012e7f38cSMilanka Ringwald free(avdtp_connection); 66112e7f38cSMilanka Ringwald } 66212e7f38cSMilanka Ringwald #endif 66312e7f38cSMilanka Ringwald 66412e7f38cSMilanka Ringwald 66591451a2bSMilanka Ringwald 66691451a2bSMilanka Ringwald // MARK: avrcp_connection_t 66791451a2bSMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 66891451a2bSMilanka Ringwald #if defined(MAX_NO_AVRCP_CONNECTIONS) 66991451a2bSMilanka 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." 67091451a2bSMilanka Ringwald #else 67191451a2bSMilanka Ringwald #define MAX_NR_AVRCP_CONNECTIONS 0 67291451a2bSMilanka Ringwald #endif 67391451a2bSMilanka Ringwald #endif 67491451a2bSMilanka Ringwald 67591451a2bSMilanka Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS 67691451a2bSMilanka Ringwald #if MAX_NR_AVRCP_CONNECTIONS > 0 67791451a2bSMilanka Ringwald static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 67891451a2bSMilanka Ringwald static btstack_memory_pool_t avrcp_connection_pool; 67991451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 680a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_connection_pool); 681a2673d88SMatthias Ringwald if (buffer){ 682a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_connection_t)); 683a2673d88SMatthias Ringwald } 684a2673d88SMatthias Ringwald return (avrcp_connection_t *) buffer; 68591451a2bSMilanka Ringwald } 68691451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 68791451a2bSMilanka Ringwald btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 68891451a2bSMilanka Ringwald } 68991451a2bSMilanka Ringwald #else 69091451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 69191451a2bSMilanka Ringwald return NULL; 69291451a2bSMilanka Ringwald } 69391451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 69491451a2bSMilanka Ringwald // silence compiler warning about unused parameter in a portable way 69591451a2bSMilanka Ringwald (void) avrcp_connection; 69691451a2bSMilanka Ringwald }; 69791451a2bSMilanka Ringwald #endif 69891451a2bSMilanka Ringwald #elif defined(HAVE_MALLOC) 69991451a2bSMilanka Ringwald avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 700a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(avrcp_connection_t)); 701a2673d88SMatthias Ringwald if (buffer){ 702a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_connection_t)); 703a2673d88SMatthias Ringwald } 704a2673d88SMatthias Ringwald return (avrcp_connection_t *) buffer; 70591451a2bSMilanka Ringwald } 70691451a2bSMilanka Ringwald void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 70791451a2bSMilanka Ringwald free(avrcp_connection); 70891451a2bSMilanka Ringwald } 70991451a2bSMilanka Ringwald #endif 71091451a2bSMilanka Ringwald 71191451a2bSMilanka Ringwald 712f12a3722SMilanka Ringwald 713f12a3722SMilanka Ringwald // MARK: avrcp_browsing_connection_t 714f12a3722SMilanka Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS) 715f12a3722SMilanka Ringwald #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS) 716f12a3722SMilanka 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." 717f12a3722SMilanka Ringwald #else 718f12a3722SMilanka Ringwald #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0 719f12a3722SMilanka Ringwald #endif 720f12a3722SMilanka Ringwald #endif 721f12a3722SMilanka Ringwald 722f12a3722SMilanka Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 723f12a3722SMilanka Ringwald #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 724f12a3722SMilanka Ringwald static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS]; 725f12a3722SMilanka Ringwald static btstack_memory_pool_t avrcp_browsing_connection_pool; 726f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 727a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool); 728a2673d88SMatthias Ringwald if (buffer){ 729a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 730a2673d88SMatthias Ringwald } 731a2673d88SMatthias Ringwald return (avrcp_browsing_connection_t *) buffer; 732f12a3722SMilanka Ringwald } 733f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 734f12a3722SMilanka Ringwald btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection); 735f12a3722SMilanka Ringwald } 736f12a3722SMilanka Ringwald #else 737f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 738f12a3722SMilanka Ringwald return NULL; 739f12a3722SMilanka Ringwald } 740f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 741f12a3722SMilanka Ringwald // silence compiler warning about unused parameter in a portable way 742f12a3722SMilanka Ringwald (void) avrcp_browsing_connection; 743f12a3722SMilanka Ringwald }; 744f12a3722SMilanka Ringwald #endif 745f12a3722SMilanka Ringwald #elif defined(HAVE_MALLOC) 746f12a3722SMilanka Ringwald avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 747a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(avrcp_browsing_connection_t)); 748a2673d88SMatthias Ringwald if (buffer){ 749a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 750a2673d88SMatthias Ringwald } 751a2673d88SMatthias Ringwald return (avrcp_browsing_connection_t *) buffer; 752f12a3722SMilanka Ringwald } 753f12a3722SMilanka Ringwald void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 754f12a3722SMilanka Ringwald free(avrcp_browsing_connection); 755f12a3722SMilanka Ringwald } 756f12a3722SMilanka Ringwald #endif 757f12a3722SMilanka Ringwald 758f12a3722SMilanka Ringwald 75944c5d856SMatthias Ringwald #endif 760a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 7612e97c149S[email protected] 7622e97c149S[email protected] // MARK: gatt_client_t 763a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 764a265b909SMatthias Ringwald #if defined(MAX_NO_GATT_CLIENTS) 76527faf85aSMilanka 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." 766a265b909SMatthias Ringwald #else 767a265b909SMatthias Ringwald #define MAX_NR_GATT_CLIENTS 0 768a265b909SMatthias Ringwald #endif 769a265b909SMatthias Ringwald #endif 770a265b909SMatthias Ringwald 771a265b909SMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS 772a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 773a265b909SMatthias Ringwald static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 77429d0c4f7SMatthias Ringwald static btstack_memory_pool_t gatt_client_pool; 775d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 776a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&gatt_client_pool); 777a2673d88SMatthias Ringwald if (buffer){ 778a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(gatt_client_t)); 779a2673d88SMatthias Ringwald } 780a2673d88SMatthias Ringwald return (gatt_client_t *) buffer; 781d0fdae3cS[email protected] } 782d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 78329d0c4f7SMatthias Ringwald btstack_memory_pool_free(&gatt_client_pool, gatt_client); 784d0fdae3cS[email protected] } 785d0fdae3cS[email protected] #else 786d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 787d0fdae3cS[email protected] return NULL; 788d0fdae3cS[email protected] } 789d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 7906f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 7916f7ecb09S[email protected] (void) gatt_client; 792d0fdae3cS[email protected] }; 793d0fdae3cS[email protected] #endif 794d0fdae3cS[email protected] #elif defined(HAVE_MALLOC) 795d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 796a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(gatt_client_t)); 797a2673d88SMatthias Ringwald if (buffer){ 798a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(gatt_client_t)); 799a2673d88SMatthias Ringwald } 800a2673d88SMatthias Ringwald return (gatt_client_t *) buffer; 801d0fdae3cS[email protected] } 802d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 803d0fdae3cS[email protected] free(gatt_client); 804d0fdae3cS[email protected] } 805d0fdae3cS[email protected] #endif 8062e97c149S[email protected] 8072e97c149S[email protected] 808656bec4fSMatthias Ringwald // MARK: whitelist_entry_t 809a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 810a265b909SMatthias Ringwald #if defined(MAX_NO_WHITELIST_ENTRIES) 81127faf85aSMilanka 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." 812a265b909SMatthias Ringwald #else 813a265b909SMatthias Ringwald #define MAX_NR_WHITELIST_ENTRIES 0 814a265b909SMatthias Ringwald #endif 815a265b909SMatthias Ringwald #endif 816a265b909SMatthias Ringwald 817a265b909SMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES 818a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 819a265b909SMatthias Ringwald static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 82029d0c4f7SMatthias Ringwald static btstack_memory_pool_t whitelist_entry_pool; 821656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 822a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&whitelist_entry_pool); 823a2673d88SMatthias Ringwald if (buffer){ 824a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(whitelist_entry_t)); 825a2673d88SMatthias Ringwald } 826a2673d88SMatthias Ringwald return (whitelist_entry_t *) buffer; 827656bec4fSMatthias Ringwald } 828656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 82929d0c4f7SMatthias Ringwald btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 830656bec4fSMatthias Ringwald } 831656bec4fSMatthias Ringwald #else 832656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 833656bec4fSMatthias Ringwald return NULL; 834656bec4fSMatthias Ringwald } 835656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 836656bec4fSMatthias Ringwald // silence compiler warning about unused parameter in a portable way 837656bec4fSMatthias Ringwald (void) whitelist_entry; 838656bec4fSMatthias Ringwald }; 839656bec4fSMatthias Ringwald #endif 840656bec4fSMatthias Ringwald #elif defined(HAVE_MALLOC) 841656bec4fSMatthias Ringwald whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 842a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(whitelist_entry_t)); 843a2673d88SMatthias Ringwald if (buffer){ 844a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(whitelist_entry_t)); 845a2673d88SMatthias Ringwald } 846a2673d88SMatthias Ringwald return (whitelist_entry_t *) buffer; 847656bec4fSMatthias Ringwald } 848656bec4fSMatthias Ringwald void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 849656bec4fSMatthias Ringwald free(whitelist_entry); 850656bec4fSMatthias Ringwald } 851656bec4fSMatthias Ringwald #endif 852656bec4fSMatthias Ringwald 853656bec4fSMatthias Ringwald 854cf49570bSMatthias Ringwald // MARK: sm_lookup_entry_t 855a265b909SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 856a265b909SMatthias Ringwald #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 85727faf85aSMilanka 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." 858a265b909SMatthias Ringwald #else 859a265b909SMatthias Ringwald #define MAX_NR_SM_LOOKUP_ENTRIES 0 860a265b909SMatthias Ringwald #endif 861a265b909SMatthias Ringwald #endif 862a265b909SMatthias Ringwald 863a265b909SMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES 864a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 865a265b909SMatthias Ringwald static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 86629d0c4f7SMatthias Ringwald static btstack_memory_pool_t sm_lookup_entry_pool; 867cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 868a2673d88SMatthias Ringwald void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool); 869a2673d88SMatthias Ringwald if (buffer){ 870a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(sm_lookup_entry_t)); 871a2673d88SMatthias Ringwald } 872a2673d88SMatthias Ringwald return (sm_lookup_entry_t *) buffer; 873cf49570bSMatthias Ringwald } 874cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 87529d0c4f7SMatthias Ringwald btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 876cf49570bSMatthias Ringwald } 877cf49570bSMatthias Ringwald #else 878cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 879cf49570bSMatthias Ringwald return NULL; 880cf49570bSMatthias Ringwald } 881cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 882cf49570bSMatthias Ringwald // silence compiler warning about unused parameter in a portable way 883cf49570bSMatthias Ringwald (void) sm_lookup_entry; 884cf49570bSMatthias Ringwald }; 885cf49570bSMatthias Ringwald #endif 886cf49570bSMatthias Ringwald #elif defined(HAVE_MALLOC) 887cf49570bSMatthias Ringwald sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 888a2673d88SMatthias Ringwald void * buffer = malloc(sizeof(sm_lookup_entry_t)); 889a2673d88SMatthias Ringwald if (buffer){ 890a2673d88SMatthias Ringwald memset(buffer, 0, sizeof(sm_lookup_entry_t)); 891a2673d88SMatthias Ringwald } 892a2673d88SMatthias Ringwald return (sm_lookup_entry_t *) buffer; 893cf49570bSMatthias Ringwald } 894cf49570bSMatthias Ringwald void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 895cf49570bSMatthias Ringwald free(sm_lookup_entry); 896cf49570bSMatthias Ringwald } 897cf49570bSMatthias Ringwald #endif 898cf49570bSMatthias Ringwald 899cf49570bSMatthias Ringwald 90044c5d856SMatthias Ringwald #endif 90144c5d856SMatthias Ringwald #ifdef ENABLE_MESH 902ebb73e1fSMatthias Ringwald 903ebb73e1fSMatthias Ringwald // MARK: mesh_network_pdu_t 904ebb73e1fSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS) 905ebb73e1fSMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_PDUS) 906ebb73e1fSMatthias 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." 907ebb73e1fSMatthias Ringwald #else 908ebb73e1fSMatthias Ringwald #define MAX_NR_MESH_NETWORK_PDUS 0 909ebb73e1fSMatthias Ringwald #endif 910ebb73e1fSMatthias Ringwald #endif 911ebb73e1fSMatthias Ringwald 912ebb73e1fSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS 913ebb73e1fSMatthias Ringwald #if MAX_NR_MESH_NETWORK_PDUS > 0 914ebb73e1fSMatthias Ringwald static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS]; 915ebb73e1fSMatthias Ringwald static btstack_memory_pool_t mesh_network_pdu_pool; 916ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 917*1c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool); 918*1c4e8084SMatthias Ringwald if (buffer){ 919*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_pdu_t)); 920*1c4e8084SMatthias Ringwald } 921*1c4e8084SMatthias Ringwald return (mesh_network_pdu_t *) buffer; 922ebb73e1fSMatthias Ringwald } 923ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 924ebb73e1fSMatthias Ringwald btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu); 925ebb73e1fSMatthias Ringwald } 926ebb73e1fSMatthias Ringwald #else 927ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 928ebb73e1fSMatthias Ringwald return NULL; 929ebb73e1fSMatthias Ringwald } 930ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 931ebb73e1fSMatthias Ringwald // silence compiler warning about unused parameter in a portable way 932ebb73e1fSMatthias Ringwald (void) mesh_network_pdu; 933ebb73e1fSMatthias Ringwald }; 934ebb73e1fSMatthias Ringwald #endif 935ebb73e1fSMatthias Ringwald #elif defined(HAVE_MALLOC) 936ebb73e1fSMatthias Ringwald mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 937*1c4e8084SMatthias Ringwald void * buffer = malloc(sizeof(mesh_network_pdu_t)); 938*1c4e8084SMatthias Ringwald if (buffer){ 939*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_pdu_t)); 940*1c4e8084SMatthias Ringwald } 941*1c4e8084SMatthias Ringwald return (mesh_network_pdu_t *) buffer; 942ebb73e1fSMatthias Ringwald } 943ebb73e1fSMatthias Ringwald void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 944ebb73e1fSMatthias Ringwald free(mesh_network_pdu); 945ebb73e1fSMatthias Ringwald } 946ebb73e1fSMatthias Ringwald #endif 947ebb73e1fSMatthias Ringwald 948ebb73e1fSMatthias Ringwald 949df5d954dSMatthias Ringwald // MARK: mesh_transport_pdu_t 950df5d954dSMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_PDUS) 951df5d954dSMatthias Ringwald #if defined(MAX_NO_MESH_TRANSPORT_PDUS) 952df5d954dSMatthias Ringwald #error "Deprecated MAX_NO_MESH_TRANSPORT_PDUS defined instead of MAX_NR_MESH_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_PDUS." 953898500f0SMatthias Ringwald #else 954df5d954dSMatthias Ringwald #define MAX_NR_MESH_TRANSPORT_PDUS 0 955898500f0SMatthias Ringwald #endif 956898500f0SMatthias Ringwald #endif 957898500f0SMatthias Ringwald 958df5d954dSMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_PDUS 959df5d954dSMatthias Ringwald #if MAX_NR_MESH_TRANSPORT_PDUS > 0 960df5d954dSMatthias Ringwald static mesh_transport_pdu_t mesh_transport_pdu_storage[MAX_NR_MESH_TRANSPORT_PDUS]; 961df5d954dSMatthias Ringwald static btstack_memory_pool_t mesh_transport_pdu_pool; 962df5d954dSMatthias Ringwald mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 963*1c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_transport_pdu_pool); 964*1c4e8084SMatthias Ringwald if (buffer){ 965*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_transport_pdu_t)); 966*1c4e8084SMatthias Ringwald } 967*1c4e8084SMatthias Ringwald return (mesh_transport_pdu_t *) buffer; 968898500f0SMatthias Ringwald } 969df5d954dSMatthias Ringwald void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 970df5d954dSMatthias Ringwald btstack_memory_pool_free(&mesh_transport_pdu_pool, mesh_transport_pdu); 971898500f0SMatthias Ringwald } 972898500f0SMatthias Ringwald #else 973df5d954dSMatthias Ringwald mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 974898500f0SMatthias Ringwald return NULL; 975898500f0SMatthias Ringwald } 976df5d954dSMatthias Ringwald void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 977898500f0SMatthias Ringwald // silence compiler warning about unused parameter in a portable way 978df5d954dSMatthias Ringwald (void) mesh_transport_pdu; 979898500f0SMatthias Ringwald }; 980898500f0SMatthias Ringwald #endif 981898500f0SMatthias Ringwald #elif defined(HAVE_MALLOC) 982df5d954dSMatthias Ringwald mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 983*1c4e8084SMatthias Ringwald void * buffer = malloc(sizeof(mesh_transport_pdu_t)); 984*1c4e8084SMatthias Ringwald if (buffer){ 985*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_transport_pdu_t)); 986*1c4e8084SMatthias Ringwald } 987*1c4e8084SMatthias Ringwald return (mesh_transport_pdu_t *) buffer; 988898500f0SMatthias Ringwald } 989df5d954dSMatthias Ringwald void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 990df5d954dSMatthias Ringwald free(mesh_transport_pdu); 991898500f0SMatthias Ringwald } 992898500f0SMatthias Ringwald #endif 993898500f0SMatthias Ringwald 994898500f0SMatthias Ringwald 995c0a711d9SMatthias Ringwald // MARK: mesh_network_key_t 996c0a711d9SMatthias Ringwald #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS) 997c0a711d9SMatthias Ringwald #if defined(MAX_NO_MESH_NETWORK_KEYS) 998c0a711d9SMatthias 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." 999c0a711d9SMatthias Ringwald #else 1000c0a711d9SMatthias Ringwald #define MAX_NR_MESH_NETWORK_KEYS 0 1001c0a711d9SMatthias Ringwald #endif 1002c0a711d9SMatthias Ringwald #endif 1003c0a711d9SMatthias Ringwald 1004c0a711d9SMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS 1005c0a711d9SMatthias Ringwald #if MAX_NR_MESH_NETWORK_KEYS > 0 1006c0a711d9SMatthias Ringwald static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS]; 1007c0a711d9SMatthias Ringwald static btstack_memory_pool_t mesh_network_key_pool; 1008c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1009*1c4e8084SMatthias Ringwald void * buffer = btstack_memory_pool_get(&mesh_network_key_pool); 1010*1c4e8084SMatthias Ringwald if (buffer){ 1011*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_key_t)); 1012*1c4e8084SMatthias Ringwald } 1013*1c4e8084SMatthias Ringwald return (mesh_network_key_t *) buffer; 1014c0a711d9SMatthias Ringwald } 1015c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1016c0a711d9SMatthias Ringwald btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key); 1017c0a711d9SMatthias Ringwald } 1018c0a711d9SMatthias Ringwald #else 1019c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1020c0a711d9SMatthias Ringwald return NULL; 1021c0a711d9SMatthias Ringwald } 1022c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1023c0a711d9SMatthias Ringwald // silence compiler warning about unused parameter in a portable way 1024c0a711d9SMatthias Ringwald (void) mesh_network_key; 1025c0a711d9SMatthias Ringwald }; 1026c0a711d9SMatthias Ringwald #endif 1027c0a711d9SMatthias Ringwald #elif defined(HAVE_MALLOC) 1028c0a711d9SMatthias Ringwald mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1029*1c4e8084SMatthias Ringwald void * buffer = malloc(sizeof(mesh_network_key_t)); 1030*1c4e8084SMatthias Ringwald if (buffer){ 1031*1c4e8084SMatthias Ringwald memset(buffer, 0, sizeof(mesh_network_key_t)); 1032*1c4e8084SMatthias Ringwald } 1033*1c4e8084SMatthias Ringwald return (mesh_network_key_t *) buffer; 1034c0a711d9SMatthias Ringwald } 1035c0a711d9SMatthias Ringwald void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1036c0a711d9SMatthias Ringwald free(mesh_network_key); 1037c0a711d9SMatthias Ringwald } 1038c0a711d9SMatthias Ringwald #endif 1039c0a711d9SMatthias Ringwald 1040c0a711d9SMatthias Ringwald 10412e97c149S[email protected] #endif 1042a3b02b71Smatthias.ringwald // init 1043a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 1044a265b909SMatthias Ringwald #if MAX_NR_HCI_CONNECTIONS > 0 1045a265b909SMatthias Ringwald btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 1046a3b02b71Smatthias.ringwald #endif 1047a265b909SMatthias Ringwald #if MAX_NR_L2CAP_SERVICES > 0 1048a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 1049a3b02b71Smatthias.ringwald #endif 1050a265b909SMatthias Ringwald #if MAX_NR_L2CAP_CHANNELS > 0 1051a265b909SMatthias Ringwald btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 1052a3b02b71Smatthias.ringwald #endif 105344c5d856SMatthias Ringwald #ifdef ENABLE_CLASSIC 105444c5d856SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 105544c5d856SMatthias Ringwald btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 1056a3b02b71Smatthias.ringwald #endif 105744c5d856SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 105844c5d856SMatthias Ringwald btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 1059a3b02b71Smatthias.ringwald #endif 106044c5d856SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 106144c5d856SMatthias Ringwald btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1062a3b02b71Smatthias.ringwald #endif 1063f12a3722SMilanka Ringwald #endif 1064a9a4c409SMatthias Ringwald #ifdef ENABLE_BLE 1065a265b909SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 1066a265b909SMatthias Ringwald btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 1067d0fdae3cS[email protected] #endif 1068a265b909SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 1069a265b909SMatthias Ringwald btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 1070656bec4fSMatthias Ringwald #endif 1071a265b909SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1072a265b909SMatthias Ringwald btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1073cf49570bSMatthias Ringwald #endif 1074ebb73e1fSMatthias Ringwald #endif 107544c5d856SMatthias Ringwald #ifdef ENABLE_MESH 107644c5d856SMatthias Ringwald #if MAX_NR_GATT_CLIENTS > 0 107744c5d856SMatthias Ringwald btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 107844c5d856SMatthias Ringwald #endif 107944c5d856SMatthias Ringwald #if MAX_NR_WHITELIST_ENTRIES > 0 108044c5d856SMatthias Ringwald btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 108144c5d856SMatthias Ringwald #endif 108244c5d856SMatthias Ringwald #if MAX_NR_SM_LOOKUP_ENTRIES > 0 108344c5d856SMatthias Ringwald btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1084c0a711d9SMatthias Ringwald #endif 1085a7d12effS[email protected] #endif 1086a3b02b71Smatthias.ringwald } 1087