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

Commit 304726c3 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2CAP: Make a common ChannelImpl interface

This allows passing the ChannelImpl to reassembler and segmenter,
instead of passing nullptr for fixed channel. This reduces some
duplicated information in parameters.

Bug: 144503952
Bug: 141557006
Test: bluetooth_test_gd and run_cert.sh
Change-Id: I737488ed1f6d6f985bc7dc45a84ce86fb6723b50
parent 22459989
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -105,11 +105,11 @@ void DynamicChannelImpl::SetIncomingMtu(Mtu mtu) {
  incoming_mtu_ = mtu;
}

RetransmissionAndFlowControlModeOption DynamicChannelImpl::GetMode() const {
RetransmissionAndFlowControlModeOption DynamicChannelImpl::GetChannelMode() const {
  return mode_;
}

void DynamicChannelImpl::SetMode(RetransmissionAndFlowControlModeOption mode) {
void DynamicChannelImpl::SetChannelMode(RetransmissionAndFlowControlModeOption mode) {
  mode_ = mode;
}

+4 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "hci/address.h"
#include "l2cap/cid.h"
#include "l2cap/classic/dynamic_channel.h"
#include "l2cap/internal/channel_impl.h"
#include "l2cap/l2cap_packets.h"
#include "l2cap/mtu.h"
#include "l2cap/psm.h"
@@ -33,7 +34,7 @@ namespace internal {

class Link;

class DynamicChannelImpl {
class DynamicChannelImpl : public l2cap::internal::ChannelImpl {
 public:
  DynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, Link* link, os::Handler* l2cap_handler);

@@ -78,8 +79,8 @@ class DynamicChannelImpl {
  virtual Mtu GetIncomingMtu() const;
  virtual void SetIncomingMtu(Mtu mtu);

  virtual RetransmissionAndFlowControlModeOption GetMode() const;
  virtual void SetMode(RetransmissionAndFlowControlModeOption mode);
  virtual RetransmissionAndFlowControlModeOption GetChannelMode() const;
  virtual void SetChannelMode(RetransmissionAndFlowControlModeOption mode);

  virtual FcsType GetFcsType() const;
  virtual void SetFcsType(FcsType fcs_type);
+19 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include "common/bidi_queue.h"
#include "l2cap/cid.h"
#include "l2cap/classic/fixed_channel.h"
#include "l2cap/internal/channel_impl.h"
#include "l2cap/l2cap_packets.h"
#include "os/handler.h"
#include "os/log.h"

@@ -29,7 +31,7 @@ namespace internal {

class Link;

class FixedChannelImpl {
class FixedChannelImpl : public l2cap::internal::ChannelImpl {
 public:
  FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler);

@@ -65,6 +67,22 @@ class FixedChannelImpl {
    return channel_queue_.GetDownEnd();
  }

  Cid GetCid() const {
    return cid_;
  }

  Cid GetRemoteCid() const {
    return cid_;
  }

  RetransmissionAndFlowControlModeOption GetChannelMode() const {
    return RetransmissionAndFlowControlModeOption::L2CAP_BASIC;
  }

  void SetChannelMode(RetransmissionAndFlowControlModeOption) {
    LOG_ERROR("Setting channel mode on a fixed channel cid 0x%02hx", cid_);
  }

 private:
  // Constructor states
  // For logging purpose only
+1 −1
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ void ClassicSignallingManager::OnConfigurationRequest(SignalId signal_id, Cid ci
      }
      case ConfigurationOptionType::RETRANSMISSION_AND_FLOW_CONTROL: {
        auto config = RetransmissionAndFlowControlConfigurationOption::Specialize(option.get());
        channel->SetMode(config->mode_);
        channel->SetChannelMode(config->mode_);
        break;
      }
      case ConfigurationOptionType::FRAME_CHECK_SEQUENCE: {
+64 −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 "common/bidi_queue.h"
#include "l2cap/cid.h"
#include "l2cap/l2cap_packets.h"

namespace bluetooth {
namespace l2cap {
namespace internal {

/**
 * Common interface for internal channel implementation
 */
class ChannelImpl {
 public:
  virtual ~ChannelImpl() = default;

  /**
   * Return the queue end for upper layer (L2CAP user)
   */
  virtual common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
  GetQueueUpEnd() = 0;

  /**
   * Return the queue end for lower layer (segmenter and reassembler)
   */
  virtual common::BidiQueueEnd<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder>*
  GetQueueDownEnd() = 0;

  virtual Cid GetCid() const = 0;

  virtual Cid GetRemoteCid() const = 0;

  /**
   * Return one of the supported channel mode as defined above
   */
  virtual RetransmissionAndFlowControlModeOption GetChannelMode() const = 0;

  /**
   * Invoked by the command signalling manager to update the channel mode. Does NOT apply to fixed channel, OR LE
   * credit-based flow control channel
   */
  virtual void SetChannelMode(RetransmissionAndFlowControlModeOption) = 0;
};

}  // namespace internal
}  // namespace l2cap
}  // namespace bluetooth
Loading