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

Commit 3aa80ee8 authored by tedwang's avatar tedwang
Browse files

Add General Reject for invalid PDU ID

Add Avrcp Browse General Reject packet
Respond general reject when undefined AVRCP Browsing PDU ID sent from
remote.

Bug: 79376704
Test: run host native test net_test_btpackets
Change-Id: I8a44d8e3f0cc5fac89e23217726c76ede4aff916
(cherry picked from commit bcaa26c7)
parent 1dd444f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ enum class BrowsePdu : uint8_t {
  CHANGE_PATH = 0x72,
  GET_ITEM_ATTRIBUTES = 0x73,
  GET_TOTAL_NUMBER_OF_ITEMS = 0x75,
  GENERAL_REJECT = 0xa0,
};

enum class Scope : uint8_t {
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ cc_test {
        "tests/avrcp/avrcp_packet_test.cc",
        "tests/avrcp/avrcp_reject_packet_test.cc",
        "tests/avrcp/change_path_packet_test.cc",
        "tests/avrcp/general_reject_packet_test.cc",
        "tests/avrcp/get_capabilities_packet_test.cc",
        "tests/avrcp/get_element_attributes_packet_test.cc",
        "tests/avrcp/get_folder_items_packet_test.cc",
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ cc_library_static {
        "avrcp_reject_packet.cc",
        "capabilities_packet.cc",
        "change_path.cc",
        "general_reject_packet.cc",
        "get_element_attributes_packet.cc",
        "get_folder_items.cc",
        "get_item_attributes.cc",
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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.
 */

#include "general_reject_packet.h"

namespace bluetooth {
namespace avrcp {

std::unique_ptr<GeneralRejectBuilder> GeneralRejectBuilder::MakeBuilder(
    BrowsePdu pdu, Status reason) {
  std::unique_ptr<GeneralRejectBuilder> builder =
      std::unique_ptr<GeneralRejectBuilder>(
          new GeneralRejectBuilder(pdu, reason));

  return builder;
}

size_t GeneralRejectBuilder::size() const {
  return BrowsePacket::kMinSize() + 1;
}

bool GeneralRejectBuilder::Serialize(
    const std::shared_ptr<::bluetooth::Packet>& pkt) {
  ReserveSpace(pkt, size());

  BrowsePacketBuilder::PushHeader(pkt, size() - BrowsePacket::kMinSize());

  AddPayloadOctets1(pkt, static_cast<uint8_t>(reason_));

  return true;
}

}  // namespace avrcp
}  // namespace bluetooth
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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 "avrcp_browse_packet.h"

namespace bluetooth {
namespace avrcp {

class GeneralRejectBuilder : public BrowsePacketBuilder {
 public:
  virtual ~GeneralRejectBuilder() = default;

  static std::unique_ptr<GeneralRejectBuilder> MakeBuilder(BrowsePdu pdu,
                                                           Status reason);

  virtual size_t size() const override;
  virtual bool Serialize(
      const std::shared_ptr<::bluetooth::Packet>& pkt) override;

 protected:
  Status reason_;

  GeneralRejectBuilder(BrowsePdu pdu, Status reason)
      : BrowsePacketBuilder(pdu), reason_(reason){};
};

}  // namespace avrcp
}  // namespace bluetooth
Loading