1 //
2 // Copyright 2015 Google, Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at:
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "logging_helpers.h"
17
18 #include <string>
19
20 #include "types/bt_transport.h"
21 #include "types/raw_address.h"
22
23 #define CASE_RETURN_TEXT(code) \
24 case code: \
25 return #code
26
BtAvConnectionStateText(const btav_connection_state_t state)27 const char* BtAvConnectionStateText(const btav_connection_state_t state) {
28 switch (state) {
29 CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTED);
30 CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTING);
31 CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTED);
32 CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTING);
33 default:
34 return "Invalid AV connection state";
35 }
36 }
37
BtAvAudioStateText(const btav_audio_state_t state)38 const char* BtAvAudioStateText(const btav_audio_state_t state) {
39 switch (state) {
40 CASE_RETURN_TEXT(BTAV_AUDIO_STATE_REMOTE_SUSPEND);
41 CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STOPPED);
42 CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STARTED);
43 default:
44 return "Invalid audio state";
45 }
46 }
47
BtTransportText(const btgatt_transport_t t)48 const char* BtTransportText(const btgatt_transport_t t) {
49 switch (t) {
50 CASE_RETURN_TEXT(BT_TRANSPORT_AUTO);
51 CASE_RETURN_TEXT(BT_TRANSPORT_BR_EDR);
52 CASE_RETURN_TEXT(BT_TRANSPORT_LE);
53 default:
54 return "unknown transport";
55 }
56 }
57
BtStateText(const bt_state_t state)58 const char* BtStateText(const bt_state_t state) {
59 switch (state) {
60 CASE_RETURN_TEXT(BT_STATE_OFF);
61 CASE_RETURN_TEXT(BT_STATE_ON);
62 default:
63 return "unknown state code";
64 }
65 }
66
BtDiscoveryStateText(const bt_discovery_state_t state)67 const char* BtDiscoveryStateText(const bt_discovery_state_t state) {
68 switch (state) {
69 CASE_RETURN_TEXT(BT_DISCOVERY_STOPPED);
70 CASE_RETURN_TEXT(BT_DISCOVERY_STARTED);
71 default:
72 return "unknown discovery state code";
73 }
74 }
75
BtScanModeText(const bt_scan_mode_t mode)76 const char* BtScanModeText(const bt_scan_mode_t mode) {
77 switch (mode) {
78 CASE_RETURN_TEXT(BT_SCAN_MODE_NONE);
79 CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE);
80 CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
81 default:
82 return "unknown scan mode";
83 }
84 }
85
BtStatusText(const bt_status_t status)86 const char* BtStatusText(const bt_status_t status) {
87 switch (status) {
88 CASE_RETURN_TEXT(BT_STATUS_SUCCESS);
89 CASE_RETURN_TEXT(BT_STATUS_FAIL);
90 CASE_RETURN_TEXT(BT_STATUS_NOT_READY);
91 CASE_RETURN_TEXT(BT_STATUS_NOMEM);
92 CASE_RETURN_TEXT(BT_STATUS_DONE);
93 CASE_RETURN_TEXT(BT_STATUS_BUSY);
94 CASE_RETURN_TEXT(BT_STATUS_UNSUPPORTED);
95 CASE_RETURN_TEXT(BT_STATUS_PARM_INVALID);
96 CASE_RETURN_TEXT(BT_STATUS_UNHANDLED);
97 CASE_RETURN_TEXT(BT_STATUS_AUTH_FAILURE);
98 CASE_RETURN_TEXT(BT_STATUS_RMT_DEV_DOWN);
99 CASE_RETURN_TEXT(BT_STATUS_AUTH_REJECTED);
100 default:
101 return "unknown status code";
102 }
103 }
104
BtPropertyText(const bt_property_type_t prop)105 const char* BtPropertyText(const bt_property_type_t prop) {
106 switch (prop) {
107 CASE_RETURN_TEXT(BT_PROPERTY_BDNAME);
108 CASE_RETURN_TEXT(BT_PROPERTY_BDADDR);
109 CASE_RETURN_TEXT(BT_PROPERTY_UUIDS);
110 CASE_RETURN_TEXT(BT_PROPERTY_CLASS_OF_DEVICE);
111 CASE_RETURN_TEXT(BT_PROPERTY_TYPE_OF_DEVICE);
112 CASE_RETURN_TEXT(BT_PROPERTY_SERVICE_RECORD);
113 CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_SCAN_MODE);
114 CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
115 CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT);
116 CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_FRIENDLY_NAME);
117 CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_RSSI);
118 CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_VERSION_INFO);
119 CASE_RETURN_TEXT(BT_PROPERTY_LOCAL_LE_FEATURES);
120 CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP);
121 default:
122 return "Invalid property";
123 }
124 }
125
BtEventText(const bt_cb_thread_evt evt)126 const char* BtEventText(const bt_cb_thread_evt evt) {
127 switch (evt) {
128 CASE_RETURN_TEXT(ASSOCIATE_JVM);
129 CASE_RETURN_TEXT(DISASSOCIATE_JVM);
130 default:
131 return "unknown state code";
132 }
133 }
134
BtAclText(const bt_acl_state_t code)135 const char* BtAclText(const bt_acl_state_t code) {
136 switch (code) {
137 CASE_RETURN_TEXT(BT_ACL_STATE_CONNECTED);
138 CASE_RETURN_TEXT(BT_ACL_STATE_DISCONNECTED);
139 default:
140 return "unknown ACL code";
141 }
142 }
143
BtAddrString(const RawAddress * addr)144 std::string BtAddrString(const RawAddress* addr) {
145 char buffer[20];
146 snprintf(buffer, sizeof(buffer), "%02X:%02X:%02X:%02X:%02X:%02X",
147 addr->address[0], addr->address[1], addr->address[2],
148 addr->address[3], addr->address[4], addr->address[5]);
149 return std::string(buffer);
150 }
151