btstack_memory.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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. * contact@bluekitchen-gmbh.com
  35. *
  36. */
  37. #define BTSTACK_FILE__ "btstack_memory.c"
  38. /*
  39. * btstack_memory.h
  40. *
  41. * @brief BTstack memory management via configurable memory pools
  42. *
  43. * @note code generated by tool/btstack_memory_generator.py
  44. * @note returnes buffers are initialized with 0
  45. *
  46. */
  47. #include "btstack_memory.h"
  48. #include "btstack_memory_pool.h"
  49. #include <stdlib.h>
  50. // MARK: hci_connection_t
  51. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_CONNECTIONS)
  52. #if defined(MAX_NO_HCI_CONNECTIONS)
  53. #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."
  54. #else
  55. #define MAX_NR_HCI_CONNECTIONS 0
  56. #endif
  57. #endif
  58. #ifdef MAX_NR_HCI_CONNECTIONS
  59. #if MAX_NR_HCI_CONNECTIONS > 0
  60. static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
  61. static btstack_memory_pool_t hci_connection_pool;
  62. hci_connection_t * btstack_memory_hci_connection_get(void){
  63. void * buffer = btstack_memory_pool_get(&hci_connection_pool);
  64. if (buffer){
  65. memset(buffer, 0, sizeof(hci_connection_t));
  66. }
  67. return (hci_connection_t *) buffer;
  68. }
  69. void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
  70. btstack_memory_pool_free(&hci_connection_pool, hci_connection);
  71. }
  72. #else
  73. hci_connection_t * btstack_memory_hci_connection_get(void){
  74. return NULL;
  75. }
  76. void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
  77. // silence compiler warning about unused parameter in a portable way
  78. (void) hci_connection;
  79. };
  80. #endif
  81. #elif defined(HAVE_MALLOC)
  82. hci_connection_t * btstack_memory_hci_connection_get(void){
  83. void * buffer = malloc(sizeof(hci_connection_t));
  84. if (buffer){
  85. memset(buffer, 0, sizeof(hci_connection_t));
  86. }
  87. return (hci_connection_t *) buffer;
  88. }
  89. void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
  90. free(hci_connection);
  91. }
  92. #endif
  93. // MARK: l2cap_service_t
  94. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_SERVICES)
  95. #if defined(MAX_NO_L2CAP_SERVICES)
  96. #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."
  97. #else
  98. #define MAX_NR_L2CAP_SERVICES 0
  99. #endif
  100. #endif
  101. #ifdef MAX_NR_L2CAP_SERVICES
  102. #if MAX_NR_L2CAP_SERVICES > 0
  103. static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
  104. static btstack_memory_pool_t l2cap_service_pool;
  105. l2cap_service_t * btstack_memory_l2cap_service_get(void){
  106. void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
  107. if (buffer){
  108. memset(buffer, 0, sizeof(l2cap_service_t));
  109. }
  110. return (l2cap_service_t *) buffer;
  111. }
  112. void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
  113. btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
  114. }
  115. #else
  116. l2cap_service_t * btstack_memory_l2cap_service_get(void){
  117. return NULL;
  118. }
  119. void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
  120. // silence compiler warning about unused parameter in a portable way
  121. (void) l2cap_service;
  122. };
  123. #endif
  124. #elif defined(HAVE_MALLOC)
  125. l2cap_service_t * btstack_memory_l2cap_service_get(void){
  126. void * buffer = malloc(sizeof(l2cap_service_t));
  127. if (buffer){
  128. memset(buffer, 0, sizeof(l2cap_service_t));
  129. }
  130. return (l2cap_service_t *) buffer;
  131. }
  132. void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
  133. free(l2cap_service);
  134. }
  135. #endif
  136. // MARK: l2cap_channel_t
  137. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_L2CAP_CHANNELS)
  138. #if defined(MAX_NO_L2CAP_CHANNELS)
  139. #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."
  140. #else
  141. #define MAX_NR_L2CAP_CHANNELS 0
  142. #endif
  143. #endif
  144. #ifdef MAX_NR_L2CAP_CHANNELS
  145. #if MAX_NR_L2CAP_CHANNELS > 0
  146. static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
  147. static btstack_memory_pool_t l2cap_channel_pool;
  148. l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
  149. void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
  150. if (buffer){
  151. memset(buffer, 0, sizeof(l2cap_channel_t));
  152. }
  153. return (l2cap_channel_t *) buffer;
  154. }
  155. void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
  156. btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
  157. }
  158. #else
  159. l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
  160. return NULL;
  161. }
  162. void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
  163. // silence compiler warning about unused parameter in a portable way
  164. (void) l2cap_channel;
  165. };
  166. #endif
  167. #elif defined(HAVE_MALLOC)
  168. l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
  169. void * buffer = malloc(sizeof(l2cap_channel_t));
  170. if (buffer){
  171. memset(buffer, 0, sizeof(l2cap_channel_t));
  172. }
  173. return (l2cap_channel_t *) buffer;
  174. }
  175. void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
  176. free(l2cap_channel);
  177. }
  178. #endif
  179. #ifdef ENABLE_CLASSIC
  180. // MARK: rfcomm_multiplexer_t
  181. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_MULTIPLEXERS)
  182. #if defined(MAX_NO_RFCOMM_MULTIPLEXERS)
  183. #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."
  184. #else
  185. #define MAX_NR_RFCOMM_MULTIPLEXERS 0
  186. #endif
  187. #endif
  188. #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
  189. #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
  190. static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
  191. static btstack_memory_pool_t rfcomm_multiplexer_pool;
  192. rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
  193. void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
  194. if (buffer){
  195. memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
  196. }
  197. return (rfcomm_multiplexer_t *) buffer;
  198. }
  199. void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
  200. btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
  201. }
  202. #else
  203. rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
  204. return NULL;
  205. }
  206. void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
  207. // silence compiler warning about unused parameter in a portable way
  208. (void) rfcomm_multiplexer;
  209. };
  210. #endif
  211. #elif defined(HAVE_MALLOC)
  212. rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
  213. void * buffer = malloc(sizeof(rfcomm_multiplexer_t));
  214. if (buffer){
  215. memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
  216. }
  217. return (rfcomm_multiplexer_t *) buffer;
  218. }
  219. void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
  220. free(rfcomm_multiplexer);
  221. }
  222. #endif
  223. // MARK: rfcomm_service_t
  224. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_SERVICES)
  225. #if defined(MAX_NO_RFCOMM_SERVICES)
  226. #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."
  227. #else
  228. #define MAX_NR_RFCOMM_SERVICES 0
  229. #endif
  230. #endif
  231. #ifdef MAX_NR_RFCOMM_SERVICES
  232. #if MAX_NR_RFCOMM_SERVICES > 0
  233. static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
  234. static btstack_memory_pool_t rfcomm_service_pool;
  235. rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
  236. void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
  237. if (buffer){
  238. memset(buffer, 0, sizeof(rfcomm_service_t));
  239. }
  240. return (rfcomm_service_t *) buffer;
  241. }
  242. void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
  243. btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
  244. }
  245. #else
  246. rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
  247. return NULL;
  248. }
  249. void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
  250. // silence compiler warning about unused parameter in a portable way
  251. (void) rfcomm_service;
  252. };
  253. #endif
  254. #elif defined(HAVE_MALLOC)
  255. rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
  256. void * buffer = malloc(sizeof(rfcomm_service_t));
  257. if (buffer){
  258. memset(buffer, 0, sizeof(rfcomm_service_t));
  259. }
  260. return (rfcomm_service_t *) buffer;
  261. }
  262. void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
  263. free(rfcomm_service);
  264. }
  265. #endif
  266. // MARK: rfcomm_channel_t
  267. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_RFCOMM_CHANNELS)
  268. #if defined(MAX_NO_RFCOMM_CHANNELS)
  269. #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."
  270. #else
  271. #define MAX_NR_RFCOMM_CHANNELS 0
  272. #endif
  273. #endif
  274. #ifdef MAX_NR_RFCOMM_CHANNELS
  275. #if MAX_NR_RFCOMM_CHANNELS > 0
  276. static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
  277. static btstack_memory_pool_t rfcomm_channel_pool;
  278. rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
  279. void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
  280. if (buffer){
  281. memset(buffer, 0, sizeof(rfcomm_channel_t));
  282. }
  283. return (rfcomm_channel_t *) buffer;
  284. }
  285. void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
  286. btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
  287. }
  288. #else
  289. rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
  290. return NULL;
  291. }
  292. void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
  293. // silence compiler warning about unused parameter in a portable way
  294. (void) rfcomm_channel;
  295. };
  296. #endif
  297. #elif defined(HAVE_MALLOC)
  298. rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
  299. void * buffer = malloc(sizeof(rfcomm_channel_t));
  300. if (buffer){
  301. memset(buffer, 0, sizeof(rfcomm_channel_t));
  302. }
  303. return (rfcomm_channel_t *) buffer;
  304. }
  305. void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
  306. free(rfcomm_channel);
  307. }
  308. #endif
  309. // MARK: btstack_link_key_db_memory_entry_t
  310. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
  311. #if defined(MAX_NO_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES)
  312. #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."
  313. #else
  314. #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
  315. #endif
  316. #endif
  317. #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
  318. #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
  319. static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
  320. static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
  321. btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
  322. void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
  323. if (buffer){
  324. memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
  325. }
  326. return (btstack_link_key_db_memory_entry_t *) buffer;
  327. }
  328. void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
  329. btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
  330. }
  331. #else
  332. btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
  333. return NULL;
  334. }
  335. void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
  336. // silence compiler warning about unused parameter in a portable way
  337. (void) btstack_link_key_db_memory_entry;
  338. };
  339. #endif
  340. #elif defined(HAVE_MALLOC)
  341. btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
  342. void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t));
  343. if (buffer){
  344. memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
  345. }
  346. return (btstack_link_key_db_memory_entry_t *) buffer;
  347. }
  348. void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
  349. free(btstack_link_key_db_memory_entry);
  350. }
  351. #endif
  352. // MARK: bnep_service_t
  353. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_SERVICES)
  354. #if defined(MAX_NO_BNEP_SERVICES)
  355. #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."
  356. #else
  357. #define MAX_NR_BNEP_SERVICES 0
  358. #endif
  359. #endif
  360. #ifdef MAX_NR_BNEP_SERVICES
  361. #if MAX_NR_BNEP_SERVICES > 0
  362. static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
  363. static btstack_memory_pool_t bnep_service_pool;
  364. bnep_service_t * btstack_memory_bnep_service_get(void){
  365. void * buffer = btstack_memory_pool_get(&bnep_service_pool);
  366. if (buffer){
  367. memset(buffer, 0, sizeof(bnep_service_t));
  368. }
  369. return (bnep_service_t *) buffer;
  370. }
  371. void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
  372. btstack_memory_pool_free(&bnep_service_pool, bnep_service);
  373. }
  374. #else
  375. bnep_service_t * btstack_memory_bnep_service_get(void){
  376. return NULL;
  377. }
  378. void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
  379. // silence compiler warning about unused parameter in a portable way
  380. (void) bnep_service;
  381. };
  382. #endif
  383. #elif defined(HAVE_MALLOC)
  384. bnep_service_t * btstack_memory_bnep_service_get(void){
  385. void * buffer = malloc(sizeof(bnep_service_t));
  386. if (buffer){
  387. memset(buffer, 0, sizeof(bnep_service_t));
  388. }
  389. return (bnep_service_t *) buffer;
  390. }
  391. void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
  392. free(bnep_service);
  393. }
  394. #endif
  395. // MARK: bnep_channel_t
  396. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_BNEP_CHANNELS)
  397. #if defined(MAX_NO_BNEP_CHANNELS)
  398. #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."
  399. #else
  400. #define MAX_NR_BNEP_CHANNELS 0
  401. #endif
  402. #endif
  403. #ifdef MAX_NR_BNEP_CHANNELS
  404. #if MAX_NR_BNEP_CHANNELS > 0
  405. static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
  406. static btstack_memory_pool_t bnep_channel_pool;
  407. bnep_channel_t * btstack_memory_bnep_channel_get(void){
  408. void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
  409. if (buffer){
  410. memset(buffer, 0, sizeof(bnep_channel_t));
  411. }
  412. return (bnep_channel_t *) buffer;
  413. }
  414. void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
  415. btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
  416. }
  417. #else
  418. bnep_channel_t * btstack_memory_bnep_channel_get(void){
  419. return NULL;
  420. }
  421. void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
  422. // silence compiler warning about unused parameter in a portable way
  423. (void) bnep_channel;
  424. };
  425. #endif
  426. #elif defined(HAVE_MALLOC)
  427. bnep_channel_t * btstack_memory_bnep_channel_get(void){
  428. void * buffer = malloc(sizeof(bnep_channel_t));
  429. if (buffer){
  430. memset(buffer, 0, sizeof(bnep_channel_t));
  431. }
  432. return (bnep_channel_t *) buffer;
  433. }
  434. void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
  435. free(bnep_channel);
  436. }
  437. #endif
  438. // MARK: hfp_connection_t
  439. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_HFP_CONNECTIONS)
  440. #if defined(MAX_NO_HFP_CONNECTIONS)
  441. #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."
  442. #else
  443. #define MAX_NR_HFP_CONNECTIONS 0
  444. #endif
  445. #endif
  446. #ifdef MAX_NR_HFP_CONNECTIONS
  447. #if MAX_NR_HFP_CONNECTIONS > 0
  448. static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
  449. static btstack_memory_pool_t hfp_connection_pool;
  450. hfp_connection_t * btstack_memory_hfp_connection_get(void){
  451. void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
  452. if (buffer){
  453. memset(buffer, 0, sizeof(hfp_connection_t));
  454. }
  455. return (hfp_connection_t *) buffer;
  456. }
  457. void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
  458. btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
  459. }
  460. #else
  461. hfp_connection_t * btstack_memory_hfp_connection_get(void){
  462. return NULL;
  463. }
  464. void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
  465. // silence compiler warning about unused parameter in a portable way
  466. (void) hfp_connection;
  467. };
  468. #endif
  469. #elif defined(HAVE_MALLOC)
  470. hfp_connection_t * btstack_memory_hfp_connection_get(void){
  471. void * buffer = malloc(sizeof(hfp_connection_t));
  472. if (buffer){
  473. memset(buffer, 0, sizeof(hfp_connection_t));
  474. }
  475. return (hfp_connection_t *) buffer;
  476. }
  477. void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
  478. free(hfp_connection);
  479. }
  480. #endif
  481. // MARK: service_record_item_t
  482. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS)
  483. #if defined(MAX_NO_SERVICE_RECORD_ITEMS)
  484. #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."
  485. #else
  486. #define MAX_NR_SERVICE_RECORD_ITEMS 0
  487. #endif
  488. #endif
  489. #ifdef MAX_NR_SERVICE_RECORD_ITEMS
  490. #if MAX_NR_SERVICE_RECORD_ITEMS > 0
  491. static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
  492. static btstack_memory_pool_t service_record_item_pool;
  493. service_record_item_t * btstack_memory_service_record_item_get(void){
  494. void * buffer = btstack_memory_pool_get(&service_record_item_pool);
  495. if (buffer){
  496. memset(buffer, 0, sizeof(service_record_item_t));
  497. }
  498. return (service_record_item_t *) buffer;
  499. }
  500. void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
  501. btstack_memory_pool_free(&service_record_item_pool, service_record_item);
  502. }
  503. #else
  504. service_record_item_t * btstack_memory_service_record_item_get(void){
  505. return NULL;
  506. }
  507. void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
  508. // silence compiler warning about unused parameter in a portable way
  509. (void) service_record_item;
  510. };
  511. #endif
  512. #elif defined(HAVE_MALLOC)
  513. service_record_item_t * btstack_memory_service_record_item_get(void){
  514. void * buffer = malloc(sizeof(service_record_item_t));
  515. if (buffer){
  516. memset(buffer, 0, sizeof(service_record_item_t));
  517. }
  518. return (service_record_item_t *) buffer;
  519. }
  520. void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
  521. free(service_record_item);
  522. }
  523. #endif
  524. // MARK: avdtp_stream_endpoint_t
  525. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_STREAM_ENDPOINTS)
  526. #if defined(MAX_NO_AVDTP_STREAM_ENDPOINTS)
  527. #error "Deprecated MAX_NO_AVDTP_STREAM_ENDPOINTS defined instead of MAX_NR_AVDTP_STREAM_ENDPOINTS. Please update your btstack_config.h to use MAX_NR_AVDTP_STREAM_ENDPOINTS."
  528. #else
  529. #define MAX_NR_AVDTP_STREAM_ENDPOINTS 0
  530. #endif
  531. #endif
  532. #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
  533. #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
  534. static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
  535. static btstack_memory_pool_t avdtp_stream_endpoint_pool;
  536. avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
  537. void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
  538. if (buffer){
  539. memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
  540. }
  541. return (avdtp_stream_endpoint_t *) buffer;
  542. }
  543. void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
  544. btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
  545. }
  546. #else
  547. avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
  548. return NULL;
  549. }
  550. void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
  551. // silence compiler warning about unused parameter in a portable way
  552. (void) avdtp_stream_endpoint;
  553. };
  554. #endif
  555. #elif defined(HAVE_MALLOC)
  556. avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
  557. void * buffer = malloc(sizeof(avdtp_stream_endpoint_t));
  558. if (buffer){
  559. memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
  560. }
  561. return (avdtp_stream_endpoint_t *) buffer;
  562. }
  563. void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
  564. free(avdtp_stream_endpoint);
  565. }
  566. #endif
  567. // MARK: avdtp_connection_t
  568. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVDTP_CONNECTIONS)
  569. #if defined(MAX_NO_AVDTP_CONNECTIONS)
  570. #error "Deprecated MAX_NO_AVDTP_CONNECTIONS defined instead of MAX_NR_AVDTP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVDTP_CONNECTIONS."
  571. #else
  572. #define MAX_NR_AVDTP_CONNECTIONS 0
  573. #endif
  574. #endif
  575. #ifdef MAX_NR_AVDTP_CONNECTIONS
  576. #if MAX_NR_AVDTP_CONNECTIONS > 0
  577. static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
  578. static btstack_memory_pool_t avdtp_connection_pool;
  579. avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
  580. void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
  581. if (buffer){
  582. memset(buffer, 0, sizeof(avdtp_connection_t));
  583. }
  584. return (avdtp_connection_t *) buffer;
  585. }
  586. void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
  587. btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
  588. }
  589. #else
  590. avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
  591. return NULL;
  592. }
  593. void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
  594. // silence compiler warning about unused parameter in a portable way
  595. (void) avdtp_connection;
  596. };
  597. #endif
  598. #elif defined(HAVE_MALLOC)
  599. avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
  600. void * buffer = malloc(sizeof(avdtp_connection_t));
  601. if (buffer){
  602. memset(buffer, 0, sizeof(avdtp_connection_t));
  603. }
  604. return (avdtp_connection_t *) buffer;
  605. }
  606. void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
  607. free(avdtp_connection);
  608. }
  609. #endif
  610. // MARK: avrcp_connection_t
  611. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_CONNECTIONS)
  612. #if defined(MAX_NO_AVRCP_CONNECTIONS)
  613. #error "Deprecated MAX_NO_AVRCP_CONNECTIONS defined instead of MAX_NR_AVRCP_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_CONNECTIONS."
  614. #else
  615. #define MAX_NR_AVRCP_CONNECTIONS 0
  616. #endif
  617. #endif
  618. #ifdef MAX_NR_AVRCP_CONNECTIONS
  619. #if MAX_NR_AVRCP_CONNECTIONS > 0
  620. static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
  621. static btstack_memory_pool_t avrcp_connection_pool;
  622. avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
  623. void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
  624. if (buffer){
  625. memset(buffer, 0, sizeof(avrcp_connection_t));
  626. }
  627. return (avrcp_connection_t *) buffer;
  628. }
  629. void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
  630. btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
  631. }
  632. #else
  633. avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
  634. return NULL;
  635. }
  636. void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
  637. // silence compiler warning about unused parameter in a portable way
  638. (void) avrcp_connection;
  639. };
  640. #endif
  641. #elif defined(HAVE_MALLOC)
  642. avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
  643. void * buffer = malloc(sizeof(avrcp_connection_t));
  644. if (buffer){
  645. memset(buffer, 0, sizeof(avrcp_connection_t));
  646. }
  647. return (avrcp_connection_t *) buffer;
  648. }
  649. void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
  650. free(avrcp_connection);
  651. }
  652. #endif
  653. // MARK: avrcp_browsing_connection_t
  654. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_AVRCP_BROWSING_CONNECTIONS)
  655. #if defined(MAX_NO_AVRCP_BROWSING_CONNECTIONS)
  656. #error "Deprecated MAX_NO_AVRCP_BROWSING_CONNECTIONS defined instead of MAX_NR_AVRCP_BROWSING_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_AVRCP_BROWSING_CONNECTIONS."
  657. #else
  658. #define MAX_NR_AVRCP_BROWSING_CONNECTIONS 0
  659. #endif
  660. #endif
  661. #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
  662. #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
  663. static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
  664. static btstack_memory_pool_t avrcp_browsing_connection_pool;
  665. avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
  666. void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
  667. if (buffer){
  668. memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
  669. }
  670. return (avrcp_browsing_connection_t *) buffer;
  671. }
  672. void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
  673. btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
  674. }
  675. #else
  676. avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
  677. return NULL;
  678. }
  679. void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
  680. // silence compiler warning about unused parameter in a portable way
  681. (void) avrcp_browsing_connection;
  682. };
  683. #endif
  684. #elif defined(HAVE_MALLOC)
  685. avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
  686. void * buffer = malloc(sizeof(avrcp_browsing_connection_t));
  687. if (buffer){
  688. memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
  689. }
  690. return (avrcp_browsing_connection_t *) buffer;
  691. }
  692. void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
  693. free(avrcp_browsing_connection);
  694. }
  695. #endif
  696. #endif
  697. #ifdef ENABLE_BLE
  698. // MARK: gatt_client_t
  699. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_GATT_CLIENTS)
  700. #if defined(MAX_NO_GATT_CLIENTS)
  701. #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."
  702. #else
  703. #define MAX_NR_GATT_CLIENTS 0
  704. #endif
  705. #endif
  706. #ifdef MAX_NR_GATT_CLIENTS
  707. #if MAX_NR_GATT_CLIENTS > 0
  708. static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
  709. static btstack_memory_pool_t gatt_client_pool;
  710. gatt_client_t * btstack_memory_gatt_client_get(void){
  711. void * buffer = btstack_memory_pool_get(&gatt_client_pool);
  712. if (buffer){
  713. memset(buffer, 0, sizeof(gatt_client_t));
  714. }
  715. return (gatt_client_t *) buffer;
  716. }
  717. void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
  718. btstack_memory_pool_free(&gatt_client_pool, gatt_client);
  719. }
  720. #else
  721. gatt_client_t * btstack_memory_gatt_client_get(void){
  722. return NULL;
  723. }
  724. void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
  725. // silence compiler warning about unused parameter in a portable way
  726. (void) gatt_client;
  727. };
  728. #endif
  729. #elif defined(HAVE_MALLOC)
  730. gatt_client_t * btstack_memory_gatt_client_get(void){
  731. void * buffer = malloc(sizeof(gatt_client_t));
  732. if (buffer){
  733. memset(buffer, 0, sizeof(gatt_client_t));
  734. }
  735. return (gatt_client_t *) buffer;
  736. }
  737. void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
  738. free(gatt_client);
  739. }
  740. #endif
  741. // MARK: whitelist_entry_t
  742. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_WHITELIST_ENTRIES)
  743. #if defined(MAX_NO_WHITELIST_ENTRIES)
  744. #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."
  745. #else
  746. #define MAX_NR_WHITELIST_ENTRIES 0
  747. #endif
  748. #endif
  749. #ifdef MAX_NR_WHITELIST_ENTRIES
  750. #if MAX_NR_WHITELIST_ENTRIES > 0
  751. static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
  752. static btstack_memory_pool_t whitelist_entry_pool;
  753. whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
  754. void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
  755. if (buffer){
  756. memset(buffer, 0, sizeof(whitelist_entry_t));
  757. }
  758. return (whitelist_entry_t *) buffer;
  759. }
  760. void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
  761. btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
  762. }
  763. #else
  764. whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
  765. return NULL;
  766. }
  767. void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
  768. // silence compiler warning about unused parameter in a portable way
  769. (void) whitelist_entry;
  770. };
  771. #endif
  772. #elif defined(HAVE_MALLOC)
  773. whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
  774. void * buffer = malloc(sizeof(whitelist_entry_t));
  775. if (buffer){
  776. memset(buffer, 0, sizeof(whitelist_entry_t));
  777. }
  778. return (whitelist_entry_t *) buffer;
  779. }
  780. void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
  781. free(whitelist_entry);
  782. }
  783. #endif
  784. // MARK: sm_lookup_entry_t
  785. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SM_LOOKUP_ENTRIES)
  786. #if defined(MAX_NO_SM_LOOKUP_ENTRIES)
  787. #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."
  788. #else
  789. #define MAX_NR_SM_LOOKUP_ENTRIES 0
  790. #endif
  791. #endif
  792. #ifdef MAX_NR_SM_LOOKUP_ENTRIES
  793. #if MAX_NR_SM_LOOKUP_ENTRIES > 0
  794. static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
  795. static btstack_memory_pool_t sm_lookup_entry_pool;
  796. sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
  797. void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
  798. if (buffer){
  799. memset(buffer, 0, sizeof(sm_lookup_entry_t));
  800. }
  801. return (sm_lookup_entry_t *) buffer;
  802. }
  803. void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
  804. btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
  805. }
  806. #else
  807. sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
  808. return NULL;
  809. }
  810. void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
  811. // silence compiler warning about unused parameter in a portable way
  812. (void) sm_lookup_entry;
  813. };
  814. #endif
  815. #elif defined(HAVE_MALLOC)
  816. sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
  817. void * buffer = malloc(sizeof(sm_lookup_entry_t));
  818. if (buffer){
  819. memset(buffer, 0, sizeof(sm_lookup_entry_t));
  820. }
  821. return (sm_lookup_entry_t *) buffer;
  822. }
  823. void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
  824. free(sm_lookup_entry);
  825. }
  826. #endif
  827. #endif
  828. #ifdef ENABLE_MESH
  829. // MARK: mesh_network_pdu_t
  830. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
  831. #if defined(MAX_NO_MESH_NETWORK_PDUS)
  832. #error "Deprecated MAX_NO_MESH_NETWORK_PDUS defined instead of MAX_NR_MESH_NETWORK_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_PDUS."
  833. #else
  834. #define MAX_NR_MESH_NETWORK_PDUS 0
  835. #endif
  836. #endif
  837. #ifdef MAX_NR_MESH_NETWORK_PDUS
  838. #if MAX_NR_MESH_NETWORK_PDUS > 0
  839. static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
  840. static btstack_memory_pool_t mesh_network_pdu_pool;
  841. mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
  842. void * buffer = btstack_memory_pool_get(&mesh_network_pdu_pool);
  843. if (buffer){
  844. memset(buffer, 0, sizeof(mesh_network_pdu_t));
  845. }
  846. return (mesh_network_pdu_t *) buffer;
  847. }
  848. void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
  849. btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
  850. }
  851. #else
  852. mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
  853. return NULL;
  854. }
  855. void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
  856. // silence compiler warning about unused parameter in a portable way
  857. (void) mesh_network_pdu;
  858. };
  859. #endif
  860. #elif defined(HAVE_MALLOC)
  861. mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
  862. void * buffer = malloc(sizeof(mesh_network_pdu_t));
  863. if (buffer){
  864. memset(buffer, 0, sizeof(mesh_network_pdu_t));
  865. }
  866. return (mesh_network_pdu_t *) buffer;
  867. }
  868. void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
  869. free(mesh_network_pdu);
  870. }
  871. #endif
  872. // MARK: mesh_transport_pdu_t
  873. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_PDUS)
  874. #if defined(MAX_NO_MESH_TRANSPORT_PDUS)
  875. #error "Deprecated MAX_NO_MESH_TRANSPORT_PDUS defined instead of MAX_NR_MESH_TRANSPORT_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_PDUS."
  876. #else
  877. #define MAX_NR_MESH_TRANSPORT_PDUS 0
  878. #endif
  879. #endif
  880. #ifdef MAX_NR_MESH_TRANSPORT_PDUS
  881. #if MAX_NR_MESH_TRANSPORT_PDUS > 0
  882. static mesh_transport_pdu_t mesh_transport_pdu_storage[MAX_NR_MESH_TRANSPORT_PDUS];
  883. static btstack_memory_pool_t mesh_transport_pdu_pool;
  884. mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){
  885. void * buffer = btstack_memory_pool_get(&mesh_transport_pdu_pool);
  886. if (buffer){
  887. memset(buffer, 0, sizeof(mesh_transport_pdu_t));
  888. }
  889. return (mesh_transport_pdu_t *) buffer;
  890. }
  891. void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){
  892. btstack_memory_pool_free(&mesh_transport_pdu_pool, mesh_transport_pdu);
  893. }
  894. #else
  895. mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){
  896. return NULL;
  897. }
  898. void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){
  899. // silence compiler warning about unused parameter in a portable way
  900. (void) mesh_transport_pdu;
  901. };
  902. #endif
  903. #elif defined(HAVE_MALLOC)
  904. mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void){
  905. void * buffer = malloc(sizeof(mesh_transport_pdu_t));
  906. if (buffer){
  907. memset(buffer, 0, sizeof(mesh_transport_pdu_t));
  908. }
  909. return (mesh_transport_pdu_t *) buffer;
  910. }
  911. void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu){
  912. free(mesh_transport_pdu);
  913. }
  914. #endif
  915. // MARK: mesh_network_key_t
  916. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
  917. #if defined(MAX_NO_MESH_NETWORK_KEYS)
  918. #error "Deprecated MAX_NO_MESH_NETWORK_KEYS defined instead of MAX_NR_MESH_NETWORK_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_KEYS."
  919. #else
  920. #define MAX_NR_MESH_NETWORK_KEYS 0
  921. #endif
  922. #endif
  923. #ifdef MAX_NR_MESH_NETWORK_KEYS
  924. #if MAX_NR_MESH_NETWORK_KEYS > 0
  925. static mesh_network_key_t mesh_network_key_storage[MAX_NR_MESH_NETWORK_KEYS];
  926. static btstack_memory_pool_t mesh_network_key_pool;
  927. mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
  928. void * buffer = btstack_memory_pool_get(&mesh_network_key_pool);
  929. if (buffer){
  930. memset(buffer, 0, sizeof(mesh_network_key_t));
  931. }
  932. return (mesh_network_key_t *) buffer;
  933. }
  934. void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
  935. btstack_memory_pool_free(&mesh_network_key_pool, mesh_network_key);
  936. }
  937. #else
  938. mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
  939. return NULL;
  940. }
  941. void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
  942. // silence compiler warning about unused parameter in a portable way
  943. (void) mesh_network_key;
  944. };
  945. #endif
  946. #elif defined(HAVE_MALLOC)
  947. mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
  948. void * buffer = malloc(sizeof(mesh_network_key_t));
  949. if (buffer){
  950. memset(buffer, 0, sizeof(mesh_network_key_t));
  951. }
  952. return (mesh_network_key_t *) buffer;
  953. }
  954. void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
  955. free(mesh_network_key);
  956. }
  957. #endif
  958. // MARK: mesh_transport_key_t
  959. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
  960. #if defined(MAX_NO_MESH_TRANSPORT_KEYS)
  961. #error "Deprecated MAX_NO_MESH_TRANSPORT_KEYS defined instead of MAX_NR_MESH_TRANSPORT_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_KEYS."
  962. #else
  963. #define MAX_NR_MESH_TRANSPORT_KEYS 0
  964. #endif
  965. #endif
  966. #ifdef MAX_NR_MESH_TRANSPORT_KEYS
  967. #if MAX_NR_MESH_TRANSPORT_KEYS > 0
  968. static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
  969. static btstack_memory_pool_t mesh_transport_key_pool;
  970. mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
  971. void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
  972. if (buffer){
  973. memset(buffer, 0, sizeof(mesh_transport_key_t));
  974. }
  975. return (mesh_transport_key_t *) buffer;
  976. }
  977. void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
  978. btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
  979. }
  980. #else
  981. mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
  982. return NULL;
  983. }
  984. void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
  985. // silence compiler warning about unused parameter in a portable way
  986. (void) mesh_transport_key;
  987. };
  988. #endif
  989. #elif defined(HAVE_MALLOC)
  990. mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
  991. void * buffer = malloc(sizeof(mesh_transport_key_t));
  992. if (buffer){
  993. memset(buffer, 0, sizeof(mesh_transport_key_t));
  994. }
  995. return (mesh_transport_key_t *) buffer;
  996. }
  997. void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
  998. free(mesh_transport_key);
  999. }
  1000. #endif
  1001. // MARK: mesh_virtual_address_t
  1002. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_VIRTUAL_ADDRESSS)
  1003. #if defined(MAX_NO_MESH_VIRTUAL_ADDRESSS)
  1004. #error "Deprecated MAX_NO_MESH_VIRTUAL_ADDRESSS defined instead of MAX_NR_MESH_VIRTUAL_ADDRESSS. Please update your btstack_config.h to use MAX_NR_MESH_VIRTUAL_ADDRESSS."
  1005. #else
  1006. #define MAX_NR_MESH_VIRTUAL_ADDRESSS 0
  1007. #endif
  1008. #endif
  1009. #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
  1010. #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
  1011. static mesh_virtual_address_t mesh_virtual_address_storage[MAX_NR_MESH_VIRTUAL_ADDRESSS];
  1012. static btstack_memory_pool_t mesh_virtual_address_pool;
  1013. mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
  1014. void * buffer = btstack_memory_pool_get(&mesh_virtual_address_pool);
  1015. if (buffer){
  1016. memset(buffer, 0, sizeof(mesh_virtual_address_t));
  1017. }
  1018. return (mesh_virtual_address_t *) buffer;
  1019. }
  1020. void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
  1021. btstack_memory_pool_free(&mesh_virtual_address_pool, mesh_virtual_address);
  1022. }
  1023. #else
  1024. mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
  1025. return NULL;
  1026. }
  1027. void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
  1028. // silence compiler warning about unused parameter in a portable way
  1029. (void) mesh_virtual_address;
  1030. };
  1031. #endif
  1032. #elif defined(HAVE_MALLOC)
  1033. mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void){
  1034. void * buffer = malloc(sizeof(mesh_virtual_address_t));
  1035. if (buffer){
  1036. memset(buffer, 0, sizeof(mesh_virtual_address_t));
  1037. }
  1038. return (mesh_virtual_address_t *) buffer;
  1039. }
  1040. void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address){
  1041. free(mesh_virtual_address);
  1042. }
  1043. #endif
  1044. // MARK: mesh_subnet_t
  1045. #if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_SUBNETS)
  1046. #if defined(MAX_NO_MESH_SUBNETS)
  1047. #error "Deprecated MAX_NO_MESH_SUBNETS defined instead of MAX_NR_MESH_SUBNETS. Please update your btstack_config.h to use MAX_NR_MESH_SUBNETS."
  1048. #else
  1049. #define MAX_NR_MESH_SUBNETS 0
  1050. #endif
  1051. #endif
  1052. #ifdef MAX_NR_MESH_SUBNETS
  1053. #if MAX_NR_MESH_SUBNETS > 0
  1054. static mesh_subnet_t mesh_subnet_storage[MAX_NR_MESH_SUBNETS];
  1055. static btstack_memory_pool_t mesh_subnet_pool;
  1056. mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
  1057. void * buffer = btstack_memory_pool_get(&mesh_subnet_pool);
  1058. if (buffer){
  1059. memset(buffer, 0, sizeof(mesh_subnet_t));
  1060. }
  1061. return (mesh_subnet_t *) buffer;
  1062. }
  1063. void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
  1064. btstack_memory_pool_free(&mesh_subnet_pool, mesh_subnet);
  1065. }
  1066. #else
  1067. mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
  1068. return NULL;
  1069. }
  1070. void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
  1071. // silence compiler warning about unused parameter in a portable way
  1072. (void) mesh_subnet;
  1073. };
  1074. #endif
  1075. #elif defined(HAVE_MALLOC)
  1076. mesh_subnet_t * btstack_memory_mesh_subnet_get(void){
  1077. void * buffer = malloc(sizeof(mesh_subnet_t));
  1078. if (buffer){
  1079. memset(buffer, 0, sizeof(mesh_subnet_t));
  1080. }
  1081. return (mesh_subnet_t *) buffer;
  1082. }
  1083. void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){
  1084. free(mesh_subnet);
  1085. }
  1086. #endif
  1087. #endif
  1088. // init
  1089. void btstack_memory_init(void){
  1090. #if MAX_NR_HCI_CONNECTIONS > 0
  1091. btstack_memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NR_HCI_CONNECTIONS, sizeof(hci_connection_t));
  1092. #endif
  1093. #if MAX_NR_L2CAP_SERVICES > 0
  1094. btstack_memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NR_L2CAP_SERVICES, sizeof(l2cap_service_t));
  1095. #endif
  1096. #if MAX_NR_L2CAP_CHANNELS > 0
  1097. btstack_memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NR_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
  1098. #endif
  1099. #ifdef ENABLE_CLASSIC
  1100. #if MAX_NR_RFCOMM_MULTIPLEXERS > 0
  1101. btstack_memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NR_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
  1102. #endif
  1103. #if MAX_NR_RFCOMM_SERVICES > 0
  1104. btstack_memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NR_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
  1105. #endif
  1106. #if MAX_NR_RFCOMM_CHANNELS > 0
  1107. btstack_memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NR_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
  1108. #endif
  1109. #if MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES > 0
  1110. 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));
  1111. #endif
  1112. #if MAX_NR_BNEP_SERVICES > 0
  1113. btstack_memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NR_BNEP_SERVICES, sizeof(bnep_service_t));
  1114. #endif
  1115. #if MAX_NR_BNEP_CHANNELS > 0
  1116. btstack_memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NR_BNEP_CHANNELS, sizeof(bnep_channel_t));
  1117. #endif
  1118. #if MAX_NR_HFP_CONNECTIONS > 0
  1119. btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t));
  1120. #endif
  1121. #if MAX_NR_SERVICE_RECORD_ITEMS > 0
  1122. btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t));
  1123. #endif
  1124. #if MAX_NR_AVDTP_STREAM_ENDPOINTS > 0
  1125. btstack_memory_pool_create(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint_storage, MAX_NR_AVDTP_STREAM_ENDPOINTS, sizeof(avdtp_stream_endpoint_t));
  1126. #endif
  1127. #if MAX_NR_AVDTP_CONNECTIONS > 0
  1128. btstack_memory_pool_create(&avdtp_connection_pool, avdtp_connection_storage, MAX_NR_AVDTP_CONNECTIONS, sizeof(avdtp_connection_t));
  1129. #endif
  1130. #if MAX_NR_AVRCP_CONNECTIONS > 0
  1131. btstack_memory_pool_create(&avrcp_connection_pool, avrcp_connection_storage, MAX_NR_AVRCP_CONNECTIONS, sizeof(avrcp_connection_t));
  1132. #endif
  1133. #if MAX_NR_AVRCP_BROWSING_CONNECTIONS > 0
  1134. btstack_memory_pool_create(&avrcp_browsing_connection_pool, avrcp_browsing_connection_storage, MAX_NR_AVRCP_BROWSING_CONNECTIONS, sizeof(avrcp_browsing_connection_t));
  1135. #endif
  1136. #endif
  1137. #ifdef ENABLE_BLE
  1138. #if MAX_NR_GATT_CLIENTS > 0
  1139. btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NR_GATT_CLIENTS, sizeof(gatt_client_t));
  1140. #endif
  1141. #if MAX_NR_WHITELIST_ENTRIES > 0
  1142. btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NR_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
  1143. #endif
  1144. #if MAX_NR_SM_LOOKUP_ENTRIES > 0
  1145. btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
  1146. #endif
  1147. #endif
  1148. #ifdef ENABLE_MESH
  1149. #if MAX_NR_MESH_NETWORK_PDUS > 0
  1150. btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
  1151. #endif
  1152. #if MAX_NR_MESH_TRANSPORT_PDUS > 0
  1153. btstack_memory_pool_create(&mesh_transport_pdu_pool, mesh_transport_pdu_storage, MAX_NR_MESH_TRANSPORT_PDUS, sizeof(mesh_transport_pdu_t));
  1154. #endif
  1155. #if MAX_NR_MESH_NETWORK_KEYS > 0
  1156. btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
  1157. #endif
  1158. #if MAX_NR_MESH_TRANSPORT_KEYS > 0
  1159. btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
  1160. #endif
  1161. #if MAX_NR_MESH_VIRTUAL_ADDRESSS > 0
  1162. btstack_memory_pool_create(&mesh_virtual_address_pool, mesh_virtual_address_storage, MAX_NR_MESH_VIRTUAL_ADDRESSS, sizeof(mesh_virtual_address_t));
  1163. #endif
  1164. #if MAX_NR_MESH_SUBNETS > 0
  1165. btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t));
  1166. #endif
  1167. #endif
  1168. }