1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
27
28
29
30
33
34
35
36
37
38
39
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
92
93
94
95
96
97
98
99
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
193
194
199
200
205
206
211
212
221
222
227
228
233
234
239
240
245
246
251
252
257
261
265
269
273
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
305
306
307
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
349
350
351
352
357
358
359
360
361
365
366
367
371
372
373
377
378
379
380
384
385
386
387
391
392
393
397
398
399
403
404
405
406
407
408
409
413
414
415
419
420
421
422
423
424
425
428
431
434
437
438
439
440
441
442
443
444
445
449
450
451
455
456
457
461
462
463
464
465
466
470
471
472
476
477
478
482
483
484
493
494
495
499
500
501
505
506
507
508
509
510
514
515
516
520
521
522
523
524
525
526
527
528
529
530
531
532
/* ... */
/* ... */
#include "common/bt_target.h"
#include <string.h>
/* ... */
#ifndef BTA_INCLUDED
#define BTA_INCLUDED FALSE
#endif
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
#include "stack/port_api.h"/* ... */
#endif
#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
#include "bnep_api.h"
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
#include "stack/gap_api.h"
#endif
#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
#include "pan_api.h"
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
#include "stack/hidh_api.h"
#endif
#if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE)
#include "stack/hidd_api.h"
#endif
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
#include "stack/avrc_api.h"
#endif
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
#include "stack/a2d_api.h"
#endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
#include "avdt_int.h"
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
#include "avct_int.h"
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
#include "stack/hidh_api.h"
#endif
#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
#include "mca_api.h"
#endif
#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
#include "stack/gatt_api.h"
#if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
#include "stack/smp_api.h"
#endif/* ... */
#endif
#if (defined(OBEX_INCLUDED) && OBEX_INCLUDED == TRUE)
#include "stack/obex_api.h"
#endif
#if (defined(GOEPC_INCLUDED) && GOEPC_INCLUDED == TRUE)
#include "stack/goep_common.h"
#include "stack/goepc_api.h"/* ... */
#endif
#if BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "osi/allocator.h"
#if BTA_HF_INCLUDED == TRUE
#include "bta_hf_client_int.h"
#endif
#if BTA_AG_INCLUDED == TRUE
#include "bta_ag_int.h"
#endif
#if BTA_SDP_INCLUDED == TRUE
#include "bta_sdp_int.h"
#endif
#if BTA_HS_INCLUDED == TRUE
#include "bta_hs_int.h"
#endif
#include "bta_dm_int.h"
#if BTA_AR_INCLUDED==TRUE
#include "bta_ar_int.h"
#endif
#if BTA_AV_INCLUDED==TRUE
#include "bta_av_int.h"
#endif
#if BTA_HH_INCLUDED==TRUE
#include "bta_hh_int.h"
#endif
#if BTA_HD_INCLUDED==TRUE
#include "bta_hd_int.h"
#endif
#if BTA_JV_INCLUDED==TRUE
#include "bta_jv_int.h"
#endif
#if BTA_HL_INCLUDED == TRUE
#include "bta_hl_int.h"
#endif
#if BTA_GATT_INCLUDED == TRUE
#include "bta_gattc_int.h"
#include "bta_gatts_int.h"/* ... */
#endif
#if BTA_PAN_INCLUDED==TRUE
#include "bta_pan_int.h"
#endif
#include "bta_sys_int.h"
/* ... */
#endif
/* ... */
/* ... */
void BTE_DeinitStack(void)
{
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
#if GATTS_INCLUDED == TRUE
if (bta_gatts_cb_ptr){
osi_free(bta_gatts_cb_ptr);
bta_gatts_cb_ptr = NULL;
}{...}
#endif/* ... */
#if GATTC_INCLUDED==TRUE
if (bta_gattc_cb_ptr){
osi_free(bta_gattc_cb_ptr);
bta_gattc_cb_ptr = NULL;
}{...}
#endif/* ... */
#if BTA_HD_INCLUDED==TRUE
if (bta_hd_cb_ptr){
osi_free(bta_hd_cb_ptr);
bta_hd_cb_ptr = NULL;
}{...}
#endif/* ... */
#if BTA_HH_INCLUDED==TRUE
if (bta_hh_cb_ptr){
osi_free(bta_hh_cb_ptr);
bta_hh_cb_ptr = NULL;
}{...}
#endif/* ... */
#if BTA_AV_INCLUDED==TRUE
if (bta_av_cb_ptr){
osi_free(bta_av_cb_ptr);
bta_av_cb_ptr = NULL;
}{...}
if (bta_av_sbc_ups_cb_ptr){
osi_free(bta_av_sbc_ups_cb_ptr);
bta_av_sbc_ups_cb_ptr = NULL;
}{...}
#endif/* ... */
#if BTA_AR_INCLUDED==TRUE
if (bta_ar_cb_ptr){
osi_free(bta_ar_cb_ptr);
bta_ar_cb_ptr = NULL;
}{...}
#endif/* ... */
#if SDP_INCLUDED == TRUE
if (g_disc_raw_data_buf){
osi_free(g_disc_raw_data_buf);
g_disc_raw_data_buf = NULL;
}{...}
#endif/* ... */
#if BTA_SDP_INCLUDED == TRUE
if (bta_sdp_cb_ptr){
osi_free(bta_sdp_cb_ptr);
bta_sdp_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if (bta_jv_cb_ptr){
osi_free(bta_jv_cb_ptr);
bta_jv_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if (bta_hf_client_cb_ptr){
osi_free(bta_hf_client_cb_ptr);
bta_hf_client_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == TRUE)
if (bta_ag_cb_ptr){
osi_free(bta_ag_cb_ptr);
bta_ag_cb_ptr = NULL;
}{...}
#endif/* ... */
if (bta_dm_conn_srvcs_ptr){
osi_free(bta_dm_conn_srvcs_ptr);
bta_dm_conn_srvcs_ptr = NULL;
}{...}
if (bta_dm_di_cb_ptr){
osi_free(bta_dm_di_cb_ptr);
bta_dm_di_cb_ptr = NULL;
}{...}
if (bta_dm_search_cb_ptr){
osi_free(bta_dm_search_cb_ptr);
bta_dm_search_cb_ptr = NULL;
}{...}
if (bta_dm_cb_ptr){
osi_free(bta_dm_cb_ptr);
bta_dm_cb_ptr = NULL;
}{...}
if (bta_sys_cb_ptr){
osi_free(bta_sys_cb_ptr);
bta_sys_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined(GOEPC_INCLUDED) && GOEPC_INCLUDED == TRUE)
GOEPC_Deinit();
#endif
#if (defined(OBEX_INCLUDED) && OBEX_INCLUDED == TRUE)
OBEX_Deinit();
#endif
#if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE)
HID_DevDeinit();
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
HID_HostDeinit();
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
GAP_Deinit();
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if (avct_cb_ptr){
osi_free(avct_cb_ptr);
avct_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if (avdt_cb_ptr){
osi_free(avdt_cb_ptr);
avdt_cb_ptr = NULL;
}{...}
#endif/* ... */
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
AVRC_Deinit();
#endif
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
A2D_Deinit();
#endif
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
RFCOMM_Deinit();
#endif
}{ ... }
/* ... */
bt_status_t BTE_InitStack(void)
{
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
if (RFCOMM_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
BNEP_Init();
#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
PAN_Init();
#endif /* ... */
#endif
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
if (A2D_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
if (AVRC_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));/* ... */
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));/* ... */
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
if (GAP_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
if (HID_HostInit() != HID_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE)
if (HID_DevInit() != HID_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
MCA_Init();
#endif
#if (defined(OBEX_INCLUDED) && OBEX_INCLUDED == TRUE)
if (OBEX_Init() != OBEX_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (defined(GOEPC_INCLUDED) && GOEPC_INCLUDED == TRUE)
if (GOEPC_Init() != GOEP_SUCCESS) {
goto error_exit;
}{...}
#endif/* ... */
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
goto error_exit;
}{...}
if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
goto error_exit;
}{...}
if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
goto error_exit;
}{...}
if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
goto error_exit;
}{...}
if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
memset((void *)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
memset((void *)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
memset((void *)bta_dm_conn_srvcs_ptr, 0, sizeof(tBTA_DM_CONNECTED_SRVCS));
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB));/* ... */
#endif
#if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == TRUE)
if ((bta_ag_cb_ptr = (tBTA_AG_CB *)osi_malloc(sizeof(tBTA_AG_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB));/* ... */
#endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));/* ... */
#endif
#if BTA_HS_INCLUDED == TRUE
memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
#endif
#if BTA_SDP_INCLUDED == TRUE
if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));/* ... */
#endif
#if SDP_INCLUDED == TRUE
if ((g_disc_raw_data_buf = (UINT8 *)osi_malloc(MAX_DISC_RAW_DATA_BUF)) == NULL) {
goto error_exit;
}{...}
memset((void *)g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);/* ... */
#endif
#if BTA_AR_INCLUDED==TRUE
if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));/* ... */
#endif
#if BTA_AV_INCLUDED==TRUE
if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
if ((bta_av_sbc_ups_cb_ptr = (tBTA_AV_SBC_UPS_CB *)osi_malloc(sizeof(tBTA_AV_SBC_UPS_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_av_sbc_ups_cb_ptr, 0, sizeof(tBTA_AV_SBC_UPS_CB));/* ... */
#endif
#if BTA_HH_INCLUDED==TRUE
if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));/* ... */
#endif
#if BTA_HD_INCLUDED==TRUE
if ((bta_hd_cb_ptr = (tBTA_HD_CB *)osi_malloc(sizeof(tBTA_HD_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_hd_cb_ptr, 0, sizeof(tBTA_HD_CB));/* ... */
#endif
#if BTA_HL_INCLUDED==TRUE
memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
#endif
#if GATTC_INCLUDED==TRUE
if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));/* ... */
#endif
#if GATTS_INCLUDED == TRUE
if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
goto error_exit;
}{...}
memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));/* ... */
#endif
#if BTA_PAN_INCLUDED==TRUE
memset((void *)bta_pan_cb_ptr, 0, sizeof(tBTA_PAN_CB));
#endif
/* ... */
#endif
return BT_STATUS_SUCCESS;
error_exit:;
LOG_ERROR("%s failed due to no memory", __func__);
BTE_DeinitStack();
return BT_STATUS_NOMEM;
}{ ... }