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

Commit e5dd0e92 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2CAP: Store channel configuration state in a separate class

Introduce ChannelConfigurationState in SignallingManager. This handles
storing configuration related information.

Remove configuration logic in DynamicChannelImpl, so we can use the same
DynamicChannelImpl for both classic and LE.

Bug: 144503952
Test: bluetooth_test_gd
Change-Id: I7873516162bed4200086debd111244cb456b2601
parent 949708fc
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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 "l2cap/l2cap_packets.h"
#include "l2cap/mtu.h"

namespace bluetooth {
namespace l2cap {
namespace classic {
namespace internal {

struct ChannelConfigurationState {
 public:
  enum State {
    /**
     * for the initiator path, a request has been sent but a positive response has not yet been received, and for the
     * acceptor path, a request with acceptable options has not yet been received.
     */
    WAIT_CONFIG_REQ_RSP,
    /**
     * the acceptor path is complete after having responded to acceptable options, but for the initiator path, a
     * positive response on the recent request has not yet been received.
     */
    WAIT_CONFIG_RSP,
    /**
     * the initiator path is complete after having received a positive response, but for the acceptor path, a request
     * with acceptable options has not yet been received.
     */
    WAIT_CONFIG_REQ,
    /**
     * Configuration is complete
     */
    CONFIGURED,
  };
  State state_ = State::WAIT_CONFIG_REQ_RSP;

  Mtu incoming_mtu_ = kDefaultClassicMtu;
  Mtu outgoing_mtu_ = kDefaultClassicMtu;
  RetransmissionAndFlowControlModeOption retransmission_and_flow_control_mode_;
  RetransmissionAndFlowControlConfigurationOption local_retransmission_and_flow_control_;
  RetransmissionAndFlowControlConfigurationOption remote_retransmission_and_flow_control_;
  FcsType fcs_type_ = FcsType::DEFAULT;
};
}  // namespace internal
}  // namespace classic
}  // namespace l2cap
}  // namespace bluetooth
+0 −33
Original line number Diff line number Diff line
@@ -82,39 +82,6 @@ std::string DynamicChannelImpl::ToString() {
  return ss.str();
}

DynamicChannelImpl::ConfigurationStatus DynamicChannelImpl::GetOutgoingConfigurationStatus() const {
  return outgoing_configuration_status_;
}

void DynamicChannelImpl::SetOutgoingConfigurationStatus(ConfigurationStatus status) {
  outgoing_configuration_status_ = status;
}

DynamicChannelImpl::ConfigurationStatus DynamicChannelImpl::GetIncomingConfigurationStatus() const {
  return incoming_configuration_status_;
}

void DynamicChannelImpl::SetIncomingConfigurationStatus(ConfigurationStatus status) {
  incoming_configuration_status_ = status;
}

void DynamicChannelImpl::SetSender(l2cap::internal::Sender* sender) {
  sender_ = sender;
}

void DynamicChannelImpl::SetIncomingMtu(Mtu mtu) {
  sender_->SetIncomingMtu(mtu);
}

void DynamicChannelImpl::SetRetransmissionFlowControlConfig(
    const RetransmissionAndFlowControlConfigurationOption& option) {
  sender_->SetChannelRetransmissionFlowControlMode(option);
}

void DynamicChannelImpl::SetFcsType(FcsType fcs_type) {
  sender_->SetFcsType(fcs_type);
}

}  // namespace internal
}  // namespace classic
}  // namespace l2cap
+0 −24
Original line number Diff line number Diff line
@@ -68,26 +68,6 @@ class DynamicChannelImpl : public l2cap::internal::ChannelImpl {
    return psm_;
  }

  enum class ConfigurationStatus { NOT_CONFIGURED, CONFIGURED };

  virtual ConfigurationStatus GetOutgoingConfigurationStatus() const;
  virtual void SetOutgoingConfigurationStatus(ConfigurationStatus status);

  virtual ConfigurationStatus GetIncomingConfigurationStatus() const;
  virtual void SetIncomingConfigurationStatus(ConfigurationStatus status);

  /**
   * Callback from the Scheduler to notify the Sender for this channel. On config update, channel might notify the
   * configuration to Sender
   */
  void SetSender(l2cap::internal::Sender* sender) override;

  virtual void SetIncomingMtu(Mtu mtu);

  virtual void SetRetransmissionFlowControlConfig(const RetransmissionAndFlowControlConfigurationOption& mode);

  virtual void SetFcsType(FcsType fcs_type);

  // TODO(cmanton) Do something a little bit better than this
  bool local_initiated_{false};

@@ -109,10 +89,6 @@ class DynamicChannelImpl : public l2cap::internal::ChannelImpl {
  static constexpr size_t kChannelQueueSize = 10;
  common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
      kChannelQueueSize};
  ConfigurationStatus outgoing_configuration_status_ = ConfigurationStatus::NOT_CONFIGURED;
  ConfigurationStatus incoming_configuration_status_ = ConfigurationStatus::NOT_CONFIGURED;

  l2cap::internal::Sender* sender_ = nullptr;

  DISALLOW_COPY_AND_ASSIGN(DynamicChannelImpl);
};
+0 −2
Original line number Diff line number Diff line
@@ -94,8 +94,6 @@ void FixedChannelImpl::Release() {
  link_->RefreshRefCount();
}

void FixedChannelImpl::SetSender(l2cap::internal::Sender* sender) {}

}  // namespace internal
}  // namespace classic
}  // namespace l2cap
+0 −1
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ class FixedChannelImpl : public l2cap::internal::ChannelImpl {
  Cid GetRemoteCid() const {
    return cid_;
  }
  void SetSender(l2cap::internal::Sender* sender) override;

 private:
  // Constructor states
Loading