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 BLUEKITCHEN 24 * GMBH 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 39 #define BTSTACK_FILE__ "btstack_memory.c" 40 41 42 /* 43 * btstack_memory.c 44 * 45 * @brief BTstack memory management via configurable memory pools 46 * 47 * @note code generated by tool/btstack_memory_generator.py 48 * @note returnes buffers are initialized with 0 49 * 50 */ 51 52 #include "btstack_memory.h" 53 #include "btstack_memory_pool.h" 54 #include "btstack_debug.h" 55 56 #include <stdlib.h> 57 58 #ifdef ENABLE_MALLOC_TEST 59 void * test_malloc(size_t size); 60 #define malloc test_malloc 61 #endif 62 63 #ifdef HAVE_MALLOC 64 typedef struct btstack_memory_buffer { 65 struct btstack_memory_buffer * next; 66 struct btstack_memory_buffer * prev; 67 } btstack_memory_buffer_t; 68 69 typedef struct { 70 btstack_memory_buffer_t tracking; 71 void * pointer; 72 } test_buffer_t; 73 74 static btstack_memory_buffer_t * btstack_memory_malloc_buffers; 75 static uint32_t btstack_memory_malloc_counter; 76 77 static void btstack_memory_tracking_add(btstack_memory_buffer_t * buffer){ 78 btstack_assert(buffer != NULL); 79 if (btstack_memory_malloc_buffers != NULL) { 80 // let current first item prev point to new first item 81 btstack_memory_malloc_buffers->prev = buffer; 82 } 83 buffer->prev = NULL; 84 buffer->next = btstack_memory_malloc_buffers; 85 btstack_memory_malloc_buffers = buffer; 86 87 btstack_memory_malloc_counter++; 88 } 89 90 static void btstack_memory_tracking_remove(btstack_memory_buffer_t * buffer){ 91 btstack_assert(buffer != NULL); 92 if (buffer->prev == NULL){ 93 // first item 94 btstack_memory_malloc_buffers = buffer->next; 95 } else { 96 buffer->prev->next = buffer->next; 97 } 98 if (buffer->next != NULL){ 99 buffer->next->prev = buffer->prev; 100 } 101 102 btstack_memory_malloc_counter--; 103 } 104 #endif 105 106 void btstack_memory_deinit(void){ 107 #ifdef HAVE_MALLOC 108 while (btstack_memory_malloc_buffers != NULL){ 109 btstack_memory_buffer_t * buffer = btstack_memory_malloc_buffers; 110 btstack_memory_malloc_buffers = buffer->next; 111 free(buffer); 112 btstack_memory_malloc_counter--; 113 } 114 btstack_assert(btstack_memory_malloc_counter == 0); 115 #endif 116 } 117 118 119 // MARK: hci_connection_t 120 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 121 #if defined(MAX_NO_HCI_CONNECTIONS) 122 #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." 123 #else 124 #define MAX_NR_HCI_CONNECTIONS 0 125 #endif 126 #endif 127 128 #ifdef MAX_NR_HCI_CONNECTIONS 129 #if MAX_NR_HCI_CONNECTIONS > 0 130 static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 131 static btstack_memory_pool_t hci_connection_pool; 132 hci_connection_t * btstack_memory_hci_connection_get(void){ 133 void * buffer = btstack_memory_pool_get(&hci_connection_pool); 134 if (buffer){ 135 memset(buffer, 0, sizeof(hci_connection_t)); 136 } 137 return (hci_connection_t *) buffer; 138 } 139 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 140 btstack_memory_pool_free(&hci_connection_pool, hci_connection); 141 } 142 #else 143 hci_connection_t * btstack_memory_hci_connection_get(void){ 144 return NULL; 145 } 146 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 147 UNUSED(hci_connection); 148 }; 149 #endif 150 #elif defined(HAVE_MALLOC) 151 152 typedef struct { 153 btstack_memory_buffer_t tracking; 154 hci_connection_t data; 155 } btstack_memory_hci_connection_t; 156 157 hci_connection_t * btstack_memory_hci_connection_get(void){ 158 btstack_memory_hci_connection_t * buffer = (btstack_memory_hci_connection_t *) malloc(sizeof(btstack_memory_hci_connection_t)); 159 if (buffer){ 160 memset(buffer, 0, sizeof(btstack_memory_hci_connection_t)); 161 btstack_memory_tracking_add(&buffer->tracking); 162 return &buffer->data; 163 } else { 164 return NULL; 165 } 166 } 167 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 168 // reconstruct buffer start 169 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_connection)[-1]; 170 btstack_memory_tracking_remove(buffer); 171 free(buffer); 172 } 173 #endif 174 175 176 177 // MARK: l2cap_service_t 178 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 179 #if defined(MAX_NO_L2CAP_SERVICES) 180 #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." 181 #else 182 #define MAX_NR_L2CAP_SERVICES 0 183 #endif 184 #endif 185 186 #ifdef MAX_NR_L2CAP_SERVICES 187 #if MAX_NR_L2CAP_SERVICES > 0 188 static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 189 static btstack_memory_pool_t l2cap_service_pool; 190 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 191 void * buffer = btstack_memory_pool_get(&l2cap_service_pool); 192 if (buffer){ 193 memset(buffer, 0, sizeof(l2cap_service_t)); 194 } 195 return (l2cap_service_t *) buffer; 196 } 197 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 198 btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 199 } 200 #else 201 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 202 return NULL; 203 } 204 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 205 UNUSED(l2cap_service); 206 }; 207 #endif 208 #elif defined(HAVE_MALLOC) 209 210 typedef struct { 211 btstack_memory_buffer_t tracking; 212 l2cap_service_t data; 213 } btstack_memory_l2cap_service_t; 214 215 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 216 btstack_memory_l2cap_service_t * buffer = (btstack_memory_l2cap_service_t *) malloc(sizeof(btstack_memory_l2cap_service_t)); 217 if (buffer){ 218 memset(buffer, 0, sizeof(btstack_memory_l2cap_service_t)); 219 btstack_memory_tracking_add(&buffer->tracking); 220 return &buffer->data; 221 } else { 222 return NULL; 223 } 224 } 225 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 226 // reconstruct buffer start 227 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_service)[-1]; 228 btstack_memory_tracking_remove(buffer); 229 free(buffer); 230 } 231 #endif 232 233 234 // MARK: l2cap_channel_t 235 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 236 #if defined(MAX_NO_L2CAP_CHANNELS) 237 #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." 238 #else 239 #define MAX_NR_L2CAP_CHANNELS 0 240 #endif 241 #endif 242 243 #ifdef MAX_NR_L2CAP_CHANNELS 244 #if MAX_NR_L2CAP_CHANNELS > 0 245 static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 246 static btstack_memory_pool_t l2cap_channel_pool; 247 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 248 void * buffer = btstack_memory_pool_get(&l2cap_channel_pool); 249 if (buffer){ 250 memset(buffer, 0, sizeof(l2cap_channel_t)); 251 } 252 return (l2cap_channel_t *) buffer; 253 } 254 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 255 btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 256 } 257 #else 258 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 259 return NULL; 260 } 261 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 262 UNUSED(l2cap_channel); 263 }; 264 #endif 265 #elif defined(HAVE_MALLOC) 266 267 typedef struct { 268 btstack_memory_buffer_t tracking; 269 l2cap_channel_t data; 270 } btstack_memory_l2cap_channel_t; 271 272 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 273 btstack_memory_l2cap_channel_t * buffer = (btstack_memory_l2cap_channel_t *) malloc(sizeof(btstack_memory_l2cap_channel_t)); 274 if (buffer){ 275 memset(buffer, 0, sizeof(btstack_memory_l2cap_channel_t)); 276 btstack_memory_tracking_add(&buffer->tracking); 277 return &buffer->data; 278 } else { 279 return NULL; 280 } 281 } 282 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 283 // reconstruct buffer start 284 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) l2cap_channel)[-1]; 285 btstack_memory_tracking_remove(buffer); 286 free(buffer); 287 } 288 #endif 289 290 291 #ifdef ENABLE_CLASSIC 292 293 // MARK: rfcomm_multiplexer_t 294 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 295 #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 296 #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." 297 #else 298 #define MAX_NR_RFCOMM_MULTIPLEXERS 0 299 #endif 300 #endif 301 302 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 303 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 304 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 305 static btstack_memory_pool_t rfcomm_multiplexer_pool; 306 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 307 void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool); 308 if (buffer){ 309 memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 310 } 311 return (rfcomm_multiplexer_t *) buffer; 312 } 313 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 314 btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 315 } 316 #else 317 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 318 return NULL; 319 } 320 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 321 UNUSED(rfcomm_multiplexer); 322 }; 323 #endif 324 #elif defined(HAVE_MALLOC) 325 326 typedef struct { 327 btstack_memory_buffer_t tracking; 328 rfcomm_multiplexer_t data; 329 } btstack_memory_rfcomm_multiplexer_t; 330 331 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 332 btstack_memory_rfcomm_multiplexer_t * buffer = (btstack_memory_rfcomm_multiplexer_t *) malloc(sizeof(btstack_memory_rfcomm_multiplexer_t)); 333 if (buffer){ 334 memset(buffer, 0, sizeof(btstack_memory_rfcomm_multiplexer_t)); 335 btstack_memory_tracking_add(&buffer->tracking); 336 return &buffer->data; 337 } else { 338 return NULL; 339 } 340 } 341 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 342 // reconstruct buffer start 343 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_multiplexer)[-1]; 344 btstack_memory_tracking_remove(buffer); 345 free(buffer); 346 } 347 #endif 348 349 350 // MARK: rfcomm_service_t 351 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 352 #if defined(MAX_NO_RFCOMM_SERVICES) 353 #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." 354 #else 355 #define MAX_NR_RFCOMM_SERVICES 0 356 #endif 357 #endif 358 359 #ifdef MAX_NR_RFCOMM_SERVICES 360 #if MAX_NR_RFCOMM_SERVICES > 0 361 static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 362 static btstack_memory_pool_t rfcomm_service_pool; 363 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 364 void * buffer = btstack_memory_pool_get(&rfcomm_service_pool); 365 if (buffer){ 366 memset(buffer, 0, sizeof(rfcomm_service_t)); 367 } 368 return (rfcomm_service_t *) buffer; 369 } 370 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 371 btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 372 } 373 #else 374 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 375 return NULL; 376 } 377 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 378 UNUSED(rfcomm_service); 379 }; 380 #endif 381 #elif defined(HAVE_MALLOC) 382 383 typedef struct { 384 btstack_memory_buffer_t tracking; 385 rfcomm_service_t data; 386 } btstack_memory_rfcomm_service_t; 387 388 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 389 btstack_memory_rfcomm_service_t * buffer = (btstack_memory_rfcomm_service_t *) malloc(sizeof(btstack_memory_rfcomm_service_t)); 390 if (buffer){ 391 memset(buffer, 0, sizeof(btstack_memory_rfcomm_service_t)); 392 btstack_memory_tracking_add(&buffer->tracking); 393 return &buffer->data; 394 } else { 395 return NULL; 396 } 397 } 398 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 399 // reconstruct buffer start 400 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_service)[-1]; 401 btstack_memory_tracking_remove(buffer); 402 free(buffer); 403 } 404 #endif 405 406 407 // MARK: rfcomm_channel_t 408 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 409 #if defined(MAX_NO_RFCOMM_CHANNELS) 410 #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." 411 #else 412 #define MAX_NR_RFCOMM_CHANNELS 0 413 #endif 414 #endif 415 416 #ifdef MAX_NR_RFCOMM_CHANNELS 417 #if MAX_NR_RFCOMM_CHANNELS > 0 418 static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 419 static btstack_memory_pool_t rfcomm_channel_pool; 420 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 421 void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool); 422 if (buffer){ 423 memset(buffer, 0, sizeof(rfcomm_channel_t)); 424 } 425 return (rfcomm_channel_t *) buffer; 426 } 427 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 428 btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 429 } 430 #else 431 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 432 return NULL; 433 } 434 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 435 UNUSED(rfcomm_channel); 436 }; 437 #endif 438 #elif defined(HAVE_MALLOC) 439 440 typedef struct { 441 btstack_memory_buffer_t tracking; 442 rfcomm_channel_t data; 443 } btstack_memory_rfcomm_channel_t; 444 445 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 446 btstack_memory_rfcomm_channel_t * buffer = (btstack_memory_rfcomm_channel_t *) malloc(sizeof(btstack_memory_rfcomm_channel_t)); 447 if (buffer){ 448 memset(buffer, 0, sizeof(btstack_memory_rfcomm_channel_t)); 449 btstack_memory_tracking_add(&buffer->tracking); 450 return &buffer->data; 451 } else { 452 return NULL; 453 } 454 } 455 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 456 // reconstruct buffer start 457 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) rfcomm_channel)[-1]; 458 btstack_memory_tracking_remove(buffer); 459 free(buffer); 460 } 461 #endif 462 463 464 465 // MARK: btstack_link_key_db_memory_entry_t 466 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 467 #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 468 #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." 469 #else 470 #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 471 #endif 472 #endif 473 474 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 475 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 476 static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 477 static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 478 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 479 void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 480 if (buffer){ 481 memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 482 } 483 return (btstack_link_key_db_memory_entry_t *) buffer; 484 } 485 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 486 btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 487 } 488 #else 489 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 490 return NULL; 491 } 492 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 493 UNUSED(btstack_link_key_db_memory_entry); 494 }; 495 #endif 496 #elif defined(HAVE_MALLOC) 497 498 typedef struct { 499 btstack_memory_buffer_t tracking; 500 btstack_link_key_db_memory_entry_t data; 501 } btstack_memory_btstack_link_key_db_memory_entry_t; 502 503 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 504 btstack_memory_btstack_link_key_db_memory_entry_t * buffer = (btstack_memory_btstack_link_key_db_memory_entry_t *) malloc(sizeof(btstack_memory_btstack_link_key_db_memory_entry_t)); 505 if (buffer){ 506 memset(buffer, 0, sizeof(btstack_memory_btstack_link_key_db_memory_entry_t)); 507 btstack_memory_tracking_add(&buffer->tracking); 508 return &buffer->data; 509 } else { 510 return NULL; 511 } 512 } 513 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 514 // reconstruct buffer start 515 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) btstack_link_key_db_memory_entry)[-1]; 516 btstack_memory_tracking_remove(buffer); 517 free(buffer); 518 } 519 #endif 520 521 522 523 // MARK: bnep_service_t 524 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 525 #if defined(MAX_NO_BNEP_SERVICES) 526 #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." 527 #else 528 #define MAX_NR_BNEP_SERVICES 0 529 #endif 530 #endif 531 532 #ifdef MAX_NR_BNEP_SERVICES 533 #if MAX_NR_BNEP_SERVICES > 0 534 static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 535 static btstack_memory_pool_t bnep_service_pool; 536 bnep_service_t * btstack_memory_bnep_service_get(void){ 537 void * buffer = btstack_memory_pool_get(&bnep_service_pool); 538 if (buffer){ 539 memset(buffer, 0, sizeof(bnep_service_t)); 540 } 541 return (bnep_service_t *) buffer; 542 } 543 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 544 btstack_memory_pool_free(&bnep_service_pool, bnep_service); 545 } 546 #else 547 bnep_service_t * btstack_memory_bnep_service_get(void){ 548 return NULL; 549 } 550 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 551 UNUSED(bnep_service); 552 }; 553 #endif 554 #elif defined(HAVE_MALLOC) 555 556 typedef struct { 557 btstack_memory_buffer_t tracking; 558 bnep_service_t data; 559 } btstack_memory_bnep_service_t; 560 561 bnep_service_t * btstack_memory_bnep_service_get(void){ 562 btstack_memory_bnep_service_t * buffer = (btstack_memory_bnep_service_t *) malloc(sizeof(btstack_memory_bnep_service_t)); 563 if (buffer){ 564 memset(buffer, 0, sizeof(btstack_memory_bnep_service_t)); 565 btstack_memory_tracking_add(&buffer->tracking); 566 return &buffer->data; 567 } else { 568 return NULL; 569 } 570 } 571 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 572 // reconstruct buffer start 573 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_service)[-1]; 574 btstack_memory_tracking_remove(buffer); 575 free(buffer); 576 } 577 #endif 578 579 580 // MARK: bnep_channel_t 581 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 582 #if defined(MAX_NO_BNEP_CHANNELS) 583 #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." 584 #else 585 #define MAX_NR_BNEP_CHANNELS 0 586 #endif 587 #endif 588 589 #ifdef MAX_NR_BNEP_CHANNELS 590 #if MAX_NR_BNEP_CHANNELS > 0 591 static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 592 static btstack_memory_pool_t bnep_channel_pool; 593 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 594 void * buffer = btstack_memory_pool_get(&bnep_channel_pool); 595 if (buffer){ 596 memset(buffer, 0, sizeof(bnep_channel_t)); 597 } 598 return (bnep_channel_t *) buffer; 599 } 600 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 601 btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 602 } 603 #else 604 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 605 return NULL; 606 } 607 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 608 UNUSED(bnep_channel); 609 }; 610 #endif 611 #elif defined(HAVE_MALLOC) 612 613 typedef struct { 614 btstack_memory_buffer_t tracking; 615 bnep_channel_t data; 616 } btstack_memory_bnep_channel_t; 617 618 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 619 btstack_memory_bnep_channel_t * buffer = (btstack_memory_bnep_channel_t *) malloc(sizeof(btstack_memory_bnep_channel_t)); 620 if (buffer){ 621 memset(buffer, 0, sizeof(btstack_memory_bnep_channel_t)); 622 btstack_memory_tracking_add(&buffer->tracking); 623 return &buffer->data; 624 } else { 625 return NULL; 626 } 627 } 628 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 629 // reconstruct buffer start 630 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) bnep_channel)[-1]; 631 btstack_memory_tracking_remove(buffer); 632 free(buffer); 633 } 634 #endif 635 636 637 638 // MARK: goep_server_service_t 639 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GOEP_SERVER_SERVICES) 640 #if defined(MAX_NO_GOEP_SERVER_SERVICES) 641 #error "Deprecated MAX_NO_GOEP_SERVER_SERVICES defined instead of MAX_NR_GOEP_SERVER_SERVICES. Please update your btstack_config.h to use MAX_NR_GOEP_SERVER_SERVICES." 642 #else 643 #define MAX_NR_GOEP_SERVER_SERVICES 0 644 #endif 645 #endif 646 647 #ifdef MAX_NR_GOEP_SERVER_SERVICES 648 #if MAX_NR_GOEP_SERVER_SERVICES > 0 649 static goep_server_service_t goep_server_service_storage[MAX_NR_GOEP_SERVER_SERVICES]; 650 static btstack_memory_pool_t goep_server_service_pool; 651 goep_server_service_t * btstack_memory_goep_server_service_get(void){ 652 void * buffer = btstack_memory_pool_get(&goep_server_service_pool); 653 if (buffer){ 654 memset(buffer, 0, sizeof(goep_server_service_t)); 655 } 656 return (goep_server_service_t *) buffer; 657 } 658 void btstack_memory_goep_server_service_free(goep_server_service_t *goep_server_service){ 659 btstack_memory_pool_free(&goep_server_service_pool, goep_server_service); 660 } 661 #else 662 goep_server_service_t * btstack_memory_goep_server_service_get(void){ 663 return NULL; 664 } 665 void btstack_memory_goep_server_service_free(goep_server_service_t *goep_server_service){ 666 UNUSED(goep_server_service); 667 }; 668 #endif 669 #elif defined(HAVE_MALLOC) 670 671 typedef struct { 672 btstack_memory_buffer_t tracking; 673 goep_server_service_t data; 674 } btstack_memory_goep_server_service_t; 675 676 goep_server_service_t * btstack_memory_goep_server_service_get(void){ 677 btstack_memory_goep_server_service_t * buffer = (btstack_memory_goep_server_service_t *) malloc(sizeof(btstack_memory_goep_server_service_t)); 678 if (buffer){ 679 memset(buffer, 0, sizeof(btstack_memory_goep_server_service_t)); 680 btstack_memory_tracking_add(&buffer->tracking); 681 return &buffer->data; 682 } else { 683 return NULL; 684 } 685 } 686 void btstack_memory_goep_server_service_free(goep_server_service_t *goep_server_service){ 687 // reconstruct buffer start 688 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) goep_server_service)[-1]; 689 btstack_memory_tracking_remove(buffer); 690 free(buffer); 691 } 692 #endif 693 694 695 // MARK: goep_server_connection_t 696 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GOEP_SERVER_CONNECTIONS) 697 #if defined(MAX_NO_GOEP_SERVER_CONNECTIONS) 698 #error "Deprecated MAX_NO_GOEP_SERVER_CONNECTIONS defined instead of MAX_NR_GOEP_SERVER_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_GOEP_SERVER_CONNECTIONS." 699 #else 700 #define MAX_NR_GOEP_SERVER_CONNECTIONS 0 701 #endif 702 #endif 703 704 #ifdef MAX_NR_GOEP_SERVER_CONNECTIONS 705 #if MAX_NR_GOEP_SERVER_CONNECTIONS > 0 706 static goep_server_connection_t goep_server_connection_storage[MAX_NR_GOEP_SERVER_CONNECTIONS]; 707 static btstack_memory_pool_t goep_server_connection_pool; 708 goep_server_connection_t * btstack_memory_goep_server_connection_get(void){ 709 void * buffer = btstack_memory_pool_get(&goep_server_connection_pool); 710 if (buffer){ 711 memset(buffer, 0, sizeof(goep_server_connection_t)); 712 } 713 return (goep_server_connection_t *) buffer; 714 } 715 void btstack_memory_goep_server_connection_free(goep_server_connection_t *goep_server_connection){ 716 btstack_memory_pool_free(&goep_server_connection_pool, goep_server_connection); 717 } 718 #else 719 goep_server_connection_t * btstack_memory_goep_server_connection_get(void){ 720 return NULL; 721 } 722 void btstack_memory_goep_server_connection_free(goep_server_connection_t *goep_server_connection){ 723 UNUSED(goep_server_connection); 724 }; 725 #endif 726 #elif defined(HAVE_MALLOC) 727 728 typedef struct { 729 btstack_memory_buffer_t tracking; 730 goep_server_connection_t data; 731 } btstack_memory_goep_server_connection_t; 732 733 goep_server_connection_t * btstack_memory_goep_server_connection_get(void){ 734 btstack_memory_goep_server_connection_t * buffer = (btstack_memory_goep_server_connection_t *) malloc(sizeof(btstack_memory_goep_server_connection_t)); 735 if (buffer){ 736 memset(buffer, 0, sizeof(btstack_memory_goep_server_connection_t)); 737 btstack_memory_tracking_add(&buffer->tracking); 738 return &buffer->data; 739 } else { 740 return NULL; 741 } 742 } 743 void btstack_memory_goep_server_connection_free(goep_server_connection_t *goep_server_connection){ 744 // reconstruct buffer start 745 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) goep_server_connection)[-1]; 746 btstack_memory_tracking_remove(buffer); 747 free(buffer); 748 } 749 #endif 750 751 752 753 // MARK: hfp_connection_t 754 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 755 #if defined(MAX_NO_HFP_CONNECTIONS) 756 #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." 757 #else 758 #define MAX_NR_HFP_CONNECTIONS 0 759 #endif 760 #endif 761 762 #ifdef MAX_NR_HFP_CONNECTIONS 763 #if MAX_NR_HFP_CONNECTIONS > 0 764 static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 765 static btstack_memory_pool_t hfp_connection_pool; 766 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 767 void * buffer = btstack_memory_pool_get(&hfp_connection_pool); 768 if (buffer){ 769 memset(buffer, 0, sizeof(hfp_connection_t)); 770 } 771 return (hfp_connection_t *) buffer; 772 } 773 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 774 btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 775 } 776 #else 777 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 778 return NULL; 779 } 780 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 781 UNUSED(hfp_connection); 782 }; 783 #endif 784 #elif defined(HAVE_MALLOC) 785 786 typedef struct { 787 btstack_memory_buffer_t tracking; 788 hfp_connection_t data; 789 } btstack_memory_hfp_connection_t; 790 791 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 792 btstack_memory_hfp_connection_t * buffer = (btstack_memory_hfp_connection_t *) malloc(sizeof(btstack_memory_hfp_connection_t)); 793 if (buffer){ 794 memset(buffer, 0, sizeof(btstack_memory_hfp_connection_t)); 795 btstack_memory_tracking_add(&buffer->tracking); 796 return &buffer->data; 797 } else { 798 return NULL; 799 } 800 } 801 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 802 // reconstruct buffer start 803 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hfp_connection)[-1]; 804 btstack_memory_tracking_remove(buffer); 805 free(buffer); 806 } 807 #endif 808 809 810 811 // MARK: hid_host_connection_t 812 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HID_HOST_CONNECTIONS) 813 #if defined(MAX_NO_HID_HOST_CONNECTIONS) 814 #error "Deprecated MAX_NO_HID_HOST_CONNECTIONS defined instead of MAX_NR_HID_HOST_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HID_HOST_CONNECTIONS." 815 #else 816 #define MAX_NR_HID_HOST_CONNECTIONS 0 817 #endif 818 #endif 819 820 #ifdef MAX_NR_HID_HOST_CONNECTIONS 821 #if MAX_NR_HID_HOST_CONNECTIONS > 0 822 static hid_host_connection_t hid_host_connection_storage[MAX_NR_HID_HOST_CONNECTIONS]; 823 static btstack_memory_pool_t hid_host_connection_pool; 824 hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 825 void * buffer = btstack_memory_pool_get(&hid_host_connection_pool); 826 if (buffer){ 827 memset(buffer, 0, sizeof(hid_host_connection_t)); 828 } 829 return (hid_host_connection_t *) buffer; 830 } 831 void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 832 btstack_memory_pool_free(&hid_host_connection_pool, hid_host_connection); 833 } 834 #else 835 hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 836 return NULL; 837 } 838 void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 839 UNUSED(hid_host_connection); 840 }; 841 #endif 842 #elif defined(HAVE_MALLOC) 843 844 typedef struct { 845 btstack_memory_buffer_t tracking; 846 hid_host_connection_t data; 847 } btstack_memory_hid_host_connection_t; 848 849 hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ 850 btstack_memory_hid_host_connection_t * buffer = (btstack_memory_hid_host_connection_t *) malloc(sizeof(btstack_memory_hid_host_connection_t)); 851 if (buffer){ 852 memset(buffer, 0, sizeof(btstack_memory_hid_host_connection_t)); 853 btstack_memory_tracking_add(&buffer->tracking); 854 return &buffer->data; 855 } else { 856 return NULL; 857 } 858 } 859 void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ 860 // reconstruct buffer start 861 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hid_host_connection)[-1]; 862 btstack_memory_tracking_remove(buffer); 863 free(buffer); 864 } 865 #endif 866 867 868 869 // MARK: avdtp_stream_endpoint_t 870 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 871 #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 872 #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." 873 #else 874 #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 875 #endif 876 #endif 877 878 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 879 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 880 static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 881 static btstack_memory_pool_t avdtp_stream_endpoint_pool; 882 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 883 void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 884 if (buffer){ 885 memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 886 } 887 return (avdtp_stream_endpoint_t *) buffer; 888 } 889 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 890 btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 891 } 892 #else 893 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 894 return NULL; 895 } 896 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 897 UNUSED(avdtp_stream_endpoint); 898 }; 899 #endif 900 #elif defined(HAVE_MALLOC) 901 902 typedef struct { 903 btstack_memory_buffer_t tracking; 904 avdtp_stream_endpoint_t data; 905 } btstack_memory_avdtp_stream_endpoint_t; 906 907 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 908 btstack_memory_avdtp_stream_endpoint_t * buffer = (btstack_memory_avdtp_stream_endpoint_t *) malloc(sizeof(btstack_memory_avdtp_stream_endpoint_t)); 909 if (buffer){ 910 memset(buffer, 0, sizeof(btstack_memory_avdtp_stream_endpoint_t)); 911 btstack_memory_tracking_add(&buffer->tracking); 912 return &buffer->data; 913 } else { 914 return NULL; 915 } 916 } 917 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 918 // reconstruct buffer start 919 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_stream_endpoint)[-1]; 920 btstack_memory_tracking_remove(buffer); 921 free(buffer); 922 } 923 #endif 924 925 926 927 // MARK: avdtp_connection_t 928 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 929 #if defined(MAX_NO_AVDTP_CONNECTIONS) 930 #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." 931 #else 932 #define MAX_NR_AVDTP_CONNECTIONS 0 933 #endif 934 #endif 935 936 #ifdef MAX_NR_AVDTP_CONNECTIONS 937 #if MAX_NR_AVDTP_CONNECTIONS > 0 938 static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 939 static btstack_memory_pool_t avdtp_connection_pool; 940 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 941 void * buffer = btstack_memory_pool_get(&avdtp_connection_pool); 942 if (buffer){ 943 memset(buffer, 0, sizeof(avdtp_connection_t)); 944 } 945 return (avdtp_connection_t *) buffer; 946 } 947 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 948 btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 949 } 950 #else 951 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 952 return NULL; 953 } 954 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 955 UNUSED(avdtp_connection); 956 }; 957 #endif 958 #elif defined(HAVE_MALLOC) 959 960 typedef struct { 961 btstack_memory_buffer_t tracking; 962 avdtp_connection_t data; 963 } btstack_memory_avdtp_connection_t; 964 965 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 966 btstack_memory_avdtp_connection_t * buffer = (btstack_memory_avdtp_connection_t *) malloc(sizeof(btstack_memory_avdtp_connection_t)); 967 if (buffer){ 968 memset(buffer, 0, sizeof(btstack_memory_avdtp_connection_t)); 969 btstack_memory_tracking_add(&buffer->tracking); 970 return &buffer->data; 971 } else { 972 return NULL; 973 } 974 } 975 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 976 // reconstruct buffer start 977 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avdtp_connection)[-1]; 978 btstack_memory_tracking_remove(buffer); 979 free(buffer); 980 } 981 #endif 982 983 984 985 // MARK: avrcp_connection_t 986 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 987 #if defined(MAX_NO_AVRCP_CONNECTIONS) 988 #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." 989 #else 990 #define MAX_NR_AVRCP_CONNECTIONS 0 991 #endif 992 #endif 993 994 #ifdef MAX_NR_AVRCP_CONNECTIONS 995 #if MAX_NR_AVRCP_CONNECTIONS > 0 996 static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 997 static btstack_memory_pool_t avrcp_connection_pool; 998 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 999 void * buffer = btstack_memory_pool_get(&avrcp_connection_pool); 1000 if (buffer){ 1001 memset(buffer, 0, sizeof(avrcp_connection_t)); 1002 } 1003 return (avrcp_connection_t *) buffer; 1004 } 1005 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 1006 btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 1007 } 1008 #else 1009 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 1010 return NULL; 1011 } 1012 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 1013 UNUSED(avrcp_connection); 1014 }; 1015 #endif 1016 #elif defined(HAVE_MALLOC) 1017 1018 typedef struct { 1019 btstack_memory_buffer_t tracking; 1020 avrcp_connection_t data; 1021 } btstack_memory_avrcp_connection_t; 1022 1023 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 1024 btstack_memory_avrcp_connection_t * buffer = (btstack_memory_avrcp_connection_t *) malloc(sizeof(btstack_memory_avrcp_connection_t)); 1025 if (buffer){ 1026 memset(buffer, 0, sizeof(btstack_memory_avrcp_connection_t)); 1027 btstack_memory_tracking_add(&buffer->tracking); 1028 return &buffer->data; 1029 } else { 1030 return NULL; 1031 } 1032 } 1033 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 1034 // reconstruct buffer start 1035 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_connection)[-1]; 1036 btstack_memory_tracking_remove(buffer); 1037 free(buffer); 1038 } 1039 #endif 1040 1041 1042 1043 // MARK: avrcp_browsing_connection_t 1044 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS) 1045 #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS) 1046 #error "Deprecated MAX_NO_AVRCP_BROWSING_CONNECTIONS defined instead of MAX_NR_AVRCP_BROWSING_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_BROWSING_CONNECTIONS." 1047 #else 1048 #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0 1049 #endif 1050 #endif 1051 1052 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 1053 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 1054 static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS]; 1055 static btstack_memory_pool_t avrcp_browsing_connection_pool; 1056 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 1057 void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool); 1058 if (buffer){ 1059 memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 1060 } 1061 return (avrcp_browsing_connection_t *) buffer; 1062 } 1063 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1064 btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection); 1065 } 1066 #else 1067 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 1068 return NULL; 1069 } 1070 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1071 UNUSED(avrcp_browsing_connection); 1072 }; 1073 #endif 1074 #elif defined(HAVE_MALLOC) 1075 1076 typedef struct { 1077 btstack_memory_buffer_t tracking; 1078 avrcp_browsing_connection_t data; 1079 } btstack_memory_avrcp_browsing_connection_t; 1080 1081 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 1082 btstack_memory_avrcp_browsing_connection_t * buffer = (btstack_memory_avrcp_browsing_connection_t *) malloc(sizeof(btstack_memory_avrcp_browsing_connection_t)); 1083 if (buffer){ 1084 memset(buffer, 0, sizeof(btstack_memory_avrcp_browsing_connection_t)); 1085 btstack_memory_tracking_add(&buffer->tracking); 1086 return &buffer->data; 1087 } else { 1088 return NULL; 1089 } 1090 } 1091 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 1092 // reconstruct buffer start 1093 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) avrcp_browsing_connection)[-1]; 1094 btstack_memory_tracking_remove(buffer); 1095 free(buffer); 1096 } 1097 #endif 1098 1099 1100 1101 // MARK: service_record_item_t 1102 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 1103 #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 1104 #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." 1105 #else 1106 #define MAX_NR_SERVICE_RECORD_ITEMS 0 1107 #endif 1108 #endif 1109 1110 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 1111 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 1112 static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 1113 static btstack_memory_pool_t service_record_item_pool; 1114 service_record_item_t * btstack_memory_service_record_item_get(void){ 1115 void * buffer = btstack_memory_pool_get(&service_record_item_pool); 1116 if (buffer){ 1117 memset(buffer, 0, sizeof(service_record_item_t)); 1118 } 1119 return (service_record_item_t *) buffer; 1120 } 1121 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 1122 btstack_memory_pool_free(&service_record_item_pool, service_record_item); 1123 } 1124 #else 1125 service_record_item_t * btstack_memory_service_record_item_get(void){ 1126 return NULL; 1127 } 1128 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 1129 UNUSED(service_record_item); 1130 }; 1131 #endif 1132 #elif defined(HAVE_MALLOC) 1133 1134 typedef struct { 1135 btstack_memory_buffer_t tracking; 1136 service_record_item_t data; 1137 } btstack_memory_service_record_item_t; 1138 1139 service_record_item_t * btstack_memory_service_record_item_get(void){ 1140 btstack_memory_service_record_item_t * buffer = (btstack_memory_service_record_item_t *) malloc(sizeof(btstack_memory_service_record_item_t)); 1141 if (buffer){ 1142 memset(buffer, 0, sizeof(btstack_memory_service_record_item_t)); 1143 btstack_memory_tracking_add(&buffer->tracking); 1144 return &buffer->data; 1145 } else { 1146 return NULL; 1147 } 1148 } 1149 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 1150 // reconstruct buffer start 1151 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) service_record_item)[-1]; 1152 btstack_memory_tracking_remove(buffer); 1153 free(buffer); 1154 } 1155 #endif 1156 1157 1158 #endif 1159 #ifdef ENABLE_BLE 1160 1161 // MARK: battery_service_client_t 1162 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BATTERY_SERVICE_CLIENTS) 1163 #if defined(MAX_NO_BATTERY_SERVICE_CLIENTS) 1164 #error "Deprecated MAX_NO_BATTERY_SERVICE_CLIENTS defined instead of MAX_NR_BATTERY_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_BATTERY_SERVICE_CLIENTS." 1165 #else 1166 #define MAX_NR_BATTERY_SERVICE_CLIENTS 0 1167 #endif 1168 #endif 1169 1170 #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 1171 #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0 1172 static battery_service_client_t battery_service_client_storage[MAX_NR_BATTERY_SERVICE_CLIENTS]; 1173 static btstack_memory_pool_t battery_service_client_pool; 1174 battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1175 void * buffer = btstack_memory_pool_get(&battery_service_client_pool); 1176 if (buffer){ 1177 memset(buffer, 0, sizeof(battery_service_client_t)); 1178 } 1179 return (battery_service_client_t *) buffer; 1180 } 1181 void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1182 btstack_memory_pool_free(&battery_service_client_pool, battery_service_client); 1183 } 1184 #else 1185 battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1186 return NULL; 1187 } 1188 void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1189 UNUSED(battery_service_client); 1190 }; 1191 #endif 1192 #elif defined(HAVE_MALLOC) 1193 1194 typedef struct { 1195 btstack_memory_buffer_t tracking; 1196 battery_service_client_t data; 1197 } btstack_memory_battery_service_client_t; 1198 1199 battery_service_client_t * btstack_memory_battery_service_client_get(void){ 1200 btstack_memory_battery_service_client_t * buffer = (btstack_memory_battery_service_client_t *) malloc(sizeof(btstack_memory_battery_service_client_t)); 1201 if (buffer){ 1202 memset(buffer, 0, sizeof(btstack_memory_battery_service_client_t)); 1203 btstack_memory_tracking_add(&buffer->tracking); 1204 return &buffer->data; 1205 } else { 1206 return NULL; 1207 } 1208 } 1209 void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){ 1210 // reconstruct buffer start 1211 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) battery_service_client)[-1]; 1212 btstack_memory_tracking_remove(buffer); 1213 free(buffer); 1214 } 1215 #endif 1216 1217 1218 // MARK: gatt_client_t 1219 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 1220 #if defined(MAX_NO_GATT_CLIENTS) 1221 #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." 1222 #else 1223 #define MAX_NR_GATT_CLIENTS 0 1224 #endif 1225 #endif 1226 1227 #ifdef MAX_NR_GATT_CLIENTS 1228 #if MAX_NR_GATT_CLIENTS > 0 1229 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 1230 static btstack_memory_pool_t gatt_client_pool; 1231 gatt_client_t * btstack_memory_gatt_client_get(void){ 1232 void * buffer = btstack_memory_pool_get(&gatt_client_pool); 1233 if (buffer){ 1234 memset(buffer, 0, sizeof(gatt_client_t)); 1235 } 1236 return (gatt_client_t *) buffer; 1237 } 1238 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1239 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 1240 } 1241 #else 1242 gatt_client_t * btstack_memory_gatt_client_get(void){ 1243 return NULL; 1244 } 1245 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1246 UNUSED(gatt_client); 1247 }; 1248 #endif 1249 #elif defined(HAVE_MALLOC) 1250 1251 typedef struct { 1252 btstack_memory_buffer_t tracking; 1253 gatt_client_t data; 1254 } btstack_memory_gatt_client_t; 1255 1256 gatt_client_t * btstack_memory_gatt_client_get(void){ 1257 btstack_memory_gatt_client_t * buffer = (btstack_memory_gatt_client_t *) malloc(sizeof(btstack_memory_gatt_client_t)); 1258 if (buffer){ 1259 memset(buffer, 0, sizeof(btstack_memory_gatt_client_t)); 1260 btstack_memory_tracking_add(&buffer->tracking); 1261 return &buffer->data; 1262 } else { 1263 return NULL; 1264 } 1265 } 1266 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 1267 // reconstruct buffer start 1268 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) gatt_client)[-1]; 1269 btstack_memory_tracking_remove(buffer); 1270 free(buffer); 1271 } 1272 #endif 1273 1274 1275 // MARK: hids_client_t 1276 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HIDS_CLIENTS) 1277 #if defined(MAX_NO_HIDS_CLIENTS) 1278 #error "Deprecated MAX_NO_HIDS_CLIENTS defined instead of MAX_NR_HIDS_CLIENTS. Please update your btstack_config.h to use MAX_NR_HIDS_CLIENTS." 1279 #else 1280 #define MAX_NR_HIDS_CLIENTS 0 1281 #endif 1282 #endif 1283 1284 #ifdef MAX_NR_HIDS_CLIENTS 1285 #if MAX_NR_HIDS_CLIENTS > 0 1286 static hids_client_t hids_client_storage[MAX_NR_HIDS_CLIENTS]; 1287 static btstack_memory_pool_t hids_client_pool; 1288 hids_client_t * btstack_memory_hids_client_get(void){ 1289 void * buffer = btstack_memory_pool_get(&hids_client_pool); 1290 if (buffer){ 1291 memset(buffer, 0, sizeof(hids_client_t)); 1292 } 1293 return (hids_client_t *) buffer; 1294 } 1295 void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1296 btstack_memory_pool_free(&hids_client_pool, hids_client); 1297 } 1298 #else 1299 hids_client_t * btstack_memory_hids_client_get(void){ 1300 return NULL; 1301 } 1302 void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1303 UNUSED(hids_client); 1304 }; 1305 #endif 1306 #elif defined(HAVE_MALLOC) 1307 1308 typedef struct { 1309 btstack_memory_buffer_t tracking; 1310 hids_client_t data; 1311 } btstack_memory_hids_client_t; 1312 1313 hids_client_t * btstack_memory_hids_client_get(void){ 1314 btstack_memory_hids_client_t * buffer = (btstack_memory_hids_client_t *) malloc(sizeof(btstack_memory_hids_client_t)); 1315 if (buffer){ 1316 memset(buffer, 0, sizeof(btstack_memory_hids_client_t)); 1317 btstack_memory_tracking_add(&buffer->tracking); 1318 return &buffer->data; 1319 } else { 1320 return NULL; 1321 } 1322 } 1323 void btstack_memory_hids_client_free(hids_client_t *hids_client){ 1324 // reconstruct buffer start 1325 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hids_client)[-1]; 1326 btstack_memory_tracking_remove(buffer); 1327 free(buffer); 1328 } 1329 #endif 1330 1331 1332 // MARK: scan_parameters_service_client_t 1333 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS) 1334 #if defined(MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS) 1335 #error "Deprecated MAX_NO_SCAN_PARAMETERS_SERVICE_CLIENTS defined instead of MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS. Please update your btstack_config.h to use MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS." 1336 #else 1337 #define MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 0 1338 #endif 1339 #endif 1340 1341 #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 1342 #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0 1343 static scan_parameters_service_client_t scan_parameters_service_client_storage[MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS]; 1344 static btstack_memory_pool_t scan_parameters_service_client_pool; 1345 scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1346 void * buffer = btstack_memory_pool_get(&scan_parameters_service_client_pool); 1347 if (buffer){ 1348 memset(buffer, 0, sizeof(scan_parameters_service_client_t)); 1349 } 1350 return (scan_parameters_service_client_t *) buffer; 1351 } 1352 void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1353 btstack_memory_pool_free(&scan_parameters_service_client_pool, scan_parameters_service_client); 1354 } 1355 #else 1356 scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1357 return NULL; 1358 } 1359 void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1360 UNUSED(scan_parameters_service_client); 1361 }; 1362 #endif 1363 #elif defined(HAVE_MALLOC) 1364 1365 typedef struct { 1366 btstack_memory_buffer_t tracking; 1367 scan_parameters_service_client_t data; 1368 } btstack_memory_scan_parameters_service_client_t; 1369 1370 scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void){ 1371 btstack_memory_scan_parameters_service_client_t * buffer = (btstack_memory_scan_parameters_service_client_t *) malloc(sizeof(btstack_memory_scan_parameters_service_client_t)); 1372 if (buffer){ 1373 memset(buffer, 0, sizeof(btstack_memory_scan_parameters_service_client_t)); 1374 btstack_memory_tracking_add(&buffer->tracking); 1375 return &buffer->data; 1376 } else { 1377 return NULL; 1378 } 1379 } 1380 void btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client){ 1381 // reconstruct buffer start 1382 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) scan_parameters_service_client)[-1]; 1383 btstack_memory_tracking_remove(buffer); 1384 free(buffer); 1385 } 1386 #endif 1387 1388 1389 // MARK: sm_lookup_entry_t 1390 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 1391 #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 1392 #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." 1393 #else 1394 #define MAX_NR_SM_LOOKUP_ENTRIES 0 1395 #endif 1396 #endif 1397 1398 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 1399 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1400 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 1401 static btstack_memory_pool_t sm_lookup_entry_pool; 1402 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1403 void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool); 1404 if (buffer){ 1405 memset(buffer, 0, sizeof(sm_lookup_entry_t)); 1406 } 1407 return (sm_lookup_entry_t *) buffer; 1408 } 1409 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1410 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 1411 } 1412 #else 1413 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1414 return NULL; 1415 } 1416 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1417 UNUSED(sm_lookup_entry); 1418 }; 1419 #endif 1420 #elif defined(HAVE_MALLOC) 1421 1422 typedef struct { 1423 btstack_memory_buffer_t tracking; 1424 sm_lookup_entry_t data; 1425 } btstack_memory_sm_lookup_entry_t; 1426 1427 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 1428 btstack_memory_sm_lookup_entry_t * buffer = (btstack_memory_sm_lookup_entry_t *) malloc(sizeof(btstack_memory_sm_lookup_entry_t)); 1429 if (buffer){ 1430 memset(buffer, 0, sizeof(btstack_memory_sm_lookup_entry_t)); 1431 btstack_memory_tracking_add(&buffer->tracking); 1432 return &buffer->data; 1433 } else { 1434 return NULL; 1435 } 1436 } 1437 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 1438 // reconstruct buffer start 1439 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) sm_lookup_entry)[-1]; 1440 btstack_memory_tracking_remove(buffer); 1441 free(buffer); 1442 } 1443 #endif 1444 1445 1446 // MARK: whitelist_entry_t 1447 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 1448 #if defined(MAX_NO_WHITELIST_ENTRIES) 1449 #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." 1450 #else 1451 #define MAX_NR_WHITELIST_ENTRIES 0 1452 #endif 1453 #endif 1454 1455 #ifdef MAX_NR_WHITELIST_ENTRIES 1456 #if MAX_NR_WHITELIST_ENTRIES > 0 1457 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 1458 static btstack_memory_pool_t whitelist_entry_pool; 1459 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1460 void * buffer = btstack_memory_pool_get(&whitelist_entry_pool); 1461 if (buffer){ 1462 memset(buffer, 0, sizeof(whitelist_entry_t)); 1463 } 1464 return (whitelist_entry_t *) buffer; 1465 } 1466 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1467 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 1468 } 1469 #else 1470 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1471 return NULL; 1472 } 1473 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1474 UNUSED(whitelist_entry); 1475 }; 1476 #endif 1477 #elif defined(HAVE_MALLOC) 1478 1479 typedef struct { 1480 btstack_memory_buffer_t tracking; 1481 whitelist_entry_t data; 1482 } btstack_memory_whitelist_entry_t; 1483 1484 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 1485 btstack_memory_whitelist_entry_t * buffer = (btstack_memory_whitelist_entry_t *) malloc(sizeof(btstack_memory_whitelist_entry_t)); 1486 if (buffer){ 1487 memset(buffer, 0, sizeof(btstack_memory_whitelist_entry_t)); 1488 btstack_memory_tracking_add(&buffer->tracking); 1489 return &buffer->data; 1490 } else { 1491 return NULL; 1492 } 1493 } 1494 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 1495 // reconstruct buffer start 1496 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) whitelist_entry)[-1]; 1497 btstack_memory_tracking_remove(buffer); 1498 free(buffer); 1499 } 1500 #endif 1501 1502 1503 // MARK: periodic_advertiser_list_entry_t 1504 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES) 1505 #if defined(MAX_NO_PERIODIC_ADVERTISER_LIST_ENTRIES) 1506 #error "Deprecated MAX_NO_PERIODIC_ADVERTISER_LIST_ENTRIES defined instead of MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES. Please update your btstack_config.h to use MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES." 1507 #else 1508 #define MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 0 1509 #endif 1510 #endif 1511 1512 #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1513 #if MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES > 0 1514 static periodic_advertiser_list_entry_t periodic_advertiser_list_entry_storage[MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES]; 1515 static btstack_memory_pool_t periodic_advertiser_list_entry_pool; 1516 periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1517 void * buffer = btstack_memory_pool_get(&periodic_advertiser_list_entry_pool); 1518 if (buffer){ 1519 memset(buffer, 0, sizeof(periodic_advertiser_list_entry_t)); 1520 } 1521 return (periodic_advertiser_list_entry_t *) buffer; 1522 } 1523 void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1524 btstack_memory_pool_free(&periodic_advertiser_list_entry_pool, periodic_advertiser_list_entry); 1525 } 1526 #else 1527 periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1528 return NULL; 1529 } 1530 void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1531 UNUSED(periodic_advertiser_list_entry); 1532 }; 1533 #endif 1534 #elif defined(HAVE_MALLOC) 1535 1536 typedef struct { 1537 btstack_memory_buffer_t tracking; 1538 periodic_advertiser_list_entry_t data; 1539 } btstack_memory_periodic_advertiser_list_entry_t; 1540 1541 periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void){ 1542 btstack_memory_periodic_advertiser_list_entry_t * buffer = (btstack_memory_periodic_advertiser_list_entry_t *) malloc(sizeof(btstack_memory_periodic_advertiser_list_entry_t)); 1543 if (buffer){ 1544 memset(buffer, 0, sizeof(btstack_memory_periodic_advertiser_list_entry_t)); 1545 btstack_memory_tracking_add(&buffer->tracking); 1546 return &buffer->data; 1547 } else { 1548 return NULL; 1549 } 1550 } 1551 void btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry){ 1552 // reconstruct buffer start 1553 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) periodic_advertiser_list_entry)[-1]; 1554 btstack_memory_tracking_remove(buffer); 1555 free(buffer); 1556 } 1557 #endif 1558 1559 1560 #endif 1561 #ifdef ENABLE_MESH 1562 1563 // MARK: mesh_network_pdu_t 1564 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS) 1565 #if defined(MAX_NO_MESH_NETWORK_PDUS) 1566 #error "Deprecated MAX_NO_MESH_NETWORK_PDUS defined instead of MAX_NR_MESH_NETWORK_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_PDUS." 1567 #else 1568 #define MAX_NR_MESH_NETWORK_PDUS 0 1569 #endif 1570 #endif 1571 1572 #ifdef MAX_NR_MESH_NETWORK_PDUS 1573 #if MAX_NR_MESH_NETWORK_PDUS > 0 1574 static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS]; 1575 static btstack_memory_pool_t mesh_network_pdu_pool; 1576 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 1577 void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool); 1578 if (buffer){ 1579 memset(buffer, 0, sizeof(mesh_network_pdu_t)); 1580 } 1581 return (mesh_network_pdu_t *) buffer; 1582 } 1583 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1584 btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu); 1585 } 1586 #else 1587 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 1588 return NULL; 1589 } 1590 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1591 UNUSED(mesh_network_pdu); 1592 }; 1593 #endif 1594 #elif defined(HAVE_MALLOC) 1595 1596 typedef struct { 1597 btstack_memory_buffer_t tracking; 1598 mesh_network_pdu_t data; 1599 } btstack_memory_mesh_network_pdu_t; 1600 1601 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 1602 btstack_memory_mesh_network_pdu_t * buffer = (btstack_memory_mesh_network_pdu_t *) malloc(sizeof(btstack_memory_mesh_network_pdu_t)); 1603 if (buffer){ 1604 memset(buffer, 0, sizeof(btstack_memory_mesh_network_pdu_t)); 1605 btstack_memory_tracking_add(&buffer->tracking); 1606 return &buffer->data; 1607 } else { 1608 return NULL; 1609 } 1610 } 1611 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 1612 // reconstruct buffer start 1613 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_pdu)[-1]; 1614 btstack_memory_tracking_remove(buffer); 1615 free(buffer); 1616 } 1617 #endif 1618 1619 1620 // MARK: mesh_segmented_pdu_t 1621 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SEGMENTED_PDUS) 1622 #if defined(MAX_NO_MESH_SEGMENTED_PDUS) 1623 #error "Deprecated MAX_NO_MESH_SEGMENTED_PDUS defined instead of MAX_NR_MESH_SEGMENTED_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_SEGMENTED_PDUS." 1624 #else 1625 #define MAX_NR_MESH_SEGMENTED_PDUS 0 1626 #endif 1627 #endif 1628 1629 #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1630 #if MAX_NR_MESH_SEGMENTED_PDUS > 0 1631 static mesh_segmented_pdu_t mesh_segmented_pdu_storage[MAX_NR_MESH_SEGMENTED_PDUS]; 1632 static btstack_memory_pool_t mesh_segmented_pdu_pool; 1633 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1634 void * buffer = btstack_memory_pool_get(&mesh_segmented_pdu_pool); 1635 if (buffer){ 1636 memset(buffer, 0, sizeof(mesh_segmented_pdu_t)); 1637 } 1638 return (mesh_segmented_pdu_t *) buffer; 1639 } 1640 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1641 btstack_memory_pool_free(&mesh_segmented_pdu_pool, mesh_segmented_pdu); 1642 } 1643 #else 1644 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1645 return NULL; 1646 } 1647 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1648 UNUSED(mesh_segmented_pdu); 1649 }; 1650 #endif 1651 #elif defined(HAVE_MALLOC) 1652 1653 typedef struct { 1654 btstack_memory_buffer_t tracking; 1655 mesh_segmented_pdu_t data; 1656 } btstack_memory_mesh_segmented_pdu_t; 1657 1658 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void){ 1659 btstack_memory_mesh_segmented_pdu_t * buffer = (btstack_memory_mesh_segmented_pdu_t *) malloc(sizeof(btstack_memory_mesh_segmented_pdu_t)); 1660 if (buffer){ 1661 memset(buffer, 0, sizeof(btstack_memory_mesh_segmented_pdu_t)); 1662 btstack_memory_tracking_add(&buffer->tracking); 1663 return &buffer->data; 1664 } else { 1665 return NULL; 1666 } 1667 } 1668 void btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu){ 1669 // reconstruct buffer start 1670 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_segmented_pdu)[-1]; 1671 btstack_memory_tracking_remove(buffer); 1672 free(buffer); 1673 } 1674 #endif 1675 1676 1677 // MARK: mesh_upper_transport_pdu_t 1678 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_UPPER_TRANSPORT_PDUS) 1679 #if defined(MAX_NO_MESH_UPPER_TRANSPORT_PDUS) 1680 #error "Deprecated MAX_NO_MESH_UPPER_TRANSPORT_PDUS defined instead of MAX_NR_MESH_UPPER_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_UPPER_TRANSPORT_PDUS." 1681 #else 1682 #define MAX_NR_MESH_UPPER_TRANSPORT_PDUS 0 1683 #endif 1684 #endif 1685 1686 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1687 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 1688 static mesh_upper_transport_pdu_t mesh_upper_transport_pdu_storage[MAX_NR_MESH_UPPER_TRANSPORT_PDUS]; 1689 static btstack_memory_pool_t mesh_upper_transport_pdu_pool; 1690 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1691 void * buffer = btstack_memory_pool_get(&mesh_upper_transport_pdu_pool); 1692 if (buffer){ 1693 memset(buffer, 0, sizeof(mesh_upper_transport_pdu_t)); 1694 } 1695 return (mesh_upper_transport_pdu_t *) buffer; 1696 } 1697 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1698 btstack_memory_pool_free(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu); 1699 } 1700 #else 1701 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1702 return NULL; 1703 } 1704 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1705 UNUSED(mesh_upper_transport_pdu); 1706 }; 1707 #endif 1708 #elif defined(HAVE_MALLOC) 1709 1710 typedef struct { 1711 btstack_memory_buffer_t tracking; 1712 mesh_upper_transport_pdu_t data; 1713 } btstack_memory_mesh_upper_transport_pdu_t; 1714 1715 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void){ 1716 btstack_memory_mesh_upper_transport_pdu_t * buffer = (btstack_memory_mesh_upper_transport_pdu_t *) malloc(sizeof(btstack_memory_mesh_upper_transport_pdu_t)); 1717 if (buffer){ 1718 memset(buffer, 0, sizeof(btstack_memory_mesh_upper_transport_pdu_t)); 1719 btstack_memory_tracking_add(&buffer->tracking); 1720 return &buffer->data; 1721 } else { 1722 return NULL; 1723 } 1724 } 1725 void btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu){ 1726 // reconstruct buffer start 1727 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_upper_transport_pdu)[-1]; 1728 btstack_memory_tracking_remove(buffer); 1729 free(buffer); 1730 } 1731 #endif 1732 1733 1734 // MARK: mesh_network_key_t 1735 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS) 1736 #if defined(MAX_NO_MESH_NETWORK_KEYS) 1737 #error "Deprecated MAX_NO_MESH_NETWORK_KEYS defined instead of MAX_NR_MESH_NETWORK_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_KEYS." 1738 #else 1739 #define MAX_NR_MESH_NETWORK_KEYS 0 1740 #endif 1741 #endif 1742 1743 #ifdef MAX_NR_MESH_NETWORK_KEYS 1744 #if MAX_NR_MESH_NETWORK_KEYS > 0 1745 static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS]; 1746 static btstack_memory_pool_t mesh_network_key_pool; 1747 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1748 void * buffer = btstack_memory_pool_get(&mesh_network_key_pool); 1749 if (buffer){ 1750 memset(buffer, 0, sizeof(mesh_network_key_t)); 1751 } 1752 return (mesh_network_key_t *) buffer; 1753 } 1754 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1755 btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key); 1756 } 1757 #else 1758 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1759 return NULL; 1760 } 1761 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1762 UNUSED(mesh_network_key); 1763 }; 1764 #endif 1765 #elif defined(HAVE_MALLOC) 1766 1767 typedef struct { 1768 btstack_memory_buffer_t tracking; 1769 mesh_network_key_t data; 1770 } btstack_memory_mesh_network_key_t; 1771 1772 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1773 btstack_memory_mesh_network_key_t * buffer = (btstack_memory_mesh_network_key_t *) malloc(sizeof(btstack_memory_mesh_network_key_t)); 1774 if (buffer){ 1775 memset(buffer, 0, sizeof(btstack_memory_mesh_network_key_t)); 1776 btstack_memory_tracking_add(&buffer->tracking); 1777 return &buffer->data; 1778 } else { 1779 return NULL; 1780 } 1781 } 1782 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1783 // reconstruct buffer start 1784 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_network_key)[-1]; 1785 btstack_memory_tracking_remove(buffer); 1786 free(buffer); 1787 } 1788 #endif 1789 1790 1791 // MARK: mesh_transport_key_t 1792 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS) 1793 #if defined(MAX_NO_MESH_TRANSPORT_KEYS) 1794 #error "Deprecated MAX_NO_MESH_TRANSPORT_KEYS defined instead of MAX_NR_MESH_TRANSPORT_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_KEYS." 1795 #else 1796 #define MAX_NR_MESH_TRANSPORT_KEYS 0 1797 #endif 1798 #endif 1799 1800 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1801 #if MAX_NR_MESH_TRANSPORT_KEYS > 0 1802 static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS]; 1803 static btstack_memory_pool_t mesh_transport_key_pool; 1804 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1805 void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool); 1806 if (buffer){ 1807 memset(buffer, 0, sizeof(mesh_transport_key_t)); 1808 } 1809 return (mesh_transport_key_t *) buffer; 1810 } 1811 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1812 btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key); 1813 } 1814 #else 1815 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1816 return NULL; 1817 } 1818 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1819 UNUSED(mesh_transport_key); 1820 }; 1821 #endif 1822 #elif defined(HAVE_MALLOC) 1823 1824 typedef struct { 1825 btstack_memory_buffer_t tracking; 1826 mesh_transport_key_t data; 1827 } btstack_memory_mesh_transport_key_t; 1828 1829 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1830 btstack_memory_mesh_transport_key_t * buffer = (btstack_memory_mesh_transport_key_t *) malloc(sizeof(btstack_memory_mesh_transport_key_t)); 1831 if (buffer){ 1832 memset(buffer, 0, sizeof(btstack_memory_mesh_transport_key_t)); 1833 btstack_memory_tracking_add(&buffer->tracking); 1834 return &buffer->data; 1835 } else { 1836 return NULL; 1837 } 1838 } 1839 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1840 // reconstruct buffer start 1841 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_transport_key)[-1]; 1842 btstack_memory_tracking_remove(buffer); 1843 free(buffer); 1844 } 1845 #endif 1846 1847 1848 // MARK: mesh_virtual_address_t 1849 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS) 1850 #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS) 1851 #error "Deprecated MAX_NO_MESH_VIRTUAL_ADDRESSS defined instead of MAX_NR_MESH_VIRTUAL_ADDRESSS. Please update your btstack_config.h to use MAX_NR_MESH_VIRTUAL_ADDRESSS." 1852 #else 1853 #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0 1854 #endif 1855 #endif 1856 1857 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1858 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 1859 static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS]; 1860 static btstack_memory_pool_t mesh_virtual_address_pool; 1861 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1862 void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool); 1863 if (buffer){ 1864 memset(buffer, 0, sizeof(mesh_virtual_address_t)); 1865 } 1866 return (mesh_virtual_address_t *) buffer; 1867 } 1868 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1869 btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address); 1870 } 1871 #else 1872 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1873 return NULL; 1874 } 1875 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1876 UNUSED(mesh_virtual_address); 1877 }; 1878 #endif 1879 #elif defined(HAVE_MALLOC) 1880 1881 typedef struct { 1882 btstack_memory_buffer_t tracking; 1883 mesh_virtual_address_t data; 1884 } btstack_memory_mesh_virtual_address_t; 1885 1886 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1887 btstack_memory_mesh_virtual_address_t * buffer = (btstack_memory_mesh_virtual_address_t *) malloc(sizeof(btstack_memory_mesh_virtual_address_t)); 1888 if (buffer){ 1889 memset(buffer, 0, sizeof(btstack_memory_mesh_virtual_address_t)); 1890 btstack_memory_tracking_add(&buffer->tracking); 1891 return &buffer->data; 1892 } else { 1893 return NULL; 1894 } 1895 } 1896 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1897 // reconstruct buffer start 1898 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_virtual_address)[-1]; 1899 btstack_memory_tracking_remove(buffer); 1900 free(buffer); 1901 } 1902 #endif 1903 1904 1905 // MARK: mesh_subnet_t 1906 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS) 1907 #if defined(MAX_NO_MESH_SUBNETS) 1908 #error "Deprecated MAX_NO_MESH_SUBNETS defined instead of MAX_NR_MESH_SUBNETS. Please update your btstack_config.h to use MAX_NR_MESH_SUBNETS." 1909 #else 1910 #define MAX_NR_MESH_SUBNETS 0 1911 #endif 1912 #endif 1913 1914 #ifdef MAX_NR_MESH_SUBNETS 1915 #if MAX_NR_MESH_SUBNETS > 0 1916 static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS]; 1917 static btstack_memory_pool_t mesh_subnet_pool; 1918 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1919 void * buffer = btstack_memory_pool_get(&mesh_subnet_pool); 1920 if (buffer){ 1921 memset(buffer, 0, sizeof(mesh_subnet_t)); 1922 } 1923 return (mesh_subnet_t *) buffer; 1924 } 1925 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1926 btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet); 1927 } 1928 #else 1929 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1930 return NULL; 1931 } 1932 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1933 UNUSED(mesh_subnet); 1934 }; 1935 #endif 1936 #elif defined(HAVE_MALLOC) 1937 1938 typedef struct { 1939 btstack_memory_buffer_t tracking; 1940 mesh_subnet_t data; 1941 } btstack_memory_mesh_subnet_t; 1942 1943 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1944 btstack_memory_mesh_subnet_t * buffer = (btstack_memory_mesh_subnet_t *) malloc(sizeof(btstack_memory_mesh_subnet_t)); 1945 if (buffer){ 1946 memset(buffer, 0, sizeof(btstack_memory_mesh_subnet_t)); 1947 btstack_memory_tracking_add(&buffer->tracking); 1948 return &buffer->data; 1949 } else { 1950 return NULL; 1951 } 1952 } 1953 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1954 // reconstruct buffer start 1955 btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) mesh_subnet)[-1]; 1956 btstack_memory_tracking_remove(buffer); 1957 free(buffer); 1958 } 1959 #endif 1960 1961 1962 #endif 1963 1964 // init 1965 void btstack_memory_init(void){ 1966 #ifdef HAVE_MALLOC 1967 // assert that there is no unexpected padding for combined buffer 1968 btstack_assert(sizeof(test_buffer_t) == sizeof(btstack_memory_buffer_t) + sizeof(void *)); 1969 #endif 1970 1971 #if MAX_NR_HCI_CONNECTIONS > 0 1972 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 1973 #endif 1974 #if MAX_NR_L2CAP_SERVICES > 0 1975 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 1976 #endif 1977 #if MAX_NR_L2CAP_CHANNELS > 0 1978 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 1979 #endif 1980 #ifdef ENABLE_CLASSIC 1981 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 1982 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 1983 #endif 1984 #if MAX_NR_RFCOMM_SERVICES > 0 1985 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 1986 #endif 1987 #if MAX_NR_RFCOMM_CHANNELS > 0 1988 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 1989 #endif 1990 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 1991 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)); 1992 #endif 1993 #if MAX_NR_BNEP_SERVICES > 0 1994 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 1995 #endif 1996 #if MAX_NR_BNEP_CHANNELS > 0 1997 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 1998 #endif 1999 #if MAX_NR_GOEP_SERVER_SERVICES > 0 2000 btstack_memory_pool_create(&goep_server_service_pool, goep_server_service_storage, MAX_NR_GOEP_SERVER_SERVICES, sizeof(goep_server_service_t)); 2001 #endif 2002 #if MAX_NR_GOEP_SERVER_CONNECTIONS > 0 2003 btstack_memory_pool_create(&goep_server_connection_pool, goep_server_connection_storage, MAX_NR_GOEP_SERVER_CONNECTIONS, sizeof(goep_server_connection_t)); 2004 #endif 2005 #if MAX_NR_HFP_CONNECTIONS > 0 2006 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 2007 #endif 2008 #if MAX_NR_HID_HOST_CONNECTIONS > 0 2009 btstack_memory_pool_create(&hid_host_connection_pool, hid_host_connection_storage, MAX_NR_HID_HOST_CONNECTIONS, sizeof(hid_host_connection_t)); 2010 #endif 2011 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 2012 btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t)); 2013 #endif 2014 #if MAX_NR_AVDTP_CONNECTIONS > 0 2015 btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t)); 2016 #endif 2017 #if MAX_NR_AVRCP_CONNECTIONS > 0 2018 btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t)); 2019 #endif 2020 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 2021 btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t)); 2022 #endif 2023 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 2024 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 2025 #endif 2026 #endif 2027 #ifdef ENABLE_BLE 2028 #if MAX_NR_BATTERY_SERVICE_CLIENTS > 0 2029 btstack_memory_pool_create(&battery_service_client_pool, battery_service_client_storage, MAX_NR_BATTERY_SERVICE_CLIENTS, sizeof(battery_service_client_t)); 2030 #endif 2031 #if MAX_NR_GATT_CLIENTS > 0 2032 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 2033 #endif 2034 #if MAX_NR_HIDS_CLIENTS > 0 2035 btstack_memory_pool_create(&hids_client_pool, hids_client_storage, MAX_NR_HIDS_CLIENTS, sizeof(hids_client_t)); 2036 #endif 2037 #if MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS > 0 2038 btstack_memory_pool_create(&scan_parameters_service_client_pool, scan_parameters_service_client_storage, MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS, sizeof(scan_parameters_service_client_t)); 2039 #endif 2040 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 2041 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 2042 #endif 2043 #if MAX_NR_WHITELIST_ENTRIES > 0 2044 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 2045 #endif 2046 #if MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES > 0 2047 btstack_memory_pool_create(&periodic_advertiser_list_entry_pool, periodic_advertiser_list_entry_storage, MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES, sizeof(periodic_advertiser_list_entry_t)); 2048 #endif 2049 #endif 2050 #ifdef ENABLE_MESH 2051 #if MAX_NR_MESH_NETWORK_PDUS > 0 2052 btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t)); 2053 #endif 2054 #if MAX_NR_MESH_SEGMENTED_PDUS > 0 2055 btstack_memory_pool_create(&mesh_segmented_pdu_pool, mesh_segmented_pdu_storage, MAX_NR_MESH_SEGMENTED_PDUS, sizeof(mesh_segmented_pdu_t)); 2056 #endif 2057 #if MAX_NR_MESH_UPPER_TRANSPORT_PDUS > 0 2058 btstack_memory_pool_create(&mesh_upper_transport_pdu_pool, mesh_upper_transport_pdu_storage, MAX_NR_MESH_UPPER_TRANSPORT_PDUS, sizeof(mesh_upper_transport_pdu_t)); 2059 #endif 2060 #if MAX_NR_MESH_NETWORK_KEYS > 0 2061 btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t)); 2062 #endif 2063 #if MAX_NR_MESH_TRANSPORT_KEYS > 0 2064 btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t)); 2065 #endif 2066 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 2067 btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t)); 2068 #endif 2069 #if MAX_NR_MESH_SUBNETS > 0 2070 btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t)); 2071 #endif 2072 #endif 2073 } 2074