1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define __BTSTACK_FILE__ "btstack_memory.c" 39 40 41 /* 42 * btstack_memory.h 43 * 44 * @brief BTstack memory management via configurable memory pools 45 * 46 * @note code generated by tool/btstack_memory_generator.py 47 * 48 */ 49 50 #include "btstack_memory.h" 51 #include "btstack_memory_pool.h" 52 53 #include <stdlib.h> 54 55 56 57 // MARK: hci_connection_t 58 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 59 #if defined(MAX_NO_HCI_CONNECTIONS) 60 #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." 61 #else 62 #define MAX_NR_HCI_CONNECTIONS 0 63 #endif 64 #endif 65 66 #ifdef MAX_NR_HCI_CONNECTIONS 67 #if MAX_NR_HCI_CONNECTIONS > 0 68 static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 69 static btstack_memory_pool_t hci_connection_pool; 70 hci_connection_t * btstack_memory_hci_connection_get(void){ 71 return (hci_connection_t *) btstack_memory_pool_get(&hci_connection_pool); 72 } 73 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 74 btstack_memory_pool_free(&hci_connection_pool, hci_connection); 75 } 76 #else 77 hci_connection_t * btstack_memory_hci_connection_get(void){ 78 return NULL; 79 } 80 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 81 // silence compiler warning about unused parameter in a portable way 82 (void) hci_connection; 83 }; 84 #endif 85 #elif defined(HAVE_MALLOC) 86 hci_connection_t * btstack_memory_hci_connection_get(void){ 87 return (hci_connection_t*) malloc(sizeof(hci_connection_t)); 88 } 89 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 90 free(hci_connection); 91 } 92 #endif 93 94 95 96 // MARK: l2cap_service_t 97 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 98 #if defined(MAX_NO_L2CAP_SERVICES) 99 #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." 100 #else 101 #define MAX_NR_L2CAP_SERVICES 0 102 #endif 103 #endif 104 105 #ifdef MAX_NR_L2CAP_SERVICES 106 #if MAX_NR_L2CAP_SERVICES > 0 107 static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 108 static btstack_memory_pool_t l2cap_service_pool; 109 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 110 return (l2cap_service_t *) btstack_memory_pool_get(&l2cap_service_pool); 111 } 112 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 113 btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 114 } 115 #else 116 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 117 return NULL; 118 } 119 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 120 // silence compiler warning about unused parameter in a portable way 121 (void) l2cap_service; 122 }; 123 #endif 124 #elif defined(HAVE_MALLOC) 125 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 126 return (l2cap_service_t*) malloc(sizeof(l2cap_service_t)); 127 } 128 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 129 free(l2cap_service); 130 } 131 #endif 132 133 134 // MARK: l2cap_channel_t 135 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 136 #if defined(MAX_NO_L2CAP_CHANNELS) 137 #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." 138 #else 139 #define MAX_NR_L2CAP_CHANNELS 0 140 #endif 141 #endif 142 143 #ifdef MAX_NR_L2CAP_CHANNELS 144 #if MAX_NR_L2CAP_CHANNELS > 0 145 static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 146 static btstack_memory_pool_t l2cap_channel_pool; 147 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 148 return (l2cap_channel_t *) btstack_memory_pool_get(&l2cap_channel_pool); 149 } 150 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 151 btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 152 } 153 #else 154 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 155 return NULL; 156 } 157 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 158 // silence compiler warning about unused parameter in a portable way 159 (void) l2cap_channel; 160 }; 161 #endif 162 #elif defined(HAVE_MALLOC) 163 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 164 return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t)); 165 } 166 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 167 free(l2cap_channel); 168 } 169 #endif 170 171 172 173 // MARK: rfcomm_multiplexer_t 174 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 175 #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 176 #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." 177 #else 178 #define MAX_NR_RFCOMM_MULTIPLEXERS 0 179 #endif 180 #endif 181 182 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 183 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 184 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 185 static btstack_memory_pool_t rfcomm_multiplexer_pool; 186 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 187 return (rfcomm_multiplexer_t *) btstack_memory_pool_get(&rfcomm_multiplexer_pool); 188 } 189 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 190 btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 191 } 192 #else 193 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 194 return NULL; 195 } 196 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 197 // silence compiler warning about unused parameter in a portable way 198 (void) rfcomm_multiplexer; 199 }; 200 #endif 201 #elif defined(HAVE_MALLOC) 202 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 203 return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t)); 204 } 205 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 206 free(rfcomm_multiplexer); 207 } 208 #endif 209 210 211 // MARK: rfcomm_service_t 212 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 213 #if defined(MAX_NO_RFCOMM_SERVICES) 214 #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." 215 #else 216 #define MAX_NR_RFCOMM_SERVICES 0 217 #endif 218 #endif 219 220 #ifdef MAX_NR_RFCOMM_SERVICES 221 #if MAX_NR_RFCOMM_SERVICES > 0 222 static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 223 static btstack_memory_pool_t rfcomm_service_pool; 224 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 225 return (rfcomm_service_t *) btstack_memory_pool_get(&rfcomm_service_pool); 226 } 227 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 228 btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 229 } 230 #else 231 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 232 return NULL; 233 } 234 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 235 // silence compiler warning about unused parameter in a portable way 236 (void) rfcomm_service; 237 }; 238 #endif 239 #elif defined(HAVE_MALLOC) 240 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 241 return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t)); 242 } 243 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 244 free(rfcomm_service); 245 } 246 #endif 247 248 249 // MARK: rfcomm_channel_t 250 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 251 #if defined(MAX_NO_RFCOMM_CHANNELS) 252 #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." 253 #else 254 #define MAX_NR_RFCOMM_CHANNELS 0 255 #endif 256 #endif 257 258 #ifdef MAX_NR_RFCOMM_CHANNELS 259 #if MAX_NR_RFCOMM_CHANNELS > 0 260 static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 261 static btstack_memory_pool_t rfcomm_channel_pool; 262 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 263 return (rfcomm_channel_t *) btstack_memory_pool_get(&rfcomm_channel_pool); 264 } 265 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 266 btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 267 } 268 #else 269 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 270 return NULL; 271 } 272 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 273 // silence compiler warning about unused parameter in a portable way 274 (void) rfcomm_channel; 275 }; 276 #endif 277 #elif defined(HAVE_MALLOC) 278 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 279 return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t)); 280 } 281 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 282 free(rfcomm_channel); 283 } 284 #endif 285 286 287 288 // MARK: btstack_link_key_db_memory_entry_t 289 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 290 #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 291 #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." 292 #else 293 #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 294 #endif 295 #endif 296 297 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 298 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 299 static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 300 static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 301 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 302 return (btstack_link_key_db_memory_entry_t *) btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 303 } 304 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 305 btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 306 } 307 #else 308 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 309 return NULL; 310 } 311 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 312 // silence compiler warning about unused parameter in a portable way 313 (void) btstack_link_key_db_memory_entry; 314 }; 315 #endif 316 #elif defined(HAVE_MALLOC) 317 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 318 return (btstack_link_key_db_memory_entry_t*) malloc(sizeof(btstack_link_key_db_memory_entry_t)); 319 } 320 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 321 free(btstack_link_key_db_memory_entry); 322 } 323 #endif 324 325 326 327 // MARK: bnep_service_t 328 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 329 #if defined(MAX_NO_BNEP_SERVICES) 330 #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." 331 #else 332 #define MAX_NR_BNEP_SERVICES 0 333 #endif 334 #endif 335 336 #ifdef MAX_NR_BNEP_SERVICES 337 #if MAX_NR_BNEP_SERVICES > 0 338 static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 339 static btstack_memory_pool_t bnep_service_pool; 340 bnep_service_t * btstack_memory_bnep_service_get(void){ 341 return (bnep_service_t *) btstack_memory_pool_get(&bnep_service_pool); 342 } 343 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 344 btstack_memory_pool_free(&bnep_service_pool, bnep_service); 345 } 346 #else 347 bnep_service_t * btstack_memory_bnep_service_get(void){ 348 return NULL; 349 } 350 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 351 // silence compiler warning about unused parameter in a portable way 352 (void) bnep_service; 353 }; 354 #endif 355 #elif defined(HAVE_MALLOC) 356 bnep_service_t * btstack_memory_bnep_service_get(void){ 357 return (bnep_service_t*) malloc(sizeof(bnep_service_t)); 358 } 359 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 360 free(bnep_service); 361 } 362 #endif 363 364 365 // MARK: bnep_channel_t 366 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 367 #if defined(MAX_NO_BNEP_CHANNELS) 368 #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." 369 #else 370 #define MAX_NR_BNEP_CHANNELS 0 371 #endif 372 #endif 373 374 #ifdef MAX_NR_BNEP_CHANNELS 375 #if MAX_NR_BNEP_CHANNELS > 0 376 static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 377 static btstack_memory_pool_t bnep_channel_pool; 378 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 379 return (bnep_channel_t *) btstack_memory_pool_get(&bnep_channel_pool); 380 } 381 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 382 btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 383 } 384 #else 385 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 386 return NULL; 387 } 388 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 389 // silence compiler warning about unused parameter in a portable way 390 (void) bnep_channel; 391 }; 392 #endif 393 #elif defined(HAVE_MALLOC) 394 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 395 return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); 396 } 397 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 398 free(bnep_channel); 399 } 400 #endif 401 402 403 404 // MARK: hfp_connection_t 405 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 406 #if defined(MAX_NO_HFP_CONNECTIONS) 407 #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." 408 #else 409 #define MAX_NR_HFP_CONNECTIONS 0 410 #endif 411 #endif 412 413 #ifdef MAX_NR_HFP_CONNECTIONS 414 #if MAX_NR_HFP_CONNECTIONS > 0 415 static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 416 static btstack_memory_pool_t hfp_connection_pool; 417 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 418 return (hfp_connection_t *) btstack_memory_pool_get(&hfp_connection_pool); 419 } 420 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 421 btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 422 } 423 #else 424 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 425 return NULL; 426 } 427 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 428 // silence compiler warning about unused parameter in a portable way 429 (void) hfp_connection; 430 }; 431 #endif 432 #elif defined(HAVE_MALLOC) 433 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 434 return (hfp_connection_t*) malloc(sizeof(hfp_connection_t)); 435 } 436 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 437 free(hfp_connection); 438 } 439 #endif 440 441 442 443 // MARK: service_record_item_t 444 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 445 #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 446 #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." 447 #else 448 #define MAX_NR_SERVICE_RECORD_ITEMS 0 449 #endif 450 #endif 451 452 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 453 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 454 static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 455 static btstack_memory_pool_t service_record_item_pool; 456 service_record_item_t * btstack_memory_service_record_item_get(void){ 457 return (service_record_item_t *) btstack_memory_pool_get(&service_record_item_pool); 458 } 459 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 460 btstack_memory_pool_free(&service_record_item_pool, service_record_item); 461 } 462 #else 463 service_record_item_t * btstack_memory_service_record_item_get(void){ 464 return NULL; 465 } 466 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 467 // silence compiler warning about unused parameter in a portable way 468 (void) service_record_item; 469 }; 470 #endif 471 #elif defined(HAVE_MALLOC) 472 service_record_item_t * btstack_memory_service_record_item_get(void){ 473 return (service_record_item_t*) malloc(sizeof(service_record_item_t)); 474 } 475 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 476 free(service_record_item); 477 } 478 #endif 479 480 481 482 // MARK: avdtp_stream_endpoint_t 483 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 484 #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 485 #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." 486 #else 487 #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 488 #endif 489 #endif 490 491 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 492 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 493 static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 494 static btstack_memory_pool_t avdtp_stream_endpoint_pool; 495 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 496 return (avdtp_stream_endpoint_t *) btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 497 } 498 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 499 btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 500 } 501 #else 502 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 503 return NULL; 504 } 505 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 506 // silence compiler warning about unused parameter in a portable way 507 (void) avdtp_stream_endpoint; 508 }; 509 #endif 510 #elif defined(HAVE_MALLOC) 511 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 512 return (avdtp_stream_endpoint_t*) malloc(sizeof(avdtp_stream_endpoint_t)); 513 } 514 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 515 free(avdtp_stream_endpoint); 516 } 517 #endif 518 519 520 521 // MARK: avdtp_connection_t 522 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 523 #if defined(MAX_NO_AVDTP_CONNECTIONS) 524 #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." 525 #else 526 #define MAX_NR_AVDTP_CONNECTIONS 0 527 #endif 528 #endif 529 530 #ifdef MAX_NR_AVDTP_CONNECTIONS 531 #if MAX_NR_AVDTP_CONNECTIONS > 0 532 static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 533 static btstack_memory_pool_t avdtp_connection_pool; 534 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 535 return (avdtp_connection_t *) btstack_memory_pool_get(&avdtp_connection_pool); 536 } 537 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 538 btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 539 } 540 #else 541 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 542 return NULL; 543 } 544 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 545 // silence compiler warning about unused parameter in a portable way 546 (void) avdtp_connection; 547 }; 548 #endif 549 #elif defined(HAVE_MALLOC) 550 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 551 return (avdtp_connection_t*) malloc(sizeof(avdtp_connection_t)); 552 } 553 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 554 free(avdtp_connection); 555 } 556 #endif 557 558 559 560 // MARK: avrcp_connection_t 561 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 562 #if defined(MAX_NO_AVRCP_CONNECTIONS) 563 #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." 564 #else 565 #define MAX_NR_AVRCP_CONNECTIONS 0 566 #endif 567 #endif 568 569 #ifdef MAX_NR_AVRCP_CONNECTIONS 570 #if MAX_NR_AVRCP_CONNECTIONS > 0 571 static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 572 static btstack_memory_pool_t avrcp_connection_pool; 573 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 574 return (avrcp_connection_t *) btstack_memory_pool_get(&avrcp_connection_pool); 575 } 576 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 577 btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 578 } 579 #else 580 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 581 return NULL; 582 } 583 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 584 // silence compiler warning about unused parameter in a portable way 585 (void) avrcp_connection; 586 }; 587 #endif 588 #elif defined(HAVE_MALLOC) 589 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 590 return (avrcp_connection_t*) malloc(sizeof(avrcp_connection_t)); 591 } 592 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 593 free(avrcp_connection); 594 } 595 #endif 596 597 598 #ifdef ENABLE_BLE 599 600 // MARK: gatt_client_t 601 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 602 #if defined(MAX_NO_GATT_CLIENTS) 603 #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." 604 #else 605 #define MAX_NR_GATT_CLIENTS 0 606 #endif 607 #endif 608 609 #ifdef MAX_NR_GATT_CLIENTS 610 #if MAX_NR_GATT_CLIENTS > 0 611 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 612 static btstack_memory_pool_t gatt_client_pool; 613 gatt_client_t * btstack_memory_gatt_client_get(void){ 614 return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool); 615 } 616 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 617 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 618 } 619 #else 620 gatt_client_t * btstack_memory_gatt_client_get(void){ 621 return NULL; 622 } 623 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 624 // silence compiler warning about unused parameter in a portable way 625 (void) gatt_client; 626 }; 627 #endif 628 #elif defined(HAVE_MALLOC) 629 gatt_client_t * btstack_memory_gatt_client_get(void){ 630 return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 631 } 632 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 633 free(gatt_client); 634 } 635 #endif 636 637 638 // MARK: whitelist_entry_t 639 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 640 #if defined(MAX_NO_WHITELIST_ENTRIES) 641 #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." 642 #else 643 #define MAX_NR_WHITELIST_ENTRIES 0 644 #endif 645 #endif 646 647 #ifdef MAX_NR_WHITELIST_ENTRIES 648 #if MAX_NR_WHITELIST_ENTRIES > 0 649 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 650 static btstack_memory_pool_t whitelist_entry_pool; 651 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 652 return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool); 653 } 654 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 655 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 656 } 657 #else 658 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 659 return NULL; 660 } 661 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 662 // silence compiler warning about unused parameter in a portable way 663 (void) whitelist_entry; 664 }; 665 #endif 666 #elif defined(HAVE_MALLOC) 667 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 668 return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t)); 669 } 670 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 671 free(whitelist_entry); 672 } 673 #endif 674 675 676 // MARK: sm_lookup_entry_t 677 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 678 #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 679 #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." 680 #else 681 #define MAX_NR_SM_LOOKUP_ENTRIES 0 682 #endif 683 #endif 684 685 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 686 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 687 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 688 static btstack_memory_pool_t sm_lookup_entry_pool; 689 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 690 return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool); 691 } 692 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 693 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 694 } 695 #else 696 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 697 return NULL; 698 } 699 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 700 // silence compiler warning about unused parameter in a portable way 701 (void) sm_lookup_entry; 702 }; 703 #endif 704 #elif defined(HAVE_MALLOC) 705 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 706 return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); 707 } 708 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 709 free(sm_lookup_entry); 710 } 711 #endif 712 713 714 #endif 715 // init 716 void btstack_memory_init(void){ 717 #if MAX_NR_HCI_CONNECTIONS > 0 718 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 719 #endif 720 #if MAX_NR_L2CAP_SERVICES > 0 721 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 722 #endif 723 #if MAX_NR_L2CAP_CHANNELS > 0 724 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 725 #endif 726 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 727 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 728 #endif 729 #if MAX_NR_RFCOMM_SERVICES > 0 730 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 731 #endif 732 #if MAX_NR_RFCOMM_CHANNELS > 0 733 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 734 #endif 735 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 736 btstack_memory_pool_create(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry_storage, MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES, sizeof(btstack_link_key_db_memory_entry_t)); 737 #endif 738 #if MAX_NR_BNEP_SERVICES > 0 739 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 740 #endif 741 #if MAX_NR_BNEP_CHANNELS > 0 742 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 743 #endif 744 #if MAX_NR_HFP_CONNECTIONS > 0 745 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 746 #endif 747 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 748 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 749 #endif 750 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 751 btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t)); 752 #endif 753 #if MAX_NR_AVDTP_CONNECTIONS > 0 754 btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t)); 755 #endif 756 #if MAX_NR_AVRCP_CONNECTIONS > 0 757 btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t)); 758 #endif 759 #ifdef ENABLE_BLE 760 #if MAX_NR_GATT_CLIENTS > 0 761 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 762 #endif 763 #if MAX_NR_WHITELIST_ENTRIES > 0 764 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 765 #endif 766 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 767 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 768 #endif 769 #endif 770 } 771