summaryrefslogtreecommitdiff
path: root/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'bluetooth')
-rw-r--r--bluetooth/Android.bp45
-rw-r--r--bluetooth/android.hardware.bluetooth@1.0-service.hikey.rc4
-rw-r--r--bluetooth/async_fd_watcher.cc181
-rw-r--r--bluetooth/async_fd_watcher.h66
-rw-r--r--bluetooth/bluetooth_hci.cc124
-rw-r--r--bluetooth/bluetooth_hci.h73
-rw-r--r--bluetooth/h4_protocol.cc71
-rw-r--r--bluetooth/h4_protocol.h60
-rw-r--r--bluetooth/hci_internals.h49
-rw-r--r--bluetooth/hci_packetizer.cc91
-rw-r--r--bluetooth/hci_packetizer.h53
-rw-r--r--bluetooth/hci_protocol.cc74
-rw-r--r--bluetooth/hci_protocol.h48
-rw-r--r--bluetooth/service.cc40
14 files changed, 0 insertions, 979 deletions
diff --git a/bluetooth/Android.bp b/bluetooth/Android.bp
deleted file mode 100644
index e421c530..00000000
--- a/bluetooth/Android.bp
+++ /dev/null
@@ -1,45 +0,0 @@
-//
-// Copyright (C) 2017 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.
-
-cc_binary {
- name: "android.hardware.bluetooth@1.0-service.hikey",
- proprietary: true,
- relative_install_path: "hw",
- srcs: [
- "async_fd_watcher.cc",
- "bluetooth_hci.cc",
- "h4_protocol.cc",
- "hci_packetizer.cc",
- "hci_protocol.cc",
- "service.cc",
- ],
- cflags: [
- "-Wall",
- "-Werror",
- "-Wno-error=unused-const-variable",
- "-Wno-error=unused-function",
- "-Wno-error=unused-lambda-capture",
- ],
- shared_libs: [
- "android.hardware.bluetooth@1.0",
- "libbase",
- "libcutils",
- "libhardware",
- "libhidlbase",
- "liblog",
- "libutils",
- ],
- init_rc: ["android.hardware.bluetooth@1.0-service.hikey.rc"],
-}
diff --git a/bluetooth/android.hardware.bluetooth@1.0-service.hikey.rc b/bluetooth/android.hardware.bluetooth@1.0-service.hikey.rc
deleted file mode 100644
index 6f31efdf..00000000
--- a/bluetooth/android.hardware.bluetooth@1.0-service.hikey.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-service bluetooth-1-0 /vendor/bin/hw/android.hardware.bluetooth@1.0-service.hikey
- class hal
- user bluetooth
- group bluetooth
diff --git a/bluetooth/async_fd_watcher.cc b/bluetooth/async_fd_watcher.cc
deleted file mode 100644
index c4470d06..00000000
--- a/bluetooth/async_fd_watcher.cc
+++ /dev/null
@@ -1,181 +0,0 @@
-//
-// Copyright 2016 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 "async_fd_watcher.h"
-
-#include <algorithm>
-#include <atomic>
-#include <condition_variable>
-#include <map>
-#include <mutex>
-#include <thread>
-#include <vector>
-#include "fcntl.h"
-#include "sys/select.h"
-#include "unistd.h"
-
-static const int INVALID_FD = -1;
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace async {
-
-int AsyncFdWatcher::WatchFdForNonBlockingReads(
- int file_descriptor, const ReadCallback& on_read_fd_ready_callback) {
- // Add file descriptor and callback
- {
- std::unique_lock<std::mutex> guard(internal_mutex_);
- watched_fds_[file_descriptor] = on_read_fd_ready_callback;
- }
-
- // Start the thread if not started yet
- return tryStartThread();
-}
-
-int AsyncFdWatcher::ConfigureTimeout(
- const std::chrono::milliseconds timeout,
- const TimeoutCallback& on_timeout_callback) {
- // Add timeout and callback
- {
- std::unique_lock<std::mutex> guard(timeout_mutex_);
- timeout_cb_ = on_timeout_callback;
- timeout_ms_ = timeout;
- }
-
- notifyThread();
- return 0;
-}
-
-void AsyncFdWatcher::StopWatchingFileDescriptors() { stopThread(); }
-
-AsyncFdWatcher::~AsyncFdWatcher() {}
-
-// Make sure to call this with at least one file descriptor ready to be
-// watched upon or the thread routine will return immediately
-int AsyncFdWatcher::tryStartThread() {
- if (std::atomic_exchange(&running_, true)) return 0;
-
- // Set up the communication channel
- int pipe_fds[2];
- if (pipe2(pipe_fds, O_NONBLOCK)) return -1;
-
- notification_listen_fd_ = pipe_fds[0];
- notification_write_fd_ = pipe_fds[1];
-
- thread_ = std::thread([this]() { ThreadRoutine(); });
- if (!thread_.joinable()) return -1;
-
- return 0;
-}
-
-int AsyncFdWatcher::stopThread() {
- if (!std::atomic_exchange(&running_, false)) return 0;
-
- notifyThread();
- if (std::this_thread::get_id() != thread_.get_id()) {
- thread_.join();
- }
-
- {
- std::unique_lock<std::mutex> guard(internal_mutex_);
- watched_fds_.clear();
- }
-
- {
- std::unique_lock<std::mutex> guard(timeout_mutex_);
- timeout_cb_ = nullptr;
- }
-
- return 0;
-}
-
-int AsyncFdWatcher::notifyThread() {
- uint8_t buffer[] = {0};
- if (TEMP_FAILURE_RETRY(write(notification_write_fd_, &buffer, 1)) < 0) {
- return -1;
- }
- return 0;
-}
-
-void AsyncFdWatcher::ThreadRoutine() {
- while (running_) {
- fd_set read_fds;
- FD_ZERO(&read_fds);
- FD_SET(notification_listen_fd_, &read_fds);
- int max_read_fd = INVALID_FD;
- for (auto& it : watched_fds_) {
- FD_SET(it.first, &read_fds);
- max_read_fd = std::max(max_read_fd, it.first);
- }
-
- struct timeval timeout;
- struct timeval* timeout_ptr = NULL;
- if (timeout_ms_ > std::chrono::milliseconds(0)) {
- timeout.tv_sec = timeout_ms_.count() / 1000;
- timeout.tv_usec = (timeout_ms_.count() % 1000) * 1000;
- timeout_ptr = &timeout;
- }
-
- // Wait until there is data available to read on some FD.
- int nfds = std::max(notification_listen_fd_, max_read_fd);
- int retval = select(nfds + 1, &read_fds, NULL, NULL, timeout_ptr);
-
- // There was some error.
- if (retval < 0) continue;
-
- // Timeout.
- if (retval == 0) {
- // Allow the timeout callback to modify the timeout.
- TimeoutCallback saved_cb;
- {
- std::unique_lock<std::mutex> guard(timeout_mutex_);
- if (timeout_ms_ > std::chrono::milliseconds(0)) saved_cb = timeout_cb_;
- }
- if (saved_cb != nullptr) saved_cb();
- continue;
- }
-
- // Read data from the notification FD.
- if (FD_ISSET(notification_listen_fd_, &read_fds)) {
- char buffer[] = {0};
- TEMP_FAILURE_RETRY(read(notification_listen_fd_, buffer, 1));
- continue;
- }
-
- // Invoke the data ready callbacks if appropriate.
- std::vector<decltype(watched_fds_)::value_type> saved_callbacks;
- {
- std::unique_lock<std::mutex> guard(internal_mutex_);
- for (auto& it : watched_fds_) {
- if (FD_ISSET(it.first, &read_fds)) {
- saved_callbacks.push_back(it);
- }
- }
- }
-
- for (auto& it : saved_callbacks) {
- if (it.second) {
- it.second(it.first);
- }
- }
- }
-}
-
-} // namespace async
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/async_fd_watcher.h b/bluetooth/async_fd_watcher.h
deleted file mode 100644
index b51f9211..00000000
--- a/bluetooth/async_fd_watcher.h
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Copyright 2016 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.
-//
-
-#pragma once
-
-#include <map>
-#include <mutex>
-#include <thread>
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace async {
-
-using ReadCallback = std::function<void(int)>;
-using TimeoutCallback = std::function<void(void)>;
-
-class AsyncFdWatcher {
- public:
- AsyncFdWatcher() = default;
- ~AsyncFdWatcher();
-
- int WatchFdForNonBlockingReads(int file_descriptor,
- const ReadCallback& on_read_fd_ready_callback);
- int ConfigureTimeout(const std::chrono::milliseconds timeout,
- const TimeoutCallback& on_timeout_callback);
- void StopWatchingFileDescriptors();
-
- private:
- AsyncFdWatcher(const AsyncFdWatcher&) = delete;
- AsyncFdWatcher& operator=(const AsyncFdWatcher&) = delete;
-
- int tryStartThread();
- int stopThread();
- int notifyThread();
- void ThreadRoutine();
-
- std::atomic_bool running_{false};
- std::thread thread_;
- std::mutex internal_mutex_;
- std::mutex timeout_mutex_;
-
- std::map<int, ReadCallback> watched_fds_;
- int notification_listen_fd_;
- int notification_write_fd_;
- TimeoutCallback timeout_cb_;
- std::chrono::milliseconds timeout_ms_;
-};
-
-} // namespace async
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/bluetooth_hci.cc b/bluetooth/bluetooth_hci.cc
deleted file mode 100644
index fe2b782b..00000000
--- a/bluetooth/bluetooth_hci.cc
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// Copyright 2016 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.
-//
-
-#define LOG_TAG "android.hardware.bluetooth@1.0.hikey"
-
-#include "bluetooth_hci.h"
-
-#include <android-base/logging.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <utils/Log.h>
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace V1_0 {
-namespace hikey {
-
-using android::hardware::hidl_vec;
-
-BluetoothHci::BluetoothHci()
- : deathRecipient(new BluetoothDeathRecipient(this)) {}
-
-Return<void> BluetoothHci::initialize(
- const ::android::sp<IBluetoothHciCallbacks>& cb) {
- ALOGI("BluetoothHci::initialize()");
-
- hci_tty_fd_ = open("/dev/hci_tty", O_RDWR);
- if (hci_tty_fd_ < 0) {
- ALOGE("%s: Can't open hci_tty (%s)", __func__, strerror(errno));
- cb->initializationComplete(Status::INITIALIZATION_ERROR);
- return Void();
- }
-
- event_cb_ = cb;
- event_cb_->linkToDeath(deathRecipient, 0);
-
- hci_ = new hci::H4Protocol(
- hci_tty_fd_,
- [cb](const hidl_vec<uint8_t>& packet) { cb->hciEventReceived(packet); },
- [cb](const hidl_vec<uint8_t>& packet) { cb->aclDataReceived(packet); },
- [cb](const hidl_vec<uint8_t>& packet) { cb->scoDataReceived(packet); });
-
- // Use a socket pair to enforce the TI FIONREAD requirement.
- int sockfd[2];
- socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd);
- int shim_fd = sockfd[0];
- int for_hci = sockfd[1];
-
- fd_watcher_.WatchFdForNonBlockingReads(hci_tty_fd_, [this, shim_fd](int fd) {
- int tty_bytes = 0;
- if (TEMP_FAILURE_RETRY(ioctl(fd, FIONREAD, &tty_bytes)))
- ALOGE("%s:FIONREAD %s", __func__, strerror(errno));
- ALOGV("%s:tty_bytes = %d", __func__, tty_bytes);
-
- uint8_t* tmp_buffer = new uint8_t[tty_bytes];
- size_t bytes_read = TEMP_FAILURE_RETRY(read(fd, tmp_buffer, tty_bytes));
- CHECK(static_cast<int>(bytes_read) == tty_bytes);
- size_t bytes_written =
- TEMP_FAILURE_RETRY(write(shim_fd, tmp_buffer, tty_bytes));
- CHECK(static_cast<int>(bytes_written) == tty_bytes);
- delete[] tmp_buffer;
- });
-
- fd_watcher_.WatchFdForNonBlockingReads(
- for_hci, [this](int fd) { hci_->OnDataReady(fd); });
-
- cb->initializationComplete(Status::SUCCESS);
- return Void();
-}
-
-Return<void> BluetoothHci::close() {
- ALOGI("BluetoothHci::close()");
-
- if (hci_tty_fd_ >= 0) {
- fd_watcher_.StopWatchingFileDescriptors();
- ::close(hci_tty_fd_);
- hci_tty_fd_ = -1;
- }
-
- event_cb_->unlinkToDeath(deathRecipient);
-
- if (hci_ != nullptr) {
- delete hci_;
- hci_ = nullptr;
- }
-
- return Void();
-}
-
-Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& packet) {
- hci_->Send(HCI_PACKET_TYPE_COMMAND, packet.data(), packet.size());
- return Void();
-}
-
-Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& packet) {
- hci_->Send(HCI_PACKET_TYPE_ACL_DATA, packet.data(), packet.size());
- return Void();
-}
-
-Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& packet) {
- hci_->Send(HCI_PACKET_TYPE_SCO_DATA, packet.data(), packet.size());
- return Void();
-}
-
-} // namespace hikey
-} // namespace V1_0
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/bluetooth_hci.h b/bluetooth/bluetooth_hci.h
deleted file mode 100644
index 2f1015a0..00000000
--- a/bluetooth/bluetooth_hci.h
+++ /dev/null
@@ -1,73 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#pragma once
-
-#include <android/hardware/bluetooth/1.0/IBluetoothHci.h>
-
-#include <hidl/MQDescriptor.h>
-
-#include "async_fd_watcher.h"
-#include "h4_protocol.h"
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace V1_0 {
-namespace hikey {
-
-using ::android::hardware::Return;
-using ::android::hardware::hidl_vec;
-
-struct BluetoothDeathRecipient : hidl_death_recipient {
- BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci) {}
-
- virtual void serviceDied(
- uint64_t /*cookie*/,
- const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
- mHci->close();
- }
- sp<IBluetoothHci> mHci;
-};
-
-class BluetoothHci : public IBluetoothHci {
- public:
- BluetoothHci();
- Return<void> initialize(
- const ::android::sp<IBluetoothHciCallbacks>& cb) override;
- Return<void> sendHciCommand(const hidl_vec<uint8_t>& packet) override;
- Return<void> sendAclData(const hidl_vec<uint8_t>& packet) override;
- Return<void> sendScoData(const hidl_vec<uint8_t>& packet) override;
- Return<void> close() override;
-
- static void OnPacketReady();
-
- private:
- ::android::sp<IBluetoothHciCallbacks> event_cb_;
- int hci_tty_fd_;
-
- async::AsyncFdWatcher fd_watcher_;
-
- hci::H4Protocol* hci_;
-
- ::android::sp<BluetoothDeathRecipient> deathRecipient;
-};
-
-} // namespace hikey
-} // namespace V1_0
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/h4_protocol.cc b/bluetooth/h4_protocol.cc
deleted file mode 100644
index 8f24b5ee..00000000
--- a/bluetooth/h4_protocol.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-// Copyright 2017 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 "h4_protocol.h"
-
-#define LOG_TAG "android.hardware.bluetooth-hci-h4"
-#include <android-base/logging.h>
-#include <assert.h>
-#include <fcntl.h>
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
- int rv = WriteSafely(uart_fd_, &type, sizeof(type));
- if (rv == sizeof(type)) {
- rv = WriteSafely(uart_fd_, data, length);
- }
- return rv;
-}
-
-void H4Protocol::OnPacketReady() {
- switch (hci_packet_type_) {
- case HCI_PACKET_TYPE_EVENT:
- event_cb_(hci_packetizer_.GetPacket());
- break;
- case HCI_PACKET_TYPE_ACL_DATA:
- acl_cb_(hci_packetizer_.GetPacket());
- break;
- case HCI_PACKET_TYPE_SCO_DATA:
- sco_cb_(hci_packetizer_.GetPacket());
- break;
- default: {
- bool bad_packet_type = true;
- CHECK(!bad_packet_type);
- }
- }
- // Get ready for the next type byte.
- hci_packet_type_ = HCI_PACKET_TYPE_UNKNOWN;
-}
-
-void H4Protocol::OnDataReady(int fd) {
- if (hci_packet_type_ == HCI_PACKET_TYPE_UNKNOWN) {
- uint8_t buffer[1] = {0};
- size_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, 1));
- CHECK(bytes_read == 1);
- hci_packet_type_ = static_cast<HciPacketType>(buffer[0]);
- } else {
- hci_packetizer_.OnDataReady(fd, hci_packet_type_);
- }
-}
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/h4_protocol.h b/bluetooth/h4_protocol.h
deleted file mode 100644
index 67e2b03e..00000000
--- a/bluetooth/h4_protocol.h
+++ /dev/null
@@ -1,60 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#pragma once
-
-#include <hidl/HidlSupport.h>
-
-#include "async_fd_watcher.h"
-#include "hci_internals.h"
-#include "hci_protocol.h"
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-class H4Protocol : public HciProtocol {
- public:
- H4Protocol(int fd, PacketReadCallback event_cb, PacketReadCallback acl_cb,
- PacketReadCallback sco_cb)
- : uart_fd_(fd),
- event_cb_(event_cb),
- acl_cb_(acl_cb),
- sco_cb_(sco_cb),
- hci_packetizer_([this]() { OnPacketReady(); }) {}
-
- size_t Send(uint8_t type, const uint8_t* data, size_t length);
-
- void OnPacketReady();
-
- void OnDataReady(int fd);
-
- private:
- int uart_fd_;
-
- PacketReadCallback event_cb_;
- PacketReadCallback acl_cb_;
- PacketReadCallback sco_cb_;
-
- HciPacketType hci_packet_type_{HCI_PACKET_TYPE_UNKNOWN};
- hci::HciPacketizer hci_packetizer_;
-};
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/hci_internals.h b/bluetooth/hci_internals.h
deleted file mode 100644
index 1e1f3001..00000000
--- a/bluetooth/hci_internals.h
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Copyright 2016 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.
-//
-
-#pragma once
-
-#include <stdlib.h>
-
-// HCI UART transport packet types (Volume 4, Part A, 2)
-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
-};
-
-// 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1)
-const size_t HCI_COMMAND_PREAMBLE_SIZE = 3;
-const size_t HCI_LENGTH_OFFSET_CMD = 2;
-
-// 2 bytes for handle, 2 bytes for data length (Volume 2, Part E, 5.4.2)
-const size_t HCI_ACL_PREAMBLE_SIZE = 4;
-const size_t HCI_LENGTH_OFFSET_ACL = 2;
-
-// 2 bytes for handle, 1 byte for data length (Volume 2, Part E, 5.4.3)
-const size_t HCI_SCO_PREAMBLE_SIZE = 3;
-const size_t HCI_LENGTH_OFFSET_SCO = 2;
-
-// 1 byte for event code, 1 byte for parameter length (Volume 2, Part E, 5.4.4)
-const size_t HCI_EVENT_PREAMBLE_SIZE = 2;
-const size_t HCI_LENGTH_OFFSET_EVT = 1;
-
-const size_t HCI_PREAMBLE_SIZE_MAX = HCI_ACL_PREAMBLE_SIZE;
-
-// Event codes (Volume 2, Part E, 7.7.14)
-const uint8_t HCI_COMMAND_COMPLETE_EVENT = 0x0E;
diff --git a/bluetooth/hci_packetizer.cc b/bluetooth/hci_packetizer.cc
deleted file mode 100644
index 9549858b..00000000
--- a/bluetooth/hci_packetizer.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-//
-// Copyright 2017 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 "hci_packetizer.h"
-
-#define LOG_TAG "android.hardware.bluetooth.hci_packetizer"
-#include <android-base/logging.h>
-#include <utils/Log.h>
-
-#include <dlfcn.h>
-#include <fcntl.h>
-
-namespace {
-
-const size_t preamble_size_for_type[] = {
- 0, HCI_COMMAND_PREAMBLE_SIZE, HCI_ACL_PREAMBLE_SIZE, HCI_SCO_PREAMBLE_SIZE,
- HCI_EVENT_PREAMBLE_SIZE};
-const size_t packet_length_offset_for_type[] = {
- 0, HCI_LENGTH_OFFSET_CMD, HCI_LENGTH_OFFSET_ACL, HCI_LENGTH_OFFSET_SCO,
- HCI_LENGTH_OFFSET_EVT};
-
-size_t HciGetPacketLengthForType(HciPacketType type, const uint8_t* preamble) {
- size_t offset = packet_length_offset_for_type[type];
- if (type != HCI_PACKET_TYPE_ACL_DATA) return preamble[offset];
- return (((preamble[offset + 1]) << 8) | preamble[offset]);
-}
-
-} // namespace
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-const hidl_vec<uint8_t>& HciPacketizer::GetPacket() const { return packet_; }
-
-void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) {
- switch (state_) {
- case HCI_PREAMBLE: {
- size_t bytes_read = TEMP_FAILURE_RETRY(
- read(fd, preamble_ + bytes_read_,
- preamble_size_for_type[packet_type] - bytes_read_));
- CHECK(bytes_read > 0);
- bytes_read_ += bytes_read;
- if (bytes_read_ == preamble_size_for_type[packet_type]) {
- size_t packet_length =
- HciGetPacketLengthForType(packet_type, preamble_);
- packet_.resize(preamble_size_for_type[packet_type] + packet_length);
- memcpy(packet_.data(), preamble_, preamble_size_for_type[packet_type]);
- bytes_remaining_ = packet_length;
- state_ = HCI_PAYLOAD;
- bytes_read_ = 0;
- }
- break;
- }
-
- case HCI_PAYLOAD: {
- size_t bytes_read = TEMP_FAILURE_RETRY(read(
- fd,
- packet_.data() + preamble_size_for_type[packet_type] + bytes_read_,
- bytes_remaining_));
- CHECK(bytes_read > 0);
- bytes_remaining_ -= bytes_read;
- bytes_read_ += bytes_read;
- if (bytes_remaining_ == 0) {
- packet_ready_cb_();
- state_ = HCI_PREAMBLE;
- bytes_read_ = 0;
- }
- break;
- }
- }
-}
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/hci_packetizer.h b/bluetooth/hci_packetizer.h
deleted file mode 100644
index 90579bd2..00000000
--- a/bluetooth/hci_packetizer.h
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#pragma once
-
-#include <functional>
-
-#include <hidl/HidlSupport.h>
-
-#include "hci_internals.h"
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-using ::android::hardware::hidl_vec;
-using HciPacketReadyCallback = std::function<void(void)>;
-
-class HciPacketizer {
- public:
- HciPacketizer(HciPacketReadyCallback packet_cb)
- : packet_ready_cb_(packet_cb){};
- void OnDataReady(int fd, HciPacketType packet_type);
- const hidl_vec<uint8_t>& GetPacket() const;
-
- protected:
- enum State { HCI_PREAMBLE, HCI_PAYLOAD };
- State state_{HCI_PREAMBLE};
- uint8_t preamble_[HCI_PREAMBLE_SIZE_MAX];
- hidl_vec<uint8_t> packet_;
- size_t bytes_remaining_{0};
- size_t bytes_read_{0};
- HciPacketReadyCallback packet_ready_cb_;
-};
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/hci_protocol.cc b/bluetooth/hci_protocol.cc
deleted file mode 100644
index cd709b43..00000000
--- a/bluetooth/hci_protocol.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-// Copyright 2017 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 "hci_protocol.h"
-
-#define LOG_TAG "android.hardware.bluetooth-hci-hci_protocol"
-#include <android-base/logging.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <utils/Log.h>
-
-namespace {
-
-const size_t preamble_size_for_type[] = {
- 0, HCI_COMMAND_PREAMBLE_SIZE, HCI_ACL_PREAMBLE_SIZE, HCI_SCO_PREAMBLE_SIZE,
- HCI_EVENT_PREAMBLE_SIZE};
-const size_t packet_length_offset_for_type[] = {
- 0, HCI_LENGTH_OFFSET_CMD, HCI_LENGTH_OFFSET_ACL, HCI_LENGTH_OFFSET_SCO,
- HCI_LENGTH_OFFSET_EVT};
-
-size_t HciGetPacketLengthForType(HciPacketType type, const uint8_t* preamble) {
- size_t offset = packet_length_offset_for_type[type];
- if (type != HCI_PACKET_TYPE_ACL_DATA) return preamble[offset];
- return (((preamble[offset + 1]) << 8) | preamble[offset]);
-}
-
-} // namespace
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-size_t HciProtocol::WriteSafely(int fd, const uint8_t* data, size_t length) {
- size_t transmitted_length = 0;
- while (length > 0) {
- ssize_t ret =
- TEMP_FAILURE_RETRY(write(fd, data + transmitted_length, length));
-
- if (ret == -1) {
- if (errno == EAGAIN) continue;
- ALOGE("%s error writing to UART (%s)", __func__, strerror(errno));
- break;
-
- } else if (ret == 0) {
- // Nothing written :(
- ALOGE("%s zero bytes written - something went wrong...", __func__);
- break;
- }
-
- transmitted_length += ret;
- length -= ret;
- }
-
- return transmitted_length;
-}
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/hci_protocol.h b/bluetooth/hci_protocol.h
deleted file mode 100644
index f76cddf5..00000000
--- a/bluetooth/hci_protocol.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#pragma once
-
-#include <hidl/HidlSupport.h>
-
-#include "hci_internals.h"
-#include "hci_packetizer.h"
-
-namespace android {
-namespace hardware {
-namespace bluetooth {
-namespace hci {
-
-using ::android::hardware::hidl_vec;
-using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>;
-
-// Implementation of HCI protocol bits common to different transports
-class HciProtocol {
- public:
- HciProtocol() = default;
- virtual ~HciProtocol(){};
-
- // Protocol-specific implementation of sending packets.
- virtual size_t Send(uint8_t type, const uint8_t* data, size_t length) = 0;
-
- protected:
- static size_t WriteSafely(int fd, const uint8_t* data, size_t length);
-};
-
-} // namespace hci
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
diff --git a/bluetooth/service.cc b/bluetooth/service.cc
deleted file mode 100644
index 05920edf..00000000
--- a/bluetooth/service.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#define LOG_TAG "android.hardware.bluetooth@1.0-service.hikey"
-
-#include <android/hardware/bluetooth/1.0/IBluetoothHci.h>
-#include <hidl/HidlSupport.h>
-#include <hidl/HidlTransportSupport.h>
-#include <utils/Log.h>
-
-#include "bluetooth_hci.h"
-
-using ::android::hardware::configureRpcThreadpool;
-using ::android::hardware::bluetooth::V1_0::IBluetoothHci;
-using ::android::hardware::bluetooth::V1_0::hikey::BluetoothHci;
-using ::android::hardware::joinRpcThreadpool;
-using ::android::sp;
-
-int main(int /* argc */, char** /* argv */) {
- sp<IBluetoothHci> bluetooth = new BluetoothHci;
- configureRpcThreadpool(1, true);
- android::status_t status = bluetooth->registerAsService();
- if (status == android::OK)
- joinRpcThreadpool();
- else
- ALOGE("Could not register as a service!");
-}