1 /******************************************************************************
2 *
3 * Copyright 2002-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 file contains the definition of the btm control block.
22 *
23 ******************************************************************************/
24
25 #include <memory>
26 #include <string>
27 #include "bt_target.h"
28 #include "bt_types.h"
29 #include "main/shim/dumpsys.h"
30 #include "stack/btm/btm_int_types.h"
31 #include "stack/include/btm_client_interface.h"
32 #include "stack_config.h"
33
34 /* Global BTM control block structure
35 */
36 tBTM_CB btm_cb;
37
38 /*******************************************************************************
39 *
40 * Function btm_init
41 *
42 * Description This function is called at BTM startup to allocate the
43 * control block (if using dynamic memory), and initializes the
44 * tracing level. It then initializes the various components
45 * of btm.
46 *
47 * Returns void
48 *
49 ******************************************************************************/
btm_init(void)50 void btm_init(void) {
51 btm_cb.Init(stack_config_get_interface()->get_pts_secure_only_mode()
52 ? BTM_SEC_MODE_SC
53 : BTM_SEC_MODE_SP);
54 }
55
56 /** This function is called to free dynamic memory and system resource allocated by btm_init */
btm_free(void)57 void btm_free(void) {
58 btm_cb.Free();
59 }
60
61 constexpr size_t kMaxLogHistoryTagLength = 6;
62 constexpr size_t kMaxLogHistoryMsgLength = 25;
63
btm_log_history(const std::string & tag,const char * addr,const std::string & msg,const std::string & extra)64 static void btm_log_history(const std::string& tag, const char* addr,
65 const std::string& msg, const std::string& extra) {
66 btm_cb.history_->Push(
67 "%-6s %-25s: %s %s", tag.substr(0, kMaxLogHistoryTagLength).c_str(),
68 msg.substr(0, kMaxLogHistoryMsgLength).c_str(), addr, extra.c_str());
69 }
70
BTM_LogHistory(const std::string & tag,const RawAddress & bd_addr,const std::string & msg,const std::string & extra)71 void BTM_LogHistory(const std::string& tag, const RawAddress& bd_addr,
72 const std::string& msg, const std::string& extra) {
73 btm_log_history(tag, PRIVATE_ADDRESS(bd_addr), msg, extra);
74 }
75
BTM_LogHistory(const std::string & tag,const RawAddress & bd_addr,const std::string & msg)76 void BTM_LogHistory(const std::string& tag, const RawAddress& bd_addr,
77 const std::string& msg) {
78 BTM_LogHistory(tag, bd_addr, msg, std::string());
79 }
80
BTM_LogHistory(const std::string & tag,const tBLE_BD_ADDR & ble_bd_addr,const std::string & msg,const std::string & extra)81 void BTM_LogHistory(const std::string& tag, const tBLE_BD_ADDR& ble_bd_addr,
82 const std::string& msg, const std::string& extra) {
83 btm_log_history(tag, PRIVATE_ADDRESS(ble_bd_addr), msg, extra);
84 }
85
BTM_LogHistory(const std::string & tag,const tBLE_BD_ADDR & ble_bd_addr,const std::string & msg)86 void BTM_LogHistory(const std::string& tag, const tBLE_BD_ADDR& ble_bd_addr,
87 const std::string& msg) {
88 BTM_LogHistory(tag, ble_bd_addr, msg, std::string());
89 }
90