xref: /btstack/src/btstack_memory.h (revision dbf84c8a4e5f19f37bf9128db249cb40829b9966)
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 BLUEKITCHEN
24  * GMBH 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 /*
41  * btstack_memory.h
42  *
43  * @brief BTstack memory management using configurable memory pools
44  *
45  */
46 
47 #ifndef BTSTACK_MEMORY_H
48 #define BTSTACK_MEMORY_H
49 
50 #if defined __cplusplus
51 extern "C" {
52 #endif
53 
54 #include "btstack_config.h"
55 
56 // Core
57 #include "hci.h"
58 #include "l2cap.h"
59 
60 // Classic
61 #ifdef ENABLE_CLASSIC
62 #include "classic/avdtp_sink.h"
63 #include "classic/avdtp_source.h"
64 #include "classic/avrcp.h"
65 #include "classic/bnep.h"
66 #include "classic/btstack_link_key_db.h"
67 #include "classic/btstack_link_key_db_memory.h"
68 #include "classic/goep_server.h"
69 #include "classic/hfp.h"
70 #include "classic/hid_host.h"
71 #include "classic/rfcomm.h"
72 #include "classic/sdp_server.h"
73 #endif
74 
75 // BLE
76 #ifdef ENABLE_BLE
77 #include "ble/gatt-service/battery_service_client.h"
78 #include "ble/gatt-service/hids_client.h"
79 #include "ble/gatt-service/scan_parameters_service_client.h"
80 #include "ble/gatt_client.h"
81 #include "ble/sm.h"
82 #endif
83 
84 #ifdef ENABLE_MESH
85 #include "mesh/mesh_network.h"
86 #include "mesh/mesh_keys.h"
87 #include "mesh/mesh_virtual_addresses.h"
88 #endif
89 
90 /* API_START */
91 
92 /**
93  * @brief Initializes BTstack memory pools.
94  */
95 void btstack_memory_init(void);
96 
97 /**
98  * @brief Deinitialize BTstack memory pools
99  * @note if HAVE_MALLOC is defined, all previously allocated buffers are free'd
100  */
101 void btstack_memory_deinit(void);
102 
103 /* API_END */
104 
105 // hci_connection
106 hci_connection_t * btstack_memory_hci_connection_get(void);
107 void   btstack_memory_hci_connection_free(hci_connection_t *hci_connection);
108 
109 // l2cap_service, l2cap_channel
110 l2cap_service_t * btstack_memory_l2cap_service_get(void);
111 void   btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service);
112 l2cap_channel_t * btstack_memory_l2cap_channel_get(void);
113 void   btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel);
114 
115 #ifdef ENABLE_CLASSIC
116 // rfcomm_multiplexer, rfcomm_service, rfcomm_channel
117 rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void);
118 void   btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer);
119 rfcomm_service_t * btstack_memory_rfcomm_service_get(void);
120 void   btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service);
121 rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void);
122 void   btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel);
123 
124 // btstack_link_key_db_memory_entry
125 btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void);
126 void   btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry);
127 
128 // bnep_service, bnep_channel
129 bnep_service_t * btstack_memory_bnep_service_get(void);
130 void   btstack_memory_bnep_service_free(bnep_service_t *bnep_service);
131 bnep_channel_t * btstack_memory_bnep_channel_get(void);
132 void   btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel);
133 
134 // goep_server_service, goep_server_connection
135 goep_server_service_t * btstack_memory_goep_server_service_get(void);
136 void   btstack_memory_goep_server_service_free(goep_server_service_t *goep_server_service);
137 goep_server_connection_t * btstack_memory_goep_server_connection_get(void);
138 void   btstack_memory_goep_server_connection_free(goep_server_connection_t *goep_server_connection);
139 
140 // hfp_connection
141 hfp_connection_t * btstack_memory_hfp_connection_get(void);
142 void   btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection);
143 
144 // hid_host_connection
145 hid_host_connection_t * btstack_memory_hid_host_connection_get(void);
146 void   btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection);
147 
148 // avdtp_stream_endpoint
149 avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void);
150 void   btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint);
151 
152 // avdtp_connection
153 avdtp_connection_t * btstack_memory_avdtp_connection_get(void);
154 void   btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection);
155 
156 // avrcp_connection
157 avrcp_connection_t * btstack_memory_avrcp_connection_get(void);
158 void   btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection);
159 
160 // avrcp_browsing_connection
161 avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void);
162 void   btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection);
163 
164 // service_record_item
165 service_record_item_t * btstack_memory_service_record_item_get(void);
166 void   btstack_memory_service_record_item_free(service_record_item_t *service_record_item);
167 
168 #endif
169 #ifdef ENABLE_BLE
170 // battery_service_client, gatt_client, hids_client, scan_parameters_service_client, sm_lookup_entry, whitelist_entry, periodic_advertiser_list_entry
171 battery_service_client_t * btstack_memory_battery_service_client_get(void);
172 void   btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client);
173 gatt_client_t * btstack_memory_gatt_client_get(void);
174 void   btstack_memory_gatt_client_free(gatt_client_t *gatt_client);
175 hids_client_t * btstack_memory_hids_client_get(void);
176 void   btstack_memory_hids_client_free(hids_client_t *hids_client);
177 scan_parameters_service_client_t * btstack_memory_scan_parameters_service_client_get(void);
178 void   btstack_memory_scan_parameters_service_client_free(scan_parameters_service_client_t *scan_parameters_service_client);
179 sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void);
180 void   btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry);
181 whitelist_entry_t * btstack_memory_whitelist_entry_get(void);
182 void   btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry);
183 periodic_advertiser_list_entry_t * btstack_memory_periodic_advertiser_list_entry_get(void);
184 void   btstack_memory_periodic_advertiser_list_entry_free(periodic_advertiser_list_entry_t *periodic_advertiser_list_entry);
185 #endif
186 #ifdef ENABLE_MESH
187 // mesh_network_pdu, mesh_segmented_pdu, mesh_upper_transport_pdu, mesh_network_key, mesh_transport_key, mesh_virtual_address, mesh_subnet
188 mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void);
189 void   btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu);
190 mesh_segmented_pdu_t * btstack_memory_mesh_segmented_pdu_get(void);
191 void   btstack_memory_mesh_segmented_pdu_free(mesh_segmented_pdu_t *mesh_segmented_pdu);
192 mesh_upper_transport_pdu_t * btstack_memory_mesh_upper_transport_pdu_get(void);
193 void   btstack_memory_mesh_upper_transport_pdu_free(mesh_upper_transport_pdu_t *mesh_upper_transport_pdu);
194 mesh_network_key_t * btstack_memory_mesh_network_key_get(void);
195 void   btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key);
196 mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void);
197 void   btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key);
198 mesh_virtual_address_t * btstack_memory_mesh_virtual_address_get(void);
199 void   btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_virtual_address);
200 mesh_subnet_t * btstack_memory_mesh_subnet_get(void);
201 void   btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet);
202 #endif
203 
204 #if defined __cplusplus
205 }
206 #endif
207 
208 #endif // BTSTACK_MEMORY_H
209 
210