1 /*
2 * Copyright 2022 The Android Open Source Project
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
17 #include "common/audit_log.h"
18
19 #include "common/strings.h"
20 #include "hci/hci_packets.h"
21 #include "os/log.h"
22
23 namespace {
24 #if defined(OS_ANDROID)
25
26 constexpr char kPrivateAddressPrefix[] = "xx:xx:xx:xx";
27 #define PRIVATE_ADDRESS(addr) \
28 ((addr).ToString().replace(0, strlen(kPrivateAddressPrefix), kPrivateAddressPrefix).c_str())
29
30 // Tags for security logging, should be in sync with
31 // frameworks/base/core/java/android/app/admin/SecurityLogTags.logtags
32 constexpr int SEC_TAG_BLUETOOTH_CONNECTION = 210039;
33
34 #endif /* defined(OS_ANDROID) */
35 } // namespace
36
37 namespace bluetooth {
38 namespace common {
39
LogConnectionAdminAuditEvent(const char * action,const hci::Address & address,hci::ErrorCode status)40 void LogConnectionAdminAuditEvent(const char* action, const hci::Address& address, hci::ErrorCode status) {
41 #if defined(OS_ANDROID)
42
43 android_log_event_list(SEC_TAG_BLUETOOTH_CONNECTION)
44 << PRIVATE_ADDRESS(address) << /* success */ int32_t(status == hci::ErrorCode::SUCCESS)
45 << common::StringFormat("%s: %s", action, ErrorCodeText(status).c_str()).c_str() << LOG_ID_SECURITY;
46
47 #endif /* defined(OS_ANDROID) */
48 }
49
50 } // namespace common
51 } // namespace bluetooth