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

Commit 5f43b167 authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Remove hci namespace

Bug: 163818400
Test: cert/run --host
Tag: #feature
Change-Id: I7076dd5c3981359c2170ec70b2d280a0363bdddc
parent ac8ce947
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
/*
 * Copyright 2018 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>

namespace test_vendor_lib {
namespace hci {

enum class PacketType : uint8_t {
  UNKNOWN = 0,
  COMMAND = 1,
  ACL = 2,
  SCO = 3,
  EVENT = 4,
  ISO = 5,
};

}  // namespace hci
}  // namespace test_vendor_lib
+0 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@

#include "hci/address.h"
#include "hci/hci_packets.h"
#include "include/hci.h"
#include "include/inquiry.h"
#include "include/phy.h"
#include "model/controller/acl_connection_handler.h"
+18 −20
Original line number Diff line number Diff line
@@ -26,11 +26,10 @@
#include "os/log.h"

namespace test_vendor_lib {
namespace hci {
size_t HciGetPacketLengthForType(hci::PacketType type,
                                 const uint8_t* preamble) {
size_t H4Packetizer::HciGetPacketLengthForType(PacketType type,
                                               const uint8_t* preamble) const {
  static const size_t
      packet_length_offset[static_cast<size_t>(hci::PacketType::ISO) + 1] = {
      packet_length_offset[static_cast<size_t>(PacketType::ISO) + 1] = {
          0,
          H4Packetizer::COMMAND_LENGTH_OFFSET,
          H4Packetizer::ACL_LENGTH_OFFSET,
@@ -41,10 +40,10 @@ size_t HciGetPacketLengthForType(hci::PacketType type,

  size_t offset = packet_length_offset[static_cast<size_t>(type)];
  size_t size = preamble[offset];
  if (type == hci::PacketType::ACL) {
  if (type == PacketType::ACL) {
    size |= ((size_t)preamble[offset + 1]) << 8u;
  }
  if (type == hci::PacketType::ISO) {
  if (type == PacketType::ISO) {
    size |= ((size_t)preamble[offset + 1] & 0x0fu) << 8u;
  }
  return size;
@@ -79,16 +78,16 @@ size_t H4Packetizer::Send(uint8_t type, const uint8_t* data, size_t length) {

void H4Packetizer::OnPacketReady() {
  switch (hci_packet_type_) {
    case hci::PacketType::COMMAND:
    case PacketType::COMMAND:
      command_cb_(packet_);
      break;
    case hci::PacketType::ACL:
    case PacketType::ACL:
      acl_cb_(packet_);
      break;
    case hci::PacketType::SCO:
    case PacketType::SCO:
      sco_cb_(packet_);
      break;
    case hci::PacketType::EVENT:
    case PacketType::EVENT:
      event_cb_(packet_);
      break;
    default:
@@ -96,7 +95,7 @@ void H4Packetizer::OnPacketReady() {
                       static_cast<int>(hci_packet_type_));
  }
  // Get ready for the next type byte.
  hci_packet_type_ = hci::PacketType::UNKNOWN;
  hci_packet_type_ = PacketType::UNKNOWN;
}

void H4Packetizer::OnDataReady(int fd) {
@@ -104,8 +103,8 @@ void H4Packetizer::OnDataReady(int fd) {
  ssize_t bytes_to_read = 0;
  uint8_t* buffer_pointer = nullptr;

  static const size_t
      preamble_size[static_cast<size_t>(hci::PacketType::ISO) + 1] = {
  static const size_t preamble_size[static_cast<size_t>(PacketType::ISO) + 1] =
      {
          0,
          H4Packetizer::COMMAND_PREAMBLE_SIZE,
          H4Packetizer::ACL_PREAMBLE_SIZE,
@@ -157,12 +156,12 @@ void H4Packetizer::OnDataReady(int fd) {

  switch (state_) {
    case HCI_TYPE:
      hci_packet_type_ = static_cast<hci::PacketType>(packet_type_);
      if (hci_packet_type_ != hci::PacketType::ACL &&
          hci_packet_type_ != hci::PacketType::SCO &&
          hci_packet_type_ != hci::PacketType::COMMAND &&
          hci_packet_type_ != hci::PacketType::EVENT &&
          hci_packet_type_ != hci::PacketType::ISO) {
      hci_packet_type_ = static_cast<PacketType>(packet_type_);
      if (hci_packet_type_ != PacketType::ACL &&
          hci_packet_type_ != PacketType::SCO &&
          hci_packet_type_ != PacketType::COMMAND &&
          hci_packet_type_ != PacketType::EVENT &&
          hci_packet_type_ != PacketType::ISO) {
        LOG_ALWAYS_FATAL("Unimplemented packet type %hhd", packet_type_);
      }
      state_ = HCI_PREAMBLE;
@@ -193,5 +192,4 @@ void H4Packetizer::OnDataReady(int fd) {
  }
}

}  // namespace hci
}  // namespace test_vendor_lib
+13 −4
Original line number Diff line number Diff line
@@ -19,15 +19,22 @@
#include <functional>
#include <vector>

#include "hci.h"
#include "hci_protocol.h"

namespace test_vendor_lib {
namespace hci {

using HciPacketReadyCallback = std::function<void(void)>;
using ClientDisconnectCallback = std::function<void()>;

enum class PacketType : uint8_t {
  UNKNOWN = 0,
  COMMAND = 1,
  ACL = 2,
  SCO = 3,
  EVENT = 4,
  ISO = 5,
};

class H4Packetizer : public HciProtocol {
 public:
  H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb,
@@ -71,7 +78,10 @@ class H4Packetizer : public HciProtocol {
  ClientDisconnectCallback disconnect_cb_;
  bool disconnected_{false};

  hci::PacketType hci_packet_type_{hci::PacketType::UNKNOWN};
  size_t HciGetPacketLengthForType(PacketType type,
                                   const uint8_t* preamble) const;

  PacketType hci_packet_type_{PacketType::UNKNOWN};

  enum State { HCI_TYPE, HCI_PREAMBLE, HCI_PAYLOAD };
  State state_{HCI_TYPE};
@@ -80,5 +90,4 @@ class H4Packetizer : public HciProtocol {
  size_t bytes_read_{0};
};

}  // namespace hci
}  // namespace test_vendor_lib
+0 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

#include "hci_protocol.h"

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
@@ -24,7 +23,6 @@
#include "os/log.h"

namespace test_vendor_lib {
namespace hci {

size_t HciProtocol::WriteSafely(int fd, const uint8_t* data, size_t length) {
  size_t transmitted_length = 0;
@@ -49,5 +47,4 @@ size_t HciProtocol::WriteSafely(int fd, const uint8_t* data, size_t length) {
  return transmitted_length;
}

}  // namespace hci
}  // namespace test_vendor_lib
Loading