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 
17 #pragma once
18 
19 #include "avrcp_packet.h"
20 
21 namespace bluetooth {
22 namespace avrcp {
23 
24 class PassThroughPacketBuilder : public PacketBuilder {
25 public:
26   virtual ~PassThroughPacketBuilder() = default;
27 
28   static std::unique_ptr<PassThroughPacketBuilder> MakeBuilder(bool response, bool pushed,
29                                                                uint8_t operation_id);
30 
31   virtual size_t size() const override;
32   virtual bool Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) override;
33 
34 private:
35   bool pushed_;
36   uint8_t operation_id_;
37 
PassThroughPacketBuilder(bool response,bool pushed,uint8_t operation_id)38   PassThroughPacketBuilder(bool response, bool pushed, uint8_t operation_id)
39       : PacketBuilder(response ? CType::ACCEPTED : CType::CONTROL, 0x09, 0x00,
40                       Opcode::PASS_THROUGH),
41         pushed_(pushed),
42         operation_id_(operation_id) {}
43 };
44 
45 class PassThroughPacket : public Packet {
46 public:
47   virtual ~PassThroughPacket() = default;
48 
49   /**
50    * Pass Through Packet Layout
51    *   AvrcpPacket:
52    *     CType c_type_;
53    *     uint8_t subunit_type_ : 5;
54    *     uint8_t subunit_id_ : 3;
55    *     Opcode opcode_;
56    *   PassThroughPacket:
57    *     uint8_t state : 1;
58    *     uint8_t operation_id : 7;
59    *     uint8_t data_length;
60    */
kMinSize()61   static constexpr size_t kMinSize() { return Packet::kMinSize() + 2; }
62 
63   // Getter Functions
64   KeyState GetKeyState() const;
65   uint8_t GetOperationId() const;
66 
67   // Overloaded Functions
68   virtual bool IsValid() const override;
69   virtual std::string ToString() const override;
70 
71 protected:
72   using Packet::Packet;
73 };
74 
75 }  // namespace avrcp
76 }  // namespace bluetooth
77