Bring multi-channel transport into the glorious new age
Some devices still use MCT as their UART protocol, so
we need to bring it forward to the fresh new HAL.
Also, adding tests for H4 while I'm here.
Test: new unit tests pass and a device using MCT now
boots BT again \o/
Fixes: 34992730
Change-Id: Idb8e536a2779929ad8a0d4bac492c3011995cd79
diff --git a/bluetooth/1.0/default/hci_packetizer.cc b/bluetooth/1.0/default/hci_packetizer.cc
index 1a50196..9549858 100644
--- a/bluetooth/1.0/default/hci_packetizer.cc
+++ b/bluetooth/1.0/default/hci_packetizer.cc
@@ -18,7 +18,6 @@
#define LOG_TAG "android.hardware.bluetooth.hci_packetizer"
#include <android-base/logging.h>
-#include <cutils/properties.h>
#include <utils/Log.h>
#include <dlfcn.h>
@@ -46,63 +45,40 @@
namespace bluetooth {
namespace hci {
-HciPacketType HciPacketizer::GetPacketType() const {
- return hci_packet_type_;
-}
+const hidl_vec<uint8_t>& HciPacketizer::GetPacket() const { return packet_; }
-const hidl_vec<uint8_t>& HciPacketizer::GetPacket() const {
- return hci_packet_;
-}
-
-void HciPacketizer::OnDataReady(int fd) {
- switch (hci_parser_state_) {
- case HCI_IDLE: {
- 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]);
- CHECK(hci_packet_type_ >= HCI_PACKET_TYPE_ACL_DATA &&
- hci_packet_type_ <= HCI_PACKET_TYPE_EVENT)
- << "buffer[0] = " << static_cast<unsigned int>(buffer[0]);
- hci_parser_state_ = HCI_TYPE_READY;
- hci_packet_bytes_remaining_ = preamble_size_for_type[hci_packet_type_];
- hci_packet_bytes_read_ = 0;
- break;
- }
-
- case HCI_TYPE_READY: {
+void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) {
+ switch (state_) {
+ case HCI_PREAMBLE: {
size_t bytes_read = TEMP_FAILURE_RETRY(
- read(fd, hci_packet_preamble_ + hci_packet_bytes_read_,
- hci_packet_bytes_remaining_));
+ read(fd, preamble_ + bytes_read_,
+ preamble_size_for_type[packet_type] - bytes_read_));
CHECK(bytes_read > 0);
- hci_packet_bytes_remaining_ -= bytes_read;
- hci_packet_bytes_read_ += bytes_read;
- if (hci_packet_bytes_remaining_ == 0) {
+ bytes_read_ += bytes_read;
+ if (bytes_read_ == preamble_size_for_type[packet_type]) {
size_t packet_length =
- HciGetPacketLengthForType(hci_packet_type_, hci_packet_preamble_);
- hci_packet_.resize(preamble_size_for_type[hci_packet_type_] +
- packet_length);
- memcpy(hci_packet_.data(), hci_packet_preamble_,
- preamble_size_for_type[hci_packet_type_]);
- hci_packet_bytes_remaining_ = packet_length;
- hci_parser_state_ = HCI_PAYLOAD;
- hci_packet_bytes_read_ = 0;
+ 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,
- hci_packet_.data() + preamble_size_for_type[hci_packet_type_] +
- hci_packet_bytes_read_,
- hci_packet_bytes_remaining_));
+ 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);
- hci_packet_bytes_remaining_ -= bytes_read;
- hci_packet_bytes_read_ += bytes_read;
- if (hci_packet_bytes_remaining_ == 0) {
- hci_packet_ready_cb_();
- hci_parser_state_ = HCI_IDLE;
+ bytes_remaining_ -= bytes_read;
+ bytes_read_ += bytes_read;
+ if (bytes_remaining_ == 0) {
+ packet_ready_cb_();
+ state_ = HCI_PREAMBLE;
+ bytes_read_ = 0;
}
break;
}