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

Commit 56f45b7e authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge changes I3a54a514,Iada70c9f,I1fb728ce,I181f0d77,I1df3c852, ...

* changes:
  rusty-gd: migrate classic acl to a directory, in prep for facade
  rusty-gd: some tidying in acl
  rusty-gd: add authentication complete for classic acl
  rusty-gd: implement connection request for classic ACL
  rusty-gd: wire through classic ACL API for disconnect
  rusty-gd: expose core byte rx/tx for classic ACL
  rusty-gd: move acl core from lib.rs to core.rs
  rusty-gd: implement connection complete for classic acl
  rusty-gd: simplify acl internal requests by using structured enums
  rusty-gd: start classic acl manager
  rusty-gd: report acl disconnections
  rusty-gd: implement ACL connection close
  rusty-gd: add ACL credit control
  rusty-gd: implement outbound fragmentation & dispatch
  rusty-gd: add packet reassembler
  rusty-gd: implement vector payloads for packets
  rusty-gd: start ACL - simple dispatch of inbound traffic
parents 2492f9e8 cbd37f44
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
void generate_rust_packet_preamble(std::ostream& s) {
  s <<
      R"(
use bytes::{Bytes, BytesMut};
use bytes::{Bytes, BytesMut, BufMut};
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive};
use std::convert::TryInto;
+71 −59
Original line number Diff line number Diff line
@@ -741,7 +741,8 @@ void PacketDef::GenBuilderConstructor(std::ostream& s) const {
}

void PacketDef::GenRustChildEnums(std::ostream& s) const {
  if (!children_.empty()) {
  if (HasChildEnums()) {
    bool payload = fields_.HasPayload();
    s << "#[derive(Debug)] ";
    s << "enum " << name_ << "DataChild {";
    for (const auto& child : children_) {
@@ -750,6 +751,9 @@ void PacketDef::GenRustChildEnums(std::ostream& s) const {
      }
      s << child->name_ << "(Arc<" << child->name_ << "Data>),";
    }
    if (payload) {
      s << "Payload(Bytes),";
    }
    s << "None,";
    s << "}\n";
    s << "#[derive(Debug)] ";
@@ -760,6 +764,9 @@ void PacketDef::GenRustChildEnums(std::ostream& s) const {
      }
      s << child->name_ << "(" << child->name_ << "Packet),";
    }
    if (payload) {
      s << "Payload(Bytes),";
    }
    s << "None,";
    s << "}\n";
  }
@@ -771,7 +778,7 @@ void PacketDef::GenRustStructDeclarations(std::ostream& s) const {

  // Generate struct fields
  GenRustStructFieldNameAndType(s);
  if (!children_.empty()) {
  if (HasChildEnums()) {
    s << "child: " << name_ << "DataChild,";
  }
  s << "}\n";
@@ -799,6 +806,9 @@ void PacketDef::GenRustStructDeclarations(std::ostream& s) const {
    param->GenRustNameAndType(s);
    s << ", ";
  }
  if (fields_.HasPayload()) {
    s << "pub payload: Option<Bytes>,";
  }
  s << "}\n";
}

@@ -855,21 +865,6 @@ void PacketDef::GenRustStructSizeField(std::ostream& s) const {

void PacketDef::GenRustStructImpls(std::ostream& s) const {
  s << "impl " << name_ << "Data {";
  s << "fn new(";
  bool fields_exist = GenRustStructFieldNameAndType(s);
  if (!children_.empty()) {
    s << "child: " << name_ << "DataChild,";
  }
  s << ") -> Self { ";

  s << "Self { ";
  GenRustStructFieldNames(s);
  if (!children_.empty()) {
    s << "child";
  }

  s << "}";
  s << "}";

  // parse function
  if (parent_constraints_.empty() && !children_.empty() && parent_ != nullptr) {
@@ -913,7 +908,6 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {

  if (!children_.empty()) {
    s << "let child = match " << constraint_name << " {";
  }

    for (const auto& desc : constrained_descendants) {
      if (desc.first->name_.rfind("LeGetVendorCapabilitiesComplete", 0) == 0) {
@@ -951,8 +945,13 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
      s << "_ => panic!(\"unexpected value " << "\"),";
    }

  if (!children_.empty()) {
    s << "};\n";
  } else if (fields_.HasPayload()) {
    s << "let child = if payload.len() > 0 {";
    s << name_ << "DataChild::Payload(Bytes::from(payload))";
    s << "} else {";
    s << name_ << "DataChild::None";
    s << "};";
  }

  s << "Ok(Self {";
@@ -966,7 +965,7 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
      FixedScalarField::kFieldType,
  });

  if (fields_exist) {
  if (fields.size() > 0) {
    for (int i = 0; i < fields.size(); i++) {
      auto field_type = fields[i]->GetFieldType();
      s << fields[i]->GetName();
@@ -974,7 +973,7 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
    }
  }

  if (!children_.empty()) {
  if (HasChildEnums()) {
    s << "child,";
  }
  s << "})\n";
@@ -982,7 +981,7 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {

  // write_to function
  s << "fn write_to(&self, buffer: &mut BytesMut) {";
  if (fields_exist) {
  if (fields.size() > 0) {
    s << " buffer.resize(buffer.len() + self.get_size(), 0);";
  }

@@ -1007,7 +1006,7 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
    field->GenRustWriter(s, start_field_offset, end_field_offset);
  }

  if (!children_.empty()) {
  if (HasChildEnums()) {
    s << "match &self.child {";
    for (const auto& child : children_) {
      if (child->name_.rfind("LeGetVendorCapabilitiesComplete", 0) == 0) {
@@ -1015,13 +1014,16 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
      }
      s << name_ << "DataChild::" << child->name_ << "(value) => value.write_to(buffer),";
    }
    if (fields_.HasPayload()) {
      s << name_ << "DataChild::Payload(p) => buffer.put(&p[..]),";
    }
    s << name_ << "DataChild::None => {}";
    s << "}";
  }

  s << "}\n";

  if (fields_exist) {
  if (fields.size() > 0) {
    s << "pub fn get_size(&self) -> usize {";
    GenRustStructSizeField(s);
    s << "}";
@@ -1061,7 +1063,7 @@ void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {
    s << "}";
  }

  if (!children_.empty()) {
  if (HasChildEnums()) {
    s << " pub fn specialize(&self) -> " << name_ << "Child {";
    s << " match &self." << util::CamelCaseToUnderScore(name_) << ".child {";
    for (const auto& child : children_) {
@@ -1071,6 +1073,9 @@ void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {
      s << name_ << "DataChild::" << child->name_ << "(_) => " << name_ << "Child::" << child->name_ << "("
        << child->name_ << "Packet::new(self." << root_accessor << ".clone())),";
    }
    if (fields_.HasPayload()) {
      s << name_ << "DataChild::Payload(p) => " << name_ << "Child::Payload(p.clone()),";
    }
    s << name_ << "DataChild::None => " << name_ << "Child::None,";
    s << "}}";
  }
@@ -1190,9 +1195,16 @@ void PacketDef::GenRustBuilderStructImpls(std::ostream& s) const {
      }
      s << ", ";
    }
    if (!ancestor->children_.empty()) {
    if (ancestor->HasChildEnums()) {
      if (prev == nullptr) {
        if (ancestor->fields_.HasPayload()) {
          s << "child: match self.payload { ";
          s << "None => " << name_ << "DataChild::None,";
          s << "Some(bytes) => " << name_ << "DataChild::Payload(bytes),";
          s << "},";
        } else {
          s << "child: " << name_ << "DataChild::None,";
        }
      } else {
        s << "child: " << ancestor->name_ << "DataChild::" << prev->name_ << "("
          << util::CamelCaseToUnderScore(prev->name_) << "),";
+4 −0
Original line number Diff line number Diff line
@@ -565,3 +565,7 @@ std::vector<const ParentDef*> ParentDef::FindPathToDescendant(std::string descen
  }
  return res;
}

bool ParentDef::HasChildEnums() const {
  return !children_.empty() || fields_.HasPayload();
}
+2 −0
Original line number Diff line number Diff line
@@ -85,4 +85,6 @@ class ParentDef : public TypeDef {

  std::map<std::string, std::variant<int64_t, std::string>> parent_constraints_;
  bool is_little_endian_;

  bool HasChildEnums() const;
};
+27 −0
Original line number Diff line number Diff line
rust_library {
    name: "libbt_acl",
    defaults: ["gd_rust_defaults"],
    crate_name: "bt_acl",
    srcs: ["src/lib.rs"],
    edition: "2018",
    rustlibs: [
        "libbt_hci",
        "libbt_hal",
        "libbt_facade_proto",
        "libbt_packets",
        "libbytes",
        "libfutures",
        "libgrpcio",
        "libnum_traits",
        "libthiserror",
        "libtokio",
        "libprotobuf",
        "libgddi",
        "liblog_rust",
        "libbt_common",
        "libbt_hci_custom_types",
    ],
    proc_macros: [
        "libnum_derive",
    ],
}
Loading