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

Commit 94012f8c authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Remove acl namespace

Bug: 163818400
Test: cert/run --host
Tag: #feature
Change-Id: I0145e75223f90c6ab161bb08a5339e4a06b9a1e4
parent 5f43b167
Loading
Loading
Loading
Loading
+0 −42
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>

namespace test_vendor_lib {
namespace acl {

// ACL data packets are specified in the Bluetooth Core Specification Version
// 4.2, Volume 2, Part E, Section 5.4.2
static constexpr uint16_t kReservedHandle = 0xF00;

enum class PacketBoundaryFlagsType : uint8_t {
  FIRST_NON_AUTOMATICALLY_FLUSHABLE = 0,
  CONTINUING = 1,
  FIRST_AUTOMATICALLY_FLUSHABLE = 2,
  COMPLETE = 3
};

enum class BroadcastFlagsType : uint8_t {
  POINT_TO_POINT = 0,
  ACTIVE_SLAVE_BROADCAST = 1,
  PARKED_SLAVE_BROADCAST = 2,
  RESERVED = 3
};
}  // namespace acl
}  // namespace test_vendor_lib
+8 −11
Original line number Diff line number Diff line
@@ -29,18 +29,15 @@ using ::bluetooth::hci::AddressType;
using ::bluetooth::hci::AddressWithType;

bool AclConnectionHandler::HasHandle(uint16_t handle) const {
  if (acl_connections_.count(handle) == 0) {
    return false;
  }
  return true;
  return acl_connections_.count(handle) != 0;
}

uint16_t AclConnectionHandler::GetUnusedHandle() {
  while (acl_connections_.count(last_handle_) == 1) {
    last_handle_ = (last_handle_ + 1) % acl::kReservedHandle;
  while (HasHandle(last_handle_)) {
    last_handle_ = (last_handle_ + 1) % kReservedHandle;
  }
  uint16_t unused_handle = last_handle_;
  last_handle_ = (last_handle_ + 1) % acl::kReservedHandle;
  last_handle_ = (last_handle_ + 1) % kReservedHandle;
  return unused_handle;
}

@@ -119,7 +116,7 @@ uint16_t AclConnectionHandler::CreateConnection(Address addr,
            Phy::Type::BR_EDR});
    return handle;
  }
  return acl::kReservedHandle;
  return kReservedHandle;
}

uint16_t AclConnectionHandler::CreateLeConnection(AddressWithType addr,
@@ -130,7 +127,7 @@ uint16_t AclConnectionHandler::CreateLeConnection(AddressWithType addr,
        handle, AclConnection{addr, own_addr, Phy::Type::LOW_ENERGY});
    return handle;
  }
  return acl::kReservedHandle;
  return kReservedHandle;
}

bool AclConnectionHandler::Disconnect(uint16_t handle) {
@@ -143,7 +140,7 @@ uint16_t AclConnectionHandler::GetHandle(AddressWithType addr) const {
      return std::get<0>(pair);
    }
  }
  return acl::kReservedHandle;
  return kReservedHandle;
}

uint16_t AclConnectionHandler::GetHandleOnlyAddress(
@@ -153,7 +150,7 @@ uint16_t AclConnectionHandler::GetHandleOnlyAddress(
      return std::get<0>(pair);
    }
  }
  return acl::kReservedHandle;
  return kReservedHandle;
}

AddressWithType AclConnectionHandler::GetAddress(uint16_t handle) const {
+2 −2
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@
#include "acl_connection.h"
#include "hci/address.h"
#include "hci/address_with_type.h"
#include "include/acl.h"
#include "phy.h"

namespace test_vendor_lib {
static constexpr uint16_t kReservedHandle = 0xF00;

class AclConnectionHandler {
 public:
@@ -75,7 +75,7 @@ class AclConnectionHandler {
      bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS};

  uint16_t GetUnusedHandle();
  uint16_t last_handle_{acl::kReservedHandle - 2};
  uint16_t last_handle_{kReservedHandle - 2};
};

}  // namespace test_vendor_lib
+20 −14
Original line number Diff line number Diff line
@@ -185,6 +185,12 @@ void LinkLayerController::IncomingPacket(
    }
  }

  // Check connection addresses
  if (connections_.GetHandleOnlyAddress(destination_address) !=
      kReservedHandle) {
    address_matches = true;
  }

  // Drop packets not addressed to me
  if (!address_matches) {
    return;
@@ -404,7 +410,7 @@ void LinkLayerController::IncomingReadRemoteSupportedFeaturesResponse(
  ASSERT(view.IsValid());
  Address source = packet.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(source);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Discarding response from a disconnected device %s",
             source.ToString().c_str());
    return;
@@ -437,7 +443,7 @@ void LinkLayerController::IncomingReadRemoteExtendedFeaturesResponse(
  ASSERT(view.IsValid());
  Address source = packet.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(source);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Discarding response from a disconnected device %s",
             source.ToString().c_str());
    return;
@@ -462,7 +468,7 @@ void LinkLayerController::IncomingReadRemoteVersionResponse(
  ASSERT(view.IsValid());
  Address source = packet.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(source);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Discarding response from a disconnected device %s",
             source.ToString().c_str());
    return;
@@ -486,7 +492,7 @@ void LinkLayerController::IncomingReadClockOffsetResponse(
  ASSERT(view.IsValid());
  Address source = packet.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(source);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Discarding response from a disconnected device %s",
             source.ToString().c_str());
    return;
@@ -503,7 +509,7 @@ void LinkLayerController::IncomingDisconnectPacket(

  Address peer = incoming.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(peer);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Discarding disconnect from a disconnected device %s",
             peer.ToString().c_str());
    return;
@@ -523,7 +529,7 @@ void LinkLayerController::IncomingEncryptConnection(
  // TODO: Check keys
  Address peer = incoming.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(peer);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Unknown connection @%s", peer.ToString().c_str());
    return;
  }
@@ -548,7 +554,7 @@ void LinkLayerController::IncomingEncryptConnectionResponse(
  // TODO: Check keys
  uint16_t handle =
      connections_.GetHandleOnlyAddress(incoming.GetSourceAddress());
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Unknown connection @%s",
             incoming.GetSourceAddress().ToString().c_str());
    return;
@@ -699,7 +705,7 @@ void LinkLayerController::IncomingIoCapabilityRequestPacket(

  uint16_t handle = connections_.GetHandle(AddressWithType(
      peer, bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS));
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Device not connected %s", peer.ToString().c_str());
    return;
  }
@@ -892,7 +898,7 @@ void LinkLayerController::HandleLeConnection(AddressWithType address,
                                             uint16_t supervision_timeout) {
  // TODO: Choose between LeConnectionComplete and LeEnhancedConnectionComplete
  uint16_t handle = connections_.CreateLeConnection(address, own_address);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_WARN("No pending connection for connection from %s",
             address.ToString().c_str());
    return;
@@ -976,7 +982,7 @@ void LinkLayerController::IncomingLeEncryptConnection(

  Address peer = incoming.GetSourceAddress();
  uint16_t handle = connections_.GetHandleOnlyAddress(peer);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("@%s: Unknown connection @%s",
             incoming.GetDestinationAddress().ToString().c_str(),
             peer.ToString().c_str());
@@ -997,7 +1003,7 @@ void LinkLayerController::IncomingLeEncryptConnectionResponse(
  // TODO: Check keys
  uint16_t handle =
      connections_.GetHandleOnlyAddress(incoming.GetSourceAddress());
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("@%s: Unknown connection @%s",
             incoming.GetDestinationAddress().ToString().c_str(),
             incoming.GetSourceAddress().ToString().c_str());
@@ -1132,7 +1138,7 @@ void LinkLayerController::IncomingPageResponsePacket(
  bool awaiting_authentication = connections_.AuthenticatePendingConnection();
  uint16_t handle =
      connections_.CreateConnection(peer, incoming.GetDestinationAddress());
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_WARN("No free handles");
    return;
  }
@@ -1299,7 +1305,7 @@ ErrorCode LinkLayerController::LinkKeyRequestNegativeReply(
  security_manager_.DeleteKey(address);
  // Simple pairing to get a key
  uint16_t handle = connections_.GetHandleOnlyAddress(address);
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("Device not connected %s", address.ToString().c_str());
    return ErrorCode::UNKNOWN_CONNECTION;
  }
@@ -1529,7 +1535,7 @@ void LinkLayerController::MakeSlaveConnection(const Address& addr,

  uint16_t handle =
      connections_.CreateConnection(addr, properties_.GetAddress());
  if (handle == acl::kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("CreateConnection failed");
    return;
  }