• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2000-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This module contains the routines that initialize the stack components.
22  *  It must be called before the BTU task is started.
23  *
24  ******************************************************************************/
25 
26 #include "common/bt_target.h"
27 #include <string.h>
28 
29 /* Stack Configuation Related Init Definaton
30  * TODO: Now Just Unmask these defination until stack layer is OK
31  */
32 
33 #ifndef BTA_INCLUDED
34 #define BTA_INCLUDED 0
35 #endif
36 
37 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == 1)
38 // Include initialization functions definitions
39 #include "stack/port_api.h"
40 #endif
41 
42 #if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == 1)
43 #include "bnep_api.h"
44 #endif
45 
46 #if (defined(GAP_INCLUDED) && GAP_INCLUDED == 1)
47 #include "stack/gap_api.h"
48 #endif
49 
50 #if (defined(PAN_INCLUDED) && PAN_INCLUDED == 1)
51 #include "pan_api.h"
52 #endif
53 
54 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == 1)
55 #include "stack/avrc_api.h"
56 #endif
57 
58 #if (defined(A2D_INCLUDED) && A2D_INCLUDED == 1)
59 #include "stack/a2d_api.h"
60 #endif
61 
62 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == 1)
63 #include "avdt_int.h"
64 #endif
65 
66 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == 1)
67 #include "avct_int.h"
68 #endif
69 
70 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == 1)
71 #include "stack/hidh_api.h"
72 #endif
73 
74 #if (defined(MCA_INCLUDED) && MCA_INCLUDED == 1)
75 #include "mca_api.h"
76 #endif
77 
78 #if (defined(BLE_INCLUDED) && BLE_INCLUDED == 1)
79 #include "stack/gatt_api.h"
80 #if (defined(SMP_INCLUDED) && SMP_INCLUDED == 1)
81 #include "stack/smp_api.h"
82 #endif
83 #endif
84 
85 //BTA Modules
86 #if BTA_INCLUDED == 1 && BTA_DYNAMIC_MEMORY == 1
87 #include "bta/bta_api.h"
88 #include "bta/bta_sys.h"
89 #include "osi/allocator.h"
90 
91 #if BTA_HF_INCLUDED == 1
92 #include "bta_hf_client_int.h"
93 #endif
94 
95 #if BTA_AG_INCLUDED == 1
96 #include "bta_ag_int.h"
97 #endif
98 
99 #if BTA_SDP_INCLUDED == 1
100 #include "bta_sdp_int.h"
101 #endif
102 
103 #if BTA_HS_INCLUDED == 1
104 #include "bta_hs_int.h"
105 #endif
106 
107 #include "bta_dm_int.h"
108 
109 #if BTA_AR_INCLUDED==1
110 #include "bta_ar_int.h"
111 #endif
112 #if BTA_AV_INCLUDED==1
113 #include "bta_av_int.h"
114 #endif
115 
116 #if BTA_HH_INCLUDED==1
117 #include "bta_hh_int.h"
118 #endif
119 
120 #if BTA_JV_INCLUDED==1
121 #include "bta_jv_int.h"
122 #endif
123 
124 #if BTA_HL_INCLUDED == 1
125 #include "bta_hl_int.h"
126 #endif
127 
128 #if BTA_GATT_INCLUDED == 1
129 #include "bta_gattc_int.h"
130 #include "bta_gatts_int.h"
131 #endif
132 
133 #if BTA_PAN_INCLUDED==1
134 #include "bta_pan_int.h"
135 #endif
136 
137 #include "bta_sys_int.h"
138 
139 // control block for patch ram downloading
140 //#include "bta_prm_int.h"
141 
142 #endif // BTA_INCLUDED == 1 && BTA_DYNAMIC_MEMORY == 1
143 
144 
145 /*****************************************************************************
146 **                          F U N C T I O N S                                *
147 ******************************************************************************/
148 
149 /*****************************************************************************
150 **
151 ** Function         BTE_DeinitStack
152 **
153 ** Description      Deinitialize control block memory for each component.
154 **
155 **                  Note: This API must be called
156 **                      after freeing the BTU Task.
157 **
158 ** Returns          void
159 **
160 ******************************************************************************/
BTE_DeinitStack(void)161 void BTE_DeinitStack(void)
162 {
163     //BTA Modules
164 #if (BTA_INCLUDED == 1 && BTA_DYNAMIC_MEMORY == 1)
165 #if GATTS_INCLUDED == 1
166     if (bta_gatts_cb_ptr){
167         osi_free(bta_gatts_cb_ptr);
168         bta_gatts_cb_ptr = NULL;
169     }
170 #endif
171 #if GATTC_INCLUDED==1
172     if (bta_gattc_cb_ptr){
173         osi_free(bta_gattc_cb_ptr);
174         bta_gattc_cb_ptr = NULL;
175     }
176 #endif
177 #if BTA_HH_INCLUDED==1
178     if (bta_hh_cb_ptr){
179         osi_free(bta_hh_cb_ptr);
180         bta_hh_cb_ptr = NULL;
181     }
182 #endif
183 #if BTA_AV_INCLUDED==1
184     if (bta_av_cb_ptr){
185         osi_free(bta_av_cb_ptr);
186         bta_av_cb_ptr = NULL;
187     }
188     if (bta_av_sbc_ups_cb_ptr){
189         osi_free(bta_av_sbc_ups_cb_ptr);
190         bta_av_sbc_ups_cb_ptr = NULL;
191     }
192 #endif
193 #if BTA_AR_INCLUDED==1
194     if (bta_ar_cb_ptr){
195         osi_free(bta_ar_cb_ptr);
196         bta_ar_cb_ptr = NULL;
197     }
198 #endif
199 #if SDP_INCLUDED == 1
200     if (g_disc_raw_data_buf){
201         osi_free(g_disc_raw_data_buf);
202         g_disc_raw_data_buf = NULL;
203     }
204 #endif
205 #if BTA_SDP_INCLUDED == 1
206     if (bta_sdp_cb_ptr){
207         osi_free(bta_sdp_cb_ptr);
208         bta_sdp_cb_ptr = NULL;
209     }
210 #endif
211 #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == 1)
212     if (bta_jv_cb_ptr){
213         osi_free(bta_jv_cb_ptr);
214         bta_jv_cb_ptr = NULL;
215     }
216 #endif //JV
217 #if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == 1)
218     if (bta_hf_client_cb_ptr){
219         osi_free(bta_hf_client_cb_ptr);
220         bta_hf_client_cb_ptr = NULL;
221     }
222 #endif
223 #if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == 1)
224     if (bta_ag_cb_ptr){
225         osi_free(bta_ag_cb_ptr);
226         bta_ag_cb_ptr = NULL;
227     }
228 #endif
229     if (bta_dm_conn_srvcs_ptr){
230         osi_free(bta_dm_conn_srvcs_ptr);
231         bta_dm_conn_srvcs_ptr = NULL;
232     }
233     if (bta_dm_di_cb_ptr){
234         osi_free(bta_dm_di_cb_ptr);
235         bta_dm_di_cb_ptr = NULL;
236     }
237     if (bta_dm_search_cb_ptr){
238         osi_free(bta_dm_search_cb_ptr);
239         bta_dm_search_cb_ptr = NULL;
240     }
241     if (bta_dm_cb_ptr){
242         osi_free(bta_dm_cb_ptr);
243         bta_dm_cb_ptr = NULL;
244     }
245     if (bta_sys_cb_ptr){
246         osi_free(bta_sys_cb_ptr);
247         bta_sys_cb_ptr = NULL;
248     }
249 #endif // BTA_INCLUDED == 1
250 
251 #if (defined(GAP_INCLUDED) && GAP_INCLUDED == 1)
252     GAP_Deinit();
253 #endif
254 
255 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == 1 && AVCT_DYNAMIC_MEMORY == 1)
256     if (avct_cb_ptr){
257         osi_free(avct_cb_ptr);
258         avct_cb_ptr = NULL;
259     }
260 #endif
261 
262 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == 1 && AVDT_DYNAMIC_MEMORY == 1)
263     if (avdt_cb_ptr){
264         osi_free(avdt_cb_ptr);
265         avdt_cb_ptr = NULL;
266     }
267 #endif
268 
269 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == 1)
270     AVRC_Deinit();
271 #endif
272 
273 #if (defined(A2D_INCLUDED) && A2D_INCLUDED == 1)
274     A2D_Deinit();
275 #endif
276 
277 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == 1)
278     RFCOMM_Deinit();
279 #endif
280 }
281 
282 /*****************************************************************************
283 **
284 ** Function         BTE_InitStack
285 **
286 ** Description      Initialize control block memory for each component.
287 **
288 **                  Note: The core stack components must be called
289 **                      before creating the BTU Task.  The rest of the
290 **                      components can be initialized at a later time if desired
291 **                      as long as the component's init function is called
292 **                      before accessing any of its functions.
293 **
294 ** Returns          status
295 **
296 ******************************************************************************/
BTE_InitStack(void)297 bt_status_t BTE_InitStack(void)
298 {
299 
300 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == 1)
301     //Initialize the optional stack components
302     if (RFCOMM_Init() != BT_STATUS_SUCCESS) {
303         goto error_exit;
304     }
305 #endif
306     //BNEP and its profiles
307 #if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == 1)
308     BNEP_Init();
309 
310 #if (defined(PAN_INCLUDED) && PAN_INCLUDED == 1)
311     PAN_Init();
312 #endif  // PAN
313 #endif  // BNEP Included
314 
315     //AVDT and its profiles
316 #if (defined(A2D_INCLUDED) && A2D_INCLUDED == 1)
317     if (A2D_Init() != BT_STATUS_SUCCESS) {
318         goto error_exit;
319     }
320 #endif  // AADP
321 
322 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == 1)
323     if (AVRC_Init() != BT_STATUS_SUCCESS) {
324         goto error_exit;
325     }
326 #endif
327 
328 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == 1 && AVDT_DYNAMIC_MEMORY == 1)
329     if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
330         goto error_exit;
331     }
332     memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));
333 #endif
334 
335 #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == 1 && AVCT_DYNAMIC_MEMORY == 1)
336     if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
337         goto error_exit;
338     }
339     memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));
340 #endif
341 
342 #if (defined(GAP_INCLUDED) && GAP_INCLUDED == 1)
343     if (GAP_Init() != BT_STATUS_SUCCESS) {
344         goto error_exit;
345     }
346 #endif
347 
348 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == 1)
349     HID_HostInit();
350 #endif
351 
352 #if (defined(MCA_INCLUDED) && MCA_INCLUDED == 1)
353     MCA_Init();
354 #endif
355 
356     //BTA Modules
357 #if (BTA_INCLUDED == 1 && BTA_DYNAMIC_MEMORY == 1)
358     if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
359         goto error_exit;
360     }
361     if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
362         goto error_exit;
363     }
364     if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
365         goto error_exit;
366     }
367     if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
368         goto error_exit;
369     }
370     if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == NULL) {
371         goto error_exit;
372     }
373     memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
374     memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
375     memset((void *)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
376     memset((void *)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
377     memset((void *)bta_dm_conn_srvcs_ptr, 0, sizeof(tBTA_DM_CONNECTED_SRVCS));
378     //memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
379 #if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == 1)
380     if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) {
381         goto error_exit;
382     }
383     memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB));
384 #endif
385 
386 #if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == 1)
387     if ((bta_ag_cb_ptr = (tBTA_AG_CB *)osi_malloc(sizeof(tBTA_AG_CB))) == NULL) {
388         goto error_exit;
389     }
390     memset((void *)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB));
391 #endif
392 
393 #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == 1)
394     if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) {
395         goto error_exit;
396     }
397     memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));
398 #endif //JV
399 
400 #if BTA_HS_INCLUDED == 1
401     memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
402 #endif
403 
404 #if BTA_SDP_INCLUDED == 1
405     if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
406         goto error_exit;
407     }
408     memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));
409 #endif
410 
411 #if SDP_INCLUDED == 1
412     if ((g_disc_raw_data_buf = (UINT8 *)osi_malloc(MAX_DISC_RAW_DATA_BUF)) == NULL) {
413         goto error_exit;
414     }
415     memset((void *)g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);
416 #endif
417 
418 #if BTA_AR_INCLUDED==1
419     if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
420         goto error_exit;
421     }
422     memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
423 #endif
424 
425 #if BTA_AV_INCLUDED==1
426     if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
427         goto error_exit;
428     }
429     memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
430 
431     if ((bta_av_sbc_ups_cb_ptr = (tBTA_AV_SBC_UPS_CB *)osi_malloc(sizeof(tBTA_AV_SBC_UPS_CB))) == NULL) {
432         goto error_exit;
433     }
434     memset((void *)bta_av_sbc_ups_cb_ptr, 0, sizeof(tBTA_AV_SBC_UPS_CB));
435 #endif
436 
437 #if BTA_HH_INCLUDED==1
438     if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
439         goto error_exit;
440     }
441     memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
442 #endif
443 
444 #if BTA_HL_INCLUDED==1
445     memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
446 #endif
447 
448 #if GATTC_INCLUDED==1
449     if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
450         goto error_exit;
451     }
452     memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
453 #endif
454 
455 #if GATTS_INCLUDED == 1
456     if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
457         goto error_exit;
458     }
459     memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
460 #endif
461 #if BTA_PAN_INCLUDED==1
462     memset((void *)bta_pan_cb_ptr, 0, sizeof(tBTA_PAN_CB));
463 #endif
464 
465 #endif // BTA_INCLUDED == 1
466     return BT_STATUS_SUCCESS;
467 
468 error_exit:;
469     LOG_ERROR("%s failed due to no memory", __func__);
470     BTE_DeinitStack();
471     return BT_STATUS_NOMEM;
472 }
473