capabilities_packet.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <set>
  18. #include "vendor_packet.h"
  19. namespace bluetooth {
  20. namespace avrcp {
  21. class GetCapabilitiesRequestBuilder : public VendorPacketBuilder {
  22. public:
  23. virtual ~GetCapabilitiesRequestBuilder() = default;
  24. static std::unique_ptr<GetCapabilitiesRequestBuilder> MakeBuilder(
  25. Capability capability);
  26. virtual size_t size() const override;
  27. virtual bool Serialize(
  28. const std::shared_ptr<::bluetooth::Packet>& pkt) override;
  29. protected:
  30. Capability capability_;
  31. GetCapabilitiesRequestBuilder(Capability capability)
  32. : VendorPacketBuilder(CType::STATUS, CommandPdu::GET_CAPABILITIES,
  33. PacketType::SINGLE),
  34. capability_(capability){};
  35. };
  36. class GetCapabilitiesRequest : public VendorPacket {
  37. public:
  38. virtual ~GetCapabilitiesRequest() = default;
  39. /**
  40. * Get Capabilities Response Packet Layout
  41. * AvrcpPacket:
  42. * CType c_type_;
  43. * uint8_t subunit_type_ : 5;
  44. * uint8_t subunit_id_ : 3;
  45. * Opcode opcode_;
  46. * VendorPacket:
  47. * uint8_t company_id[3];
  48. * uint8_t command_pdu;
  49. * uint8_t packet_type;
  50. * uint16_t param_length;
  51. * GetCapabilitiesRequestPacket:
  52. * uint8_t capability_requested:
  53. */
  54. static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 1; };
  55. // Getter Functions
  56. Capability GetCapabilityRequested() const;
  57. // Overloaded Functions
  58. virtual bool IsValid() const override;
  59. virtual std::string ToString() const override;
  60. protected:
  61. using VendorPacket::VendorPacket;
  62. };
  63. class GetCapabilitiesResponseBuilder : public VendorPacketBuilder {
  64. public:
  65. virtual ~GetCapabilitiesResponseBuilder() = default;
  66. static std::unique_ptr<GetCapabilitiesResponseBuilder> MakeCompanyIdBuilder(
  67. uint32_t company_id_element);
  68. static std::unique_ptr<GetCapabilitiesResponseBuilder>
  69. MakeEventsSupportedBuilder(Event event);
  70. GetCapabilitiesResponseBuilder* AddCompanyId(uint32_t company_id);
  71. GetCapabilitiesResponseBuilder* AddEvent(Event event);
  72. virtual size_t size() const override;
  73. virtual bool Serialize(
  74. const std::shared_ptr<::bluetooth::Packet>& pkt) override;
  75. private:
  76. Capability capability_;
  77. std::set<uint32_t> elements_;
  78. GetCapabilitiesResponseBuilder(Capability capability)
  79. : VendorPacketBuilder(CType::STABLE, CommandPdu::GET_CAPABILITIES,
  80. PacketType::SINGLE),
  81. capability_(capability){};
  82. };
  83. class GetCapabilitiesResponse : public VendorPacket {
  84. public:
  85. /**
  86. * Get Capabilities Response Packet Layout
  87. * AvrcpPacket:
  88. * CType c_type_;
  89. * uint8_t subunit_type_ : 5;
  90. * uint8_t subunit_id_ : 3;
  91. * Opcode opcode_;
  92. * VendorPacket:
  93. * uint8_t company_id[3];
  94. * uint8_t command_pdu;
  95. * uint8_t packet_type;
  96. * uint16_t param_length;
  97. * GetCapabilitiesRequestPacket;
  98. * uint8_t capability_requested;
  99. * uint16_t capability_count;
  100. * union {
  101. * uint8_t event_supported;
  102. * uint8_t company_id[3];
  103. * } capability_array[];
  104. */
  105. static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 2; };
  106. // TODO: Implement these for AVRCP Controller
  107. // virtual uint8_t GetCapabilityReturned() const;
  108. // virtual uint8_t GetCapabilityCount() const;
  109. // virtual std::vector<Event> GetEventsSupported() const;
  110. // virtual std::vector<uint32_t> GetCompanyIds() const;
  111. virtual std::string ToString() const override;
  112. };
  113. } // namespace avrcp
  114. } // namespace bluetooth