Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70dbc558 authored by Myles Watson's avatar Myles Watson Committed by android-build-merger
Browse files

Merge "test_vendor: Add base implementation" am: 812bbc86

am: 4f2cfb7a

Change-Id: I83bd78131cc69969d1b1f3c06af9d57a1f284d73
parents 95be347d 4f2cfb7a
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -55,3 +55,41 @@ cc_binary {
    ],
    init_rc: ["android.hardware.bluetooth@1.0-service.sim.rc"],
}

cc_library_shared {
    name: "android.hardware.bluetooth@1.0-impl-sim",
    proprietary: true,
    relative_install_path: "hw",
    srcs: [
        "bluetooth_hci.cc",
    ],

    shared_libs: [
        "android.hardware.bluetooth@1.0",
        "libbase",
        "libchrome",
        "libcutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "liblog",
        "libutils",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-DHAS_NO_BDROID_BUILDCFG",
    ],
    static_libs: [
        "android.hardware.bluetooth-async",
        "android.hardware.bluetooth-hci",
        "libbt-rootcanal",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/hci/include",
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/stack/include",
    ],
}
+55 −8
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@
#include <string.h>
#include <utils/Log.h>

#include "acl_packet.h"
#include "event_packet.h"
#include "hci_internals.h"
#include "sco_packet.h"

namespace android {
namespace hardware {
@@ -31,11 +34,13 @@ namespace V1_0 {
namespace sim {

using android::hardware::hidl_vec;
using test_vendor_lib::AclPacket;
using test_vendor_lib::AsyncManager;
using test_vendor_lib::AsyncTaskId;
using test_vendor_lib::CommandPacket;
using test_vendor_lib::DualModeController;
using test_vendor_lib::EventPacket;
using test_vendor_lib::ScoPacket;
using test_vendor_lib::TaskCallback;
using test_vendor_lib::TestChannelTransport;

@@ -92,10 +97,24 @@ Return<void> BluetoothHci::initialize(const sp<IBluetoothHciCallbacks>& cb) {
    cb->hciEventReceived(hci_event);
  });

  /* RegisterAcl and RegisterSco
        cb->aclDataReceived(hci_packet);
        cb->scoDataReceived(hci_packet);
  */
  controller_.RegisterAclChannel([cb](std::unique_ptr<AclPacket> packet) {
    std::vector<uint8_t> acl_vector = packet->GetPacket();
    hidl_vec<uint8_t> acl_packet = acl_vector;

    cb->aclDataReceived(acl_packet);
  });

  controller_.RegisterScoChannel([cb](std::unique_ptr<ScoPacket> packet) {
    size_t header_bytes = packet->GetHeaderSize();
    size_t payload_bytes = packet->GetPayloadSize();
    hidl_vec<uint8_t> sco_packet;
    sco_packet.resize(header_bytes + payload_bytes);
    memcpy(sco_packet.data(), packet->GetHeader().data(), header_bytes);
    memcpy(sco_packet.data() + header_bytes, packet->GetPayload().data(),
           payload_bytes);

    cb->scoDataReceived(sco_packet);
  });

  controller_.RegisterTaskScheduler(
      [this](std::chrono::milliseconds delay, const TaskCallback& task) {
@@ -142,13 +161,36 @@ Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& packet) {
  return Void();
}

Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& /* packet */) {
  CHECK(false) << __func__ << " not yet implemented";
Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& packet) {
  async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() {
    uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff;
    AclPacket::PacketBoundaryFlags boundary_flags =
        static_cast<AclPacket::PacketBoundaryFlags>((packet[1] & 0x30) >> 4);
    AclPacket::BroadcastFlags broadcast_flags =
        static_cast<AclPacket::BroadcastFlags>((packet[1] & 0xC0) >> 6);

    std::unique_ptr<AclPacket> acl = std::unique_ptr<AclPacket>(
        new AclPacket(channel, boundary_flags, broadcast_flags));
    for (size_t i = 4; i < packet.size(); i++)
      acl->AddPayloadOctets1(packet[i]);

    controller_.HandleAcl(std::move(acl));
  });
  return Void();
}

Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& /* packet */) {
  CHECK(false) << __func__ << " not yet implemented";
Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& packet) {
  async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() {
    uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff;
    ScoPacket::PacketStatusFlags packet_status =
        static_cast<ScoPacket::PacketStatusFlags>((packet[1] & 0x30) >> 4);
    std::unique_ptr<ScoPacket> sco =
        std::unique_ptr<ScoPacket>(new ScoPacket(channel, packet_status));
    for (size_t i = 3; i < packet.size(); i++)
      sco->AddPayloadOctets1(packet[i]);

    controller_.HandleSco(std::move(sco));
  });
  return Void();
}

@@ -176,6 +218,11 @@ void BluetoothHci::SetUpTestChannel(int port) {
  });
}

/* Fallback to shared library if there is no service. */
IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) {
  return new BluetoothHci();
}

}  // namespace gce
}  // namespace V1_0
}  // namespace bluetooth
+2 −0
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ class BluetoothHci : public IBluetoothHci {
  test_vendor_lib::TestChannelTransport test_channel_transport_;
};

extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name);

}  // namespace sim
}  // namespace V1_0
}  // namespace bluetooth
+10 −0
Original line number Diff line number Diff line
@@ -4,13 +4,23 @@ cc_library_static {
    name: "libbt-rootcanal",
    proprietary: true,
    srcs: [
        "src/acl_packet.cc",
        "src/async_manager.cc",
        "src/beacon.cc",
        "src/beacon_swarm.cc",
        "src/broken_adv.cc",
        "src/bt_address.cc",
        "src/classic.cc",
        "src/command_packet.cc",
        "src/connection.cc",
        "src/device.cc",
        "src/device_factory.cc",
        "src/dual_mode_controller.cc",
        "src/event_packet.cc",
        "src/keyboard.cc",
        "src/packet.cc",
        "src/packet_stream.cc",
        "src/sco_packet.cc",
        "src/test_channel_transport.cc",
    ],
    cflags: [
+85 −0
Original line number Diff line number Diff line
//
// 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 <cstdint>
#include <string>
#include <vector>

namespace test_vendor_lib {

// ACL data packets are specified in the Bluetooth Core Specification Version
// 4.2, Volume 2, Part E, Section 5.4.2
class AclPacket {
 public:
  typedef enum {
    FirstNonAutomaticallyFlushable,
    Continuing,
    FirstAutomaticallyFlushable,
    Complete
  } PacketBoundaryFlags;
  typedef enum {
    PointToPoint,
    ActiveSlaveBroadcast,
    ParkedSlaveBroadcast,
    Reserved
  } BroadcastFlags;

  virtual ~AclPacket() = default;

  uint16_t GetChannel() const {
    return (raw_packet_[0] | (raw_packet_[1] << 8)) & 0xfff;
  }

  PacketBoundaryFlags GetPacketBoundaryFlags() const {
    return static_cast<PacketBoundaryFlags>((raw_packet_[1] & 0x30) >> 4);
  }

  BroadcastFlags GetBroadcastFlags() const {
    return static_cast<BroadcastFlags>((raw_packet_[1] & 0xC0) >> 6);
  }

  explicit AclPacket(uint16_t channel,
                     AclPacket::PacketBoundaryFlags boundary_flags,
                     AclPacket::BroadcastFlags broadcast);

  size_t GetPacketSize() const;

  const std::vector<uint8_t>& GetPacket() const;

  void AddPayloadOctets(size_t octets, const std::vector<uint8_t>& bytes);

 private:
  // Add |octets| bytes to the payload.
  void AddPayloadOctets(size_t octets, uint64_t value);

  static const size_t kHeaderSize = 4;

 public:
  // Add type-checking versions
  void AddPayloadOctets1(uint8_t value) { AddPayloadOctets(1, value); }
  void AddPayloadOctets2(uint16_t value) { AddPayloadOctets(2, value); }
  void AddPayloadOctets3(uint32_t value) { AddPayloadOctets(3, value); }
  void AddPayloadOctets4(uint32_t value) { AddPayloadOctets(4, value); }
  void AddPayloadOctets6(uint64_t value) { AddPayloadOctets(6, value); }
  void AddPayloadOctets8(uint64_t value) { AddPayloadOctets(8, value); }

 private:
  std::vector<uint8_t> raw_packet_;
};

}  // namespace test_vendor_lib
Loading