12e97c149S[email protected] 2a3b02b71Smatthias.ringwald /* 32e97c149S[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 * 212e97c149S[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 * 342e97c149S[email protected] * Please inquire about commercial licensing options at 352e97c149S[email protected] * [email protected] 366b64433eSmatthias.ringwald * 37a3b02b71Smatthias.ringwald */ 38a3b02b71Smatthias.ringwald 392e97c149S[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 592e97c149S[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){ 66*21b856f3S[email protected] return (hci_connection_t *) 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 772e97c149S[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 922e97c149S[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){ 99*21b856f3S[email protected] return (l2cap_service_t *) 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){ 131*21b856f3S[email protected] return (l2cap_channel_t *) 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 1572e97c149S[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){ 164*21b856f3S[email protected] return (rfcomm_multiplexer_t *) 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){ 196*21b856f3S[email protected] return (rfcomm_service_t *) 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){ 228*21b856f3S[email protected] return (rfcomm_channel_t *) 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){ 261*21b856f3S[email protected] return (db_mem_device_name_t *) 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){ 293*21b856f3S[email protected] return (db_mem_device_link_key_t *) 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){ 325*21b856f3S[email protected] return (db_mem_service_t *) 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 3502e97c149S[email protected] 3512e97c149S[email protected] 3522e97c149S[email protected] // MARK: bnep_service_t 3532e97c149S[email protected] #ifdef MAX_NO_BNEP_SERVICES 3542e97c149S[email protected] #if MAX_NO_BNEP_SERVICES > 0 3552e97c149S[email protected] static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES]; 3562e97c149S[email protected] static memory_pool_t bnep_service_pool; 3572e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 358*21b856f3S[email protected] return (bnep_service_t *) memory_pool_get(&bnep_service_pool); 3592e97c149S[email protected] } 3602e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 3612e97c149S[email protected] memory_pool_free(&bnep_service_pool, bnep_service); 3622e97c149S[email protected] } 3632e97c149S[email protected] #else 3642e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 3652e97c149S[email protected] return NULL; 3662e97c149S[email protected] } 3672e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 3682e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 3692e97c149S[email protected] (void) bnep_service; 3702e97c149S[email protected] }; 3712e97c149S[email protected] #endif 3722e97c149S[email protected] #elif defined(HAVE_MALLOC) 3732e97c149S[email protected] bnep_service_t * btstack_memory_bnep_service_get(void){ 3742e97c149S[email protected] return (bnep_service_t*) malloc(sizeof(bnep_service_t)); 3752e97c149S[email protected] } 3762e97c149S[email protected] void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 3772e97c149S[email protected] free(bnep_service); 3782e97c149S[email protected] } 3792e97c149S[email protected] #else 3802e97c149S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file." 3812e97c149S[email protected] #endif 3822e97c149S[email protected] 3832e97c149S[email protected] 3842e97c149S[email protected] // MARK: bnep_channel_t 3852e97c149S[email protected] #ifdef MAX_NO_BNEP_CHANNELS 3862e97c149S[email protected] #if MAX_NO_BNEP_CHANNELS > 0 3872e97c149S[email protected] static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS]; 3882e97c149S[email protected] static memory_pool_t bnep_channel_pool; 3892e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 390*21b856f3S[email protected] return (bnep_channel_t *) memory_pool_get(&bnep_channel_pool); 3912e97c149S[email protected] } 3922e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 3932e97c149S[email protected] memory_pool_free(&bnep_channel_pool, bnep_channel); 3942e97c149S[email protected] } 3952e97c149S[email protected] #else 3962e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 3972e97c149S[email protected] return NULL; 3982e97c149S[email protected] } 3992e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 4002e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 4012e97c149S[email protected] (void) bnep_channel; 4022e97c149S[email protected] }; 4032e97c149S[email protected] #endif 4042e97c149S[email protected] #elif defined(HAVE_MALLOC) 4052e97c149S[email protected] bnep_channel_t * btstack_memory_bnep_channel_get(void){ 4062e97c149S[email protected] return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); 4072e97c149S[email protected] } 4082e97c149S[email protected] void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 4092e97c149S[email protected] free(bnep_channel); 4102e97c149S[email protected] } 4112e97c149S[email protected] #else 4122e97c149S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file." 4132e97c149S[email protected] #endif 4142e97c149S[email protected] 4152e97c149S[email protected] 416d0fdae3cS[email protected] #ifdef HAVE_BLE 4172e97c149S[email protected] 4182e97c149S[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){ 424*21b856f3S[email protected] return (gatt_client_t *) 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 4482e97c149S[email protected] 4492e97c149S[email protected] 4502e97c149S[email protected] // MARK: gatt_subclient_t 4512e97c149S[email protected] #ifdef MAX_NO_GATT_SUBCLIENTS 4522e97c149S[email protected] #if MAX_NO_GATT_SUBCLIENTS > 0 4532e97c149S[email protected] static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS]; 4542e97c149S[email protected] static memory_pool_t gatt_subclient_pool; 4552e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 456*21b856f3S[email protected] return (gatt_subclient_t *) memory_pool_get(&gatt_subclient_pool); 4572e97c149S[email protected] } 4582e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 4592e97c149S[email protected] memory_pool_free(&gatt_subclient_pool, gatt_subclient); 4602e97c149S[email protected] } 4612e97c149S[email protected] #else 4622e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 4632e97c149S[email protected] return NULL; 4642e97c149S[email protected] } 4652e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 4662e97c149S[email protected] // silence compiler warning about unused parameter in a portable way 4672e97c149S[email protected] (void) gatt_subclient; 4682e97c149S[email protected] }; 4692e97c149S[email protected] #endif 4702e97c149S[email protected] #elif defined(HAVE_MALLOC) 4712e97c149S[email protected] gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 4722e97c149S[email protected] return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t)); 4732e97c149S[email protected] } 4742e97c149S[email protected] void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 4752e97c149S[email protected] free(gatt_subclient); 4762e97c149S[email protected] } 4772e97c149S[email protected] #else 4782e97c149S[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] 4812e97c149S[email protected] 4822e97c149S[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 5122e97c149S[email protected] #if MAX_NO_BNEP_SERVICES > 0 5132e97c149S[email protected] memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t)); 5142e97c149S[email protected] #endif 5152e97c149S[email protected] #if MAX_NO_BNEP_CHANNELS > 0 5162e97c149S[email protected] memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t)); 5172e97c149S[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 5222e97c149S[email protected] #if MAX_NO_GATT_SUBCLIENTS > 0 5232e97c149S[email protected] memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); 5242e97c149S[email protected] #endif 525a7d12effS[email protected] #endif 526a3b02b71Smatthias.ringwald } 527