1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2013 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 #include <string.h>
20 
21 #include "common/bt_target.h"
22 //#include "bt_utils.h"
23 #include "gap_int.h"
24 #include "osi/allocator.h"
25 
26 #if GAP_DYNAMIC_MEMORY == FALSE
27 tGAP_CB  gap_cb;
28 #else
29 tGAP_CB  *gap_cb_ptr;
30 #endif
31 
32 /*******************************************************************************
33 **
34 ** Function         GAP_SetTraceLevel
35 **
36 ** Description      This function sets the trace level for GAP.  If called with
37 **                  a value of 0xFF, it simply returns the current trace level.
38 **
39 ** Returns          The new or current trace level
40 **
41 *******************************************************************************/
GAP_SetTraceLevel(UINT8 new_level)42 UINT8 GAP_SetTraceLevel (UINT8 new_level)
43 {
44     if (new_level != 0xFF) {
45         gap_cb.trace_level = new_level;
46     }
47 
48     return (gap_cb.trace_level);
49 }
50 
51 /*******************************************************************************
52 **
53 ** Function         GAP_Init
54 **
55 ** Description      Initializes the control blocks used by GAP.
56 **
57 **                  This routine should not be called except once per
58 **                      stack invocation.
59 **
60 ** Returns          status
61 **
62 *******************************************************************************/
GAP_Init(void)63 bt_status_t GAP_Init(void)
64 {
65 #if GAP_DYNAMIC_MEMORY == TRUE
66     gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB));
67     if (!gap_cb_ptr) {
68         return BT_STATUS_NOMEM;
69     }
70 #endif
71 
72     memset (&gap_cb, 0, sizeof (tGAP_CB));
73 
74 #if defined(GAP_INITIAL_TRACE_LEVEL)
75     gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL;
76 #else
77     gap_cb.trace_level = BT_TRACE_LEVEL_NONE;    /* No traces */
78 #endif
79 
80 #if GAP_CONN_INCLUDED == TRUE
81     gap_conn_init();
82 #endif
83 
84 #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
85     gap_attr_db_init();
86 #endif
87 
88     return BT_STATUS_SUCCESS;
89 }
90 
91 /*******************************************************************************
92 **
93 ** Function         GAP_Deinit
94 **
95 ** Description      This function is called to deinitialize the control block
96 **                  for this layer.
97 **
98 ** Returns          void
99 **
100 *******************************************************************************/
GAP_Deinit(void)101 void GAP_Deinit(void)
102 {
103 #if GAP_DYNAMIC_MEMORY == TRUE
104     if (gap_cb_ptr) {
105         osi_free(gap_cb_ptr);
106         gap_cb_ptr = NULL;
107     }
108 #endif
109 }
110