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