1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define BTSTACK_FILE__ "btstack_memory.c" 39 40 41 /* 42 * btstack_memory.h 43 * 44 * @brief BTstack memory management via configurable memory pools 45 * 46 * @note code generated by tool/btstack_memory_generator.py 47 * @note returnes buffers are initialized with 0 48 * 49 */ 50 51 #include "btstack_memory.h" 52 #include "btstack_memory_pool.h" 53 54 #include <stdlib.h> 55 56 57 58 // MARK: hci_connection_t 59 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS) 60 #if defined(MAX_NO_HCI_CONNECTIONS) 61 #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." 62 #else 63 #define MAX_NR_HCI_CONNECTIONS 0 64 #endif 65 #endif 66 67 #ifdef MAX_NR_HCI_CONNECTIONS 68 #if MAX_NR_HCI_CONNECTIONS > 0 69 static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS]; 70 static btstack_memory_pool_t hci_connection_pool; 71 hci_connection_t * btstack_memory_hci_connection_get(void){ 72 void * buffer = btstack_memory_pool_get(&hci_connection_pool); 73 if (buffer){ 74 memset(buffer, 0, sizeof(hci_connection_t)); 75 } 76 return (hci_connection_t *) buffer; 77 } 78 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 79 btstack_memory_pool_free(&hci_connection_pool, hci_connection); 80 } 81 #else 82 hci_connection_t * btstack_memory_hci_connection_get(void){ 83 return NULL; 84 } 85 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 86 // silence compiler warning about unused parameter in a portable way 87 (void) hci_connection; 88 }; 89 #endif 90 #elif defined(HAVE_MALLOC) 91 hci_connection_t * btstack_memory_hci_connection_get(void){ 92 void * buffer = malloc(sizeof(hci_connection_t)); 93 if (buffer){ 94 memset(buffer, 0, sizeof(hci_connection_t)); 95 } 96 return (hci_connection_t *) buffer; 97 } 98 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 99 free(hci_connection); 100 } 101 #endif 102 103 104 105 // MARK: l2cap_service_t 106 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES) 107 #if defined(MAX_NO_L2CAP_SERVICES) 108 #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." 109 #else 110 #define MAX_NR_L2CAP_SERVICES 0 111 #endif 112 #endif 113 114 #ifdef MAX_NR_L2CAP_SERVICES 115 #if MAX_NR_L2CAP_SERVICES > 0 116 static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES]; 117 static btstack_memory_pool_t l2cap_service_pool; 118 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 119 void * buffer = btstack_memory_pool_get(&l2cap_service_pool); 120 if (buffer){ 121 memset(buffer, 0, sizeof(l2cap_service_t)); 122 } 123 return (l2cap_service_t *) buffer; 124 } 125 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 126 btstack_memory_pool_free(&l2cap_service_pool, l2cap_service); 127 } 128 #else 129 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 130 return NULL; 131 } 132 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 133 // silence compiler warning about unused parameter in a portable way 134 (void) l2cap_service; 135 }; 136 #endif 137 #elif defined(HAVE_MALLOC) 138 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 139 void * buffer = malloc(sizeof(l2cap_service_t)); 140 if (buffer){ 141 memset(buffer, 0, sizeof(l2cap_service_t)); 142 } 143 return (l2cap_service_t *) buffer; 144 } 145 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 146 free(l2cap_service); 147 } 148 #endif 149 150 151 // MARK: l2cap_channel_t 152 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS) 153 #if defined(MAX_NO_L2CAP_CHANNELS) 154 #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." 155 #else 156 #define MAX_NR_L2CAP_CHANNELS 0 157 #endif 158 #endif 159 160 #ifdef MAX_NR_L2CAP_CHANNELS 161 #if MAX_NR_L2CAP_CHANNELS > 0 162 static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS]; 163 static btstack_memory_pool_t l2cap_channel_pool; 164 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 165 void * buffer = btstack_memory_pool_get(&l2cap_channel_pool); 166 if (buffer){ 167 memset(buffer, 0, sizeof(l2cap_channel_t)); 168 } 169 return (l2cap_channel_t *) buffer; 170 } 171 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 172 btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel); 173 } 174 #else 175 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 176 return NULL; 177 } 178 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 179 // silence compiler warning about unused parameter in a portable way 180 (void) l2cap_channel; 181 }; 182 #endif 183 #elif defined(HAVE_MALLOC) 184 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 185 void * buffer = malloc(sizeof(l2cap_channel_t)); 186 if (buffer){ 187 memset(buffer, 0, sizeof(l2cap_channel_t)); 188 } 189 return (l2cap_channel_t *) buffer; 190 } 191 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 192 free(l2cap_channel); 193 } 194 #endif 195 196 197 #ifdef ENABLE_CLASSIC 198 199 // MARK: rfcomm_multiplexer_t 200 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS) 201 #if defined(MAX_NO_RFCOMM_MULTIPLEXERS) 202 #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." 203 #else 204 #define MAX_NR_RFCOMM_MULTIPLEXERS 0 205 #endif 206 #endif 207 208 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 209 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 210 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS]; 211 static btstack_memory_pool_t rfcomm_multiplexer_pool; 212 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 213 void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool); 214 if (buffer){ 215 memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 216 } 217 return (rfcomm_multiplexer_t *) buffer; 218 } 219 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 220 btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 221 } 222 #else 223 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 224 return NULL; 225 } 226 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 227 // silence compiler warning about unused parameter in a portable way 228 (void) rfcomm_multiplexer; 229 }; 230 #endif 231 #elif defined(HAVE_MALLOC) 232 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 233 void * buffer = malloc(sizeof(rfcomm_multiplexer_t)); 234 if (buffer){ 235 memset(buffer, 0, sizeof(rfcomm_multiplexer_t)); 236 } 237 return (rfcomm_multiplexer_t *) buffer; 238 } 239 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 240 free(rfcomm_multiplexer); 241 } 242 #endif 243 244 245 // MARK: rfcomm_service_t 246 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES) 247 #if defined(MAX_NO_RFCOMM_SERVICES) 248 #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." 249 #else 250 #define MAX_NR_RFCOMM_SERVICES 0 251 #endif 252 #endif 253 254 #ifdef MAX_NR_RFCOMM_SERVICES 255 #if MAX_NR_RFCOMM_SERVICES > 0 256 static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES]; 257 static btstack_memory_pool_t rfcomm_service_pool; 258 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 259 void * buffer = btstack_memory_pool_get(&rfcomm_service_pool); 260 if (buffer){ 261 memset(buffer, 0, sizeof(rfcomm_service_t)); 262 } 263 return (rfcomm_service_t *) buffer; 264 } 265 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 266 btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service); 267 } 268 #else 269 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 270 return NULL; 271 } 272 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 273 // silence compiler warning about unused parameter in a portable way 274 (void) rfcomm_service; 275 }; 276 #endif 277 #elif defined(HAVE_MALLOC) 278 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 279 void * buffer = malloc(sizeof(rfcomm_service_t)); 280 if (buffer){ 281 memset(buffer, 0, sizeof(rfcomm_service_t)); 282 } 283 return (rfcomm_service_t *) buffer; 284 } 285 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 286 free(rfcomm_service); 287 } 288 #endif 289 290 291 // MARK: rfcomm_channel_t 292 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS) 293 #if defined(MAX_NO_RFCOMM_CHANNELS) 294 #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." 295 #else 296 #define MAX_NR_RFCOMM_CHANNELS 0 297 #endif 298 #endif 299 300 #ifdef MAX_NR_RFCOMM_CHANNELS 301 #if MAX_NR_RFCOMM_CHANNELS > 0 302 static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS]; 303 static btstack_memory_pool_t rfcomm_channel_pool; 304 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 305 void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool); 306 if (buffer){ 307 memset(buffer, 0, sizeof(rfcomm_channel_t)); 308 } 309 return (rfcomm_channel_t *) buffer; 310 } 311 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 312 btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 313 } 314 #else 315 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 316 return NULL; 317 } 318 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 319 // silence compiler warning about unused parameter in a portable way 320 (void) rfcomm_channel; 321 }; 322 #endif 323 #elif defined(HAVE_MALLOC) 324 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 325 void * buffer = malloc(sizeof(rfcomm_channel_t)); 326 if (buffer){ 327 memset(buffer, 0, sizeof(rfcomm_channel_t)); 328 } 329 return (rfcomm_channel_t *) buffer; 330 } 331 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 332 free(rfcomm_channel); 333 } 334 #endif 335 336 337 338 // MARK: btstack_link_key_db_memory_entry_t 339 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 340 #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES) 341 #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." 342 #else 343 #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 344 #endif 345 #endif 346 347 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 348 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 349 static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES]; 350 static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool; 351 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 352 void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool); 353 if (buffer){ 354 memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 355 } 356 return (btstack_link_key_db_memory_entry_t *) buffer; 357 } 358 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 359 btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry); 360 } 361 #else 362 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 363 return NULL; 364 } 365 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 366 // silence compiler warning about unused parameter in a portable way 367 (void) btstack_link_key_db_memory_entry; 368 }; 369 #endif 370 #elif defined(HAVE_MALLOC) 371 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){ 372 void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t)); 373 if (buffer){ 374 memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t)); 375 } 376 return (btstack_link_key_db_memory_entry_t *) buffer; 377 } 378 void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){ 379 free(btstack_link_key_db_memory_entry); 380 } 381 #endif 382 383 384 385 // MARK: bnep_service_t 386 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES) 387 #if defined(MAX_NO_BNEP_SERVICES) 388 #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." 389 #else 390 #define MAX_NR_BNEP_SERVICES 0 391 #endif 392 #endif 393 394 #ifdef MAX_NR_BNEP_SERVICES 395 #if MAX_NR_BNEP_SERVICES > 0 396 static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES]; 397 static btstack_memory_pool_t bnep_service_pool; 398 bnep_service_t * btstack_memory_bnep_service_get(void){ 399 void * buffer = btstack_memory_pool_get(&bnep_service_pool); 400 if (buffer){ 401 memset(buffer, 0, sizeof(bnep_service_t)); 402 } 403 return (bnep_service_t *) buffer; 404 } 405 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 406 btstack_memory_pool_free(&bnep_service_pool, bnep_service); 407 } 408 #else 409 bnep_service_t * btstack_memory_bnep_service_get(void){ 410 return NULL; 411 } 412 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 413 // silence compiler warning about unused parameter in a portable way 414 (void) bnep_service; 415 }; 416 #endif 417 #elif defined(HAVE_MALLOC) 418 bnep_service_t * btstack_memory_bnep_service_get(void){ 419 void * buffer = malloc(sizeof(bnep_service_t)); 420 if (buffer){ 421 memset(buffer, 0, sizeof(bnep_service_t)); 422 } 423 return (bnep_service_t *) buffer; 424 } 425 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 426 free(bnep_service); 427 } 428 #endif 429 430 431 // MARK: bnep_channel_t 432 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS) 433 #if defined(MAX_NO_BNEP_CHANNELS) 434 #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." 435 #else 436 #define MAX_NR_BNEP_CHANNELS 0 437 #endif 438 #endif 439 440 #ifdef MAX_NR_BNEP_CHANNELS 441 #if MAX_NR_BNEP_CHANNELS > 0 442 static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS]; 443 static btstack_memory_pool_t bnep_channel_pool; 444 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 445 void * buffer = btstack_memory_pool_get(&bnep_channel_pool); 446 if (buffer){ 447 memset(buffer, 0, sizeof(bnep_channel_t)); 448 } 449 return (bnep_channel_t *) buffer; 450 } 451 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 452 btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 453 } 454 #else 455 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 456 return NULL; 457 } 458 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 459 // silence compiler warning about unused parameter in a portable way 460 (void) bnep_channel; 461 }; 462 #endif 463 #elif defined(HAVE_MALLOC) 464 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 465 void * buffer = malloc(sizeof(bnep_channel_t)); 466 if (buffer){ 467 memset(buffer, 0, sizeof(bnep_channel_t)); 468 } 469 return (bnep_channel_t *) buffer; 470 } 471 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 472 free(bnep_channel); 473 } 474 #endif 475 476 477 478 // MARK: hfp_connection_t 479 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS) 480 #if defined(MAX_NO_HFP_CONNECTIONS) 481 #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." 482 #else 483 #define MAX_NR_HFP_CONNECTIONS 0 484 #endif 485 #endif 486 487 #ifdef MAX_NR_HFP_CONNECTIONS 488 #if MAX_NR_HFP_CONNECTIONS > 0 489 static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS]; 490 static btstack_memory_pool_t hfp_connection_pool; 491 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 492 void * buffer = btstack_memory_pool_get(&hfp_connection_pool); 493 if (buffer){ 494 memset(buffer, 0, sizeof(hfp_connection_t)); 495 } 496 return (hfp_connection_t *) buffer; 497 } 498 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 499 btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 500 } 501 #else 502 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 503 return NULL; 504 } 505 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 506 // silence compiler warning about unused parameter in a portable way 507 (void) hfp_connection; 508 }; 509 #endif 510 #elif defined(HAVE_MALLOC) 511 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 512 void * buffer = malloc(sizeof(hfp_connection_t)); 513 if (buffer){ 514 memset(buffer, 0, sizeof(hfp_connection_t)); 515 } 516 return (hfp_connection_t *) buffer; 517 } 518 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 519 free(hfp_connection); 520 } 521 #endif 522 523 524 525 // MARK: service_record_item_t 526 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) 527 #if defined(MAX_NO_SERVICE_RECORD_ITEMS) 528 #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." 529 #else 530 #define MAX_NR_SERVICE_RECORD_ITEMS 0 531 #endif 532 #endif 533 534 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 535 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 536 static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS]; 537 static btstack_memory_pool_t service_record_item_pool; 538 service_record_item_t * btstack_memory_service_record_item_get(void){ 539 void * buffer = btstack_memory_pool_get(&service_record_item_pool); 540 if (buffer){ 541 memset(buffer, 0, sizeof(service_record_item_t)); 542 } 543 return (service_record_item_t *) buffer; 544 } 545 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 546 btstack_memory_pool_free(&service_record_item_pool, service_record_item); 547 } 548 #else 549 service_record_item_t * btstack_memory_service_record_item_get(void){ 550 return NULL; 551 } 552 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 553 // silence compiler warning about unused parameter in a portable way 554 (void) service_record_item; 555 }; 556 #endif 557 #elif defined(HAVE_MALLOC) 558 service_record_item_t * btstack_memory_service_record_item_get(void){ 559 void * buffer = malloc(sizeof(service_record_item_t)); 560 if (buffer){ 561 memset(buffer, 0, sizeof(service_record_item_t)); 562 } 563 return (service_record_item_t *) buffer; 564 } 565 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 566 free(service_record_item); 567 } 568 #endif 569 570 571 572 // MARK: avdtp_stream_endpoint_t 573 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS) 574 #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS) 575 #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." 576 #else 577 #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0 578 #endif 579 #endif 580 581 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 582 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 583 static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS]; 584 static btstack_memory_pool_t avdtp_stream_endpoint_pool; 585 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 586 void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool); 587 if (buffer){ 588 memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 589 } 590 return (avdtp_stream_endpoint_t *) buffer; 591 } 592 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 593 btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint); 594 } 595 #else 596 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 597 return NULL; 598 } 599 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 600 // silence compiler warning about unused parameter in a portable way 601 (void) avdtp_stream_endpoint; 602 }; 603 #endif 604 #elif defined(HAVE_MALLOC) 605 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){ 606 void * buffer = malloc(sizeof(avdtp_stream_endpoint_t)); 607 if (buffer){ 608 memset(buffer, 0, sizeof(avdtp_stream_endpoint_t)); 609 } 610 return (avdtp_stream_endpoint_t *) buffer; 611 } 612 void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){ 613 free(avdtp_stream_endpoint); 614 } 615 #endif 616 617 618 619 // MARK: avdtp_connection_t 620 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS) 621 #if defined(MAX_NO_AVDTP_CONNECTIONS) 622 #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." 623 #else 624 #define MAX_NR_AVDTP_CONNECTIONS 0 625 #endif 626 #endif 627 628 #ifdef MAX_NR_AVDTP_CONNECTIONS 629 #if MAX_NR_AVDTP_CONNECTIONS > 0 630 static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS]; 631 static btstack_memory_pool_t avdtp_connection_pool; 632 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 633 void * buffer = btstack_memory_pool_get(&avdtp_connection_pool); 634 if (buffer){ 635 memset(buffer, 0, sizeof(avdtp_connection_t)); 636 } 637 return (avdtp_connection_t *) buffer; 638 } 639 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 640 btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection); 641 } 642 #else 643 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 644 return NULL; 645 } 646 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 647 // silence compiler warning about unused parameter in a portable way 648 (void) avdtp_connection; 649 }; 650 #endif 651 #elif defined(HAVE_MALLOC) 652 avdtp_connection_t * btstack_memory_avdtp_connection_get(void){ 653 void * buffer = malloc(sizeof(avdtp_connection_t)); 654 if (buffer){ 655 memset(buffer, 0, sizeof(avdtp_connection_t)); 656 } 657 return (avdtp_connection_t *) buffer; 658 } 659 void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){ 660 free(avdtp_connection); 661 } 662 #endif 663 664 665 666 // MARK: avrcp_connection_t 667 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS) 668 #if defined(MAX_NO_AVRCP_CONNECTIONS) 669 #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." 670 #else 671 #define MAX_NR_AVRCP_CONNECTIONS 0 672 #endif 673 #endif 674 675 #ifdef MAX_NR_AVRCP_CONNECTIONS 676 #if MAX_NR_AVRCP_CONNECTIONS > 0 677 static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS]; 678 static btstack_memory_pool_t avrcp_connection_pool; 679 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 680 void * buffer = btstack_memory_pool_get(&avrcp_connection_pool); 681 if (buffer){ 682 memset(buffer, 0, sizeof(avrcp_connection_t)); 683 } 684 return (avrcp_connection_t *) buffer; 685 } 686 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 687 btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection); 688 } 689 #else 690 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 691 return NULL; 692 } 693 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 694 // silence compiler warning about unused parameter in a portable way 695 (void) avrcp_connection; 696 }; 697 #endif 698 #elif defined(HAVE_MALLOC) 699 avrcp_connection_t * btstack_memory_avrcp_connection_get(void){ 700 void * buffer = malloc(sizeof(avrcp_connection_t)); 701 if (buffer){ 702 memset(buffer, 0, sizeof(avrcp_connection_t)); 703 } 704 return (avrcp_connection_t *) buffer; 705 } 706 void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){ 707 free(avrcp_connection); 708 } 709 #endif 710 711 712 713 // MARK: avrcp_browsing_connection_t 714 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS) 715 #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS) 716 #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." 717 #else 718 #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0 719 #endif 720 #endif 721 722 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 723 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 724 static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS]; 725 static btstack_memory_pool_t avrcp_browsing_connection_pool; 726 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 727 void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool); 728 if (buffer){ 729 memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 730 } 731 return (avrcp_browsing_connection_t *) buffer; 732 } 733 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 734 btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection); 735 } 736 #else 737 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 738 return NULL; 739 } 740 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 741 // silence compiler warning about unused parameter in a portable way 742 (void) avrcp_browsing_connection; 743 }; 744 #endif 745 #elif defined(HAVE_MALLOC) 746 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){ 747 void * buffer = malloc(sizeof(avrcp_browsing_connection_t)); 748 if (buffer){ 749 memset(buffer, 0, sizeof(avrcp_browsing_connection_t)); 750 } 751 return (avrcp_browsing_connection_t *) buffer; 752 } 753 void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){ 754 free(avrcp_browsing_connection); 755 } 756 #endif 757 758 759 #endif 760 #ifdef ENABLE_BLE 761 762 // MARK: gatt_client_t 763 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 764 #if defined(MAX_NO_GATT_CLIENTS) 765 #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." 766 #else 767 #define MAX_NR_GATT_CLIENTS 0 768 #endif 769 #endif 770 771 #ifdef MAX_NR_GATT_CLIENTS 772 #if MAX_NR_GATT_CLIENTS > 0 773 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 774 static btstack_memory_pool_t gatt_client_pool; 775 gatt_client_t * btstack_memory_gatt_client_get(void){ 776 void * buffer = btstack_memory_pool_get(&gatt_client_pool); 777 if (buffer){ 778 memset(buffer, 0, sizeof(gatt_client_t)); 779 } 780 return (gatt_client_t *) buffer; 781 } 782 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 783 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 784 } 785 #else 786 gatt_client_t * btstack_memory_gatt_client_get(void){ 787 return NULL; 788 } 789 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 790 // silence compiler warning about unused parameter in a portable way 791 (void) gatt_client; 792 }; 793 #endif 794 #elif defined(HAVE_MALLOC) 795 gatt_client_t * btstack_memory_gatt_client_get(void){ 796 void * buffer = malloc(sizeof(gatt_client_t)); 797 if (buffer){ 798 memset(buffer, 0, sizeof(gatt_client_t)); 799 } 800 return (gatt_client_t *) buffer; 801 } 802 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 803 free(gatt_client); 804 } 805 #endif 806 807 808 // MARK: whitelist_entry_t 809 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 810 #if defined(MAX_NO_WHITELIST_ENTRIES) 811 #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." 812 #else 813 #define MAX_NR_WHITELIST_ENTRIES 0 814 #endif 815 #endif 816 817 #ifdef MAX_NR_WHITELIST_ENTRIES 818 #if MAX_NR_WHITELIST_ENTRIES > 0 819 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 820 static btstack_memory_pool_t whitelist_entry_pool; 821 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 822 void * buffer = btstack_memory_pool_get(&whitelist_entry_pool); 823 if (buffer){ 824 memset(buffer, 0, sizeof(whitelist_entry_t)); 825 } 826 return (whitelist_entry_t *) buffer; 827 } 828 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 829 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 830 } 831 #else 832 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 833 return NULL; 834 } 835 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 836 // silence compiler warning about unused parameter in a portable way 837 (void) whitelist_entry; 838 }; 839 #endif 840 #elif defined(HAVE_MALLOC) 841 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 842 void * buffer = malloc(sizeof(whitelist_entry_t)); 843 if (buffer){ 844 memset(buffer, 0, sizeof(whitelist_entry_t)); 845 } 846 return (whitelist_entry_t *) buffer; 847 } 848 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 849 free(whitelist_entry); 850 } 851 #endif 852 853 854 // MARK: sm_lookup_entry_t 855 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 856 #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 857 #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." 858 #else 859 #define MAX_NR_SM_LOOKUP_ENTRIES 0 860 #endif 861 #endif 862 863 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 864 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 865 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 866 static btstack_memory_pool_t sm_lookup_entry_pool; 867 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 868 void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool); 869 if (buffer){ 870 memset(buffer, 0, sizeof(sm_lookup_entry_t)); 871 } 872 return (sm_lookup_entry_t *) buffer; 873 } 874 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 875 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 876 } 877 #else 878 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 879 return NULL; 880 } 881 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 882 // silence compiler warning about unused parameter in a portable way 883 (void) sm_lookup_entry; 884 }; 885 #endif 886 #elif defined(HAVE_MALLOC) 887 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 888 void * buffer = malloc(sizeof(sm_lookup_entry_t)); 889 if (buffer){ 890 memset(buffer, 0, sizeof(sm_lookup_entry_t)); 891 } 892 return (sm_lookup_entry_t *) buffer; 893 } 894 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 895 free(sm_lookup_entry); 896 } 897 #endif 898 899 900 #endif 901 #ifdef ENABLE_MESH 902 903 // MARK: mesh_network_pdu_t 904 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS) 905 #if defined(MAX_NO_MESH_NETWORK_PDUS) 906 #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." 907 #else 908 #define MAX_NR_MESH_NETWORK_PDUS 0 909 #endif 910 #endif 911 912 #ifdef MAX_NR_MESH_NETWORK_PDUS 913 #if MAX_NR_MESH_NETWORK_PDUS > 0 914 static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS]; 915 static btstack_memory_pool_t mesh_network_pdu_pool; 916 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 917 void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool); 918 if (buffer){ 919 memset(buffer, 0, sizeof(mesh_network_pdu_t)); 920 } 921 return (mesh_network_pdu_t *) buffer; 922 } 923 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 924 btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu); 925 } 926 #else 927 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 928 return NULL; 929 } 930 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 931 // silence compiler warning about unused parameter in a portable way 932 (void) mesh_network_pdu; 933 }; 934 #endif 935 #elif defined(HAVE_MALLOC) 936 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){ 937 void * buffer = malloc(sizeof(mesh_network_pdu_t)); 938 if (buffer){ 939 memset(buffer, 0, sizeof(mesh_network_pdu_t)); 940 } 941 return (mesh_network_pdu_t *) buffer; 942 } 943 void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){ 944 free(mesh_network_pdu); 945 } 946 #endif 947 948 949 // MARK: mesh_transport_pdu_t 950 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_PDUS) 951 #if defined(MAX_NO_MESH_TRANSPORT_PDUS) 952 #error "Deprecated MAX_NO_MESH_TRANSPORT_PDUS defined instead of MAX_NR_MESH_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_PDUS." 953 #else 954 #define MAX_NR_MESH_TRANSPORT_PDUS 0 955 #endif 956 #endif 957 958 #ifdef MAX_NR_MESH_TRANSPORT_PDUS 959 #if MAX_NR_MESH_TRANSPORT_PDUS > 0 960 static mesh_transport_pdu_t mesh_transport_pdu_storage[MAX_NR_MESH_TRANSPORT_PDUS]; 961 static btstack_memory_pool_t mesh_transport_pdu_pool; 962 mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 963 void * buffer = btstack_memory_pool_get(&mesh_transport_pdu_pool); 964 if (buffer){ 965 memset(buffer, 0, sizeof(mesh_transport_pdu_t)); 966 } 967 return (mesh_transport_pdu_t *) buffer; 968 } 969 void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 970 btstack_memory_pool_free(&mesh_transport_pdu_pool, mesh_transport_pdu); 971 } 972 #else 973 mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 974 return NULL; 975 } 976 void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 977 // silence compiler warning about unused parameter in a portable way 978 (void) mesh_transport_pdu; 979 }; 980 #endif 981 #elif defined(HAVE_MALLOC) 982 mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){ 983 void * buffer = malloc(sizeof(mesh_transport_pdu_t)); 984 if (buffer){ 985 memset(buffer, 0, sizeof(mesh_transport_pdu_t)); 986 } 987 return (mesh_transport_pdu_t *) buffer; 988 } 989 void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){ 990 free(mesh_transport_pdu); 991 } 992 #endif 993 994 995 // MARK: mesh_network_key_t 996 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS) 997 #if defined(MAX_NO_MESH_NETWORK_KEYS) 998 #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." 999 #else 1000 #define MAX_NR_MESH_NETWORK_KEYS 0 1001 #endif 1002 #endif 1003 1004 #ifdef MAX_NR_MESH_NETWORK_KEYS 1005 #if MAX_NR_MESH_NETWORK_KEYS > 0 1006 static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS]; 1007 static btstack_memory_pool_t mesh_network_key_pool; 1008 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1009 void * buffer = btstack_memory_pool_get(&mesh_network_key_pool); 1010 if (buffer){ 1011 memset(buffer, 0, sizeof(mesh_network_key_t)); 1012 } 1013 return (mesh_network_key_t *) buffer; 1014 } 1015 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1016 btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key); 1017 } 1018 #else 1019 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1020 return NULL; 1021 } 1022 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1023 // silence compiler warning about unused parameter in a portable way 1024 (void) mesh_network_key; 1025 }; 1026 #endif 1027 #elif defined(HAVE_MALLOC) 1028 mesh_network_key_t * btstack_memory_mesh_network_key_get(void){ 1029 void * buffer = malloc(sizeof(mesh_network_key_t)); 1030 if (buffer){ 1031 memset(buffer, 0, sizeof(mesh_network_key_t)); 1032 } 1033 return (mesh_network_key_t *) buffer; 1034 } 1035 void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){ 1036 free(mesh_network_key); 1037 } 1038 #endif 1039 1040 1041 // MARK: mesh_transport_key_t 1042 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS) 1043 #if defined(MAX_NO_MESH_TRANSPORT_KEYS) 1044 #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." 1045 #else 1046 #define MAX_NR_MESH_TRANSPORT_KEYS 0 1047 #endif 1048 #endif 1049 1050 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1051 #if MAX_NR_MESH_TRANSPORT_KEYS > 0 1052 static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS]; 1053 static btstack_memory_pool_t mesh_transport_key_pool; 1054 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1055 void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool); 1056 if (buffer){ 1057 memset(buffer, 0, sizeof(mesh_transport_key_t)); 1058 } 1059 return (mesh_transport_key_t *) buffer; 1060 } 1061 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1062 btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key); 1063 } 1064 #else 1065 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1066 return NULL; 1067 } 1068 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1069 // silence compiler warning about unused parameter in a portable way 1070 (void) mesh_transport_key; 1071 }; 1072 #endif 1073 #elif defined(HAVE_MALLOC) 1074 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){ 1075 void * buffer = malloc(sizeof(mesh_transport_key_t)); 1076 if (buffer){ 1077 memset(buffer, 0, sizeof(mesh_transport_key_t)); 1078 } 1079 return (mesh_transport_key_t *) buffer; 1080 } 1081 void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){ 1082 free(mesh_transport_key); 1083 } 1084 #endif 1085 1086 1087 // MARK: mesh_virtual_address_t 1088 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS) 1089 #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS) 1090 #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." 1091 #else 1092 #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0 1093 #endif 1094 #endif 1095 1096 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1097 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 1098 static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS]; 1099 static btstack_memory_pool_t mesh_virtual_address_pool; 1100 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1101 void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool); 1102 if (buffer){ 1103 memset(buffer, 0, sizeof(mesh_virtual_address_t)); 1104 } 1105 return (mesh_virtual_address_t *) buffer; 1106 } 1107 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1108 btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address); 1109 } 1110 #else 1111 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1112 return NULL; 1113 } 1114 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1115 // silence compiler warning about unused parameter in a portable way 1116 (void) mesh_virtual_address; 1117 }; 1118 #endif 1119 #elif defined(HAVE_MALLOC) 1120 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){ 1121 void * buffer = malloc(sizeof(mesh_virtual_address_t)); 1122 if (buffer){ 1123 memset(buffer, 0, sizeof(mesh_virtual_address_t)); 1124 } 1125 return (mesh_virtual_address_t *) buffer; 1126 } 1127 void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){ 1128 free(mesh_virtual_address); 1129 } 1130 #endif 1131 1132 1133 // MARK: mesh_subnet_t 1134 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS) 1135 #if defined(MAX_NO_MESH_SUBNETS) 1136 #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." 1137 #else 1138 #define MAX_NR_MESH_SUBNETS 0 1139 #endif 1140 #endif 1141 1142 #ifdef MAX_NR_MESH_SUBNETS 1143 #if MAX_NR_MESH_SUBNETS > 0 1144 static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS]; 1145 static btstack_memory_pool_t mesh_subnet_pool; 1146 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1147 void * buffer = btstack_memory_pool_get(&mesh_subnet_pool); 1148 if (buffer){ 1149 memset(buffer, 0, sizeof(mesh_subnet_t)); 1150 } 1151 return (mesh_subnet_t *) buffer; 1152 } 1153 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1154 btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet); 1155 } 1156 #else 1157 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1158 return NULL; 1159 } 1160 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1161 // silence compiler warning about unused parameter in a portable way 1162 (void) mesh_subnet; 1163 }; 1164 #endif 1165 #elif defined(HAVE_MALLOC) 1166 mesh_subnet_t * btstack_memory_mesh_subnet_get(void){ 1167 void * buffer = malloc(sizeof(mesh_subnet_t)); 1168 if (buffer){ 1169 memset(buffer, 0, sizeof(mesh_subnet_t)); 1170 } 1171 return (mesh_subnet_t *) buffer; 1172 } 1173 void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ 1174 free(mesh_subnet); 1175 } 1176 #endif 1177 1178 1179 #endif 1180 // init 1181 void btstack_memory_init(void){ 1182 #if MAX_NR_HCI_CONNECTIONS > 0 1183 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 1184 #endif 1185 #if MAX_NR_L2CAP_SERVICES > 0 1186 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 1187 #endif 1188 #if MAX_NR_L2CAP_CHANNELS > 0 1189 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 1190 #endif 1191 #ifdef ENABLE_CLASSIC 1192 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 1193 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 1194 #endif 1195 #if MAX_NR_RFCOMM_SERVICES > 0 1196 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 1197 #endif 1198 #if MAX_NR_RFCOMM_CHANNELS > 0 1199 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 1200 #endif 1201 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 1202 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)); 1203 #endif 1204 #if MAX_NR_BNEP_SERVICES > 0 1205 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 1206 #endif 1207 #if MAX_NR_BNEP_CHANNELS > 0 1208 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 1209 #endif 1210 #if MAX_NR_HFP_CONNECTIONS > 0 1211 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 1212 #endif 1213 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 1214 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 1215 #endif 1216 #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0 1217 btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t)); 1218 #endif 1219 #if MAX_NR_AVDTP_CONNECTIONS > 0 1220 btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t)); 1221 #endif 1222 #if MAX_NR_AVRCP_CONNECTIONS > 0 1223 btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t)); 1224 #endif 1225 #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0 1226 btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t)); 1227 #endif 1228 #endif 1229 #ifdef ENABLE_BLE 1230 #if MAX_NR_GATT_CLIENTS > 0 1231 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 1232 #endif 1233 #if MAX_NR_WHITELIST_ENTRIES > 0 1234 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 1235 #endif 1236 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 1237 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 1238 #endif 1239 #endif 1240 #ifdef ENABLE_MESH 1241 #if MAX_NR_MESH_NETWORK_PDUS > 0 1242 btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t)); 1243 #endif 1244 #if MAX_NR_MESH_TRANSPORT_PDUS > 0 1245 btstack_memory_pool_create(&mesh_transport_pdu_pool, mesh_transport_pdu_storage, MAX_NR_MESH_TRANSPORT_PDUS, sizeof(mesh_transport_pdu_t)); 1246 #endif 1247 #if MAX_NR_MESH_NETWORK_KEYS > 0 1248 btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t)); 1249 #endif 1250 #if MAX_NR_MESH_TRANSPORT_KEYS > 0 1251 btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t)); 1252 #endif 1253 #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0 1254 btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t)); 1255 #endif 1256 #if MAX_NR_MESH_SUBNETS > 0 1257 btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t)); 1258 #endif 1259 #endif 1260 } 1261