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 480 // MARK: avdtp_sink_connection_t 481 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_SINK_CONNECTIONS) 482 #if defined(MAX_NO_AVDTP_SINK_CONNECTIONS) 483 #error "Deprecated MAX_NO_AVDTP_SINK_CONNECTIONS defined instead of MAX_NR_AVDTP_SINK_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVDTP_SINK_CONNECTIONS." 484 #else 485 #define MAX_NR_AVDTP_SINK_CONNECTIONS 0 486 #endif 487 #endif 488 489 #ifdef MAX_NR_AVDTP_SINK_CONNECTIONS 490 #if MAX_NR_AVDTP_SINK_CONNECTIONS > 0 491 static avdtp_sink_connection_t avdtp_sink_connection_storage[MAX_NR_AVDTP_SINK_CONNECTIONS]; 492 static btstack_memory_pool_t avdtp_sink_connection_pool; 493 avdtp_sink_connection_t * btstack_memory_avdtp_sink_connection_get(void){ 494 return (avdtp_sink_connection_t *) btstack_memory_pool_get(&avdtp_sink_connection_pool); 495 } 496 void btstack_memory_avdtp_sink_connection_free(avdtp_sink_connection_t *avdtp_sink_connection){ 497 btstack_memory_pool_free(&avdtp_sink_connection_pool, avdtp_sink_connection); 498 } 499 #else 500 avdtp_sink_connection_t * btstack_memory_avdtp_sink_connection_get(void){ 501 return NULL; 502 } 503 void btstack_memory_avdtp_sink_connection_free(avdtp_sink_connection_t *avdtp_sink_connection){ 504 // silence compiler warning about unused parameter in a portable way 505 (void) avdtp_sink_connection; 506 }; 507 #endif 508 #elif defined(HAVE_MALLOC) 509 avdtp_sink_connection_t * btstack_memory_avdtp_sink_connection_get(void){ 510 return (avdtp_sink_connection_t*) malloc(sizeof(avdtp_sink_connection_t)); 511 } 512 void btstack_memory_avdtp_sink_connection_free(avdtp_sink_connection_t *avdtp_sink_connection){ 513 free(avdtp_sink_connection); 514 } 515 #endif 516 517 518 #ifdef ENABLE_BLE 519 520 // MARK: gatt_client_t 521 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS) 522 #if defined(MAX_NO_GATT_CLIENTS) 523 #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." 524 #else 525 #define MAX_NR_GATT_CLIENTS 0 526 #endif 527 #endif 528 529 #ifdef MAX_NR_GATT_CLIENTS 530 #if MAX_NR_GATT_CLIENTS > 0 531 static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS]; 532 static btstack_memory_pool_t gatt_client_pool; 533 gatt_client_t * btstack_memory_gatt_client_get(void){ 534 return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool); 535 } 536 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 537 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 538 } 539 #else 540 gatt_client_t * btstack_memory_gatt_client_get(void){ 541 return NULL; 542 } 543 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 544 // silence compiler warning about unused parameter in a portable way 545 (void) gatt_client; 546 }; 547 #endif 548 #elif defined(HAVE_MALLOC) 549 gatt_client_t * btstack_memory_gatt_client_get(void){ 550 return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 551 } 552 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 553 free(gatt_client); 554 } 555 #endif 556 557 558 // MARK: whitelist_entry_t 559 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES) 560 #if defined(MAX_NO_WHITELIST_ENTRIES) 561 #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." 562 #else 563 #define MAX_NR_WHITELIST_ENTRIES 0 564 #endif 565 #endif 566 567 #ifdef MAX_NR_WHITELIST_ENTRIES 568 #if MAX_NR_WHITELIST_ENTRIES > 0 569 static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES]; 570 static btstack_memory_pool_t whitelist_entry_pool; 571 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 572 return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool); 573 } 574 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 575 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 576 } 577 #else 578 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 579 return NULL; 580 } 581 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 582 // silence compiler warning about unused parameter in a portable way 583 (void) whitelist_entry; 584 }; 585 #endif 586 #elif defined(HAVE_MALLOC) 587 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 588 return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t)); 589 } 590 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 591 free(whitelist_entry); 592 } 593 #endif 594 595 596 // MARK: sm_lookup_entry_t 597 #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES) 598 #if defined(MAX_NO_SM_LOOKUP_ENTRIES) 599 #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." 600 #else 601 #define MAX_NR_SM_LOOKUP_ENTRIES 0 602 #endif 603 #endif 604 605 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 606 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 607 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES]; 608 static btstack_memory_pool_t sm_lookup_entry_pool; 609 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 610 return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool); 611 } 612 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 613 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 614 } 615 #else 616 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 617 return NULL; 618 } 619 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 620 // silence compiler warning about unused parameter in a portable way 621 (void) sm_lookup_entry; 622 }; 623 #endif 624 #elif defined(HAVE_MALLOC) 625 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 626 return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); 627 } 628 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 629 free(sm_lookup_entry); 630 } 631 #endif 632 633 634 #endif 635 // init 636 void btstack_memory_init(void){ 637 #if MAX_NR_HCI_CONNECTIONS > 0 638 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t)); 639 #endif 640 #if MAX_NR_L2CAP_SERVICES > 0 641 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t)); 642 #endif 643 #if MAX_NR_L2CAP_CHANNELS > 0 644 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 645 #endif 646 #if MAX_NR_RFCOMM_MULTIPLEXERS > 0 647 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 648 #endif 649 #if MAX_NR_RFCOMM_SERVICES > 0 650 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 651 #endif 652 #if MAX_NR_RFCOMM_CHANNELS > 0 653 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 654 #endif 655 #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0 656 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)); 657 #endif 658 #if MAX_NR_BNEP_SERVICES > 0 659 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t)); 660 #endif 661 #if MAX_NR_BNEP_CHANNELS > 0 662 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t)); 663 #endif 664 #if MAX_NR_HFP_CONNECTIONS > 0 665 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 666 #endif 667 #if MAX_NR_SERVICE_RECORD_ITEMS > 0 668 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 669 #endif 670 #if MAX_NR_AVDTP_SINK_CONNECTIONS > 0 671 btstack_memory_pool_create(&avdtp_sink_connection_pool, avdtp_sink_connection_storage, MAX_NR_AVDTP_SINK_CONNECTIONS, sizeof(avdtp_sink_connection_t)); 672 #endif 673 #ifdef ENABLE_BLE 674 #if MAX_NR_GATT_CLIENTS > 0 675 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t)); 676 #endif 677 #if MAX_NR_WHITELIST_ENTRIES > 0 678 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 679 #endif 680 #if MAX_NR_SM_LOOKUP_ENTRIES > 0 681 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 682 #endif 683 #endif 684 } 685