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 * btstack_memory.h 41 * 42 * @brief BTstack memory management via configurable memory pools 43 * 44 * @note code generated by tool/btstack_memory_generator.py 45 * 46 */ 47 48 #include "btstack_memory.h" 49 #include "btstack_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 btstack_memory_pool_t hci_connection_pool; 60 hci_connection_t * btstack_memory_hci_connection_get(void){ 61 return (hci_connection_t *) btstack_memory_pool_get(&hci_connection_pool); 62 } 63 void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 64 btstack_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 btstack_memory_pool_t l2cap_service_pool; 93 l2cap_service_t * btstack_memory_l2cap_service_get(void){ 94 return (l2cap_service_t *) btstack_memory_pool_get(&l2cap_service_pool); 95 } 96 void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 97 btstack_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 btstack_memory_pool_t l2cap_channel_pool; 125 l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 126 return (l2cap_channel_t *) btstack_memory_pool_get(&l2cap_channel_pool); 127 } 128 void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 129 btstack_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 btstack_memory_pool_t rfcomm_multiplexer_pool; 158 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 159 return (rfcomm_multiplexer_t *) btstack_memory_pool_get(&rfcomm_multiplexer_pool); 160 } 161 void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 162 btstack_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 btstack_memory_pool_t rfcomm_service_pool; 190 rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 191 return (rfcomm_service_t *) btstack_memory_pool_get(&rfcomm_service_pool); 192 } 193 void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 194 btstack_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 btstack_memory_pool_t rfcomm_channel_pool; 222 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 223 return (rfcomm_channel_t *) btstack_memory_pool_get(&rfcomm_channel_pool); 224 } 225 void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 226 btstack_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: btstack_link_key_db_memory_t 251 #ifdef MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS 252 #if MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS > 0 253 static btstack_link_key_db_memory_t btstack_link_key_db_memory_storage[MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS]; 254 static btstack_memory_pool_t btstack_link_key_db_memory_pool; 255 btstack_link_key_db_memory_t * btstack_memory_btstack_link_key_db_memory_get(void){ 256 return (btstack_link_key_db_memory_t *) btstack_memory_pool_get(&btstack_link_key_db_memory_pool); 257 } 258 void btstack_memory_btstack_link_key_db_memory_free(btstack_link_key_db_memory_t *btstack_link_key_db_memory){ 259 btstack_memory_pool_free(&btstack_link_key_db_memory_pool, btstack_link_key_db_memory); 260 } 261 #else 262 btstack_link_key_db_memory_t * btstack_memory_btstack_link_key_db_memory_get(void){ 263 return NULL; 264 } 265 void btstack_memory_btstack_link_key_db_memory_free(btstack_link_key_db_memory_t *btstack_link_key_db_memory){ 266 // silence compiler warning about unused parameter in a portable way 267 (void) btstack_link_key_db_memory; 268 }; 269 #endif 270 #elif defined(HAVE_MALLOC) 271 btstack_link_key_db_memory_t * btstack_memory_btstack_link_key_db_memory_get(void){ 272 return (btstack_link_key_db_memory_t*) malloc(sizeof(btstack_link_key_db_memory_t)); 273 } 274 void btstack_memory_btstack_link_key_db_memory_free(btstack_link_key_db_memory_t *btstack_link_key_db_memory){ 275 free(btstack_link_key_db_memory); 276 } 277 #else 278 #error "Neither HAVE_MALLOC nor MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS for struct btstack_link_key_db_memory is defined. Please, edit the config file." 279 #endif 280 281 282 283 // MARK: bnep_service_t 284 #ifdef MAX_NO_BNEP_SERVICES 285 #if MAX_NO_BNEP_SERVICES > 0 286 static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES]; 287 static btstack_memory_pool_t bnep_service_pool; 288 bnep_service_t * btstack_memory_bnep_service_get(void){ 289 return (bnep_service_t *) btstack_memory_pool_get(&bnep_service_pool); 290 } 291 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 292 btstack_memory_pool_free(&bnep_service_pool, bnep_service); 293 } 294 #else 295 bnep_service_t * btstack_memory_bnep_service_get(void){ 296 return NULL; 297 } 298 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 299 // silence compiler warning about unused parameter in a portable way 300 (void) bnep_service; 301 }; 302 #endif 303 #elif defined(HAVE_MALLOC) 304 bnep_service_t * btstack_memory_bnep_service_get(void){ 305 return (bnep_service_t*) malloc(sizeof(bnep_service_t)); 306 } 307 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 308 free(bnep_service); 309 } 310 #else 311 #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file." 312 #endif 313 314 315 // MARK: bnep_channel_t 316 #ifdef MAX_NO_BNEP_CHANNELS 317 #if MAX_NO_BNEP_CHANNELS > 0 318 static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS]; 319 static btstack_memory_pool_t bnep_channel_pool; 320 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 321 return (bnep_channel_t *) btstack_memory_pool_get(&bnep_channel_pool); 322 } 323 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 324 btstack_memory_pool_free(&bnep_channel_pool, bnep_channel); 325 } 326 #else 327 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 328 return NULL; 329 } 330 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 331 // silence compiler warning about unused parameter in a portable way 332 (void) bnep_channel; 333 }; 334 #endif 335 #elif defined(HAVE_MALLOC) 336 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 337 return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); 338 } 339 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 340 free(bnep_channel); 341 } 342 #else 343 #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file." 344 #endif 345 346 347 348 // MARK: hfp_connection_t 349 #ifdef MAX_NO_HFP_CONNECTIONS 350 #if MAX_NO_HFP_CONNECTIONS > 0 351 static hfp_connection_t hfp_connection_storage[MAX_NO_HFP_CONNECTIONS]; 352 static btstack_memory_pool_t hfp_connection_pool; 353 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 354 return (hfp_connection_t *) btstack_memory_pool_get(&hfp_connection_pool); 355 } 356 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 357 btstack_memory_pool_free(&hfp_connection_pool, hfp_connection); 358 } 359 #else 360 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 361 return NULL; 362 } 363 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 364 // silence compiler warning about unused parameter in a portable way 365 (void) hfp_connection; 366 }; 367 #endif 368 #elif defined(HAVE_MALLOC) 369 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 370 return (hfp_connection_t*) malloc(sizeof(hfp_connection_t)); 371 } 372 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 373 free(hfp_connection); 374 } 375 #else 376 #error "Neither HAVE_MALLOC nor MAX_NO_HFP_CONNECTIONS for struct hfp_connection is defined. Please, edit the config file." 377 #endif 378 379 380 381 // MARK: service_record_item_t 382 #ifdef MAX_NO_SERVICE_RECORD_ITEMS 383 #if MAX_NO_SERVICE_RECORD_ITEMS > 0 384 static service_record_item_t service_record_item_storage[MAX_NO_SERVICE_RECORD_ITEMS]; 385 static btstack_memory_pool_t service_record_item_pool; 386 service_record_item_t * btstack_memory_service_record_item_get(void){ 387 return (service_record_item_t *) btstack_memory_pool_get(&service_record_item_pool); 388 } 389 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 390 btstack_memory_pool_free(&service_record_item_pool, service_record_item); 391 } 392 #else 393 service_record_item_t * btstack_memory_service_record_item_get(void){ 394 return NULL; 395 } 396 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 397 // silence compiler warning about unused parameter in a portable way 398 (void) service_record_item; 399 }; 400 #endif 401 #elif defined(HAVE_MALLOC) 402 service_record_item_t * btstack_memory_service_record_item_get(void){ 403 return (service_record_item_t*) malloc(sizeof(service_record_item_t)); 404 } 405 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 406 free(service_record_item); 407 } 408 #else 409 #error "Neither HAVE_MALLOC nor MAX_NO_SERVICE_RECORD_ITEMS for struct service_record_item is defined. Please, edit the config file." 410 #endif 411 412 413 #ifdef ENABLE_BLE 414 415 // MARK: gatt_client_t 416 #ifdef MAX_NO_GATT_CLIENTS 417 #if MAX_NO_GATT_CLIENTS > 0 418 static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; 419 static btstack_memory_pool_t gatt_client_pool; 420 gatt_client_t * btstack_memory_gatt_client_get(void){ 421 return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool); 422 } 423 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 424 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 425 } 426 #else 427 gatt_client_t * btstack_memory_gatt_client_get(void){ 428 return NULL; 429 } 430 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 431 // silence compiler warning about unused parameter in a portable way 432 (void) gatt_client; 433 }; 434 #endif 435 #elif defined(HAVE_MALLOC) 436 gatt_client_t * btstack_memory_gatt_client_get(void){ 437 return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 438 } 439 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 440 free(gatt_client); 441 } 442 #else 443 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." 444 #endif 445 446 447 // MARK: gatt_subclient_t 448 #ifdef MAX_NO_GATT_SUBCLIENTS 449 #if MAX_NO_GATT_SUBCLIENTS > 0 450 static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS]; 451 static btstack_memory_pool_t gatt_subclient_pool; 452 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 453 return (gatt_subclient_t *) btstack_memory_pool_get(&gatt_subclient_pool); 454 } 455 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 456 btstack_memory_pool_free(&gatt_subclient_pool, gatt_subclient); 457 } 458 #else 459 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 460 return NULL; 461 } 462 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 463 // silence compiler warning about unused parameter in a portable way 464 (void) gatt_subclient; 465 }; 466 #endif 467 #elif defined(HAVE_MALLOC) 468 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 469 return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t)); 470 } 471 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 472 free(gatt_subclient); 473 } 474 #else 475 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file." 476 #endif 477 478 479 // MARK: whitelist_entry_t 480 #ifdef MAX_NO_WHITELIST_ENTRIES 481 #if MAX_NO_WHITELIST_ENTRIES > 0 482 static whitelist_entry_t whitelist_entry_storage[MAX_NO_WHITELIST_ENTRIES]; 483 static btstack_memory_pool_t whitelist_entry_pool; 484 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 485 return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool); 486 } 487 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 488 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 489 } 490 #else 491 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 492 return NULL; 493 } 494 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 495 // silence compiler warning about unused parameter in a portable way 496 (void) whitelist_entry; 497 }; 498 #endif 499 #elif defined(HAVE_MALLOC) 500 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 501 return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t)); 502 } 503 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 504 free(whitelist_entry); 505 } 506 #else 507 #error "Neither HAVE_MALLOC nor MAX_NO_WHITELIST_ENTRIES for struct whitelist_entry is defined. Please, edit the config file." 508 #endif 509 510 511 // MARK: sm_lookup_entry_t 512 #ifdef MAX_NO_SM_LOOKUP_ENTRIES 513 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 514 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NO_SM_LOOKUP_ENTRIES]; 515 static btstack_memory_pool_t sm_lookup_entry_pool; 516 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 517 return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool); 518 } 519 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 520 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 521 } 522 #else 523 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 524 return NULL; 525 } 526 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 527 // silence compiler warning about unused parameter in a portable way 528 (void) sm_lookup_entry; 529 }; 530 #endif 531 #elif defined(HAVE_MALLOC) 532 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 533 return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); 534 } 535 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 536 free(sm_lookup_entry); 537 } 538 #else 539 #error "Neither HAVE_MALLOC nor MAX_NO_SM_LOOKUP_ENTRIES for struct sm_lookup_entry is defined. Please, edit the config file." 540 #endif 541 542 543 #endif 544 // init 545 void btstack_memory_init(void){ 546 #if MAX_NO_HCI_CONNECTIONS > 0 547 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 548 #endif 549 #if MAX_NO_L2CAP_SERVICES > 0 550 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 551 #endif 552 #if MAX_NO_L2CAP_CHANNELS > 0 553 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 554 #endif 555 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 556 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 557 #endif 558 #if MAX_NO_RFCOMM_SERVICES > 0 559 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 560 #endif 561 #if MAX_NO_RFCOMM_CHANNELS > 0 562 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 563 #endif 564 #if MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS > 0 565 btstack_memory_pool_create(&btstack_link_key_db_memory_pool, btstack_link_key_db_memory_storage, MAX_NO_BTSTACK_LINK_KEY_DB_MEMORYS, sizeof(btstack_link_key_db_memory_t)); 566 #endif 567 #if MAX_NO_BNEP_SERVICES > 0 568 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t)); 569 #endif 570 #if MAX_NO_BNEP_CHANNELS > 0 571 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t)); 572 #endif 573 #if MAX_NO_HFP_CONNECTIONS > 0 574 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NO_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 575 #endif 576 #if MAX_NO_SERVICE_RECORD_ITEMS > 0 577 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NO_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 578 #endif 579 #ifdef ENABLE_BLE 580 #if MAX_NO_GATT_CLIENTS > 0 581 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); 582 #endif 583 #if MAX_NO_GATT_SUBCLIENTS > 0 584 btstack_memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); 585 #endif 586 #if MAX_NO_WHITELIST_ENTRIES > 0 587 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 588 #endif 589 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 590 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NO_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 591 #endif 592 #endif 593 } 594