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 "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: 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 btstack_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 *) btstack_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 btstack_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 btstack_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 *) btstack_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 btstack_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 btstack_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 *) btstack_memory_pool_get(&db_mem_service_pool); 321 } 322 void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 323 btstack_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 btstack_memory_pool_t bnep_service_pool; 352 bnep_service_t * btstack_memory_bnep_service_get(void){ 353 return (bnep_service_t *) btstack_memory_pool_get(&bnep_service_pool); 354 } 355 void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ 356 btstack_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 btstack_memory_pool_t bnep_channel_pool; 384 bnep_channel_t * btstack_memory_bnep_channel_get(void){ 385 return (bnep_channel_t *) btstack_memory_pool_get(&bnep_channel_pool); 386 } 387 void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ 388 btstack_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 btstack_memory_pool_t hfp_connection_pool; 417 hfp_connection_t * btstack_memory_hfp_connection_get(void){ 418 return (hfp_connection_t *) btstack_memory_pool_get(&hfp_connection_pool); 419 } 420 void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ 421 btstack_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 445 // MARK: service_record_item_t 446 #ifdef MAX_NO_SERVICE_RECORD_ITEMS 447 #if MAX_NO_SERVICE_RECORD_ITEMS > 0 448 static service_record_item_t service_record_item_storage[MAX_NO_SERVICE_RECORD_ITEMS]; 449 static btstack_memory_pool_t service_record_item_pool; 450 service_record_item_t * btstack_memory_service_record_item_get(void){ 451 return (service_record_item_t *) btstack_memory_pool_get(&service_record_item_pool); 452 } 453 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 454 btstack_memory_pool_free(&service_record_item_pool, service_record_item); 455 } 456 #else 457 service_record_item_t * btstack_memory_service_record_item_get(void){ 458 return NULL; 459 } 460 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 461 // silence compiler warning about unused parameter in a portable way 462 (void) service_record_item; 463 }; 464 #endif 465 #elif defined(HAVE_MALLOC) 466 service_record_item_t * btstack_memory_service_record_item_get(void){ 467 return (service_record_item_t*) malloc(sizeof(service_record_item_t)); 468 } 469 void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){ 470 free(service_record_item); 471 } 472 #else 473 #error "Neither HAVE_MALLOC nor MAX_NO_SERVICE_RECORD_ITEMS for struct service_record_item is defined. Please, edit the config file." 474 #endif 475 476 477 #ifdef HAVE_BLE 478 479 // MARK: gatt_client_t 480 #ifdef MAX_NO_GATT_CLIENTS 481 #if MAX_NO_GATT_CLIENTS > 0 482 static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; 483 static btstack_memory_pool_t gatt_client_pool; 484 gatt_client_t * btstack_memory_gatt_client_get(void){ 485 return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool); 486 } 487 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 488 btstack_memory_pool_free(&gatt_client_pool, gatt_client); 489 } 490 #else 491 gatt_client_t * btstack_memory_gatt_client_get(void){ 492 return NULL; 493 } 494 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 495 // silence compiler warning about unused parameter in a portable way 496 (void) gatt_client; 497 }; 498 #endif 499 #elif defined(HAVE_MALLOC) 500 gatt_client_t * btstack_memory_gatt_client_get(void){ 501 return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 502 } 503 void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 504 free(gatt_client); 505 } 506 #else 507 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." 508 #endif 509 510 511 // MARK: gatt_subclient_t 512 #ifdef MAX_NO_GATT_SUBCLIENTS 513 #if MAX_NO_GATT_SUBCLIENTS > 0 514 static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS]; 515 static btstack_memory_pool_t gatt_subclient_pool; 516 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 517 return (gatt_subclient_t *) btstack_memory_pool_get(&gatt_subclient_pool); 518 } 519 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 520 btstack_memory_pool_free(&gatt_subclient_pool, gatt_subclient); 521 } 522 #else 523 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 524 return NULL; 525 } 526 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 527 // silence compiler warning about unused parameter in a portable way 528 (void) gatt_subclient; 529 }; 530 #endif 531 #elif defined(HAVE_MALLOC) 532 gatt_subclient_t * btstack_memory_gatt_subclient_get(void){ 533 return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t)); 534 } 535 void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){ 536 free(gatt_subclient); 537 } 538 #else 539 #error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file." 540 #endif 541 542 543 // MARK: whitelist_entry_t 544 #ifdef MAX_NO_WHITELIST_ENTRIES 545 #if MAX_NO_WHITELIST_ENTRIES > 0 546 static whitelist_entry_t whitelist_entry_storage[MAX_NO_WHITELIST_ENTRIES]; 547 static btstack_memory_pool_t whitelist_entry_pool; 548 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 549 return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool); 550 } 551 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 552 btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry); 553 } 554 #else 555 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 556 return NULL; 557 } 558 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 559 // silence compiler warning about unused parameter in a portable way 560 (void) whitelist_entry; 561 }; 562 #endif 563 #elif defined(HAVE_MALLOC) 564 whitelist_entry_t * btstack_memory_whitelist_entry_get(void){ 565 return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t)); 566 } 567 void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ 568 free(whitelist_entry); 569 } 570 #else 571 #error "Neither HAVE_MALLOC nor MAX_NO_WHITELIST_ENTRIES for struct whitelist_entry is defined. Please, edit the config file." 572 #endif 573 574 575 // MARK: sm_lookup_entry_t 576 #ifdef MAX_NO_SM_LOOKUP_ENTRIES 577 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 578 static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NO_SM_LOOKUP_ENTRIES]; 579 static btstack_memory_pool_t sm_lookup_entry_pool; 580 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 581 return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool); 582 } 583 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 584 btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); 585 } 586 #else 587 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 588 return NULL; 589 } 590 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 591 // silence compiler warning about unused parameter in a portable way 592 (void) sm_lookup_entry; 593 }; 594 #endif 595 #elif defined(HAVE_MALLOC) 596 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ 597 return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); 598 } 599 void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ 600 free(sm_lookup_entry); 601 } 602 #else 603 #error "Neither HAVE_MALLOC nor MAX_NO_SM_LOOKUP_ENTRIES for struct sm_lookup_entry is defined. Please, edit the config file." 604 #endif 605 606 607 #endif 608 // init 609 void btstack_memory_init(void){ 610 #if MAX_NO_HCI_CONNECTIONS > 0 611 btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 612 #endif 613 #if MAX_NO_L2CAP_SERVICES > 0 614 btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 615 #endif 616 #if MAX_NO_L2CAP_CHANNELS > 0 617 btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 618 #endif 619 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 620 btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 621 #endif 622 #if MAX_NO_RFCOMM_SERVICES > 0 623 btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 624 #endif 625 #if MAX_NO_RFCOMM_CHANNELS > 0 626 btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 627 #endif 628 #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 629 btstack_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)); 630 #endif 631 #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 632 btstack_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)); 633 #endif 634 #if MAX_NO_DB_MEM_SERVICES > 0 635 btstack_memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 636 #endif 637 #if MAX_NO_BNEP_SERVICES > 0 638 btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t)); 639 #endif 640 #if MAX_NO_BNEP_CHANNELS > 0 641 btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t)); 642 #endif 643 #if MAX_NO_HFP_CONNECTIONS > 0 644 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NO_HFP_CONNECTIONS, sizeof(hfp_connection_t)); 645 #endif 646 #if MAX_NO_SERVICE_RECORD_ITEMS > 0 647 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NO_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); 648 #endif 649 #ifdef HAVE_BLE 650 #if MAX_NO_GATT_CLIENTS > 0 651 btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); 652 #endif 653 #if MAX_NO_GATT_SUBCLIENTS > 0 654 btstack_memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); 655 #endif 656 #if MAX_NO_WHITELIST_ENTRIES > 0 657 btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); 658 #endif 659 #if MAX_NO_SM_LOOKUP_ENTRIES > 0 660 btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NO_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); 661 #endif 662 #endif 663 } 664