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

Commit 7226faf4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "L2CAP: Cid, Mtu, SignalId type and constant"

parents 743e4e91 a447c5df
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,5 +3,6 @@ filegroup {
    srcs: [
        "l2cap_packet_test.cc",
        "fcs.cc",
        "signal_id_test.cc",
    ],
}

system/gd/l2cap/cid.h

0 → 100644
+33 −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 <cstdint>

namespace bluetooth {
namespace l2cap {

using Cid = uint16_t;

constexpr Cid kInvalidCid = 0;
constexpr Cid kFirstFixedChannel = 1;
constexpr Cid kLastFixedChannel = 63;
constexpr Cid kFirstDynamicChannel = kLastFixedChannel + 1;
constexpr Cid kLastDynamicChannel = (uint16_t)(0xffff + 1);

}  // namespace l2cap
}  // namespace bluetooth
+53 −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 <chrono>
#include <cstddef>

#include "l2cap/cid.h"
#include "l2cap/signal_id.h"

namespace bluetooth {
namespace l2cap {

constexpr size_t kChannelQueueCapacity = 10;
constexpr size_t kLinkQueueCapacity = 10;
constexpr std::chrono::milliseconds bogus_link_wakeup_time = std::chrono::milliseconds(15000);

constexpr SignalId kInitialSignalId = SignalId(0x80);

constexpr Cid kClassicSignallingCid = 1;
constexpr Cid kConnectionlessCid = 2;
constexpr Cid kLeAttributeCid = 4;
constexpr Cid kLeSignallingCid = 5;
constexpr Cid kSmpCid = 6;
constexpr Cid kSmpBrCid = 7;

// Time after last channels closes before link is torn down
constexpr auto kLinkDisconnectTimeout = std::chrono::seconds(30);

// TODO(cmanton) Random numbers for now
constexpr auto kChannelConnectionTimeout = std::chrono::seconds(30);
constexpr auto kChannelConnectionPendingTimeout = std::chrono::seconds(30);
constexpr auto kChannelConfigurationTimeout = std::chrono::seconds(30);
constexpr auto kChannelDisconnectionTimeout = std::chrono::seconds(30);

// The depth of buffering that the signalling channel can handle.
constexpr auto kSignallingChannelSize = 20;

}  // namespace l2cap
}  // namespace bluetooth

system/gd/l2cap/mtu.h

0 → 100644
+32 −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 <cstdint>

namespace bluetooth {
namespace l2cap {

using mtu_t = uint16_t;

constexpr mtu_t kDefaultMinimumClassicMtu = 48;
constexpr mtu_t kDefaultMinimumLeMtu = 23;
constexpr mtu_t kMinimumClassicMtu = 48;
constexpr mtu_t kDefaultClassicMtu = 672;
constexpr mtu_t kMinimumLeMtu = 23;

}  // namespace l2cap
}  // namespace bluetooth
+85 −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 <cstdint>

namespace bluetooth {
namespace l2cap {

struct SignalId {
 public:
  constexpr SignalId(uint8_t value) : value_(value) {}
  constexpr SignalId() : value_(1) {}
  ~SignalId() = default;

  uint8_t Value() const {
    return value_;
  }

  bool IsValid() const {
    return value_ != 0;
  }

  friend bool operator==(const SignalId& lhs, const SignalId& rhs);
  friend bool operator!=(const SignalId& lhs, const SignalId& rhs);

  struct SignalId& operator++();    // Prefix increment operator.
  struct SignalId operator++(int);  // Postfix increment operator.
  struct SignalId& operator--();    // Prefix decrement operator.
  struct SignalId operator--(int);  // Postfix decrement operator.

 private:
  uint8_t value_;
};

constexpr SignalId kInvalidSignalId{0};

inline bool operator==(const SignalId& lhs, const SignalId& rhs) {
  return lhs.value_ == rhs.value_;
}

inline bool operator!=(const SignalId& lhs, const SignalId& rhs) {
  return !(lhs == rhs);
}

inline struct SignalId& SignalId::operator++() {
  value_++;
  if (value_ == 0) value_++;
  return *this;
}

inline struct SignalId SignalId::operator++(int) {
  struct SignalId tmp = *this;
  ++*this;
  return tmp;
}

inline struct SignalId& SignalId::operator--() {
  value_--;
  if (value_ == 0) value_ = 0xff;
  return *this;
}

inline struct SignalId SignalId::operator--(int) {
  struct SignalId tmp = *this;
  --*this;
  return tmp;
}

}  // namespace l2cap
}  // namespace bluetooth
Loading