summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/bta/csis/csis_client_test.cc2
-rw-r--r--system/bta/include/bta_csis_api.h2
-rw-r--r--system/btcore/src/device_class.cc1
-rw-r--r--system/btif/Android.bp1
-rw-r--r--system/btif/co/bta_hh_co.cc2
-rw-r--r--system/btif/src/btif_csis_client.cc2
-rw-r--r--system/btif/src/btif_pan.cc2
-rw-r--r--system/btif/src/btif_sock_thread.cc2
-rw-r--r--system/btif/test/btif_stack_test.cc188
-rw-r--r--system/device/include/esco_parameters.h3
-rw-r--r--system/gd/os/linux_generic/reactive_semaphore.cc1
-rw-r--r--system/gd/rust/linux/stack/src/bluetooth.rs2
-rw-r--r--system/hci/Android.bp1
-rw-r--r--system/hci/include/userial.h57
-rw-r--r--system/hci/src/hci_inject.cc208
-rw-r--r--system/hci/src/hci_layer_android.cc260
-rw-r--r--system/hci/src/hci_layer_linux.cc410
-rw-r--r--system/hci/test/hci_layer_test.cc122
-rw-r--r--system/hci/test/other_stack_stub.cc45
-rw-r--r--system/main/shim/le_scanning_manager.cc7
-rw-r--r--system/stack/Android.bp4
-rw-r--r--system/stack/BUILD.gn1
-rw-r--r--system/stack/btm/btm_ble_gap.cc35
-rw-r--r--system/stack/btm/btm_sco.cc44
-rw-r--r--system/stack/btm/btm_sco.h32
-rw-r--r--system/stack/btm/btm_sco_hci.cc106
-rw-r--r--system/stack/btu/btu_hcif.cc9
-rw-r--r--system/stack/smp/smp_act.cc9
-rw-r--r--system/stack/smp/smp_keys.cc2
-rw-r--r--system/test/mock/mock_hci_layer.cc110
-rw-r--r--system/test/mock/mock_hci_layer.h137
-rw-r--r--system/test/mock/mock_osi_thread_scheduler.h2
-rw-r--r--system/test/mock/mock_udrv_ulinux_uipc.cc2
-rw-r--r--system/udrv/Android.bp1
-rw-r--r--system/udrv/ulinux/uipc.cc134
-rw-r--r--system/vendor_libs/linux/interface/h4_protocol.cc10
-rw-r--r--system/vendor_libs/test_vendor_lib/net/async_data_channel.h4
37 files changed, 297 insertions, 1663 deletions
diff --git a/system/bta/csis/csis_client_test.cc b/system/bta/csis/csis_client_test.cc
index af9151472d..5d1858fe26 100644
--- a/system/bta/csis/csis_client_test.cc
+++ b/system/bta/csis/csis_client_test.cc
@@ -16,10 +16,10 @@
*/
#include <base/bind.h>
-#include <base/bind_helpers.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include "bind_helpers.h"
#include "bta_csis_api.h"
#include "bta_dm_api_mock.h"
#include "bta_gatt_api_mock.h"
diff --git a/system/bta/include/bta_csis_api.h b/system/bta/include/bta_csis_api.h
index e3f6cf3870..d3ede74fde 100644
--- a/system/bta/include/bta_csis_api.h
+++ b/system/bta/include/bta_csis_api.h
@@ -16,8 +16,8 @@
*/
#pragma once
-#include "base/bind_helpers.h"
#include "base/callback.h"
+#include "bind_helpers.h"
#include "bta/include/bta_groups.h"
#include "hardware/bt_csis.h"
diff --git a/system/btcore/src/device_class.cc b/system/btcore/src/device_class.cc
index baa0dd6700..35ed1eda49 100644
--- a/system/btcore/src/device_class.cc
+++ b/system/btcore/src/device_class.cc
@@ -18,6 +18,7 @@
#include <arpa/inet.h>
#include <base/logging.h>
+#include <endian.h>
#include <string.h>
#include "btcore/include/device_class.h"
diff --git a/system/btif/Android.bp b/system/btif/Android.bp
index a70d4c05c5..f86f3ccb2f 100644
--- a/system/btif/Android.bp
+++ b/system/btif/Android.bp
@@ -376,7 +376,6 @@ cc_test {
":TestMockUdrv",
":TestMockUtils",
"test/btif_core_test.cc",
- "test/btif_stack_test.cc",
],
generated_headers: [
"BluetoothGeneratedBundlerSchema_h_bfbs",
diff --git a/system/btif/co/bta_hh_co.cc b/system/btif/co/bta_hh_co.cc
index 491f026db7..eb7790f498 100644
--- a/system/btif/co/bta_hh_co.cc
+++ b/system/btif/co/bta_hh_co.cc
@@ -21,11 +21,11 @@
#include <errno.h>
#include <fcntl.h>
#include <linux/uhid.h>
+#include <poll.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <sys/poll.h>
#include <unistd.h>
#include "bta_api.h"
diff --git a/system/btif/src/btif_csis_client.cc b/system/btif/src/btif_csis_client.cc
index 7bd633370b..174f0803e7 100644
--- a/system/btif/src/btif_csis_client.cc
+++ b/system/btif/src/btif_csis_client.cc
@@ -16,12 +16,12 @@
*/
#include <base/bind.h>
-#include <base/bind_helpers.h>
#include <base/location.h>
#include <base/logging.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_csis.h>
+#include "bind_helpers.h"
#include "bta_csis_api.h"
#include "btif_common.h"
#include "btif_storage.h"
diff --git a/system/btif/src/btif_pan.cc b/system/btif/src/btif_pan.cc
index c175f41ffe..888994d8d7 100644
--- a/system/btif/src/btif_pan.cc
+++ b/system/btif/src/btif_pan.cc
@@ -34,8 +34,8 @@
#include <linux/if_ether.h>
#include <linux/if_tun.h>
#include <net/if.h>
+#include <poll.h>
#include <sys/ioctl.h>
-#include <sys/poll.h>
#include <unistd.h>
#include "bt_target.h" // Must be first to define build configuration
diff --git a/system/btif/src/btif_sock_thread.cc b/system/btif/src/btif_sock_thread.cc
index 96395e91c0..88f40e75cc 100644
--- a/system/btif/src/btif_sock_thread.cc
+++ b/system/btif/src/btif_sock_thread.cc
@@ -33,12 +33,12 @@
#include <errno.h>
#include <fcntl.h>
#include <features.h>
+#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/poll.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
diff --git a/system/btif/test/btif_stack_test.cc b/system/btif/test/btif_stack_test.cc
deleted file mode 100644
index 52f861fd41..0000000000
--- a/system/btif/test/btif_stack_test.cc
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "btif/include/btif_profile_queue.h"
-
-#include <gtest/gtest.h>
-
-#include <base/bind.h>
-#include <base/callback.h>
-#include <base/location.h>
-
-#include "hci/include/hci_layer.h" // hci_t
-#include "osi/include/log.h"
-#include "stack_manager.h"
-#include "test/common/mock_functions.h"
-#include "test/mock/mock_hci_layer.h"
-#include "types/raw_address.h"
-
-void set_hal_cbacks(bt_callbacks_t* callbacks); // btif/src/bluetooth.cc
-
-namespace {
-
-namespace _adapter_state_changed {
-bt_state_t state{BT_STATE_OFF};
-}
-void adapter_state_changed(bt_state_t state) {
- LOG_INFO("%u => %u", _adapter_state_changed::state, state);
-}
-
-void adapter_properties(bt_status_t status, int num_properties,
- bt_property_t* properties) {
- LOG_INFO("Callback rx");
-}
-
-void remote_device_properties(bt_status_t status, RawAddress* bd_addr,
- int num_properties, bt_property_t* properties) {
- LOG_INFO("Callback rx");
-}
-
-void device_found(int num_properties, bt_property_t* properties) {
- LOG_INFO("Callback rx");
-}
-
-void discovery_state_changed(bt_discovery_state_t state) {
- LOG_INFO("Callback rx");
-}
-
-/** Bluetooth Legacy PinKey Request callback */
-void pin_request(RawAddress* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod,
- bool min_16_digit) {
- LOG_INFO("Callback rx");
-}
-
-void ssp_request(RawAddress* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod,
- bt_ssp_variant_t pairing_variant, uint32_t pass_key) {
- LOG_INFO("Callback rx");
-}
-
-/** Bluetooth Bond state changed callback */
-/* Invoked in response to create_bond, cancel_bond or remove_bond */
-void bond_state_changed(bt_status_t status, RawAddress* remote_bd_addr,
- bt_bond_state_t state, int fail_reason) {
- LOG_INFO("Callback rx");
-}
-
-/** Bluetooth ACL connection state changed callback */
-void acl_state_changed(bt_status_t status, RawAddress* remote_bd_addr,
- bt_acl_state_t state, int transport_link_type,
- bt_hci_error_code_t hci_reason) {
- LOG_INFO("status:%s device:%s state:%s", bt_status_text(status).c_str(),
- remote_bd_addr->ToString().c_str(),
- (state) ? "disconnected" : "connected");
-}
-
-/** Bluetooth Link Quality Report callback */
-void link_quality_report(uint64_t timestamp, int report_id, int rssi, int snr,
- int retransmission_count,
- int packets_not_receive_count,
- int negative_acknowledgement_count) {
- LOG_INFO("Callback rx");
-}
-
-void thread_event(bt_cb_thread_evt evt) { LOG_INFO("Callback rx"); }
-
-void dut_mode_recv(uint16_t opcode, uint8_t* buf, uint8_t len) {
- LOG_INFO("Callback rx");
-}
-
-void le_test_mode(bt_status_t status, uint16_t num_packets) {
- LOG_INFO("Callback rx");
-}
-
-void energy_info(bt_activity_energy_info* energy_info,
- bt_uid_traffic_t* uid_data) {
- LOG_INFO("Callback rx");
-}
-
-bt_callbacks_t bt_callbacks{
- /** set to sizeof(bt_callbacks_t) */
- .size = sizeof(bt_callbacks_t),
- .adapter_state_changed_cb = adapter_state_changed,
- .adapter_properties_cb = adapter_properties,
- .remote_device_properties_cb = remote_device_properties,
- .device_found_cb = device_found,
- .discovery_state_changed_cb = discovery_state_changed,
- .pin_request_cb = pin_request,
- .ssp_request_cb = ssp_request,
- .bond_state_changed_cb = bond_state_changed,
- .acl_state_changed_cb = acl_state_changed,
- .thread_evt_cb = thread_event,
- .dut_mode_recv_cb = dut_mode_recv,
- .le_test_mode_cb = le_test_mode,
- .energy_info_cb = energy_info,
- .link_quality_report_cb = link_quality_report,
-};
-
-void set_data_cb(
- base::Callback<void(const base::Location&, BT_HDR*)> send_data_cb) {
- mock_function_count_map[__func__]++;
-}
-
-void transmit_command(BT_HDR* command, command_complete_cb complete_callback,
- command_status_cb status_cb, void* context) {
- mock_function_count_map[__func__]++;
-}
-
-future_t* transmit_command_futured(BT_HDR* command) {
- mock_function_count_map[__func__]++;
- return nullptr;
-}
-
-void transmit_downward(uint16_t type, void* data) {
- mock_function_count_map[__func__]++;
-}
-
-} // namespace
-
-hci_t mock_hci = {
- .set_data_cb = set_data_cb,
- .transmit_command = transmit_command,
- .transmit_command_futured = transmit_command_futured,
- .transmit_downward = transmit_downward,
-};
-
-namespace bluetooth {
-namespace common {
-
-class BluetoothMetricsLogger {};
-
-} // namespace common
-} // namespace bluetooth
-
-class StackCycleTest : public ::testing::Test {
- protected:
- void SetUp() override {
- test::mock::hci_layer::hci_layer_get_interface.hci = &mock_hci;
- stack_manager_ = stack_manager_get_interface();
- }
-
- void TearDown() override { stack_manager_ = nullptr; }
- const stack_manager_t* stack_manager_{nullptr};
-};
-
-TEST_F(StackCycleTest, stack_init) {
- // TODO load init flags
- // bluetooth::common::InitFlags::Load(init_flags);
-
- set_hal_cbacks(&bt_callbacks);
-
- stack_manager_get_interface()->init_stack();
-
- LOG_INFO("Initialized stack");
-
- dump_mock_function_count_map();
-}
diff --git a/system/device/include/esco_parameters.h b/system/device/include/esco_parameters.h
index 6df628949d..52b51f19b8 100644
--- a/system/device/include/esco_parameters.h
+++ b/system/device/include/esco_parameters.h
@@ -60,8 +60,7 @@ typedef uint8_t esco_pcm_data_format_t;
// SCO Data Path
#define ESCO_DATA_PATH_PCM 1 /* 0x01-0xFE (PCM Chan) */
-#define ESCO_DATA_PATH_HCI ((uint8_t)0x00) /* HCI-0, 0x01-0xFE (PCM Chan) */
-#define ESCO_DATA_PATH_TEST ((uint8_t)0xFF) /* 0xFF-Audio Test */
+#define ESCO_DATA_PATH_HCI 0 /* HCI-0, 0x01-0xFE (PCM Chan) */
typedef uint8_t esco_data_path_t;
// eSCO constants
diff --git a/system/gd/os/linux_generic/reactive_semaphore.cc b/system/gd/os/linux_generic/reactive_semaphore.cc
index 03339f99e8..cf2a636be8 100644
--- a/system/gd/os/linux_generic/reactive_semaphore.cc
+++ b/system/gd/os/linux_generic/reactive_semaphore.cc
@@ -16,7 +16,6 @@
#include "reactive_semaphore.h"
-#include <error.h>
#include <string.h>
#include <sys/eventfd.h>
#include <unistd.h>
diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs
index d91d04421d..12fbe25473 100644
--- a/system/gd/rust/linux/stack/src/bluetooth.rs
+++ b/system/gd/rust/linux/stack/src/bluetooth.rs
@@ -285,7 +285,7 @@ impl BtifBluetoothCallbacks for Bluetooth {
_status: BtStatus,
mut addr: RawAddress,
bond_state: BtBondState,
- fail_reason: i32,
+ _fail_reason: i32,
) {
if bond_state == BtBondState::Bonded {
// We are assuming that peer is a HID device and automatically connect to that profile.
diff --git a/system/hci/Android.bp b/system/hci/Android.bp
index 570854d3bd..d6efd247bb 100644
--- a/system/hci/Android.bp
+++ b/system/hci/Android.bp
@@ -27,7 +27,6 @@ cc_library_static {
"src/btsnoop_net.cc",
"src/buffer_allocator.cc",
"src/hci_inject.cc",
- "src/hci_layer.cc",
"src/hci_packet_factory.cc",
"src/hci_packet_parser.cc",
"src/packet_fragmenter.cc",
diff --git a/system/hci/include/userial.h b/system/hci/include/userial.h
index 2d1424fd13..9521806703 100644
--- a/system/hci/include/userial.h
+++ b/system/hci/include/userial.h
@@ -16,56 +16,13 @@
*
******************************************************************************/
-// This module manages the serial port over which HCI commands
-// and data are sent/received.
+#pragma message "This header file userial.h is no longer supported"
+#pragma message "Please update to remove these declarations"
#pragma once
-#include <stdbool.h>
-#include <stdint.h>
-
-typedef enum {
- USERIAL_PORT_1,
- USERIAL_PORT_2,
- USERIAL_PORT_3,
- USERIAL_PORT_4,
- USERIAL_PORT_5,
- USERIAL_PORT_6,
- USERIAL_PORT_7,
- USERIAL_PORT_8,
- USERIAL_PORT_9,
- USERIAL_PORT_10,
- USERIAL_PORT_11,
- USERIAL_PORT_12,
- USERIAL_PORT_13,
- USERIAL_PORT_14,
- USERIAL_PORT_15,
- USERIAL_PORT_16,
- USERIAL_PORT_17,
- USERIAL_PORT_18,
-} userial_port_t;
-
-// Initializes the userial module. This function should only be called once.
-// It returns true if the module was initialized, false if there was an error.
-bool userial_init(void);
-
-// Opens the given serial port. Returns true if successful, false otherwise.
-// Once this function is called, the userial module will begin producing
-// buffers from data read off the serial port. If you wish to pause the
-// production of buffers, call |userial_pause_reading|. You can then resume
-// by calling |userial_resume_reading|. This function returns true if the
-// serial port was successfully opened and buffer production has started. It
-// returns false if there was an error.
-bool userial_open(userial_port_t port);
-void userial_close(void);
-void userial_close_reader(void);
-
-// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
-// This function returns the number of bytes actually read, which may be
-// less than |len|. This function will not block.
-uint16_t userial_read(uint16_t msg_id, uint8_t* p_buffer, uint16_t len);
-
-// Writes a maximum of |len| bytes from |p_data| to the serial port.
-// This function returns the number of bytes actually written, which may be
-// less than |len|. This function may block.
-uint16_t userial_write(uint16_t msg_id, const uint8_t* p_data, uint16_t len);
+// Currently still included by:
+// hardware/broadcom/libbt/include/userial_vendor.h
+// vendor/amlogic/common/wifi_bt/bluetooth/realtek/rtkbt/code/libbt-vendor/include/userial_vendor.h
+// vendor/amlogic/common/wifi_bt/bluetooth/broadcom/vendor/include/userial_vendor.h
+// vendor/amlogic/common/wifi_bt/bluetooth/amlogic/aml_libbt-vendor/include/userial_vendor.h
diff --git a/system/hci/src/hci_inject.cc b/system/hci/src/hci_inject.cc
index 9fff248888..e69de29bb2 100644
--- a/system/hci/src/hci_inject.cc
+++ b/system/hci/src/hci_inject.cc
@@ -1,208 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2014 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-#define LOG_TAG "bt_hci_inject"
-
-#include "hci_inject.h"
-
-#include <base/logging.h>
-#include <errno.h>
-#include <string.h>
-
-#include "bt_types.h"
-#include "check.h"
-#include "hci/include/buffer_allocator.h"
-#include "hci_layer.h"
-#include "osi/include/allocator.h"
-#include "osi/include/list.h"
-#include "osi/include/log.h"
-#include "osi/include/osi.h"
-#include "osi/include/socket.h"
-#include "osi/include/thread.h"
-
-typedef enum {
- HCI_PACKET_COMMAND = 1,
- HCI_PACKET_ACL_DATA = 2,
- HCI_PACKET_SCO_DATA = 3,
- HCI_PACKET_EVENT = 4,
- HCI_PACKET_ISO_DATA = 5,
-} hci_packet_t;
-
-typedef struct {
- socket_t* socket;
- uint8_t buffer[65536 + 3]; // 2 bytes length prefix, 1 byte type prefix.
- size_t buffer_size;
-} client_t;
-
-static bool hci_inject_open(const hci_t* hci_interface);
-static void hci_inject_close(void);
-static int hci_packet_to_event(hci_packet_t packet);
-static void accept_ready(socket_t* socket, void* context);
-static void read_ready(socket_t* socket, void* context);
-static void client_free(void* ptr);
-
-static const port_t LISTEN_PORT = 8873;
-
-static const hci_inject_t interface = {hci_inject_open, hci_inject_close};
-
-static const hci_t* hci;
-static const allocator_t* buffer_allocator;
-static socket_t* listen_socket;
-static thread_t* thread;
-static list_t* clients;
-
-static bool hci_inject_open(const hci_t* hci_interface) {
-#if (BT_NET_DEBUG != true)
- return true; // Disable using network sockets for security reasons
-#endif
-
- CHECK(listen_socket == NULL);
- CHECK(thread == NULL);
- CHECK(clients == NULL);
- CHECK(hci_interface != NULL);
-
- hci = hci_interface;
-
- thread = thread_new("hci_inject");
- if (!thread) goto error;
-
- clients = list_new(client_free);
- if (!clients) goto error;
-
- listen_socket = socket_new();
- if (!listen_socket) goto error;
-
- if (!socket_listen(listen_socket, LISTEN_PORT)) goto error;
-
- socket_register(listen_socket, thread_get_reactor(thread), NULL, accept_ready,
- NULL);
- return true;
-
-error:;
- interface.close();
- return false;
-}
-
-static void hci_inject_close(void) {
-#if (BT_NET_DEBUG != true)
- return; // Disable using network sockets for security reasons
-#endif
-
- socket_free(listen_socket);
- list_free(clients);
- thread_free(thread);
-
- listen_socket = NULL;
- thread = NULL;
- clients = NULL;
-}
-
-static int hci_packet_to_event(hci_packet_t packet) {
- switch (packet) {
- case HCI_PACKET_COMMAND:
- return MSG_STACK_TO_HC_HCI_CMD;
- case HCI_PACKET_ACL_DATA:
- return MSG_STACK_TO_HC_HCI_ACL;
- case HCI_PACKET_SCO_DATA:
- return MSG_STACK_TO_HC_HCI_SCO;
- case HCI_PACKET_ISO_DATA:
- return MSG_STACK_TO_HC_HCI_ISO;
- default:
- LOG_ERROR("%s unsupported packet type: %d", __func__, packet);
- return -1;
- }
-}
-
-static void accept_ready(socket_t* socket, UNUSED_ATTR void* context) {
- CHECK(socket != NULL);
- CHECK(socket == listen_socket);
-
- socket = socket_accept(socket);
- if (!socket) return;
-
- client_t* client = (client_t*)osi_calloc(sizeof(client_t));
-
- client->socket = socket;
-
- if (!list_append(clients, client)) {
- LOG_ERROR("%s unable to add client to list.", __func__);
- client_free(client);
- return;
- }
-
- socket_register(socket, thread_get_reactor(thread), client, read_ready, NULL);
-}
-
-static void read_ready(UNUSED_ATTR socket_t* socket, void* context) {
- CHECK(socket != NULL);
- CHECK(context != NULL);
-
- client_t* client = (client_t*)context;
-
- ssize_t ret =
- socket_read(client->socket, client->buffer + client->buffer_size,
- sizeof(client->buffer) - client->buffer_size);
- if (ret == 0 || (ret == -1 && ret != EWOULDBLOCK && ret != EAGAIN)) {
- list_remove(clients, client);
- return;
- }
- client->buffer_size += ret;
-
- while (client->buffer_size > 3) {
- uint8_t* buffer = client->buffer;
- hci_packet_t packet_type = (hci_packet_t)buffer[0];
- size_t packet_len = (buffer[2] << 8) | buffer[1];
- size_t frame_len = 3 + packet_len;
-
- if (client->buffer_size < frame_len) break;
-
- // TODO(sharvil): validate incoming HCI messages.
- // TODO(sharvil): once we have an HCI parser, we can eliminate
- // the 2-byte size field since it will be contained in the packet.
-
- BT_HDR* buf = (BT_HDR*)buffer_allocator->alloc(BT_HDR_SIZE + packet_len);
- if (buf) {
- buf->event = hci_packet_to_event(packet_type);
- buf->offset = 0;
- buf->layer_specific = 0;
- buf->len = packet_len;
- memcpy(buf->data, buffer + 3, packet_len);
- hci->transmit_downward(buf->event, buf);
- } else {
- LOG_ERROR("%s dropping injected packet of length %zu", __func__,
- packet_len);
- }
-
- size_t remainder = client->buffer_size - frame_len;
- memmove(buffer, buffer + frame_len, remainder);
- client->buffer_size -= frame_len;
- }
-}
-
-static void client_free(void* ptr) {
- if (!ptr) return;
-
- client_t* client = (client_t*)ptr;
- socket_free(client->socket);
- osi_free(client);
-}
-
-const hci_inject_t* hci_inject_get_interface() {
- buffer_allocator = buffer_allocator_get_interface();
- return &interface;
-}
diff --git a/system/hci/src/hci_layer_android.cc b/system/hci/src/hci_layer_android.cc
index 58c35940d3..e69de29bb2 100644
--- a/system/hci/src/hci_layer_android.cc
+++ b/system/hci/src/hci_layer_android.cc
@@ -1,260 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2017 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-#define LOG_TAG "bt_hci"
-
-#include "hci_layer.h"
-
-#include <iomanip>
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <android/hardware/bluetooth/1.0/IBluetoothHci.h>
-#include <android/hardware/bluetooth/1.0/IBluetoothHciCallbacks.h>
-#include <android/hardware/bluetooth/1.0/types.h>
-#include <android/hardware/bluetooth/1.1/IBluetoothHci.h>
-#include <android/hardware/bluetooth/1.1/IBluetoothHciCallbacks.h>
-
-#include <base/location.h>
-#include <base/logging.h>
-
-#include "check.h"
-#include "common/stop_watch_legacy.h"
-#include "hci/include/buffer_allocator.h"
-#include "osi/include/log.h"
-
-#define LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log"
-#define LAST_LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log.last"
-
-using ::android::hardware::hidl_death_recipient;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::hardware::bluetooth::V1_0::HciPacket;
-using ::android::hardware::bluetooth::V1_0::Status;
-using ::bluetooth::common::StopWatchLegacy;
-
-using namespace ::android::hardware::bluetooth;
-
-extern void initialization_complete();
-extern void hci_event_received(const base::Location& from_here, BT_HDR* packet);
-extern void acl_event_received(BT_HDR* packet);
-extern void sco_data_received(BT_HDR* packet);
-extern void iso_data_received(BT_HDR* packet);
-extern void hal_service_died();
-extern bool hci_is_root_inflammation_event_received();
-
-android::sp<V1_0::IBluetoothHci> btHci;
-android::sp<V1_1::IBluetoothHci> btHci_1_1;
-
-std::string GetTimerText(std::string func_name, const hidl_vec<uint8_t>& vec) {
- std::stringstream ss;
- const unsigned char* vec_char =
- reinterpret_cast<const unsigned char*>(vec.data());
- int length = 5;
- if ((int)vec.size() < 5) {
- length = vec.size();
- }
- for (int i = 0; i < length; i++) {
- ss << std::setw(2) << std::setfill('0') << std::hex << (int)vec_char[i];
- }
- std::string text = func_name + ": len " + std::to_string(vec.size()) +
- ", 1st 5 bytes '" + ss.str() + "'";
- return text;
-}
-
-class BluetoothHciDeathRecipient : public hidl_death_recipient {
- public:
- virtual void serviceDied(uint64_t /*cookie*/, const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
- LOG_ERROR("Bluetooth HAL service died!");
- StopWatchLegacy::DumpStopWatchLog();
- hal_service_died();
- }
-};
-android::sp<BluetoothHciDeathRecipient> bluetoothHciDeathRecipient = new BluetoothHciDeathRecipient();
-
-class BluetoothHciCallbacks : public V1_1::IBluetoothHciCallbacks {
- public:
- BluetoothHciCallbacks() {
- buffer_allocator = buffer_allocator_get_interface();
- }
-
- BT_HDR* WrapPacketAndCopy(uint16_t event, const hidl_vec<uint8_t>& data) {
- size_t packet_size = data.size() + BT_HDR_SIZE;
- BT_HDR* packet =
- reinterpret_cast<BT_HDR*>(buffer_allocator->alloc(packet_size));
- packet->offset = 0;
- packet->len = data.size();
- packet->layer_specific = 0;
- packet->event = event;
- // TODO(eisenbach): Avoid copy here; if BT_HDR->data can be ensured to
- // be the only way the data is accessed, a pointer could be passed here...
- memcpy(packet->data, data.data(), data.size());
- return packet;
- }
-
- Return<void> initializationComplete(Status status) override {
- StopWatchLegacy(__func__);
- if (hci_is_root_inflammation_event_received()) {
- // Ignore the initializationComplete here as we have already received
- // root inflammation event earlier.
- LOG_ERROR(
- "initializationComplete after root inflammation event! status=%d",
- status);
- return Void();
- }
- CHECK(status == Status::SUCCESS);
- initialization_complete();
- return Void();
- }
-
- Return<void> hciEventReceived(const hidl_vec<uint8_t>& event) override {
- StopWatchLegacy(GetTimerText(__func__, event));
- BT_HDR* packet = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, event);
- hci_event_received(FROM_HERE, packet);
- return Void();
- }
-
- Return<void> aclDataReceived(const hidl_vec<uint8_t>& data) override {
- StopWatchLegacy(GetTimerText(__func__, data));
- BT_HDR* packet = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_ACL, data);
- acl_event_received(packet);
- return Void();
- }
-
- Return<void> scoDataReceived(const hidl_vec<uint8_t>& data) override {
- StopWatchLegacy(GetTimerText(__func__, data));
- BT_HDR* packet = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_SCO, data);
- sco_data_received(packet);
- return Void();
- }
-
- Return<void> isoDataReceived(const hidl_vec<uint8_t>& data) override {
- StopWatchLegacy(GetTimerText(__func__, data));
- BT_HDR* packet = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_ISO, data);
- iso_data_received(packet);
- return Void();
- }
-
- const allocator_t* buffer_allocator;
-};
-
-void hci_initialize() {
- LOG_INFO("%s", __func__);
-
- btHci_1_1 = V1_1::IBluetoothHci::getService();
-
- if (btHci_1_1 != nullptr) {
- btHci = btHci_1_1;
- } else {
- btHci = V1_0::IBluetoothHci::getService();
- }
-
- // If android.hardware.bluetooth* is not found, Bluetooth can not continue.
- CHECK(btHci != nullptr);
- auto death_link = btHci->linkToDeath(bluetoothHciDeathRecipient, 0);
- if (!death_link.isOk()) {
- LOG_ERROR("%s: Unable to set the death recipient for the Bluetooth HAL",
- __func__);
- abort();
- }
- LOG_INFO("%s: IBluetoothHci::getService() returned %p (%s)", __func__,
- btHci.get(), (btHci->isRemote() ? "remote" : "local"));
-
- // Block allows allocation of a variable that might be bypassed by goto.
- {
- android::sp<V1_1::IBluetoothHciCallbacks> callbacks =
- new BluetoothHciCallbacks();
- if (btHci_1_1 != nullptr) {
- btHci_1_1->initialize_1_1(callbacks);
- } else {
- btHci->initialize(callbacks);
- }
- }
-}
-
-void hci_close() {
- if (btHci != nullptr) {
- auto death_unlink = btHci->unlinkToDeath(bluetoothHciDeathRecipient);
- if (!death_unlink.isOk()) {
- LOG_ERROR("%s: Error unlinking death recipient from the Bluetooth HAL",
- __func__);
- }
- auto close_status = btHci->close();
- if (!close_status.isOk()) {
- LOG_ERROR("%s: Error closing the Bluetooth HAL", __func__);
- }
- btHci = nullptr;
- }
-}
-
-void hci_transmit(BT_HDR* packet) {
- HciPacket data;
- data.setToExternal(packet->data + packet->offset, packet->len);
-
- uint16_t event = packet->event & MSG_EVT_MASK;
- switch (event & MSG_EVT_MASK) {
- case MSG_STACK_TO_HC_HCI_CMD:
- btHci->sendHciCommand(data);
- break;
- case MSG_STACK_TO_HC_HCI_ACL:
- btHci->sendAclData(data);
- break;
- case MSG_STACK_TO_HC_HCI_SCO:
- btHci->sendScoData(data);
- break;
- case MSG_STACK_TO_HC_HCI_ISO:
- if (btHci_1_1 != nullptr) {
- btHci_1_1->sendIsoData(data);
- } else {
- LOG_ERROR("ISO is not supported in HAL v1.0");
- }
- break;
- default:
- LOG_ERROR("Unknown packet type (%d)", event);
- break;
- }
-}
-
-int hci_open_firmware_log_file() {
- if (rename(LOG_PATH, LAST_LOG_PATH) == -1 && errno != ENOENT) {
- LOG_ERROR("%s unable to rename '%s' to '%s': %s", __func__, LOG_PATH,
- LAST_LOG_PATH, strerror(errno));
- }
-
- mode_t prevmask = umask(0);
- int logfile_fd = open(LOG_PATH, O_WRONLY | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- umask(prevmask);
- if (logfile_fd == INVALID_FD) {
- LOG_ERROR("%s unable to open '%s': %s", __func__, LOG_PATH,
- strerror(errno));
- }
-
- return logfile_fd;
-}
-
-void hci_close_firmware_log_file(int fd) {
- if (fd != INVALID_FD) close(fd);
-}
-
-void hci_log_firmware_debug_packet(int fd, BT_HDR* packet) {
- TEMP_FAILURE_RETRY(write(fd, packet->data, packet->len));
-}
diff --git a/system/hci/src/hci_layer_linux.cc b/system/hci/src/hci_layer_linux.cc
index 42cefde642..e69de29bb2 100644
--- a/system/hci/src/hci_layer_linux.cc
+++ b/system/hci/src/hci_layer_linux.cc
@@ -1,410 +0,0 @@
-/**********************************************************************
- *
- * Copyright 2017 The Android Open Source Project
- * Copyright 2015 Intel Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- **********************************************************************/
-#include <base/bind.h>
-#include <base/location.h>
-#include <base/logging.h>
-#include <base/threading/thread.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <poll.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <algorithm>
-
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-
-#include "check.h"
-#include "gd/common/init_flags.h"
-#include "hci/include/buffer_allocator.h"
-#include "hci_layer.h"
-#include "osi/include/compat.h"
-#include "osi/include/log.h"
-#include "osi/include/osi.h"
-#include "osi/include/properties.h"
-
-using base::Thread;
-
-#define BTPROTO_HCI 1
-#define HCI_CHANNEL_USER 1
-#define HCI_CHANNEL_CONTROL 3
-#define HCI_DEV_NONE 0xffff
-
-#define RFKILL_TYPE_BLUETOOTH 2
-#define RFKILL_OP_CHANGE_ALL 3
-
-#define MGMT_OP_INDEX_LIST 0x0003
-#define MGMT_EV_INDEX_ADDED 0x0004
-#define MGMT_EV_COMMAND_COMP 0x0001
-#define MGMT_EV_SIZE_MAX 1024
-#define MGMT_EV_POLL_TIMEOUT 3000 /* 3000ms */
-
-struct sockaddr_hci {
- sa_family_t hci_family;
- unsigned short hci_dev;
- unsigned short hci_channel;
-};
-
-struct rfkill_event {
- uint32_t idx;
- uint8_t type;
- uint8_t op;
- uint8_t soft, hard;
-} __attribute__((packed));
-
-struct mgmt_pkt {
- uint16_t opcode;
- uint16_t index;
- uint16_t len;
- uint8_t data[MGMT_EV_SIZE_MAX];
-} __attribute__((packed));
-
-struct mgmt_event_read_index {
- uint16_t cc_opcode;
- uint8_t status;
- uint16_t num_intf;
- uint16_t index[0];
-} __attribute__((packed));
-
-enum HciPacketType {
- HCI_PACKET_TYPE_UNKNOWN = 0,
- HCI_PACKET_TYPE_COMMAND = 1,
- HCI_PACKET_TYPE_ACL_DATA = 2,
- HCI_PACKET_TYPE_SCO_DATA = 3,
- HCI_PACKET_TYPE_EVENT = 4
-};
-
-extern void initialization_complete();
-extern void hci_event_received(const base::Location& from_here, BT_HDR* packet);
-extern void acl_event_received(BT_HDR* packet);
-extern void sco_data_received(BT_HDR* packet);
-
-static int bt_vendor_fd = -1;
-static int hci_interface;
-static int rfkill_en;
-static int wait_hcidev(void);
-static int rfkill(int block);
-
-int reader_thread_ctrl_fd = -1;
-Thread* reader_thread = NULL;
-
-void monitor_socket(int ctrl_fd, int fd) {
- const allocator_t* buffer_allocator = buffer_allocator_get_interface();
- const size_t buf_size = 2000;
- uint8_t buf[buf_size];
- ssize_t len = read(fd, buf, buf_size);
-
- while (len > 0) {
- if (len == buf_size)
- LOG(FATAL) << "This packet filled buffer, if it have continuation we "
- "don't know how to merge it, increase buffer size!";
-
- uint8_t type = buf[0];
-
- size_t packet_size = buf_size + BT_HDR_SIZE;
- BT_HDR* packet =
- reinterpret_cast<BT_HDR*>(buffer_allocator->alloc(packet_size));
- packet->offset = 0;
- packet->layer_specific = 0;
- packet->len = len - 1;
- memcpy(packet->data, buf + 1, len - 1);
-
- switch (type) {
- case HCI_PACKET_TYPE_COMMAND:
- packet->event = MSG_HC_TO_STACK_HCI_EVT;
- hci_event_received(FROM_HERE, packet);
- break;
- case HCI_PACKET_TYPE_ACL_DATA:
- packet->event = MSG_HC_TO_STACK_HCI_ACL;
- acl_event_received(packet);
- break;
- case HCI_PACKET_TYPE_SCO_DATA:
- packet->event = MSG_HC_TO_STACK_HCI_SCO;
- sco_data_received(packet);
- break;
- case HCI_PACKET_TYPE_EVENT:
- packet->event = MSG_HC_TO_STACK_HCI_EVT;
- hci_event_received(FROM_HERE, packet);
- break;
- default:
- LOG(FATAL) << "Unexpected event type: " << +type;
- break;
- }
-
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(ctrl_fd, &fds);
- FD_SET(fd, &fds);
- int res = select(std::max(fd, ctrl_fd) + 1, &fds, NULL, NULL, NULL);
- if (res <= 0) LOG(INFO) << "Nothing more to read";
-
- if (FD_ISSET(ctrl_fd, &fds)) {
- LOG(INFO) << "exitting";
- return;
- }
-
- len = read(fd, buf, buf_size);
- }
-}
-
-/* TODO: should thread the device waiting and return immedialty */
-void hci_initialize() {
- LOG(INFO) << __func__;
-
- char prop_value[PROPERTY_VALUE_MAX];
- int read = osi_property_get("bluetooth.interface", prop_value, nullptr);
-
- // If bluetooth.interface was read from properties, use it. Otherwise, default
- // to the value read from the init flags.
- if (read) {
- errno = 0;
- if (memcmp(prop_value, "hci", 3))
- hci_interface = strtol(prop_value, NULL, 10);
- else
- hci_interface = strtol(prop_value + 3, NULL, 10);
- if (errno) hci_interface = 0;
- } else {
- hci_interface = bluetooth::common::InitFlags::GetAdapterIndex();
- }
-
- LOG(INFO) << "Using interface hci" << +hci_interface;
-
-#if !defined(TARGET_FLOSS)
- osi_property_get("bluetooth.rfkill", prop_value, "1");
-
- rfkill_en = atoi(prop_value);
- if (rfkill_en) {
- rfkill(0);
- }
-#endif
-
- int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- CHECK(fd >= 0) << "socket create error" << strerror(errno);
-
- bt_vendor_fd = fd;
-
- if (wait_hcidev()) {
- LOG(FATAL) << "HCI interface hci" << +hci_interface << " not found";
- }
-
- struct sockaddr_hci addr;
- memset(&addr, 0, sizeof(addr));
- addr.hci_family = AF_BLUETOOTH;
- addr.hci_dev = hci_interface;
- addr.hci_channel = HCI_CHANNEL_USER;
- if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
- PLOG(FATAL) << "socket bind error";
- }
-
- int sv[2];
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
- PLOG(FATAL) << "socketpair failed";
- }
-
- reader_thread_ctrl_fd = sv[0];
- reader_thread = new Thread("hci_sock_reader");
- reader_thread->Start();
- reader_thread->task_runner()->PostTask(
- FROM_HERE, base::Bind(&monitor_socket, sv[1], bt_vendor_fd));
-
- LOG(INFO) << "HCI device ready";
- initialization_complete();
-}
-
-void hci_close() {
- LOG(INFO) << __func__;
-
- if (bt_vendor_fd != -1) {
- close(bt_vendor_fd);
- bt_vendor_fd = -1;
- }
-
- if (reader_thread_ctrl_fd != -1) {
- uint8_t msg[] = {1};
- send(reader_thread_ctrl_fd, msg, sizeof(msg), 0);
- reader_thread_ctrl_fd = -1;
- }
-
- if (reader_thread != NULL) {
- reader_thread->Stop();
- delete reader_thread;
- reader_thread = NULL;
- }
-
-#if !defined(TARGET_FLOSS)
- rfkill(1);
-#endif
-}
-
-void hci_transmit(BT_HDR* packet) {
- uint8_t type = 0;
-
- CHECK(bt_vendor_fd != -1);
-
- uint16_t event = packet->event & MSG_EVT_MASK;
- switch (event & MSG_EVT_MASK) {
- case MSG_STACK_TO_HC_HCI_CMD:
- type = 1;
- break;
- case MSG_STACK_TO_HC_HCI_ACL:
- type = 2;
- break;
- case MSG_STACK_TO_HC_HCI_SCO:
- type = 3;
- break;
- default:
- LOG(FATAL) << "Unknown packet type " << event;
- break;
- }
-
- uint8_t* addr = packet->data + packet->offset - 1;
- uint8_t store = *addr;
- *addr = type;
- ssize_t ret = write(bt_vendor_fd, addr, packet->len + 1);
-
- *(addr) = store;
-
- if (ret != packet->len + 1) LOG(ERROR) << "Should have send whole packet";
-
- if (ret == -1) PLOG(FATAL) << "write failed";
-}
-
-static int wait_hcidev(void) {
- struct sockaddr_hci addr;
- struct pollfd fds[1];
- struct mgmt_pkt ev;
- int fd;
- int ret = 0;
-
- LOG(INFO) << __func__;
-
- fd = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (fd < 0) {
- PLOG(ERROR) << "Bluetooth socket error";
- return -1;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.hci_family = AF_BLUETOOTH;
- addr.hci_dev = HCI_DEV_NONE;
- addr.hci_channel = HCI_CHANNEL_CONTROL;
-
- if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
- PLOG(ERROR) << "HCI Channel Control";
- close(fd);
- return -1;
- }
-
- fds[0].fd = fd;
- fds[0].events = POLLIN;
-
- /* Read Controller Index List Command */
- ev.opcode = MGMT_OP_INDEX_LIST;
- ev.index = HCI_DEV_NONE;
- ev.len = 0;
-
- ssize_t wrote;
- OSI_NO_INTR(wrote = write(fd, &ev, 6));
- if (wrote != 6) {
- PLOG(ERROR) << "Unable to write mgmt command";
- ret = -1;
- goto end;
- }
-
- while (1) {
- int n;
- OSI_NO_INTR(n = poll(fds, 1, MGMT_EV_POLL_TIMEOUT));
- if (n == -1) {
- PLOG(ERROR) << "Poll error";
- ret = -1;
- break;
- } else if (n == 0) {
- LOG(ERROR) << "Timeout, no HCI device detected";
- ret = -1;
- break;
- }
-
- if (fds[0].revents & POLLIN) {
- OSI_NO_INTR(n = read(fd, &ev, sizeof(struct mgmt_pkt)));
- if (n < 0) {
- PLOG(ERROR) << "Error reading control channel";
- ret = -1;
- break;
- }
-
- if (ev.opcode == MGMT_EV_INDEX_ADDED && ev.index == hci_interface) {
- goto end;
- } else if (ev.opcode == MGMT_EV_COMMAND_COMP) {
- struct mgmt_event_read_index* cc;
- int i;
-
- cc = (struct mgmt_event_read_index*)ev.data;
-
- if (cc->cc_opcode != MGMT_OP_INDEX_LIST || cc->status != 0) continue;
-
- for (i = 0; i < cc->num_intf; i++) {
- if (cc->index[i] == hci_interface) goto end;
- }
- }
- }
- }
-
-end:
- close(fd);
- return ret;
-}
-
-static int rfkill(int block) {
- struct rfkill_event event;
- int fd;
-
- LOG(INFO) << __func__;
-
- fd = open("/dev/rfkill", O_WRONLY);
- if (fd < 0) {
- LOG(ERROR) << "Unable to open /dev/rfkill";
- return -1;
- }
-
- memset(&event, 0, sizeof(struct rfkill_event));
- event.op = RFKILL_OP_CHANGE_ALL;
- event.type = RFKILL_TYPE_BLUETOOTH;
- event.hard = block;
- event.soft = block;
-
- ssize_t len;
- OSI_NO_INTR(len = write(fd, &event, sizeof(event)));
- if (len < 0) {
- LOG(ERROR) << "Failed to change rfkill state";
- close(fd);
- return 1;
- }
-
- close(fd);
- return 0;
-}
-
-int hci_open_firmware_log_file() { return INVALID_FD; }
-
-void hci_close_firmware_log_file(int fd) {}
-
-void hci_log_firmware_debug_packet(int fd, BT_HDR* packet) {}
diff --git a/system/hci/test/hci_layer_test.cc b/system/hci/test/hci_layer_test.cc
index 536346e8f8..e69de29bb2 100644
--- a/system/hci/test/hci_layer_test.cc
+++ b/system/hci/test/hci_layer_test.cc
@@ -1,122 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <base/logging.h>
-#include <gtest/gtest.h>
-#include <stdint.h>
-
-#include "common/message_loop_thread.h"
-#include "hci/src/hci_layer.cc"
-#include "osi/include/allocator.h"
-#include "osi/include/osi.h"
-#include "osi/test/AllocationTestHarness.h"
-#include "osi/test/test_stubs.h"
-#include "stack/include/bt_types.h"
-
-extern void allocation_tracker_uninit(void);
-
-allocator_t buffer_allocator_ = {
- .alloc = osi_malloc,
- .free = osi_free,
-};
-
-void monitor_socket(int ctrl_fd, int fd) {
- LOG(INFO) << __func__ << " UNIMPLEMENTED";
-}
-void hci_initialize() { LOG(INFO) << __func__ << " UNIMPLEMENTED"; }
-void hci_close() { LOG(INFO) << __func__ << " UNIMPLEMENTED"; }
-void hci_transmit(BT_HDR* packet) { LOG(INFO) << __func__ << " UNIMPLEMENTED"; }
-int hci_open_firmware_log_file() { return INVALID_FD; }
-void hci_close_firmware_log_file(int fd) {}
-void hci_log_firmware_debug_packet(int fd, BT_HDR* packet) {}
-const allocator_t* buffer_allocator_get_interface() {
- return &buffer_allocator_;
-}
-
-/**
- * Test class to test selected functionality in hci/src/hci_layer.cc
- */
-class HciLayerTest : public AllocationTestHarness {
- protected:
- void SetUp() override {
- AllocationTestHarness::SetUp();
- // Disable our allocation tracker to allow ASAN full range
- allocation_tracker_uninit();
- commands_pending_response = list_new(NULL);
- buffer_allocator = &buffer_allocator_;
- }
-
- void TearDown() override {
- list_free(commands_pending_response);
- AllocationTestHarness::TearDown();
- }
-
- BT_HDR* AllocateHciEventPacket(size_t packet_length) const {
- return AllocatePacket(packet_length, MSG_HC_TO_STACK_HCI_EVT);
- }
-
- uint8_t* GetPayloadPointer(BT_HDR* packet) const {
- return static_cast<uint8_t*>(packet->data);
- }
-
- private:
- BT_HDR* AllocatePacket(size_t packet_length, uint16_t event) const {
- BT_HDR* packet =
- static_cast<BT_HDR*>(osi_calloc(sizeof(BT_HDR) + packet_length));
- packet->offset = 0;
- packet->len = packet_length;
- packet->layer_specific = 0;
- packet->event = MSG_HC_TO_STACK_HCI_EVT;
- return packet;
- }
-};
-
-TEST_F(HciLayerTest, FilterIncomingEvent) {
- {
- BT_HDR* packet = AllocateHciEventPacket(3);
-
- auto p = GetPayloadPointer(packet);
- *p++ = HCI_COMMAND_STATUS_EVT;
- *p++ = 0x0; // length
-
- CHECK(filter_incoming_event(packet));
- }
-
- {
- BT_HDR* packet = AllocateHciEventPacket(3);
-
- auto p = GetPayloadPointer(packet);
- *p++ = HCI_COMMAND_STATUS_EVT;
- *p++ = 0x1; // length
- *p++ = 0xff;
-
- CHECK(filter_incoming_event(packet));
- }
-
- {
- BT_HDR* packet = AllocateHciEventPacket(6);
-
- auto p = GetPayloadPointer(packet);
- *p++ = HCI_COMMAND_STATUS_EVT;
- *p++ = 0x04; // length
- *p++ = 0x00; // status
- *p++ = 0x01; // credits
- *p++ = 0x34; // opcode0
- *p++ = 0x12; // opcode1
-
- CHECK(filter_incoming_event(packet));
- }
-}
diff --git a/system/hci/test/other_stack_stub.cc b/system/hci/test/other_stack_stub.cc
index 43bcbc8e82..e69de29bb2 100644
--- a/system/hci/test/other_stack_stub.cc
+++ b/system/hci/test/other_stack_stub.cc
@@ -1,45 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Gabeldorsche related legacy-only-stack-side expansion and support code.
- */
-#include "base/bind.h"
-#include "btcore/include/module.h" // base::OnceClosure
-#include "hci/include/btsnoop.h"
-#include "hci/include/hci_layer.h"
-
-const btsnoop_t* btsnoop_get_interface() { return nullptr; }
-const packet_fragmenter_t* packet_fragmenter_get_interface() { return nullptr; }
-bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
-
-namespace bluetooth {
-namespace bqr {
-
-void DumpLmpLlMessage(uint8_t length, uint8_t* p_lmp_ll_message_event) {}
-void DumpBtScheduling(unsigned char, unsigned char*) {}
-
-} // namespace bqr
-
-namespace shim {
-
-bool is_gd_shim_enabled() { return false; }
-bool is_gd_stack_started_up() { return false; }
-void Post(base::OnceClosure task) {}
-const hci_t* hci_layer_get_interface() { return nullptr; }
-
-} // namespace shim
-} // namespace bluetooth
diff --git a/system/main/shim/le_scanning_manager.cc b/system/main/shim/le_scanning_manager.cc
index 816745cda7..726aa8b2b8 100644
--- a/system/main/shim/le_scanning_manager.cc
+++ b/system/main/shim/le_scanning_manager.cc
@@ -50,6 +50,9 @@ extern void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
BD_NAME bd_name,
tBT_DEVICE_TYPE dev_type);
+extern void btm_ble_process_adv_addr(RawAddress& raw_address,
+ tBLE_ADDR_TYPE* address_type);
+
class BleScannerInterfaceImpl : public BleScannerInterface,
public bluetooth::hci::ScanningCallback {
public:
@@ -253,6 +256,10 @@ class BleScannerInterfaceImpl : public BleScannerInterface,
std::vector<uint8_t> advertising_data) {
RawAddress raw_address = ToRawAddress(address);
+ if (address_type != BLE_ADDR_ANONYMOUS) {
+ btm_ble_process_adv_addr(raw_address, &address_type);
+ }
+
do_in_jni_thread(
FROM_HERE,
base::BindOnce(&BleScannerInterfaceImpl::handle_remote_properties,
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index 5bab757433..978ba532c9 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -136,6 +136,7 @@ cc_library_static {
"btm/btm_main.cc",
"acl/btm_pm.cc",
"btm/btm_sco.cc",
+ "btm/btm_sco_hci.cc",
"btm/btm_iso.cc",
"btm/btm_sec.cc",
"btm/btm_scn.cc",
@@ -811,6 +812,7 @@ cc_test {
"btm/btm_iso.cc",
"btm/btm_main.cc",
"btm/btm_sco.cc",
+ "btm/btm_sco_hci.cc",
"btm/btm_scn.cc",
"btm/btm_sec.cc",
"metrics/stack_metrics_logging.cc",
@@ -821,9 +823,11 @@ cc_test {
"libbt-common",
"libbt-protos-lite",
"libbtdevice",
+ "libbt-utils",
"libgmock",
"liblog",
"libosi",
+ "libudrv-uipc",
],
shared_libs: [
"libcrypto",
diff --git a/system/stack/BUILD.gn b/system/stack/BUILD.gn
index 09756297aa..a0c1b6be41 100644
--- a/system/stack/BUILD.gn
+++ b/system/stack/BUILD.gn
@@ -120,6 +120,7 @@ source_set("stack") {
"btm/btm_main.cc",
"btm/btm_scn.cc",
"btm/btm_sco.cc",
+ "btm/btm_sco_hci.cc",
"btm/btm_sec.cc",
"btu/btu_hcif.cc",
"btu/btu_task.cc",
diff --git a/system/stack/btm/btm_ble_gap.cc b/system/stack/btm/btm_ble_gap.cc
index 7d675c8243..04688b35f9 100644
--- a/system/stack/btm/btm_ble_gap.cc
+++ b/system/stack/btm/btm_ble_gap.cc
@@ -377,7 +377,8 @@ void BTM_BleOpportunisticObserve(bool enable,
tBTM_INQ_RESULTS_CB* p_results_cb) {
if (bluetooth::shim::is_gd_shim_enabled()) {
bluetooth::shim::BTM_BleOpportunisticObserve(enable, p_results_cb);
- return;
+ // NOTE: passthrough, no return here. GD would send the results back to BTM,
+ // and it needs the callbacks set properly.
}
if (enable) {
@@ -1996,6 +1997,14 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type,
secondary_phy, advertising_sid, tx_power, rssi,
periodic_adv_int, adv_data);
+ tBTM_INQ_RESULTS_CB* p_opportunistic_obs_results_cb =
+ btm_cb.ble_ctr_cb.p_opportunistic_obs_results_cb;
+ if (p_opportunistic_obs_results_cb) {
+ (p_opportunistic_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
+ const_cast<uint8_t*>(adv_data.data()),
+ adv_data.size());
+ }
+
uint8_t result = btm_ble_is_discoverable(bda, adv_data);
if (result == 0) {
// Device no longer discoverable so discard outstanding advertising packet
@@ -2017,14 +2026,6 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type,
const_cast<uint8_t*>(adv_data.data()), adv_data.size());
}
- tBTM_INQ_RESULTS_CB* p_opportunistic_obs_results_cb =
- btm_cb.ble_ctr_cb.p_opportunistic_obs_results_cb;
- if (p_opportunistic_obs_results_cb) {
- (p_opportunistic_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,
- const_cast<uint8_t*>(adv_data.data()),
- adv_data.size());
- }
-
cache.Clear(addr_type, bda);
}
@@ -2078,6 +2079,14 @@ void btm_ble_process_adv_pkt_cont_for_inquiry(
secondary_phy, advertising_sid, tx_power, rssi,
periodic_adv_int, advertising_data);
+ tBTM_INQ_RESULTS_CB* p_opportunistic_obs_results_cb =
+ btm_cb.ble_ctr_cb.p_opportunistic_obs_results_cb;
+ if (p_opportunistic_obs_results_cb) {
+ (p_opportunistic_obs_results_cb)(
+ (tBTM_INQ_RESULTS*)&p_i->inq_info.results,
+ const_cast<uint8_t*>(advertising_data.data()), advertising_data.size());
+ }
+
uint8_t result = btm_ble_is_discoverable(bda, advertising_data);
if (result == 0) {
return;
@@ -2091,14 +2100,6 @@ void btm_ble_process_adv_pkt_cont_for_inquiry(
const_cast<uint8_t*>(advertising_data.data()),
advertising_data.size());
}
-
- tBTM_INQ_RESULTS_CB* p_opportunistic_obs_results_cb =
- btm_cb.ble_ctr_cb.p_opportunistic_obs_results_cb;
- if (p_opportunistic_obs_results_cb) {
- (p_opportunistic_obs_results_cb)(
- (tBTM_INQ_RESULTS*)&p_i->inq_info.results,
- const_cast<uint8_t*>(advertising_data.data()), advertising_data.size());
- }
}
void btm_ble_process_phy_update_pkt(uint8_t len, uint8_t* data) {
diff --git a/system/stack/btm/btm_sco.cc b/system/stack/btm/btm_sco.cc
index edabe45ad6..7f08074d57 100644
--- a/system/stack/btm/btm_sco.cc
+++ b/system/stack/btm/btm_sco.cc
@@ -40,14 +40,6 @@
#include "types/class_of_device.h"
#include "types/raw_address.h"
-#ifndef ESCO_DATA_PATH
-#ifdef OS_ANDROID
-#define ESCO_DATA_PATH ESCO_DATA_PATH_PCM
-#else
-#define ESCO_DATA_PATH ESCO_DATA_PATH_HCI
-#endif
-#endif
-
extern tBTM_CB btm_cb;
namespace {
@@ -167,6 +159,16 @@ static void btm_esco_conn_rsp(uint16_t sco_inx, uint8_t hci_status,
}
}
+// Return the active (first connected) SCO connection block
+static tSCO_CONN* btm_get_active_sco() {
+ for (auto& link : btm_cb.sco_cb.sco_db) {
+ if (link.state == SCO_ST_CONNECTED) {
+ return &link;
+ }
+ }
+ return nullptr;
+}
+
/*******************************************************************************
*
* Function btm_route_sco_data
@@ -193,13 +195,27 @@ void btm_route_sco_data(BT_HDR* p_msg) {
return;
}
LOG_INFO("Received SCO packet from HCI. Dropping it since no handler so far");
- // TODO(b/195344796): Implement the SCO over HCI data path
- // std::vector<uint8_t> data(payload, payload + length);
+ uint16_t handle = handle_with_flags & 0xeff;
+ auto* active_sco = btm_get_active_sco();
+ if (active_sco != nullptr && active_sco->hci_handle == handle) {
+ // TODO: For MSBC, we need to decode here
+ bluetooth::audio::sco::write(payload, length);
+ }
osi_free(p_msg);
+ // For Chrome OS, we send the outgoing data after receiving an incoming one
+ uint8_t out_buf[BTM_SCO_DATA_SIZE_MAX];
+ auto size_read = bluetooth::audio::sco::read(out_buf, BTM_SCO_DATA_SIZE_MAX);
+ auto data = std::vector<uint8_t>(out_buf, out_buf + size_read);
+ // TODO: For MSBC, we need to encode here
+ btm_send_sco_packet(std::move(data));
}
-void btm_send_sco_packet(std::vector<uint8_t> data, uint16_t sco_handle) {
- BT_HDR* packet = btm_sco_make_packet(std::move(data), sco_handle);
+void btm_send_sco_packet(std::vector<uint8_t> data) {
+ auto* active_sco = btm_get_active_sco();
+ if (active_sco == nullptr || data.empty()) {
+ return;
+ }
+ BT_HDR* packet = btm_sco_make_packet(std::move(data), active_sco->hci_handle);
bte_main_hci_send(packet, BT_EVT_TO_LM_HCI_SCO);
}
@@ -782,6 +798,8 @@ void btm_sco_connected(tHCI_STATUS hci_status, const RawAddress& bda,
(*p->p_conn_cb)(xx);
+ bluetooth::audio::sco::open();
+
return;
}
}
@@ -927,6 +945,8 @@ void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason) {
BTM_LogHistory(kBtmLogTag, bd_addr, "Disconnected",
base::StringPrintf("handle:0x%04x reason:%s", hci_handle,
hci_reason_code_text(reason).c_str()));
+
+ bluetooth::audio::sco::cleanup();
}
/*******************************************************************************
diff --git a/system/stack/btm/btm_sco.h b/system/stack/btm/btm_sco.h
index 0689217351..d542a14060 100644
--- a/system/stack/btm/btm_sco.h
+++ b/system/stack/btm/btm_sco.h
@@ -24,6 +24,33 @@
constexpr uint16_t kMaxScoLinks = static_cast<uint16_t>(BTM_MAX_SCO_LINKS);
+#ifndef ESCO_DATA_PATH
+#ifdef OS_ANDROID
+#define ESCO_DATA_PATH ESCO_DATA_PATH_PCM
+#else
+#define ESCO_DATA_PATH ESCO_DATA_PATH_HCI
+#endif
+#endif
+
+// SCO-over-HCI audio related definitions
+namespace bluetooth::audio::sco {
+
+// Initialize SCO-over-HCI socket (UIPC); the client is audio server.
+void init();
+
+// Open the socket when there is SCO connection open
+void open();
+
+// Clean up the socket when the SCO connection is done
+void cleanup();
+
+// Read from the socket (audio server) for SCO Tx
+size_t read(uint8_t* p_buf, uint32_t len);
+
+// Write to the socket from SCO Rx
+size_t write(const uint8_t* buf, uint32_t len);
+} // namespace bluetooth::audio::sco
+
/* Define the structures needed by sco
*/
@@ -62,8 +89,6 @@ inline std::string sco_state_text(const tSCO_STATE& state) {
}
}
-typedef void(tBTM_SCO_IND_CBACK)(uint16_t sco_inx);
-
/* Define the structure that contains (e)SCO data */
typedef struct {
tBTM_ESCO_CBACK* p_esco_cback; /* Callback for eSCO events */
@@ -112,6 +137,7 @@ typedef struct {
void Init() {
def_esco_parms = esco_parameters_for_codec(ESCO_CODEC_CVSD_S3);
+ bluetooth::audio::sco::init();
}
uint16_t get_index(const tSCO_CONN* p_sco) const {
@@ -134,4 +160,4 @@ extern void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle);
BT_HDR* btm_sco_make_packet(std::vector<uint8_t> data, uint16_t sco_handle);
// Send a SCO packet
-void btm_send_sco_packet(std::vector<uint8_t> data, uint16_t sco_handle);
+void btm_send_sco_packet(std::vector<uint8_t> data);
diff --git a/system/stack/btm/btm_sco_hci.cc b/system/stack/btm/btm_sco_hci.cc
new file mode 100644
index 0000000000..d0109f2072
--- /dev/null
+++ b/system/stack/btm/btm_sco_hci.cc
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <grp.h>
+#include <sys/stat.h>
+
+#include <memory>
+
+#include "osi/include/log.h"
+#include "stack/btm/btm_sco.h"
+#include "udrv/include/uipc.h"
+
+#if ESCO_DATA_PATH == ESCO_DATA_PATH_PCM
+// For hardware encoding path, provide an empty implementation
+
+namespace bluetooth::audio::sco {
+void init() {}
+void open() {}
+void cleanup() {}
+size_t read(uint8_t*, uint32_t) { return 0; }
+size_t write(const uint8_t*, uint32_t) { return 0; }
+} // namespace bluetooth::audio::sco
+#else
+
+#define SCO_DATA_READ_POLL_MS 10
+#define SCO_HOST_DATA_PATH "/var/run/bluetooth/audio/.sco_data"
+// TODO(b/198260375): Make SCO data owner group configurable.
+#define SCO_HOST_DATA_GROUP "bluetooth-audio"
+
+namespace {
+
+std::unique_ptr<tUIPC_STATE> sco_uipc = nullptr;
+
+void sco_data_cb(tUIPC_CH_ID, tUIPC_EVENT event) {
+ switch (event) {
+ case UIPC_OPEN_EVT:
+ /*
+ * Read directly from media task from here on (keep callback for
+ * connection events.
+ */
+ UIPC_Ioctl(*sco_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_REG_REMOVE_ACTIVE_READSET,
+ NULL);
+ UIPC_Ioctl(*sco_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
+ reinterpret_cast<void*>(SCO_DATA_READ_POLL_MS));
+ break;
+ default:
+ break;
+ }
+}
+
+} // namespace
+
+namespace bluetooth {
+namespace audio {
+namespace sco {
+
+void init() { sco_uipc = UIPC_Init(); }
+
+void open() {
+ UIPC_Open(*sco_uipc, UIPC_CH_ID_AV_AUDIO, sco_data_cb, SCO_HOST_DATA_PATH);
+ struct group* grp = getgrnam(SCO_HOST_DATA_GROUP);
+ chmod(SCO_HOST_DATA_PATH, 0770);
+ if (grp) {
+ int res = chown(SCO_HOST_DATA_PATH, -1, grp->gr_gid);
+ if (res == -1) {
+ LOG_ERROR("%s failed: %s", __func__, strerror(errno));
+ }
+ }
+}
+
+void cleanup() {
+ if (sco_uipc != nullptr) {
+ UIPC_Close(*sco_uipc, UIPC_CH_ID_ALL);
+ }
+}
+
+size_t read(uint8_t* p_buf, uint32_t len) {
+ if (sco_uipc == nullptr) {
+ return 0;
+ }
+ return UIPC_Read(*sco_uipc, UIPC_CH_ID_AV_AUDIO, p_buf, len);
+}
+
+size_t write(const uint8_t* p_buf, uint32_t len) {
+ return UIPC_Send(*sco_uipc, UIPC_CH_ID_AV_AUDIO, 0, p_buf, len);
+}
+
+} // namespace sco
+} // namespace audio
+} // namespace bluetooth
+
+#endif
diff --git a/system/stack/btu/btu_hcif.cc b/system/stack/btu/btu_hcif.cc
index 951b6fdcf7..f06de1a882 100644
--- a/system/stack/btu/btu_hcif.cc
+++ b/system/stack/btu/btu_hcif.cc
@@ -1534,14 +1534,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
*
******************************************************************************/
static void btu_hcif_hardware_error_evt(uint8_t* p) {
- HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p);
- if (hci_is_root_inflammation_event_received()) {
- // Ignore the hardware error event here as we have already received
- // root inflammation event earlier.
- HCI_TRACE_ERROR("H/w error event after root inflammation event!");
- return;
- }
-
+ LOG_ERROR("UNHANDLED Ctlr H/w error event - code:0x%x", *p);
BTA_sys_signal_hw_error();
}
diff --git a/system/stack/smp/smp_act.cc b/system/stack/smp/smp_act.cc
index 7a353dfde6..78a656fcfc 100644
--- a/system/stack/smp/smp_act.cc
+++ b/system/stack/smp/smp_act.cc
@@ -910,6 +910,15 @@ void smp_br_check_authorization_request(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
}
SMP_TRACE_DEBUG("%s: use h7 = %d", __func__, p_cb->key_derivation_h7_used);
+ /* SMP over BR/EDR should always be used with CTKD, so derive LTK from
+ * LK before receiving keys */
+ if ((p_cb->role == HCI_ROLE_CENTRAL &&
+ (p_cb->local_i_key & SMP_SEC_KEY_TYPE_ENC)) ||
+ (p_cb->role == HCI_ROLE_PERIPHERAL &&
+ (p_cb->local_r_key & SMP_SEC_KEY_TYPE_ENC))) {
+ smp_generate_ltk(p_cb, p_data);
+ }
+
SMP_TRACE_DEBUG(
"%s rcvs upgrades: i_keys=0x%x r_keys=0x%x (i-initiator r-responder)",
__func__, p_cb->local_i_key, p_cb->local_r_key);
diff --git a/system/stack/smp/smp_keys.cc b/system/stack/smp/smp_keys.cc
index a49890d83c..c9649f20d1 100644
--- a/system/stack/smp/smp_keys.cc
+++ b/system/stack/smp/smp_keys.cc
@@ -530,7 +530,7 @@ static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) {
void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
SMP_TRACE_DEBUG("%s", __func__);
- if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) {
+ if (p_cb->smp_over_br) {
smp_br_process_link_key(p_cb, NULL);
return;
} else if (p_cb->le_secure_connections_mode_is_used) {
diff --git a/system/test/mock/mock_hci_layer.cc b/system/test/mock/mock_hci_layer.cc
index 198af1a734..e69de29bb2 100644
--- a/system/test/mock/mock_hci_layer.cc
+++ b/system/test/mock/mock_hci_layer.cc
@@ -1,110 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Generated mock file from original source file
- * Functions generated:13
- *
- * mockcify.pl ver 0.2
- */
-
-#include <map>
-#include <string>
-
-extern std::map<std::string, int> mock_function_count_map;
-
-// Original included files, if any
-// NOTE: Since this is a mock file with mock definitions some number of
-// include files may not be required. The include-what-you-use
-// still applies, but crafting proper inclusion is out of scope
-// for this effort. This compilation unit may compile as-is, or
-// may need attention to prune the inclusion set.
-
-// Mock include file to share data between tests and mock
-#include "test/mock/mock_hci_layer.h"
-
-// Mocked compile conditionals, if any
-#ifndef UNUSED_ATTR
-#define UNUSED_ATTR
-#endif
-
-// Mocked internal structures, if any
-typedef struct {
-} waiting_command_t;
-
-namespace test {
-namespace mock {
-namespace hci_layer {
-
-// Function state capture and return values, if needed
-struct initialization_complete initialization_complete;
-struct hci_event_received hci_event_received;
-struct acl_event_received acl_event_received;
-struct sco_data_received sco_data_received;
-struct iso_data_received iso_data_received;
-struct hal_service_died hal_service_died;
-struct process_command_credits process_command_credits;
-struct hci_is_root_inflammation_event_received
- hci_is_root_inflammation_event_received;
-struct handle_root_inflammation_event handle_root_inflammation_event;
-struct hci_layer_get_interface hci_layer_get_interface;
-
-} // namespace hci_layer
-} // namespace mock
-} // namespace test
-
-// Mocked functions, if any
-void initialization_complete() {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::initialization_complete();
-}
-void hci_event_received(const base::Location& from_here, BT_HDR* packet) {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::hci_event_received(from_here, packet);
-}
-void acl_event_received(BT_HDR* packet) {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::acl_event_received(packet);
-}
-void sco_data_received(BT_HDR* packet) {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::sco_data_received(packet);
-}
-void iso_data_received(BT_HDR* packet) {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::iso_data_received(packet);
-}
-void hal_service_died() {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::hal_service_died();
-}
-void process_command_credits(int credits) {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::process_command_credits(credits);
-}
-bool hci_is_root_inflammation_event_received() {
- mock_function_count_map[__func__]++;
- return test::mock::hci_layer::hci_is_root_inflammation_event_received();
-}
-void handle_root_inflammation_event() {
- mock_function_count_map[__func__]++;
- test::mock::hci_layer::handle_root_inflammation_event();
-}
-const hci_t* hci_layer_get_interface() {
- mock_function_count_map[__func__]++;
- return test::mock::hci_layer::hci_layer_get_interface();
-}
-// END mockcify generation
diff --git a/system/test/mock/mock_hci_layer.h b/system/test/mock/mock_hci_layer.h
index aa52515498..e69de29bb2 100644
--- a/system/test/mock/mock_hci_layer.h
+++ b/system/test/mock/mock_hci_layer.h
@@ -1,137 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Generated mock file from original source file
- * Functions generated:13
- *
- * mockcify.pl ver 0.2
- */
-
-#include <map>
-#include <string>
-
-extern std::map<std::string, int> mock_function_count_map;
-
-// Original included files, if any
-// NOTE: Since this is a mock file with mock definitions some number of
-// include files may not be required. The include-what-you-use
-// still applies, but crafting proper inclusion is out of scope
-// for this effort. This compilation unit may compile as-is, or
-// may need attention to prune the inclusion set.
-
-#include "hci/include/hci_layer.h"
-
-// Mocked compile conditionals, if any
-#ifndef UNUSED_ATTR
-#define UNUSED_ATTR
-#endif
-
-namespace test {
-namespace mock {
-namespace hci_layer {
-
-// Shared state between mocked functions and tests
-// Name: initialization_complete
-// Params:
-// Returns: void
-struct initialization_complete {
- std::function<void()> body{[]() {}};
- void operator()() { body(); };
-};
-extern struct initialization_complete initialization_complete;
-// Name: hci_event_received
-// Params: const base::Location& from_here, BT_HDR* packet
-// Returns: void
-struct hci_event_received {
- std::function<void(const base::Location& from_here, BT_HDR* packet)> body{
- [](const base::Location& from_here, BT_HDR* packet) {}};
- void operator()(const base::Location& from_here, BT_HDR* packet) {
- body(from_here, packet);
- };
-};
-extern struct hci_event_received hci_event_received;
-// Name: acl_event_received
-// Params: BT_HDR* packet
-// Returns: void
-struct acl_event_received {
- std::function<void(BT_HDR* packet)> body{[](BT_HDR* packet) {}};
- void operator()(BT_HDR* packet) { body(packet); };
-};
-extern struct acl_event_received acl_event_received;
-// Name: sco_data_received
-// Params: BT_HDR* packet
-// Returns: void
-struct sco_data_received {
- std::function<void(BT_HDR* packet)> body{[](BT_HDR* packet) {}};
- void operator()(BT_HDR* packet) { body(packet); };
-};
-extern struct sco_data_received sco_data_received;
-// Name: iso_data_received
-// Params: BT_HDR* packet
-// Returns: void
-struct iso_data_received {
- std::function<void(BT_HDR* packet)> body{[](BT_HDR* packet) {}};
- void operator()(BT_HDR* packet) { body(packet); };
-};
-extern struct iso_data_received iso_data_received;
-// Name: hal_service_died
-// Params:
-// Returns: void
-struct hal_service_died {
- std::function<void()> body{[]() {}};
- void operator()() { body(); };
-};
-extern struct hal_service_died hal_service_died;
-// Name: process_command_credits
-// Params: int credits
-// Returns: void
-struct process_command_credits {
- std::function<void(int credits)> body{[](int credits) {}};
- void operator()(int credits) { body(credits); };
-};
-extern struct process_command_credits process_command_credits;
-// Name: hci_is_root_inflammation_event_received
-// Params:
-// Returns: bool
-struct hci_is_root_inflammation_event_received {
- std::function<bool()> body{[]() { return false; }};
- bool operator()() { return body(); };
-};
-extern struct hci_is_root_inflammation_event_received
- hci_is_root_inflammation_event_received;
-// Name: handle_root_inflammation_event
-// Params:
-// Returns: void
-struct handle_root_inflammation_event {
- std::function<void()> body{[]() {}};
- void operator()() { body(); };
-};
-extern struct handle_root_inflammation_event handle_root_inflammation_event;
-// Name: hci_layer_get_interface
-// Params:
-// Returns: const hci_t*
-struct hci_layer_get_interface {
- hci_t* hci;
- std::function<const hci_t*()> body{[this]() { return hci; }};
- const hci_t* operator()() { return body(); };
-};
-extern struct hci_layer_get_interface hci_layer_get_interface;
-} // namespace hci_layer
-} // namespace mock
-} // namespace test
-
-// END mockcify generation
diff --git a/system/test/mock/mock_osi_thread_scheduler.h b/system/test/mock/mock_osi_thread_scheduler.h
index da88a94dd0..d048d2d1b7 100644
--- a/system/test/mock/mock_osi_thread_scheduler.h
+++ b/system/test/mock/mock_osi_thread_scheduler.h
@@ -21,6 +21,8 @@
* mockcify.pl ver 0.3.0
*/
+#include <sys/types.h>
+
#include <cstdint>
#include <functional>
#include <map>
diff --git a/system/test/mock/mock_udrv_ulinux_uipc.cc b/system/test/mock/mock_udrv_ulinux_uipc.cc
index 1ed966bac9..6e32173a1f 100644
--- a/system/test/mock/mock_udrv_ulinux_uipc.cc
+++ b/system/test/mock/mock_udrv_ulinux_uipc.cc
@@ -26,12 +26,12 @@ extern std::map<std::string, int> mock_function_count_map;
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
-#include <sys/poll.h>
#include <sys/prctl.h>
#include <sys/select.h>
#include <sys/socket.h>
diff --git a/system/udrv/Android.bp b/system/udrv/Android.bp
index 365915b0f9..62cb4e3e5d 100644
--- a/system/udrv/Android.bp
+++ b/system/udrv/Android.bp
@@ -15,6 +15,7 @@ cc_library_static {
],
include_dirs: [
"packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/gd",
"packages/modules/Bluetooth/system/internal_include",
"packages/modules/Bluetooth/system/utils/include",
"packages/modules/Bluetooth/system/stack/include",
diff --git a/system/udrv/ulinux/uipc.cc b/system/udrv/ulinux/uipc.cc
index 7ccc7ca6f5..4e93235df8 100644
--- a/system/udrv/ulinux/uipc.cc
+++ b/system/udrv/ulinux/uipc.cc
@@ -26,12 +26,12 @@
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
-#include <sys/poll.h>
#include <sys/prctl.h>
#include <sys/select.h>
#include <sys/socket.h>
@@ -42,8 +42,8 @@
#include <set>
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
-#include "bt_trace.h"
#include "bt_utils.h"
+#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/socket_utils/sockets.h"
#include "uipc.h"
@@ -52,8 +52,6 @@
* Constants & Macros
*****************************************************************************/
-#define PCM_FILENAME "/data/test.pcm"
-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CASE_RETURN_STR(const) \
@@ -107,7 +105,7 @@ static inline int create_server_socket(const char* name) {
int s = socket(AF_LOCAL, SOCK_STREAM, 0);
if (s < 0) return -1;
- BTIF_TRACE_EVENT("create_server_socket %s", name);
+ LOG_DEBUG("create_server_socket %s", name);
if (osi_socket_local_server_bind(s, name,
#if defined(OS_GENERIC)
@@ -116,18 +114,18 @@ static inline int create_server_socket(const char* name) {
ANDROID_SOCKET_NAMESPACE_ABSTRACT
#endif // defined(OS_GENERIC)
) < 0) {
- BTIF_TRACE_EVENT("socket failed to create (%s)", strerror(errno));
+ LOG_DEBUG("socket failed to create (%s)", strerror(errno));
close(s);
return -1;
}
if (listen(s, 5) < 0) {
- BTIF_TRACE_EVENT("listen failed", strerror(errno));
+ LOG_DEBUG("listen failed: %s", strerror(errno));
close(s);
return -1;
}
- BTIF_TRACE_EVENT("created socket fd %d", s);
+ LOG_DEBUG("created socket fd %d", s);
return s;
}
@@ -137,7 +135,7 @@ static int accept_server_socket(int sfd) {
int fd;
socklen_t len = sizeof(struct sockaddr_un);
- BTIF_TRACE_EVENT("accept fd %d", sfd);
+ LOG_DEBUG("accept fd %d", sfd);
/* make sure there is data to process */
pfd.fd = sfd;
@@ -146,15 +144,13 @@ static int accept_server_socket(int sfd) {
int poll_ret;
OSI_NO_INTR(poll_ret = poll(&pfd, 1, 0));
if (poll_ret == 0) {
- BTIF_TRACE_WARNING("accept poll timeout");
+ LOG_WARN("accept poll timeout");
return -1;
}
- // BTIF_TRACE_EVENT("poll revents 0x%x", pfd.revents);
-
OSI_NO_INTR(fd = accept(sfd, (struct sockaddr*)&remote, &len));
if (fd == -1) {
- BTIF_TRACE_ERROR("sock accept failed (%s)", strerror(errno));
+ LOG_ERROR("sock accept failed (%s)", strerror(errno));
return -1;
}
@@ -163,11 +159,9 @@ static int accept_server_socket(int sfd) {
int ret =
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&size, (int)sizeof(size));
if (ret < 0) {
- BTIF_TRACE_ERROR("setsockopt failed (%s)", strerror(errno));
+ LOG_ERROR("setsockopt failed (%s)", strerror(errno));
}
- // BTIF_TRACE_EVENT("new fd %d", fd);
-
return fd;
}
@@ -180,7 +174,7 @@ static int accept_server_socket(int sfd) {
static int uipc_main_init(tUIPC_STATE& uipc) {
int i;
- BTIF_TRACE_EVENT("### uipc_main_init ###");
+ LOG_DEBUG("### uipc_main_init ###");
uipc.tid = 0;
uipc.running = 0;
@@ -212,7 +206,7 @@ static int uipc_main_init(tUIPC_STATE& uipc) {
void uipc_main_cleanup(tUIPC_STATE& uipc) {
int i;
- BTIF_TRACE_EVENT("uipc_main_cleanup");
+ LOG_DEBUG("uipc_main_cleanup");
close(uipc.signal_fds[0]);
close(uipc.signal_fds[1]);
@@ -238,15 +232,12 @@ static void uipc_check_task_flags_locked(tUIPC_STATE& uipc) {
static int uipc_check_fd_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
if (ch_id >= UIPC_CH_NUM) return -1;
- // BTIF_TRACE_EVENT("CHECK SRVFD %d (ch %d)", uipc.ch[ch_id].srvfd,
- // ch_id);
-
if (SAFE_FD_ISSET(uipc.ch[ch_id].srvfd, &uipc.read_set)) {
- BTIF_TRACE_EVENT("INCOMING CONNECTION ON CH %d", ch_id);
+ LOG_DEBUG("INCOMING CONNECTION ON CH %d", ch_id);
// Close the previous connection
if (uipc.ch[ch_id].fd != UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("CLOSE CONNECTION (FD %d)", uipc.ch[ch_id].fd);
+ LOG_DEBUG("CLOSE CONNECTION (FD %d)", uipc.ch[ch_id].fd);
close(uipc.ch[ch_id].fd);
FD_CLR(uipc.ch[ch_id].fd, &uipc.active_set);
uipc.ch[ch_id].fd = UIPC_DISCONNECTED;
@@ -254,28 +245,25 @@ static int uipc_check_fd_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
uipc.ch[ch_id].fd = accept_server_socket(uipc.ch[ch_id].srvfd);
- BTIF_TRACE_EVENT("NEW FD %d", uipc.ch[ch_id].fd);
+ LOG_DEBUG("NEW FD %d", uipc.ch[ch_id].fd);
if ((uipc.ch[ch_id].fd >= 0) && uipc.ch[ch_id].cback) {
/* if we have a callback we should add this fd to the active set
and notify user with callback event */
- BTIF_TRACE_EVENT("ADD FD %d TO ACTIVE SET", uipc.ch[ch_id].fd);
+ LOG_DEBUG("ADD FD %d TO ACTIVE SET", uipc.ch[ch_id].fd);
FD_SET(uipc.ch[ch_id].fd, &uipc.active_set);
uipc.max_fd = MAX(uipc.max_fd, uipc.ch[ch_id].fd);
}
if (uipc.ch[ch_id].fd < 0) {
- BTIF_TRACE_ERROR("FAILED TO ACCEPT CH %d", ch_id);
+ LOG_ERROR("FAILED TO ACCEPT CH %d", ch_id);
return -1;
}
if (uipc.ch[ch_id].cback) uipc.ch[ch_id].cback(ch_id, UIPC_OPEN_EVT);
}
- // BTIF_TRACE_EVENT("CHECK FD %d (ch %d)", uipc.ch[ch_id].fd, ch_id);
-
if (SAFE_FD_ISSET(uipc.ch[ch_id].fd, &uipc.read_set)) {
- // BTIF_TRACE_EVENT("INCOMING DATA ON CH %d", ch_id);
if (uipc.ch[ch_id].cback)
uipc.ch[ch_id].cback(ch_id, UIPC_RX_DATA_READY_EVT);
@@ -293,7 +281,7 @@ static void uipc_check_interrupt_locked(tUIPC_STATE& uipc) {
static inline void uipc_wakeup_locked(tUIPC_STATE& uipc) {
char sig_on = 1;
- BTIF_TRACE_EVENT("UIPC SEND WAKE UP");
+ LOG_DEBUG("UIPC SEND WAKE UP");
OSI_NO_INTR(send(uipc.signal_fds[1], &sig_on, sizeof(sig_on), 0));
}
@@ -302,7 +290,7 @@ static int uipc_setup_server_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id,
const char* name, tUIPC_RCV_CBACK* cback) {
int fd;
- BTIF_TRACE_EVENT("SETUP CHANNEL SERVER %d", ch_id);
+ LOG_DEBUG("SETUP CHANNEL SERVER %d", ch_id);
if (ch_id >= UIPC_CH_NUM) return -1;
@@ -311,11 +299,11 @@ static int uipc_setup_server_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id,
fd = create_server_socket(name);
if (fd < 0) {
- BTIF_TRACE_ERROR("failed to setup %s", name, strerror(errno));
+ LOG_ERROR("failed to setup %s: %s", name, strerror(errno));
return -1;
}
- BTIF_TRACE_EVENT("ADD SERVER FD TO ACTIVE SET %d", fd);
+ LOG_DEBUG("ADD SERVER FD TO ACTIVE SET %d", fd);
FD_SET(fd, &uipc.active_set);
uipc.max_fd = MAX(uipc.max_fd, fd);
@@ -337,7 +325,7 @@ static void uipc_flush_ch_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
pfd.fd = uipc.ch[ch_id].fd;
if (uipc.ch[ch_id].fd == UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("%s() - fd disconnected. Exiting", __func__);
+ LOG_DEBUG("%s() - fd disconnected. Exiting", __func__);
return;
}
@@ -345,20 +333,18 @@ static void uipc_flush_ch_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
int ret;
OSI_NO_INTR(ret = poll(&pfd, 1, 1));
if (ret == 0) {
- BTIF_TRACE_VERBOSE("%s(): poll() timeout - nothing to do. Exiting",
- __func__);
+ LOG_VERBOSE("%s(): poll() timeout - nothing to do. Exiting", __func__);
return;
}
if (ret < 0) {
- BTIF_TRACE_WARNING(
- "%s() - poll() failed: return %d errno %d (%s). Exiting", __func__,
- ret, errno, strerror(errno));
+ LOG_WARN("%s() - poll() failed: return %d errno %d (%s). Exiting",
+ __func__, ret, errno, strerror(errno));
return;
}
- BTIF_TRACE_VERBOSE("%s() - polling fd %d, revents: 0x%x, ret %d", __func__,
- pfd.fd, pfd.revents, ret);
+ LOG_VERBOSE("%s() - polling fd %d, revents: 0x%x, ret %d", __func__, pfd.fd,
+ pfd.revents, ret);
if (pfd.revents & (POLLERR | POLLHUP)) {
- BTIF_TRACE_WARNING("%s() - POLLERR or POLLHUP. Exiting", __func__);
+ LOG_WARN("%s() - POLLERR or POLLHUP. Exiting", __func__);
return;
}
@@ -385,12 +371,12 @@ static void uipc_flush_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
static int uipc_close_ch_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
int wakeup = 0;
- BTIF_TRACE_EVENT("CLOSE CHANNEL %d", ch_id);
+ LOG_DEBUG("CLOSE CHANNEL %d", ch_id);
if (ch_id >= UIPC_CH_NUM) return -1;
if (uipc.ch[ch_id].srvfd != UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("CLOSE SERVER (FD %d)", uipc.ch[ch_id].srvfd);
+ LOG_DEBUG("CLOSE SERVER (FD %d)", uipc.ch[ch_id].srvfd);
close(uipc.ch[ch_id].srvfd);
FD_CLR(uipc.ch[ch_id].srvfd, &uipc.active_set);
uipc.ch[ch_id].srvfd = UIPC_DISCONNECTED;
@@ -398,7 +384,7 @@ static int uipc_close_ch_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
}
if (uipc.ch[ch_id].fd != UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("CLOSE CONNECTION (FD %d)", uipc.ch[ch_id].fd);
+ LOG_DEBUG("CLOSE CONNECTION (FD %d)", uipc.ch[ch_id].fd);
close(uipc.ch[ch_id].fd);
FD_CLR(uipc.ch[ch_id].fd, &uipc.active_set);
uipc.ch[ch_id].fd = UIPC_DISCONNECTED;
@@ -416,7 +402,7 @@ static int uipc_close_ch_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
void uipc_close_locked(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
if (uipc.ch[ch_id].srvfd == UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("CHANNEL %d ALREADY CLOSED", ch_id);
+ LOG_DEBUG("CHANNEL %d ALREADY CLOSED", ch_id);
return;
}
@@ -440,12 +426,12 @@ static void* uipc_read_task(void* arg) {
result = select(uipc.max_fd + 1, &uipc.read_set, NULL, NULL, NULL);
if (result == 0) {
- BTIF_TRACE_EVENT("select timeout");
+ LOG_DEBUG("select timeout");
continue;
}
if (result < 0) {
if (errno != EINTR) {
- BTIF_TRACE_EVENT("select failed %s", strerror(errno));
+ LOG_DEBUG("select failed %s", strerror(errno));
}
continue;
}
@@ -469,13 +455,13 @@ static void* uipc_read_task(void* arg) {
}
}
- BTIF_TRACE_EVENT("UIPC READ THREAD EXITING");
+ LOG_DEBUG("UIPC READ THREAD EXITING");
uipc_main_cleanup(uipc);
uipc.tid = 0;
- BTIF_TRACE_EVENT("UIPC READ THREAD DONE");
+ LOG_DEBUG("UIPC READ THREAD DONE");
return nullptr;
}
@@ -485,7 +471,7 @@ int uipc_start_main_server_thread(tUIPC_STATE& uipc) {
if (pthread_create(&uipc.tid, (const pthread_attr_t*)NULL, uipc_read_task,
&uipc) != 0) {
- BTIF_TRACE_ERROR("uipc_thread_create pthread_create failed:%d", errno);
+ LOG_ERROR("uipc_thread_create pthread_create failed:%d", errno);
return -1;
}
@@ -519,7 +505,7 @@ void uipc_stop_main_server_thread(tUIPC_STATE& uipc) {
******************************************************************************/
std::unique_ptr<tUIPC_STATE> UIPC_Init() {
std::unique_ptr<tUIPC_STATE> uipc = std::make_unique<tUIPC_STATE>();
- BTIF_TRACE_DEBUG("UIPC_Init");
+ LOG_DEBUG("UIPC_Init");
std::lock_guard<std::recursive_mutex> lock(uipc->mutex);
@@ -540,7 +526,7 @@ std::unique_ptr<tUIPC_STATE> UIPC_Init() {
******************************************************************************/
bool UIPC_Open(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback,
const char* socket_path) {
- BTIF_TRACE_DEBUG("UIPC_Open : ch_id %d, p_cback %x", ch_id, p_cback);
+ LOG_DEBUG("UIPC_Open : ch_id %d", ch_id);
std::lock_guard<std::recursive_mutex> lock(uipc.mutex);
@@ -549,7 +535,7 @@ bool UIPC_Open(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback,
}
if (uipc.ch[ch_id].srvfd != UIPC_DISCONNECTED) {
- BTIF_TRACE_EVENT("CHANNEL %d ALREADY OPEN", ch_id);
+ LOG_DEBUG("CHANNEL %d ALREADY OPEN", ch_id);
return 0;
}
@@ -568,7 +554,7 @@ bool UIPC_Open(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback,
**
******************************************************************************/
void UIPC_Close(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
- BTIF_TRACE_DEBUG("UIPC_Close : ch_id %d", ch_id);
+ LOG_DEBUG("UIPC_Close : ch_id %d", ch_id);
/* special case handling uipc shutdown */
if (ch_id != UIPC_CH_ID_ALL) {
@@ -577,9 +563,9 @@ void UIPC_Close(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
return;
}
- BTIF_TRACE_DEBUG("UIPC_Close : waiting for shutdown to complete");
+ LOG_DEBUG("UIPC_Close : waiting for shutdown to complete");
uipc_stop_main_server_thread(uipc);
- BTIF_TRACE_DEBUG("UIPC_Close : shutdown complete");
+ LOG_DEBUG("UIPC_Close : shutdown complete");
}
/*******************************************************************************
@@ -594,14 +580,14 @@ void UIPC_Close(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id) {
bool UIPC_Send(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id,
UNUSED_ATTR uint16_t msg_evt, const uint8_t* p_buf,
uint16_t msglen) {
- BTIF_TRACE_DEBUG("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen);
+ LOG_DEBUG("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen);
std::lock_guard<std::recursive_mutex> lock(uipc.mutex);
ssize_t ret;
OSI_NO_INTR(ret = write(uipc.ch[ch_id].fd, p_buf, msglen));
if (ret < 0) {
- BTIF_TRACE_ERROR("failed to write (%s)", strerror(errno));
+ LOG_ERROR("failed to write (%s)", strerror(errno));
}
return false;
@@ -620,7 +606,7 @@ bool UIPC_Send(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id,
uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint8_t* p_buf,
uint32_t len) {
if (ch_id >= UIPC_CH_NUM) {
- BTIF_TRACE_ERROR("UIPC_Read : invalid ch id %d", ch_id);
+ LOG_ERROR("UIPC_Read : invalid ch id %d", ch_id);
return 0;
}
@@ -629,7 +615,7 @@ uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint8_t* p_buf,
struct pollfd pfd;
if (fd == UIPC_DISCONNECTED) {
- BTIF_TRACE_ERROR("UIPC_Read : channel %d closed", ch_id);
+ LOG_ERROR("UIPC_Read : channel %d closed", ch_id);
return 0;
}
@@ -643,20 +629,17 @@ uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint8_t* p_buf,
int poll_ret;
OSI_NO_INTR(poll_ret = poll(&pfd, 1, uipc.ch[ch_id].read_poll_tmo_ms));
if (poll_ret == 0) {
- BTIF_TRACE_WARNING("poll timeout (%d ms)",
- uipc.ch[ch_id].read_poll_tmo_ms);
+ LOG_WARN("poll timeout (%d ms)", uipc.ch[ch_id].read_poll_tmo_ms);
break;
}
if (poll_ret < 0) {
- BTIF_TRACE_ERROR("%s(): poll() failed: return %d errno %d (%s)", __func__,
- poll_ret, errno, strerror(errno));
+ LOG_ERROR("%s(): poll() failed: return %d errno %d (%s)", __func__,
+ poll_ret, errno, strerror(errno));
break;
}
- // BTIF_TRACE_EVENT("poll revents %x", pfd.revents);
-
if (pfd.revents & (POLLHUP | POLLNVAL)) {
- BTIF_TRACE_WARNING("poll : channel detached remotely");
+ LOG_WARN("poll : channel detached remotely");
std::lock_guard<std::recursive_mutex> lock(uipc.mutex);
uipc_close_locked(uipc, ch_id);
return 0;
@@ -665,17 +648,15 @@ uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint8_t* p_buf,
ssize_t n;
OSI_NO_INTR(n = recv(fd, p_buf + n_read, len - n_read, 0));
- // BTIF_TRACE_EVENT("read %d bytes", n);
-
if (n == 0) {
- BTIF_TRACE_WARNING("UIPC_Read : channel detached remotely");
+ LOG_WARN("UIPC_Read : channel detached remotely");
std::lock_guard<std::recursive_mutex> lock(uipc.mutex);
uipc_close_locked(uipc, ch_id);
return 0;
}
if (n < 0) {
- BTIF_TRACE_WARNING("UIPC_Read : read failed (%s)", strerror(errno));
+ LOG_WARN("UIPC_Read : read failed (%s)", strerror(errno));
return 0;
}
@@ -697,8 +678,7 @@ uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint8_t* p_buf,
extern bool UIPC_Ioctl(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint32_t request,
void* param) {
- BTIF_TRACE_DEBUG("#### UIPC_Ioctl : ch_id %d, request %d ####", ch_id,
- request);
+ LOG_DEBUG("#### UIPC_Ioctl : ch_id %d, request %d ####", ch_id, request);
std::lock_guard<std::recursive_mutex> lock(uipc.mutex);
switch (request) {
@@ -719,12 +699,12 @@ extern bool UIPC_Ioctl(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint32_t request,
case UIPC_SET_READ_POLL_TMO:
uipc.ch[ch_id].read_poll_tmo_ms = (intptr_t)param;
- BTIF_TRACE_EVENT("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id,
- uipc.ch[ch_id].read_poll_tmo_ms);
+ LOG_DEBUG("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id,
+ uipc.ch[ch_id].read_poll_tmo_ms);
break;
default:
- BTIF_TRACE_EVENT("UIPC_Ioctl : request not handled (%d)", request);
+ LOG_DEBUG("UIPC_Ioctl : request not handled (%d)", request);
break;
}
diff --git a/system/vendor_libs/linux/interface/h4_protocol.cc b/system/vendor_libs/linux/interface/h4_protocol.cc
index e7c0f6289f..76792b92e8 100644
--- a/system/vendor_libs/linux/interface/h4_protocol.cc
+++ b/system/vendor_libs/linux/interface/h4_protocol.cc
@@ -97,7 +97,15 @@ void H4Protocol::OnDataReady(int fd) {
const size_t max_plen = 64*1024;
hidl_vec<uint8_t> tpkt;
tpkt.resize(max_plen);
- size_t bytes_read = TEMP_FAILURE_RETRY(read(fd, tpkt.data(), max_plen));
+ ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, tpkt.data(), max_plen));
+ if (bytes_read == 0) {
+ ALOGI("No bytes read");
+ return;
+ }
+ if (bytes_read < 0) {
+ ALOGW("error reading from UART (%s)", strerror(errno));
+ return;
+ }
hci_packet_type_ = static_cast<HciPacketType>(tpkt.data()[0]);
hci_packetizer_.CbHciPacket(tpkt.data()+1, bytes_read-1);
}
diff --git a/system/vendor_libs/test_vendor_lib/net/async_data_channel.h b/system/vendor_libs/test_vendor_lib/net/async_data_channel.h
index 098812879f..8d358ea223 100644
--- a/system/vendor_libs/test_vendor_lib/net/async_data_channel.h
+++ b/system/vendor_libs/test_vendor_lib/net/async_data_channel.h
@@ -16,6 +16,8 @@
#include "msvc-posix.h"
#endif
+#include <sys/types.h>
+
#include <cstdint>
#include <functional>
#include <memory>
@@ -86,4 +88,4 @@ class AsyncDataChannel {
};
} // namespace net
-} // namespace android \ No newline at end of file
+} // namespace android