1*2e97c149S[email protected] 2a3b02b71Smatthias.ringwald /* 3*2e97c149S[email protected] * Copyright (C) 2009 by BlueKitchen GmbH 4a3b02b71Smatthias.ringwald * 5a3b02b71Smatthias.ringwald * Redistribution and use in source and binary forms, with or without 6a3b02b71Smatthias.ringwald * modification, are permitted provided that the following conditions 7a3b02b71Smatthias.ringwald * are met: 8a3b02b71Smatthias.ringwald * 9a3b02b71Smatthias.ringwald * 1. Redistributions of source code must retain the above copyright 10a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer. 11a3b02b71Smatthias.ringwald * 2. Redistributions in binary form must reproduce the above copyright 12a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer in the 13a3b02b71Smatthias.ringwald * documentation and/or other materials provided with the distribution. 14a3b02b71Smatthias.ringwald * 3. Neither the name of the copyright holders nor the names of 15a3b02b71Smatthias.ringwald * contributors may be used to endorse or promote products derived 16a3b02b71Smatthias.ringwald * from this software without specific prior written permission. 176b64433eSmatthias.ringwald * 4. Any redistribution, use, or modification is done solely for 186b64433eSmatthias.ringwald * personal benefit and not for any commercial purpose or for 196b64433eSmatthias.ringwald * monetary gain. 20a3b02b71Smatthias.ringwald * 21*2e97c149S[email protected] * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 22a3b02b71Smatthias.ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23a3b02b71Smatthias.ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24a3b02b71Smatthias.ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 25a3b02b71Smatthias.ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26a3b02b71Smatthias.ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27a3b02b71Smatthias.ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28a3b02b71Smatthias.ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29a3b02b71Smatthias.ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30a3b02b71Smatthias.ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 31a3b02b71Smatthias.ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32a3b02b71Smatthias.ringwald * SUCH DAMAGE. 33a3b02b71Smatthias.ringwald * 34*2e97c149S[email protected] * Please inquire about commercial licensing options at 35*2e97c149S[email protected] * [email protected] 366b64433eSmatthias.ringwald * 37a3b02b71Smatthias.ringwald */ 38a3b02b71Smatthias.ringwald 39*2e97c149S[email protected] 40a3b02b71Smatthias.ringwald /* 41a3b02b71Smatthias.ringwald * btstsack_memory.h 42a3b02b71Smatthias.ringwald * 43a3b02b71Smatthias.ringwald * @brief BTstack memory management via configurable memory pools 44a3b02b71Smatthias.ringwald * 456f7ecb09S[email protected] * @note code semi-atuomatically generated by tools/btstack_memory_generator.py 46a3b02b71Smatthias.ringwald * 47a3b02b71Smatthias.ringwald */ 48a3b02b71Smatthias.ringwald 49a3b02b71Smatthias.ringwald #include "btstack_memory.h" 50a3b02b71Smatthias.ringwald #include <btstack/memory_pool.h> 51a3b02b71Smatthias.ringwald 52a3b02b71Smatthias.ringwald #include <stdlib.h> 53a3b02b71Smatthias.ringwald 54bde315ceS[email protected] #include "btstack-config.h" 55a3b02b71Smatthias.ringwald #include "hci.h" 56a3b02b71Smatthias.ringwald #include "l2cap.h" 57a3b02b71Smatthias.ringwald #include "rfcomm.h" 58a3b02b71Smatthias.ringwald 59*2e97c149S[email protected] 60a3b02b71Smatthias.ringwald // MARK: hci_connection_t 61a3b02b71Smatthias.ringwald #ifdef MAX_NO_HCI_CONNECTIONS 62c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0 63a3b02b71Smatthias.ringwald static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS]; 64a3b02b71Smatthias.ringwald static memory_pool_t hci_connection_pool; 656527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 66a3b02b71Smatthias.ringwald return memory_pool_get(&hci_connection_pool); 67a3b02b71Smatthias.ringwald } 686527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 69a3b02b71Smatthias.ringwald memory_pool_free(&hci_connection_pool, hci_connection); 70a3b02b71Smatthias.ringwald } 71c4d3f927Smatthias.ringwald #else 726527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 73c4d3f927Smatthias.ringwald return NULL; 74c4d3f927Smatthias.ringwald } 756527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 766f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 77*2e97c149S[email protected] (void) hci_connection; 78c4d3f927Smatthias.ringwald }; 79c4d3f927Smatthias.ringwald #endif 80a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 816527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 826527a633S[email protected] return (hci_connection_t*) malloc(sizeof(hci_connection_t)); 83a3b02b71Smatthias.ringwald } 846527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 85a3b02b71Smatthias.ringwald free(hci_connection); 86a3b02b71Smatthias.ringwald } 87e045abdeSmatthias.ringwald #else 886527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS for struct hci_connection is defined. Please, edit the config file." 89a3b02b71Smatthias.ringwald #endif 90a3b02b71Smatthias.ringwald 91a3b02b71Smatthias.ringwald 92*2e97c149S[email protected] 93a3b02b71Smatthias.ringwald // MARK: l2cap_service_t 94a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_SERVICES 95c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0 96a3b02b71Smatthias.ringwald static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES]; 97a3b02b71Smatthias.ringwald static memory_pool_t l2cap_service_pool; 986527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 99a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_service_pool); 100a3b02b71Smatthias.ringwald } 1016527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 102a3b02b71Smatthias.ringwald memory_pool_free(&l2cap_service_pool, l2cap_service); 103a3b02b71Smatthias.ringwald } 104c4d3f927Smatthias.ringwald #else 1056527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 106c4d3f927Smatthias.ringwald return NULL; 107c4d3f927Smatthias.ringwald } 1086527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 1096f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 1106f7ecb09S[email protected] (void) l2cap_service; 111c4d3f927Smatthias.ringwald }; 112c4d3f927Smatthias.ringwald #endif 113a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1146527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 1156527a633S[email protected] return (l2cap_service_t*) malloc(sizeof(l2cap_service_t)); 116a3b02b71Smatthias.ringwald } 1176527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 118a3b02b71Smatthias.ringwald free(l2cap_service); 119a3b02b71Smatthias.ringwald } 120e045abdeSmatthias.ringwald #else 1216527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES for struct l2cap_service is defined. Please, edit the config file." 122a3b02b71Smatthias.ringwald #endif 123a3b02b71Smatthias.ringwald 124a3b02b71Smatthias.ringwald 125a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t 126a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_CHANNELS 127c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0 128a3b02b71Smatthias.ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS]; 129a3b02b71Smatthias.ringwald static memory_pool_t l2cap_channel_pool; 1306527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 131a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_channel_pool); 132a3b02b71Smatthias.ringwald } 1336527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 134a3b02b71Smatthias.ringwald memory_pool_free(&l2cap_channel_pool, l2cap_channel); 135a3b02b71Smatthias.ringwald } 136c4d3f927Smatthias.ringwald #else 1376527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 138c4d3f927Smatthias.ringwald return NULL; 139c4d3f927Smatthias.ringwald } 1406527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 1416f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 1426f7ecb09S[email protected] (void) l2cap_channel; 143c4d3f927Smatthias.ringwald }; 144c4d3f927Smatthias.ringwald #endif 145a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1466527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 1476527a633S[email protected] return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t)); 148a3b02b71Smatthias.ringwald } 1496527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 150a3b02b71Smatthias.ringwald free(l2cap_channel); 151a3b02b71Smatthias.ringwald } 152e045abdeSmatthias.ringwald #else 1536527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS for struct l2cap_channel is defined. Please, edit the config file." 154a3b02b71Smatthias.ringwald #endif 155a3b02b71Smatthias.ringwald 156a3b02b71Smatthias.ringwald 157*2e97c149S[email protected] 158a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t 159a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_MULTIPLEXERS 160c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 161a3b02b71Smatthias.ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS]; 162a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_multiplexer_pool; 1636527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 164a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_multiplexer_pool); 165a3b02b71Smatthias.ringwald } 1666527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 167a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 168a3b02b71Smatthias.ringwald } 169c4d3f927Smatthias.ringwald #else 1706527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 171c4d3f927Smatthias.ringwald return NULL; 172c4d3f927Smatthias.ringwald } 1736527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 1746f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 1756f7ecb09S[email protected] (void) rfcomm_multiplexer; 176c4d3f927Smatthias.ringwald }; 177c4d3f927Smatthias.ringwald #endif 178a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1796527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 1806527a633S[email protected] return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t)); 181a3b02b71Smatthias.ringwald } 1826527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 183a3b02b71Smatthias.ringwald free(rfcomm_multiplexer); 184a3b02b71Smatthias.ringwald } 185e045abdeSmatthias.ringwald #else 1866527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS for struct rfcomm_multiplexer is defined. Please, edit the config file." 187a3b02b71Smatthias.ringwald #endif 188a3b02b71Smatthias.ringwald 189a3b02b71Smatthias.ringwald 190a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t 191a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_SERVICES 192c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0 193a3b02b71Smatthias.ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES]; 194a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_service_pool; 1956527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 196a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_service_pool); 197a3b02b71Smatthias.ringwald } 1986527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 199a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_service_pool, rfcomm_service); 200a3b02b71Smatthias.ringwald } 201c4d3f927Smatthias.ringwald #else 2026527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 203c4d3f927Smatthias.ringwald return NULL; 204c4d3f927Smatthias.ringwald } 2056527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 2066f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 2076f7ecb09S[email protected] (void) rfcomm_service; 208c4d3f927Smatthias.ringwald }; 209c4d3f927Smatthias.ringwald #endif 210a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2116527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 2126527a633S[email protected] return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t)); 213a3b02b71Smatthias.ringwald } 2146527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 215a3b02b71Smatthias.ringwald free(rfcomm_service); 216a3b02b71Smatthias.ringwald } 217e045abdeSmatthias.ringwald #else 2186527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES for struct rfcomm_service is defined. Please, edit the config file." 219a3b02b71Smatthias.ringwald #endif 220a3b02b71Smatthias.ringwald 221a3b02b71Smatthias.ringwald 222a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t 223a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_CHANNELS 224c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0 225a3b02b71Smatthias.ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS]; 226a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_channel_pool; 2276527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 228a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_channel_pool); 229a3b02b71Smatthias.ringwald } 2306527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 231a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 232a3b02b71Smatthias.ringwald } 233c4d3f927Smatthias.ringwald #else 2346527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 235c4d3f927Smatthias.ringwald return NULL; 236c4d3f927Smatthias.ringwald } 2376527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 2386f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 2396f7ecb09S[email protected] (void) rfcomm_channel; 240c4d3f927Smatthias.ringwald }; 241c4d3f927Smatthias.ringwald #endif 242a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2436527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 2446527a633S[email protected] return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t)); 245a3b02b71Smatthias.ringwald } 2466527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 247a3b02b71Smatthias.ringwald free(rfcomm_channel); 248a3b02b71Smatthias.ringwald } 249e045abdeSmatthias.ringwald #else 2506527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file." 251a3b02b71Smatthias.ringwald #endif 252a3b02b71Smatthias.ringwald 253fdb398c2S[email protected] 254e0e5e285Smatthias.ringwald 255e0e5e285Smatthias.ringwald // MARK: db_mem_device_name_t 256e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_NAMES 257c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 258e0e5e285Smatthias.ringwald static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES]; 259e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_name_pool; 2606527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 261e0e5e285Smatthias.ringwald return memory_pool_get(&db_mem_device_name_pool); 2621801b596Smatthias.ringwald } 2636527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 264e0e5e285Smatthias.ringwald memory_pool_free(&db_mem_device_name_pool, db_mem_device_name); 2651801b596Smatthias.ringwald } 266c4d3f927Smatthias.ringwald #else 2676527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 268c4d3f927Smatthias.ringwald return NULL; 269c4d3f927Smatthias.ringwald } 2706527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 2716f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 2726f7ecb09S[email protected] (void) db_mem_device_name; 273c4d3f927Smatthias.ringwald }; 274c4d3f927Smatthias.ringwald #endif 2751801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 2766527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 2776527a633S[email protected] return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t)); 2781801b596Smatthias.ringwald } 2796527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 280e0e5e285Smatthias.ringwald free(db_mem_device_name); 281e0e5e285Smatthias.ringwald } 282e045abdeSmatthias.ringwald #else 2836527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES for struct db_mem_device_name is defined. Please, edit the config file." 284e0e5e285Smatthias.ringwald #endif 285e0e5e285Smatthias.ringwald 286e0e5e285Smatthias.ringwald 287e0e5e285Smatthias.ringwald // MARK: db_mem_device_link_key_t 288e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS 289c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 290e0e5e285Smatthias.ringwald static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS]; 291e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_link_key_pool; 2926527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 293e0e5e285Smatthias.ringwald return memory_pool_get(&db_mem_device_link_key_pool); 294e0e5e285Smatthias.ringwald } 2956527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 296e0e5e285Smatthias.ringwald memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key); 297e0e5e285Smatthias.ringwald } 298c4d3f927Smatthias.ringwald #else 2996527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 300c4d3f927Smatthias.ringwald return NULL; 301c4d3f927Smatthias.ringwald } 3026527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 3036f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 3046f7ecb09S[email protected] (void) db_mem_device_link_key; 305c4d3f927Smatthias.ringwald }; 306c4d3f927Smatthias.ringwald #endif 307e0e5e285Smatthias.ringwald #elif defined(HAVE_MALLOC) 3086527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 3096527a633S[email protected] return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t)); 310e0e5e285Smatthias.ringwald } 3116527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 312e0e5e285Smatthias.ringwald free(db_mem_device_link_key); 3131801b596Smatthias.ringwald } 314e045abdeSmatthias.ringwald #else 3156527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS for struct db_mem_device_link_key is defined. Please, edit the config file." 3161801b596Smatthias.ringwald #endif 3171801b596Smatthias.ringwald 3181801b596Smatthias.ringwald 3191801b596Smatthias.ringwald // MARK: db_mem_service_t 3201801b596Smatthias.ringwald #ifdef MAX_NO_DB_MEM_SERVICES 321c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0 3221801b596Smatthias.ringwald static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES]; 3231801b596Smatthias.ringwald static memory_pool_t db_mem_service_pool; 3246527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 3251801b596Smatthias.ringwald return memory_pool_get(&db_mem_service_pool); 3261801b596Smatthias.ringwald } 3276527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 3281801b596Smatthias.ringwald memory_pool_free(&db_mem_service_pool, db_mem_service); 3291801b596Smatthias.ringwald } 330c4d3f927Smatthias.ringwald #else 3316527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 332c4d3f927Smatthias.ringwald return NULL; 333c4d3f927Smatthias.ringwald } 3346527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 3356f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 3366f7ecb09S[email protected] (void) db_mem_service; 337c4d3f927Smatthias.ringwald }; 338c4d3f927Smatthias.ringwald #endif 3391801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 3406527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 3416527a633S[email protected] return (db_mem_service_t*) malloc(sizeof(db_mem_service_t)); 3421801b596Smatthias.ringwald } 3436527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 3441801b596Smatthias.ringwald free(db_mem_service); 3451801b596Smatthias.ringwald } 346e045abdeSmatthias.ringwald #else 3476527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file." 3481801b596Smatthias.ringwald #endif 3491801b596Smatthias.ringwald 350*2e97c149S[email protected] 351*2e97c149S[email protected] 352*2e97c149S[email protected] // MARK: bnep_service_t 353*2e97c149S[email protected] #ifdef MAX_NO_BNEP_SERVICES 354*2e97c149S[email protected] #if MAX_NO_BNEP_SERVICES > 0 355*2e97c149S[email protected] static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES]; 356*2e97c149S[email protected] static memory_pool_t bnep_service_pool; 357*2e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 358*2e97c149S[email protected] return memory_pool_get(&bnep_service_pool); 359*2e97c149S[email protected] } 360*2e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 361*2e97c149S[email protected] memory_pool_free(&bnep_service_pool, bnep_service); 362*2e97c149S[email protected] } 363*2e97c149S[email protected] #else 364*2e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 365*2e97c149S[email protected] return NULL; 366*2e97c149S[email protected] } 367*2e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 368*2e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 369*2e97c149S[email protected] (void) bnep_service; 370*2e97c149S[email protected] }; 371*2e97c149S[email protected] #endif 372*2e97c149S[email protected] #elif defined(HAVE_MALLOC) 373*2e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 374*2e97c149S[email protected] return (bnep_service_t*) malloc(sizeof(bnep_service_t)); 375*2e97c149S[email protected] } 376*2e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 377*2e97c149S[email protected] free(bnep_service); 378*2e97c149S[email protected] } 379*2e97c149S[email protected] #else 380*2e97c149S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file." 381*2e97c149S[email protected] #endif 382*2e97c149S[email protected] 383*2e97c149S[email protected] 384*2e97c149S[email protected] // MARK: bnep_channel_t 385*2e97c149S[email protected] #ifdef MAX_NO_BNEP_CHANNELS 386*2e97c149S[email protected] #if MAX_NO_BNEP_CHANNELS > 0 387*2e97c149S[email protected] static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS]; 388*2e97c149S[email protected] static memory_pool_t bnep_channel_pool; 389*2e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 390*2e97c149S[email protected] return memory_pool_get(&bnep_channel_pool); 391*2e97c149S[email protected] } 392*2e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 393*2e97c149S[email protected] memory_pool_free(&bnep_channel_pool, bnep_channel); 394*2e97c149S[email protected] } 395*2e97c149S[email protected] #else 396*2e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 397*2e97c149S[email protected] return NULL; 398*2e97c149S[email protected] } 399*2e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 400*2e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 401*2e97c149S[email protected] (void) bnep_channel; 402*2e97c149S[email protected] }; 403*2e97c149S[email protected] #endif 404*2e97c149S[email protected] #elif defined(HAVE_MALLOC) 405*2e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 406*2e97c149S[email protected] return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); 407*2e97c149S[email protected] } 408*2e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 409*2e97c149S[email protected] free(bnep_channel); 410*2e97c149S[email protected] } 411*2e97c149S[email protected] #else 412*2e97c149S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file." 413*2e97c149S[email protected] #endif 414*2e97c149S[email protected] 415*2e97c149S[email protected] 416d0fdae3cS[email protected] #ifdef HAVE_BLE 417*2e97c149S[email protected] 418*2e97c149S[email protected] // MARK: gatt_client_t 419d0fdae3cS[email protected] #ifdef MAX_NO_GATT_CLIENTS 420d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0 421d0fdae3cS[email protected] static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; 422d0fdae3cS[email protected] static memory_pool_t gatt_client_pool; 423d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 424d0fdae3cS[email protected] return memory_pool_get(&gatt_client_pool); 425d0fdae3cS[email protected] } 426d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 427d0fdae3cS[email protected] memory_pool_free(&gatt_client_pool, gatt_client); 428d0fdae3cS[email protected] } 429d0fdae3cS[email protected] #else 430d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 431d0fdae3cS[email protected] return NULL; 432d0fdae3cS[email protected] } 433d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 4346f7ecb09S[email protected] // silence compiler warning about unused parameter in a portable way 4356f7ecb09S[email protected] (void) gatt_client; 436d0fdae3cS[email protected] }; 437d0fdae3cS[email protected] #endif 438d0fdae3cS[email protected] #elif defined(HAVE_MALLOC) 439d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 440d0fdae3cS[email protected] return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 441d0fdae3cS[email protected] } 442d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 443d0fdae3cS[email protected] free(gatt_client); 444d0fdae3cS[email protected] } 445d0fdae3cS[email protected] #else 446d0fdae3cS[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." 447d0fdae3cS[email protected] #endif 448*2e97c149S[email protected] 449*2e97c149S[email protected] 450*2e97c149S[email protected] // MARK: gatt_subclient_t 451*2e97c149S[email protected] #ifdef MAX_NO_GATT_SUBCLIENTS 452*2e97c149S[email protected] #if MAX_NO_GATT_SUBCLIENTS > 0 453*2e97c149S[email protected] static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS]; 454*2e97c149S[email protected] static memory_pool_t gatt_subclient_pool; 455*2e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 456*2e97c149S[email protected] return memory_pool_get(&gatt_subclient_pool); 457*2e97c149S[email protected] } 458*2e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 459*2e97c149S[email protected] memory_pool_free(&gatt_subclient_pool, gatt_subclient); 460*2e97c149S[email protected] } 461*2e97c149S[email protected] #else 462*2e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 463*2e97c149S[email protected] return NULL; 464*2e97c149S[email protected] } 465*2e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 466*2e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 467*2e97c149S[email protected] (void) gatt_subclient; 468*2e97c149S[email protected] }; 469*2e97c149S[email protected] #endif 470*2e97c149S[email protected] #elif defined(HAVE_MALLOC) 471*2e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 472*2e97c149S[email protected] return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t)); 473*2e97c149S[email protected] } 474*2e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 475*2e97c149S[email protected] free(gatt_subclient); 476*2e97c149S[email protected] } 477*2e97c149S[email protected] #else 478*2e97c149S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file." 479d0fdae3cS[email protected] #endif 480fdb398c2S[email protected] 481*2e97c149S[email protected] 482*2e97c149S[email protected] #endif 483a3b02b71Smatthias.ringwald // init 484a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 485c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0 486a3b02b71Smatthias.ringwald memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 487a3b02b71Smatthias.ringwald #endif 488c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0 489a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 490a3b02b71Smatthias.ringwald #endif 491c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0 492a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 493a3b02b71Smatthias.ringwald #endif 494c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 495a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 496a3b02b71Smatthias.ringwald #endif 497c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0 498a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 499a3b02b71Smatthias.ringwald #endif 500c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0 501a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 502a3b02b71Smatthias.ringwald #endif 503c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 504e0e5e285Smatthias.ringwald memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t)); 505e0e5e285Smatthias.ringwald #endif 506c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 507e0e5e285Smatthias.ringwald memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t)); 5081801b596Smatthias.ringwald #endif 509c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0 5101801b596Smatthias.ringwald memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 5111801b596Smatthias.ringwald #endif 512*2e97c149S[email protected] #if MAX_NO_BNEP_SERVICES > 0 513*2e97c149S[email protected] memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t)); 514*2e97c149S[email protected] #endif 515*2e97c149S[email protected] #if MAX_NO_BNEP_CHANNELS > 0 516*2e97c149S[email protected] memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t)); 517*2e97c149S[email protected] #endif 518a7d12effS[email protected] #ifdef HAVE_BLE 519d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0 520d0fdae3cS[email protected] memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); 521d0fdae3cS[email protected] #endif 522*2e97c149S[email protected] #if MAX_NO_GATT_SUBCLIENTS > 0 523*2e97c149S[email protected] memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); 524*2e97c149S[email protected] #endif 525a7d12effS[email protected] #endif 526a3b02b71Smatthias.ringwald } 527