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

Commit a458312c authored by johnshamoon's avatar johnshamoon Committed by android-build-merger
Browse files

test_vendor: Add L2cap and L2capSdu assemble tests

am: b045f948

Change-Id: Ibc8c535d8f5f366a47307eb2e782671fc8033533
parents 81cc8a24 b045f948
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ cc_test_host {
        "test/async_manager_unittest.cc",
        "test/bt_address_unittest.cc",
        "test/packet_stream_unittest.cc",
        "test/l2cap_test.cc",
        "test/l2cap_sdu_test.cc",
    ],
    local_include_dirs: [
        "include",
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ class L2capPacket {

  // Construct a vector of just the L2CAP payload. This essentially
  // will remove the L2CAP header from the private member variable.
  // TODO: Remove this in favor of custom iterators.
  std::vector<uint8_t> get_l2cap_payload() const;

  uint16_t get_l2cap_cid() const;
+3 −0
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@ class L2capSdu {
  // Returns a completed L2capSdu object.
  L2capSdu(std::vector<uint8_t> create_from);

  // Adds an FCS to create_from and returns an L2capSdu object
  static L2capSdu L2capSduBuilder(std::vector<uint8_t> create_from);

  // Get a vector iterator that points to the first byte of the
  // L2CAP payload within an SDU. The offset parameter will be the
  // number of bytes that are in the SDU header. This should always
+1446 −0

File added.

Preview size limit exceeded, changes collapsed.

+13 −0
Original line number Diff line number Diff line
@@ -60,6 +60,19 @@ L2capSdu::L2capSdu(std::vector<uint8_t> create_from) {
  sdu_data_.insert(sdu_data_.end(), create_from.begin(), create_from.end());
}

L2capSdu L2capSdu::L2capSduBuilder(std::vector<uint8_t> create_from) {
  L2capSdu packet(create_from);

  packet.sdu_data_.resize(packet.sdu_data_.size() + 2, 0x00);

  uint16_t fcs = packet.calculate_fcs();

  packet.sdu_data_[packet.sdu_data_.size() - 2] = fcs & 0xFF;
  packet.sdu_data_[packet.sdu_data_.size() - 1] = (fcs & 0xFF00) >> 8;

  return packet;
}

uint16_t L2capSdu::convert_from_little_endian(
    const unsigned int starting_index) const {
  uint16_t convert = sdu_data_[starting_index + 1];
Loading