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