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 /* 40 * btstsack_memory.h 41 * 42 * @brief BTstack memory management via configurable memory pools 43 * 44 * @note code semi-atuomatically generated by tools/btstack_memory_generator.py 45 * 46 */ 47 48 #include "btstack_memory.h" 49 #include "memory_pool.h" 50 51 #include <stdlib.h> 52 53 54 55 // MARK: hci_connection_t 56 #ifdef MAX_NO_HCI_CONNECTIONS 57 #if MAX_NO_HCI_CONNECTIONS > 0 58 static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS]; 59 static memory_pool_t hci_connection_pool; 60 hci_connection_t * btstack_memory_hci_connection_get(void){ 61 return (hci_connection_t *) memory_pool_get(&hci_connection_pool); 62 } 63 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 64 memory_pool_free(&hci_connection_pool, hci_connection); 65 } 66 #else 67 hci_connection_t * btstack_memory_hci_connection_get(void){ 68 return NULL; 69 } 70 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 71 // silence compiler warning about unused parameter in a portable way 72 (void) hci_connection; 73 }; 74 #endif 75 #elif defined(HAVE_MALLOC) 76 hci_connection_t * btstack_memory_hci_connection_get(void){ 77 return (hci_connection_t*) malloc(sizeof(hci_connection_t)); 78 } 79 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 80 free(hci_connection); 81 } 82 #else 83 #error "Neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS for struct hci_connection is defined. Please, edit the config file." 84 #endif 85 86 87 88 // MARK: l2cap_service_t 89 #ifdef MAX_NO_L2CAP_SERVICES 90 #if MAX_NO_L2CAP_SERVICES > 0 91 static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES]; 92 static memory_pool_t l2cap_service_pool; 93 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 94 return (l2cap_service_t *) memory_pool_get(&l2cap_service_pool); 95 } 96 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 97 memory_pool_free(&l2cap_service_pool, l2cap_service); 98 } 99 #else 100 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 101 return NULL; 102 } 103 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 104 // silence compiler warning about unused parameter in a portable way 105 (void) l2cap_service; 106 }; 107 #endif 108 #elif defined(HAVE_MALLOC) 109 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 110 return (l2cap_service_t*) malloc(sizeof(l2cap_service_t)); 111 } 112 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 113 free(l2cap_service); 114 } 115 #else 116 #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES for struct l2cap_service is defined. Please, edit the config file." 117 #endif 118 119 120 // MARK: l2cap_channel_t 121 #ifdef MAX_NO_L2CAP_CHANNELS 122 #if MAX_NO_L2CAP_CHANNELS > 0 123 static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS]; 124 static memory_pool_t l2cap_channel_pool; 125 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 126 return (l2cap_channel_t *) memory_pool_get(&l2cap_channel_pool); 127 } 128 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 129 memory_pool_free(&l2cap_channel_pool, l2cap_channel); 130 } 131 #else 132 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 133 return NULL; 134 } 135 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 136 // silence compiler warning about unused parameter in a portable way 137 (void) l2cap_channel; 138 }; 139 #endif 140 #elif defined(HAVE_MALLOC) 141 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 142 return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t)); 143 } 144 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 145 free(l2cap_channel); 146 } 147 #else 148 #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS for struct l2cap_channel is defined. Please, edit the config file." 149 #endif 150 151 152 153 // MARK: rfcomm_multiplexer_t 154 #ifdef MAX_NO_RFCOMM_MULTIPLEXERS 155 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 156 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS]; 157 static memory_pool_t rfcomm_multiplexer_pool; 158 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 159 return (rfcomm_multiplexer_t *) memory_pool_get(&rfcomm_multiplexer_pool); 160 } 161 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 162 memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 163 } 164 #else 165 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 166 return NULL; 167 } 168 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 169 // silence compiler warning about unused parameter in a portable way 170 (void) rfcomm_multiplexer; 171 }; 172 #endif 173 #elif defined(HAVE_MALLOC) 174 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 175 return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t)); 176 } 177 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 178 free(rfcomm_multiplexer); 179 } 180 #else 181 #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS for struct rfcomm_multiplexer is defined. Please, edit the config file." 182 #endif 183 184 185 // MARK: rfcomm_service_t 186 #ifdef MAX_NO_RFCOMM_SERVICES 187 #if MAX_NO_RFCOMM_SERVICES > 0 188 static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES]; 189 static memory_pool_t rfcomm_service_pool; 190 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 191 return (rfcomm_service_t *) memory_pool_get(&rfcomm_service_pool); 192 } 193 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 194 memory_pool_free(&rfcomm_service_pool, rfcomm_service); 195 } 196 #else 197 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 198 return NULL; 199 } 200 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 201 // silence compiler warning about unused parameter in a portable way 202 (void) rfcomm_service; 203 }; 204 #endif 205 #elif defined(HAVE_MALLOC) 206 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 207 return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t)); 208 } 209 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 210 free(rfcomm_service); 211 } 212 #else 213 #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES for struct rfcomm_service is defined. Please, edit the config file." 214 #endif 215 216 217 // MARK: rfcomm_channel_t 218 #ifdef MAX_NO_RFCOMM_CHANNELS 219 #if MAX_NO_RFCOMM_CHANNELS > 0 220 static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS]; 221 static memory_pool_t rfcomm_channel_pool; 222 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 223 return (rfcomm_channel_t *) memory_pool_get(&rfcomm_channel_pool); 224 } 225 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 226 memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 227 } 228 #else 229 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 230 return NULL; 231 } 232 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 233 // silence compiler warning about unused parameter in a portable way 234 (void) rfcomm_channel; 235 }; 236 #endif 237 #elif defined(HAVE_MALLOC) 238 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 239 return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t)); 240 } 241 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 242 free(rfcomm_channel); 243 } 244 #else 245 #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file." 246 #endif 247 248 249 250 // MARK: db_mem_device_name_t 251 #ifdef MAX_NO_DB_MEM_DEVICE_NAMES 252 #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 253 static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES]; 254 static memory_pool_t db_mem_device_name_pool; 255 db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 256 return (db_mem_device_name_t *) memory_pool_get(&db_mem_device_name_pool); 257 } 258 void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 259 memory_pool_free(&db_mem_device_name_pool, db_mem_device_name); 260 } 261 #else 262 db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 263 return NULL; 264 } 265 void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 266 // silence compiler warning about unused parameter in a portable way 267 (void) db_mem_device_name; 268 }; 269 #endif 270 #elif defined(HAVE_MALLOC) 271 db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 272 return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t)); 273 } 274 void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 275 free(db_mem_device_name); 276 } 277 #else 278 #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES for struct db_mem_device_name is defined. Please, edit the config file." 279 #endif 280 281 282 // MARK: db_mem_device_link_key_t 283 #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS 284 #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 285 static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS]; 286 static memory_pool_t db_mem_device_link_key_pool; 287 db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 288 return (db_mem_device_link_key_t *) memory_pool_get(&db_mem_device_link_key_pool); 289 } 290 void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 291 memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key); 292 } 293 #else 294 db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 295 return NULL; 296 } 297 void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 298 // silence compiler warning about unused parameter in a portable way 299 (void) db_mem_device_link_key; 300 }; 301 #endif 302 #elif defined(HAVE_MALLOC) 303 db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 304 return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t)); 305 } 306 void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 307 free(db_mem_device_link_key); 308 } 309 #else 310 #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS for struct db_mem_device_link_key is defined. Please, edit the config file." 311 #endif 312 313 314 // MARK: db_mem_service_t 315 #ifdef MAX_NO_DB_MEM_SERVICES 316 #if MAX_NO_DB_MEM_SERVICES > 0 317 static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES]; 318 static memory_pool_t db_mem_service_pool; 319 db_mem_service_t * btstack_memory_db_mem_service_get(void){ 320 return (db_mem_service_t *) memory_pool_get(&db_mem_service_pool); 321 } 322 void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 323 memory_pool_free(&db_mem_service_pool, db_mem_service); 324 } 325 #else 326 db_mem_service_t * btstack_memory_db_mem_service_get(void){ 327 return NULL; 328 } 329 void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 330 // silence compiler warning about unused parameter in a portable way 331 (void) db_mem_service; 332 }; 333 #endif 334 #elif defined(HAVE_MALLOC) 335 db_mem_service_t * btstack_memory_db_mem_service_get(void){ 336 return (db_mem_service_t*) malloc(sizeof(db_mem_service_t)); 337 } 338 void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 339 free(db_mem_service); 340 } 341 #else 342 #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file." 343 #endif 344 345 346 347 // MARK: bnep_service_t 348 #ifdef MAX_NO_BNEP_SERVICES 349 #if MAX_NO_BNEP_SERVICES > 0 350 static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES]; 351 static memory_pool_t bnep_service_pool; 352 bnep_service_t * btstack_memory_bnep_service_get(void){ 353 return (bnep_service_t *) memory_pool_get(&bnep_service_pool); 354 } 355 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 356 memory_pool_free(&bnep_service_pool, bnep_service); 357 } 358 #else 359 bnep_service_t * btstack_memory_bnep_service_get(void){ 360 return NULL; 361 } 362 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 363 // silence compiler warning about unused parameter in a portable way 364 (void) bnep_service; 365 }; 366 #endif 367 #elif defined(HAVE_MALLOC) 368 bnep_service_t * btstack_memory_bnep_service_get(void){ 369 return (bnep_service_t*) malloc(sizeof(bnep_service_t)); 370 } 371 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 372 free(bnep_service); 373 } 374 #else 375 #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file." 376 #endif 377 378 379 // MARK: bnep_channel_t 380 #ifdef MAX_NO_BNEP_CHANNELS 381 #if MAX_NO_BNEP_CHANNELS > 0 382 static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS]; 383 static memory_pool_t bnep_channel_pool; 384 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 385 return (bnep_channel_t *) memory_pool_get(&bnep_channel_pool); 386 } 387 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 388 memory_pool_free(&bnep_channel_pool, bnep_channel); 389 } 390 #else 391 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 392 return NULL; 393 } 394 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 395 // silence compiler warning about unused parameter in a portable way 396 (void) bnep_channel; 397 }; 398 #endif 399 #elif defined(HAVE_MALLOC) 400 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 401 return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); 402 } 403 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 404 free(bnep_channel); 405 } 406 #else 407 #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file." 408 #endif 409 410 411 412 // MARK: hfp_connection_t 413 #ifdef MAX_NO_HFP_CONNECTIONS 414 #if MAX_NO_HFP_CONNECTIONS > 0 415 static hfp_connection_t hfp_connection_storage[MAX_NO_HFP_CONNECTIONS]; 416 static memory_pool_t hfp_connection_pool; 417 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 418 return (hfp_connection_t *) memory_pool_get(&hfp_connection_pool); 419 } 420 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 421 memory_pool_free(&hfp_connection_pool, hfp_connection); 422 } 423 #else 424 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 425 return NULL; 426 } 427 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 428 // silence compiler warning about unused parameter in a portable way 429 (void) hfp_connection; 430 }; 431 #endif 432 #elif defined(HAVE_MALLOC) 433 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 434 return (hfp_connection_t*) malloc(sizeof(hfp_connection_t)); 435 } 436 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 437 free(hfp_connection); 438 } 439 #else 440 #error "Neither HAVE_MALLOC nor MAX_NO_HFP_CONNECTIONS for struct hfp_connection is defined. Please, edit the config file." 441 #endif 442 443 444 #ifdef HAVE_BLE 445 446 // MARK: gatt_client_t 447 #ifdef MAX_NO_GATT_CLIENTS 448 #if MAX_NO_GATT_CLIENTS > 0 449 static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; 450 static memory_pool_t gatt_client_pool; 451 gatt_client_t * btstack_memory_gatt_client_get(void){ 452 return (gatt_client_t *) memory_pool_get(&gatt_client_pool); 453 } 454 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 455 memory_pool_free(&gatt_client_pool, gatt_client); 456 } 457 #else 458 gatt_client_t * btstack_memory_gatt_client_get(void){ 459 return NULL; 460 } 461 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 462 // silence compiler warning about unused parameter in a portable way 463 (void) gatt_client; 464 }; 465 #endif 466 #elif defined(HAVE_MALLOC) 467 gatt_client_t * btstack_memory_gatt_client_get(void){ 468 return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 469 } 470 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 471 free(gatt_client); 472 } 473 #else 474 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." 475 #endif 476 477 478 // MARK: gatt_subclient_t 479 #ifdef MAX_NO_GATT_SUBCLIENTS 480 #if MAX_NO_GATT_SUBCLIENTS > 0 481 static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS]; 482 static memory_pool_t gatt_subclient_pool; 483 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 484 return (gatt_subclient_t *) memory_pool_get(&gatt_subclient_pool); 485 } 486 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 487 memory_pool_free(&gatt_subclient_pool, gatt_subclient); 488 } 489 #else 490 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 491 return NULL; 492 } 493 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 494 // silence compiler warning about unused parameter in a portable way 495 (void) gatt_subclient; 496 }; 497 #endif 498 #elif defined(HAVE_MALLOC) 499 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 500 return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t)); 501 } 502 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 503 free(gatt_subclient); 504 } 505 #else 506 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file." 507 #endif 508 509 510 // MARK: whitelist_entry_t 511 #ifdef MAX_NO_WHITELIST_ENTRIES 512 #if MAX_NO_WHITELIST_ENTRIES > 0 513 static whitelist_entry_t whitelist_entry_storage[MAX_NO_WHITELIST_ENTRIES]; 514 static memory_pool_t whitelist_entry_pool; 515 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 516 return (whitelist_entry_t *) memory_pool_get(&whitelist_entry_pool); 517 } 518 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 519 memory_pool_free(&whitelist_entry_pool, whitelist_entry); 520 } 521 #else 522 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 523 return NULL; 524 } 525 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 526 // silence compiler warning about unused parameter in a portable way 527 (void) whitelist_entry; 528 }; 529 #endif 530 #elif defined(HAVE_MALLOC) 531 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 532 return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t)); 533 } 534 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 535 free(whitelist_entry); 536 } 537 #else 538 #error "Neither HAVE_MALLOC nor MAX_NO_WHITELIST_ENTRIES for struct whitelist_entry is defined. Please, edit the config file." 539 #endif 540 541 542 // MARK: sm_lookup_entry_t 543 #ifdef MAX_NO_SM_LOOKUP_ENTRIES 544 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 545 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NO_SM_LOOKUP_ENTRIES]; 546 static memory_pool_t sm_lookup_entry_pool; 547 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 548 return (sm_lookup_entry_t *) memory_pool_get(&sm_lookup_entry_pool); 549 } 550 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 551 memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 552 } 553 #else 554 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 555 return NULL; 556 } 557 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 558 // silence compiler warning about unused parameter in a portable way 559 (void) sm_lookup_entry; 560 }; 561 #endif 562 #elif defined(HAVE_MALLOC) 563 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 564 return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); 565 } 566 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 567 free(sm_lookup_entry); 568 } 569 #else 570 #error "Neither HAVE_MALLOC nor MAX_NO_SM_LOOKUP_ENTRIES for struct sm_lookup_entry is defined. Please, edit the config file." 571 #endif 572 573 574 #endif 575 // init 576 void btstack_memory_init(void){ 577 #if MAX_NO_HCI_CONNECTIONS > 0 578 memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 579 #endif 580 #if MAX_NO_L2CAP_SERVICES > 0 581 memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 582 #endif 583 #if MAX_NO_L2CAP_CHANNELS > 0 584 memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 585 #endif 586 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 587 memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 588 #endif 589 #if MAX_NO_RFCOMM_SERVICES > 0 590 memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 591 #endif 592 #if MAX_NO_RFCOMM_CHANNELS > 0 593 memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 594 #endif 595 #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 596 memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t)); 597 #endif 598 #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 599 memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t)); 600 #endif 601 #if MAX_NO_DB_MEM_SERVICES > 0 602 memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 603 #endif 604 #if MAX_NO_BNEP_SERVICES > 0 605 memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t)); 606 #endif 607 #if MAX_NO_BNEP_CHANNELS > 0 608 memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t)); 609 #endif 610 #if MAX_NO_HFP_CONNECTIONS > 0 611 memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NO_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 612 #endif 613 #ifdef HAVE_BLE 614 #if MAX_NO_GATT_CLIENTS > 0 615 memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); 616 #endif 617 #if MAX_NO_GATT_SUBCLIENTS > 0 618 memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); 619 #endif 620 #if MAX_NO_WHITELIST_ENTRIES > 0 621 memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 622 #endif 623 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 624 memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NO_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 625 #endif 626 #endif 627 } 628