1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file avrcp_tg_vendor.h
18  *
19  * @brief Declares the class of the VENDOR DEPENDENT command, including attributes and methods.
20  */
21 
22 #ifndef AVRCP_TG_VENDOR_H
23 #define AVRCP_TG_VENDOR_H
24 
25 #include "avrcp_tg_packet.h"
26 
27 namespace OHOS {
28 namespace bluetooth {
29 /**
30  * @brief This enumeration declares the values of the <b>VENDOR DEPENDENT</b> command.
31  */
32 enum AvrcTgVendor {
33     AVRC_TG_VENDOR_MIN_COMMAND_SIZE = 0x07,         // The min size of the command frame.
34     AVRC_TG_VENDOR_FIXED_OPERAND_SIZE = 0x0A,       // The size of the fixed operand in the frame.
35     AVRC_TG_VENDOR_PACKET_TYPE_SIZE = 0x01,         // The size of the "Packet Type".
36     AVRC_TG_VENDOR_PARAMETER_LENGTH_SIZE = 0x02,    // The size of the "Parameter Length".
37     AVRC_TG_VENDOR_ERROR_CODE_SIZE = 0x01,          // The size of the "Error Code".
38     AVRC_TG_VENDOR_SUBUNIT_TYPE = 0x09,             // The value of the "Subunit_type".
39     AVRC_TG_VENDOR_SUBUNIT_ID = 0x00,               // The value of the "Subunit_ID".
40     AVRC_TG_VENDOR_PACKET_TYPE = 0x00,              // The value of the "Packet type".
41     AVRC_TG_VENDOR_PACKET_TYPE_START = 0x01,        // The value of the "Packet type - Start(01)".
42     AVRC_TG_VENDOR_PACKET_TYPE_CONTINUE = 0x02,     // The value of the "Packet type - Continue(10)".
43     AVRC_TG_VENDOR_PACKET_TYPE_END = 0x03,          // The value of the "Packet type - End(11)".
44     AVRC_TG_VENDOR_UID = 0xFFFFFFFFFFFFFFFF,        // The value of the "UID".
45     AVRC_TG_VENDOR_UID_COUNTER = 0x0000,            // The value of the "UID Counter".
46     AVRC_TG_VENDOR_PARAMETER_LENGTH = 0x0000,       // The value of the "Parameter Length".
47     AVRC_TG_VENDOR_CTYPE_OFFSET = 0x00,             // The offset of the "Ctype".
48     AVRC_TG_VENDOR_OPCODE_OFFSET = 0x02,            // The offset of the "Opcode".
49     AVRC_TG_VENDOR_COMPANY_ID_OFFSET = 0x03,        // The offset of the "Company ID".
50     AVRC_TG_VENDOR_PDU_ID_OFFSET = 0x06,            // The offset of the "PDU ID".
51     AVRC_TG_VENDOR_PACKET_TYPE_OFFSET = 0x07,       // The offset of the "Packet Type".
52     AVRC_TG_VENDOR_PARAMETER_LENGTH_OFFSET = 0x08,  // The offset of the "Parameter Length".
53     AVRC_TG_VENDOR_NUM_OF_PACKETS = 0x0000,         // The default number of the packets.
54     AVRC_TG_VENDOR_BIT3 = 0x03                      // Offset three bits.
55 };
56 
57 /**
58  * @brief This class provides a set of methods of assemble / disassemble the packet of the <b>VENDOR DEPENDENT</b>
59  * command.
60  */
61 class AvrcTgVendorPacket : public AvrcTgPacket {
62 public:
63     /**
64      * @brief A constructor used to create an <b>AvrcTgVendorPacket</b> instance.
65      */
66     AvrcTgVendorPacket();
67 
68     /**
69      * @brief A constructor used to create an <b>AvrcTgVendorPacket</b> instance.
70      */
71     AvrcTgVendorPacket(uint8_t pduId, uint8_t status, uint8_t label);
72 
73     /**
74      * @brief A destructor used to delete the <b>AvrcTgVendorPacket</b> instance.
75      */
76     virtual ~AvrcTgVendorPacket();
77 
78     /**
79      * @brief Assembles the operands behind the "PDU ID" of the frame.
80      *
81      * @details Response frame:<br>
82      *                        msb           lsb<br>
83      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
84      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
85      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
86      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
87      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
88      *
89      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
90      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
91      *                        0 0 0 0 | 0 0 0 0     other operands                                      n octets<br>
92      * @return The frame packet.
93      */
94     virtual Packet *AssembleParameters(Packet *pkt);
95 
96     /**
97      * @brief Assembles the packet of the frame.
98      *
99      * @retval nullptr Always return nullptr.
100      */
101     const Packet *AssemblePacket(void) override;
102 
103     /**
104      * @brief Disassembles the packet of the frame.
105      *
106      * @details Response frame:<br>
107      *                        msb           lsb<br>
108      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
109      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
110      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
111      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
112      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
113      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
114      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
115      *                        0 0 0 0 | 0 0 0 0     other operands                                      n octets<br>
116      */
117     void AssemblePackets(void);
118 
119     /**
120      * @brief Disassembles the packet of the frame.
121      *
122      * @details Command frame:<br>
123      *                        msb           lsb<br>
124      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
125      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
126      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
127      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
128      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
129      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
130      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
131      *                        0 0 0 0 | 0 0 0 0     other operands                                      n octets<br>
132      * @return The result of the method execution.
133      * @retval true  The packet is valid.
134      * @retval false The packet is invalid.
135      */
136     bool DisassemblePacket(Packet *pkt) override;
137 
138     /**
139      * @brief Disassembles the operands behind the "Packet Type" of the frame.
140      *
141      * @param[in] buffer The buffer of the frame.
142      * @return The result of the method execution.
143      * @retval true  The parameters is valid.
144      * @retval false The parameters is invalid.
145      */
146     virtual bool DisassembleParameters(uint8_t *buffer);
147 
148     /**
149      * @brief Gets the number of the packets.
150      *
151      * @return The number of the packets.
152      */
153     virtual uint16_t GetNumberOfPackets(void);
154 
155     /**
156      * @brief Pops a assembled frame packet.
157      *
158      * @return The frame packet.
159      */
160     Packet *PopAssembledPacket(void);
161 
162     /**
163      * @brief Checks frame the packet is exist or not.
164      *
165      * @return The result of the method execution.
166      * @retval true   The packet is exist.
167      * @retval false  The packet is not exist.
168      */
IsPacketExist(void)169     bool IsPacketExist(void) const
170     {
171         return pkts_.size() > 0;
172     }
173 
174     /**
175      * @brief Gets the "response".
176      *
177      * @return The value of the "response".
178      */
GetCrCode(void)179     uint8_t GetCrCode(void) const
180     {
181         return crCode_;
182     };
183 
184     /**
185      * @brief Sets the "response".
186      *
187      * @param[in] crCode The value the "response".
188      */
SetCrCode(uint8_t crCode)189     void SetCrCode(uint8_t crCode)
190     {
191         crCode_ = crCode;
192     }
193 
194     /**
195      * @brief Gets the "PDU ID".
196      *
197      * @return The value of the "PDU ID".
198      */
GetPduId(void)199     uint8_t GetPduId(void) const
200     {
201         return pduId_;
202     }
203 
204     /**
205      * @brief Gets the label.
206      *
207      * @return The value of the label.
208      */
GetLabel(void)209     uint8_t GetLabel(void) const
210     {
211         return label_;
212     }
213 
214     /**
215      * @brief Sets the label.
216      *
217      * @param[in] label The value of the label.
218      */
SetLabel(uint8_t label)219     void SetLabel(uint8_t label)
220     {
221         label_ = label;
222     }
223 
224     /**
225      * @brief Checks the frame packet is valid or not.
226      *
227      * @return The result of the method execution.
228      * @retval true  The packet is valid.
229      * @retval false The packet is invalid.
230      */
IsValid(void)231     bool IsValid(void) const
232     {
233         return isValid_;
234     }
235 
236 protected:
237     uint8_t crCode_ {AVRC_TG_RSP_CODE_STABLE};                       // The value of the "ctype" or the "response".
238     uint8_t subunitType_ {AVRC_TG_VENDOR_SUBUNIT_TYPE};              // The value of the "Subunit_type".
239     uint8_t subunitId_ {AVRC_TG_VENDOR_SUBUNIT_ID};                  // The value of the "Subunit_ID".
240     uint8_t opCode_ {AVRC_TG_OP_CODE_VENDOR};                        // The value of the "Opcode".
241     uint32_t companyId_ {AVRC_TG_DEFAULT_BLUETOOTH_SIG_COMPANY_ID};  // The value of the "Company ID".
242     uint8_t pduId_ {AVRC_TG_PDU_ID_INVALID};                         // The value of the "PDU ID".
243     uint8_t packetType_ {AVRC_TG_VENDOR_PACKET_TYPE};                // The value of the "Packet type".
244     uint16_t parameterLength_ {AVRC_TG_VENDOR_PARAMETER_LENGTH};     // The value of the "Parameter Length".
245     uint8_t status_ {AVRC_ES_CODE_INVALID};                          // The value of the "Status".
246     uint16_t mtu_ {AVRC_TG_DEFAULT_CONTROL_MTU_SIZE};                // The value of the maximum transmission unit.
247     std::deque<Packet *> pkts_ {};                                   // The frame packets.
248     uint8_t label_ {AVRC_INVALID_LABEL};  // The label which is used to distinguish different call.
249     bool isValid_ {false};                // The frame packet is valid or not.
250 
251     /**
252      * @brief Assembles the reject packet of the frame.
253      *
254      * @details Reject Response frame:<br>
255      *                        msb           lsb<br>
256      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
257      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
258      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
259      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
260      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
261      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
262      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
263      *                        0 0 0 0 | 0 0 0 0     Status(some command have this operand)              1 octets<br>
264      * @return The frame packet.
265      * @retval nullptr The packet is not reject packet, need to assemble packet.
266      */
267     Packet *AssembleRejectPacket(void);
268 
269     /**
270      * @brief Assembles the operands in the front of the "Packet Type" of the frame.
271      *
272      * @details Response frame:<br>
273      *                        msb           lsb<br>
274      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
275      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
276      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
277      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
278      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
279      *
280      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
281      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
282      *                        0 0 0 0 | 0 0 0 0     other operands                                      n octets<br>
283      * @return The frame packet.
284      */
285     Packet *AssembleMinOperands(void);
286 
287     /**
288      * @brief Checks the "Parameter Length" is valid or not.
289      *
290      * @param[in] pkt The frame packet.
291      * @return The result of the method execution.
292      * @retval true  The "Parameter Length" is valid.
293      * @retval false The "Parameter Length" is invalid.
294      */
295     bool IsValidParameterLength(Packet *pkt);
296 
297     BT_DISALLOW_COPY_AND_ASSIGN(AvrcTgVendorPacket);
298 };
299 
300 /******************************************************************
301  * GetCapability                                                  *
302  ******************************************************************/
303 
304 /**
305  * @brief This enumeration declares a set of values associated with the <b>GetCapability<b>
306  * frame.
307  */
308 enum AvrcTgGc {
309     AVRC_TG_GC_EVENT_PARA_LENGTH = 0x01,    // The Length of each "EventID" supported by "TG".
310     AVRC_TG_GC_COMPANY_PARA_LENGTH = 0x03,  // The Length of each "CompanyID" supported by  "TG".
311     AVRC_TG_GC_NUM_OF_PACKETS = 0x01,       // The packet num sent by "TG".
312     AVRC_TG_GC_CAPABILITY_COUT = 0x00,      // The init value of "CapabilityID".
313 };
314 
315 /**
316  * @brief This class provides a set of methods associated with assemble / disassemble the packet of the
317  * <b>GetCapabilities<b> command.
318  * @see Audio/Video Remote Control 1.6.2 Section 6.4.1 GetCapabilities.
319  */
320 class AvrcTgGcPacket : public AvrcTgVendorPacket {
321 public:
322     /**
323      * @brief A constructor used to create an <b>GetCapabilities</b> instance.
324      *
325      * @details You can use this constructor when wants to initialize the [label].
326      */
327     AvrcTgGcPacket(uint8_t crCode, const std::vector<uint32_t> &companies, uint8_t label);
328 
329     /**
330      * @brief A constructor used to create an <b>GetCapabilities</b> instance.
331      *
332      * @details You can use this constructor when wants to initialize the [label].
333      */
334     AvrcTgGcPacket(uint8_t crCode, const std::vector<uint8_t> &events, uint8_t label);
335 
336     /**
337      * @brief A constructor used to create an <b>GetCapabilities</b> instance.
338      *
339      * @details You can use this constructor when wants to disassemble the packet.
340      */
341     AvrcTgGcPacket(Packet *pkt, uint8_t label);
342 
343     /**
344      * @brief A destructor used to delete the <b>GetCapabilities</b> instance.
345      */
346     ~AvrcTgGcPacket();
347 
348     /**
349      * @brief Assembles the operands behind the "Packet Type" of the frame.
350      *
351      * @details Command frame:
352      *                        msb           lsb
353      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits
354      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
355      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
356      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
357      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
358      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
359      *
360      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
361      *                        0 0 0 0 | 0 0 0 0     Capability ID                                       1 octets
362      *                        0 0 0 0 | 0 0 0 0     Capability Count                                    1 octets
363      *                        0 0 0 0 | 0 0 0 0     Capability ID or EVENT               3*3n octets or n octets
364      * @return The packet of the frame.
365      */
366     Packet *AssembleParameters(Packet *pkt) override;
367 
368     /**
369      * @brief Disassembles the operands behind the "Parameter Length" of the frame.
370      *
371      * @details Command frame:
372      *                        msb           lsb
373      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits
374      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
375      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
376      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
377      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
378      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
379      *
380      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
381      *                        0 0 0 0 | 0 0 0 0     Capability ID 0x2 (CompanyID)/0x3 (EventsID)        1 octets
382      * @param[in] buffer The buffer of the frame.
383      * @return @c true  : The packet is valid.
384      *         @c false : The packet is invalid.
385      */
386     bool DisassembleParameters(uint8_t *buffer) override;
387 
388     /**
389      * @brief Gets the number of the packets.
390      *
391      * @return The number of the packets.
392      */
393     uint16_t GetNumberOfPackets(void) override;
394 
395     /**
396      * @brief Gets the capabilities.
397      *
398      * @return The companies of the packets.
399      */
GetCompanies(void)400     const std::vector<uint32_t> &GetCompanies(void) const
401     {
402         return companies_;
403     }
404 
405     /**
406      * @brief Gets the capabilities.
407      *
408      * @return The events of the packets.
409      */
GetEventId(void)410     const std::vector<uint8_t> &GetEventId(void) const
411     {
412         return events_;
413     }
414 
415     /**
416      * @brief Gets the capabilityId.
417      *
418      * @return The capabilityId of the packets.
419      */
GetCapabilityId(void)420     uint8_t GetCapabilityId(void) const
421     {
422         return capabilityId_;
423     }
424 
425 private:
426     uint8_t capabilityId_ {AVRC_TG_GC_CAPABILITY_INVALID};  // Specific "Capability" requested.
427     uint8_t capabilityCount_ {AVRC_TG_GC_CAPABILITY_COUT};  // The Num of "Capability" Supported by "TG".
428     std::vector<uint32_t> companies_ {};                    // The list of CompanyID supported by TG.
429     std::vector<uint8_t> events_ {};                        // The list of EventIDs supported by the TG.
430 
431     /**
432      * @brief A constructor used to create an <b>GetCapabilities</b> instance.
433      */
434     AvrcTgGcPacket() = delete;
435 
436     /**
437      * @brief Assemble the companies.
438      */
439     void AssembleCompanies(Packet *pkt);
440 
441     /**
442      * @brief Assemble the events.
443      */
444     void AssembleEvents(Packet *pkt);
445 };
446 
447 /******************************************************************
448  * GetElementAttributes                                           *
449  ******************************************************************/
450 
451 /**
452  * @brief This enumeration declares the values of the <b>GetElementAttribute</b> command.
453  */
454 enum AvrcTgGea {
455     AVRC_TG_GEA_ATTRIBUTE_LENGTH = 0x08,          // The value of the attributeID charactersetID AttributeValueLength
456     AVRC_TG_GEA_SIZE_OF_ATTRIBUTE_LENGTH = 0x01,  // The remaining length of each packet
457     AVRC_TG_GEA_MAX_NUM_OF_ATTRIBUTES = 0xff,     // The number of the packets.
458     AVRC_TG_GEA_PARAMETER_LENGTH_SIZE = 0x03,     // The size of parameter length.
459     AVRC_TG_GEA_ASSEMBLE_MAX_SIZE = 0x01f5,       // max size of the parameter of frame.
460     AVRC_TG_GEA_INITIALIZATION = 0x00,            // The value of init parameter.
461     AVRC_TG_GEA_NUMBER_OF_ATTRIBUTES = 0x00       // The num of attributes.
462 };
463 
464 class AvrcTgGeaPacket : public AvrcTgVendorPacket {
465 public:
466     /**
467      * @brief A constructor used to create an <b>AvrcTgGeaPacket</b> instance.
468      *
469      * @details You can use this constructor when wants to initialize the [attributes] [values] and [label].
470      */
471     AvrcTgGeaPacket(
472         uint8_t crCode, const std::vector<uint32_t> &attribtues, const std::vector<std::string> &values, uint8_t label);
473 
474     /**
475      * @brief A constructor used to create an <b>AvrcTgGeaPacket</b> instance.
476      *
477      * @details You can use this constructor when wants to disassemble the packet.
478      */
479     AvrcTgGeaPacket(Packet *pkt, uint8_t label);
480 
481     /**
482      * @brief A destructor used to delete the <b>AvrcTgGeaPacket</b> instance.
483      */
484     ~AvrcTgGeaPacket();
485 
486     /**
487      * @brief Assembles the operands behind the "PDU ID" of the frame.
488      *
489      * @details Response frame:
490      *                        msb           lsb
491      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits
492      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
493      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
494      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
495      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
496      *
497      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
498      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
499      *                        0 0 0 0 | 0 0 0 0     Number of Attributes                                1 octets
500      *
501      *                        0 0 0 0 | 0 0 0 0     Attribute ID1                                       4 octets
502      *                        0 0 0 0 | 0 0 0 0     CharacterSetID1                                     2 octets
503      *                        0 0 0 0 | 0 0 0 0     AttributeValueLength1                               2 octets
504      *                        0 0 0 0 | 0 0 0 0     AttributeValue1                  AttributeValueLength octets
505      * @return The packet of the frame.
506      */
507     Packet *AssembleParameters(Packet *pkt) override;
508 
509     /**
510      * @brief Assembles the operands behind the "Packet Type" of the frame.
511      *
512      * @details Command frame:
513      *                        msb           lsb
514      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits
515      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
516      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
517      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
518      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
519      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
520      *
521      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
522      *                        0 0 0 0 | 0 0 0 0     Identifier                                          8 octets
523      *                        0 0 0 0 | 0 0 0 0     AttributeCount                                      4 octets
524      *                        0 0 0 0 | 0 0 0 0     Attribute1  N                                       1 octets
525      * @return The packet of the frame.
526      * @return @c true  : The packet is valid.
527      *         @c false : The packet is invalid.
528      */
529     bool DisassembleParameters(uint8_t *buffer) override;
530 
531     /**
532      * @brief  Gets the number of the packets.
533      *
534      * @return The number of the packets.
535      */
536     uint16_t GetNumberOfPackets(void) override;
537 
538     /**
539      * @brief  Get the Unique identifier.
540      *
541      * @return The Unique identifier.
542      */
GetIdentifier(void)543     uint64_t GetIdentifier(void) const
544     {
545         return identifier_;
546     }
547 
548     /**
549      * @brief  Gets the number of  Attribute.
550      *
551      * @return The number of  Attribute.
552      */
GetNumberOfAttribute(void)553     uint8_t GetNumberOfAttribute(void) const
554     {
555         return number_;
556     }
557 
558     /**
559      * @brief Specifies the attribute ID for the attributes to be retrieved.
560      *
561      * @return Specifies the attribute ID for the attributes to be retrieved.
562      */
GetAttributes(void)563     const std::vector<uint32_t> &GetAttributes(void) const
564     {
565         return attributes_;
566     }
567 
568 private:
569     uint8_t number_ {AVRC_TG_GEA_INITIALIZATION};  // The num of the "Element Attribute" in one packet.
570     uint64_t identifier_ {AVRC_TG_VENDOR_UID};     // Unique identifier to identify an element on TG.
571     std::vector<uint32_t> attributes_ {};          // Specifies the attribute ID for the attributes to be retrieved.
572     uint16_t numOfValues_ {AVRC_TG_GEA_INITIALIZATION};      // The value of the "NumGetElementAttribute".
573     std::vector<std::string> values_ {};                     // The list of the value of this attribute.
574     std::deque<std::pair<uint8_t, uint16_t>> packetPos_ {};  // record each packet's attribute count and parameter
575                                                             // length.
576 
577     /**
578      * @brief A constructor used to create an <b>AvrcTgGeaPacket</b> instance.
579      */
580     AvrcTgGeaPacket() = delete;
581 };
582 
583 /******************************************************************
584  * GetPlayStatus                                                  *
585  ******************************************************************/
586 
587 /**
588  * @brief This enumeration declares the values of the <b>GetPlayStatus</b> command.
589  */
590 enum AvrcTgGps {
591     AVRC_TG_GPS_PARAMETER_LENGTH = 0x0009,  // The value of the "Parameter Length".
592     AVRC_TG_GPS_NUM_OF_PACKETS = 0x0001     // The number of the packets.
593 };
594 
595 /**
596  * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>GetPlayStatus</b>
597  * command.
598  * @see Audio/Video Remote Control 1.6.2 Section 6.7.1 GetPlayStatus.
599  */
600 class AvrcTgGpsPacket : public AvrcTgVendorPacket {
601 public:
602     /**
603      * @brief A constructor used to create an <b>AvrcTgGpsPacket</b> instance.
604      *
605      * @details You can use this constructor when wants to initialize the attributes [songLength], [songPosition],
606      * [playStatus] and [label].
607      */
608     AvrcTgGpsPacket(uint8_t crCode, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, uint8_t label);
609 
610     /**
611      * @brief A constructor used to create an <b>AvrcTgGpsPacket</b> instance.
612      *
613      * @details You can use this constructor when wants to disassemble the packet.
614      */
615     AvrcTgGpsPacket(Packet *pkt, uint8_t label);
616 
617     /**
618      * @brief A destructor used to delete the <b>AvrcTgGpsPacket</b> instance.
619      */
620     ~AvrcTgGpsPacket();
621 
622     /**
623      * @brief Assembles the operands behind the "PDU ID" of the frame.
624      *
625      * @details Response frame:<br>
626      *                        msb           lsb<br>
627      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
628      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
629      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
630      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
631      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
632      *
633      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
634      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
635      *                        0 0 0 0 | 0 0 0 0     Song Length                                         4 octets<br>
636      *                        0 0 0 0 | 0 0 0 0     Song Position                                       4 octets<br>
637      *                        0 0 0 0 | 0 0 0 0     Play Status                                         1 octets<br>
638      * @return The frame packet.
639      */
640     Packet *AssembleParameters(Packet *pkt) override;
641 
642     /**
643      * @brief Disassembles the operands behind the "Packet Type" of the frame.
644      *
645      * @details Command frame:<br>
646      *                        msb           lsb<br>
647      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
648      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
649      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
650      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
651      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
652      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
653      *
654      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
655      * @param[in] buffer The buffer of the frame.
656      * @return The result of the method execution.
657      * @retval true  The packet is valid.
658      * @retval false The packet is invalid.
659      */
660     bool DisassembleParameters(uint8_t *buffer) override;
661 
662     /**
663      * @brief Gets the number of the packets.
664      *
665      * @return The number of the packets.
666      */
667     uint16_t GetNumberOfPackets(void) override;
668 
669     /**
670      * @brief Gets the total length of the playing song in milliseconds.
671      *
672      * @return The total length of the playing song in milliseconds.
673      */
GetSongLength()674     uint32_t GetSongLength() const
675     {
676         return songLength_;
677     }
678 
679     /**
680      * @brief Gets the current position of the playing in milliseconds elapsed.
681      *
682      * @return The current position of the playing in milliseconds elapsed.
683      */
GetSongPosition(void)684     uint32_t GetSongPosition(void) const
685     {
686         return songPosition_;
687     }
688 
689     /**
690      * @brief Gets the current status of playing.
691      *
692      * @return The current status of playing.
693      */
GetPlayStatus(void)694     uint8_t GetPlayStatus(void) const
695     {
696         return playStatus_;
697     }
698 
699 private:
700     uint32_t songLength_ {AVRC_PLAY_STATUS_INVALID_SONG_LENGTH};      // The value of the "SongLength".
701     uint32_t songPosition_ {AVRC_PLAY_STATUS_INVALID_SONG_POSITION};  // The value of the "SongPosition".
702     uint8_t playStatus_ {AVRC_PLAY_STATUS_ERROR};                     // The value of the "PlayStatus".
703 
704     /**
705      * @brief A constructor used to create an <b>AvrcTgGpsPacket</b> instance.
706      */
707     AvrcTgGpsPacket() = delete;
708 };
709 
710 /******************************************************************
711  * SetAddressedPlayer                                             *
712  ******************************************************************/
713 
714 /**
715  * @brief This enumeration declares the values of the <b>SetAddressedPlayer</b> command.
716  */
717 enum AvrcTgSap {
718     AVRC_TG_SAP_PARAMETER_LENGTH = 0x0001,  // The value of the "Parameter Length".
719     AVRC_TG_SAP_PLAYER_ID = 0xFFFF,         // The value of the "Player Id".
720     AVRC_TG_SAP_NUM_OF_PACKETS = 0x0001,    // The number of the packets.
721 };
722 
723 /**
724  * @brief This class provides a set of methods for assembling / disassembling the packet of the
725  * <b>SetAddressedPlayer</b> command.
726  * @see Audio/Video Remote Control 1.6.2 Section 6.9.1 SetAddressedPlayer.
727  */
728 class AvrcTgSapPacket : public AvrcTgVendorPacket {
729 public:
730     /**
731      * @brief A constructor used to create an <b>AvrcTgSapPacket</b> instance.
732      *
733      * @details You can use this constructor when wants to initialize the attributes [crCode], [status] and [label].
734      */
735     AvrcTgSapPacket(uint8_t crCode, uint8_t status, uint8_t label);
736 
737     /**
738      * @brief A constructor used to create an <b>AvrcTgSapPacket</b> instance.
739      *
740      * @details You can use this constructor when wants to disassemble the packet.
741      */
742     AvrcTgSapPacket(Packet *pkt, uint8_t label);
743 
744     /**
745      * @brief A destructor used to delete the <b>AvrcTgSapPacket</b> instance.
746      */
747     ~AvrcTgSapPacket();
748 
749     /**
750      * @brief Assembles the operands behind the "PDU ID" of the frame.
751      *
752      * @details Response frame:<br>
753      *                        msb           lsb<br>
754      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
755      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
756      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
757      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
758      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
759      *
760      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
761      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
762      *                        0 0 0 0 | 0 0 0 0     Status                                              1 octets<br>
763      * @return The frame packet.
764      */
765     Packet *AssembleParameters(Packet *pkt) override;
766 
767     /**
768      * @brief Disassembles the operands behind the "Packet Type" of the frame.
769      *
770      * @details Command frame:<br>
771      *                        msb           lsb<br>
772      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
773      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
774      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
775      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
776      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
777      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
778      *
779      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
780      *                        0 0 0 0 | 0 0 0 0     Scope                                               1 octets<br>
781      *                        0 0 0 0 | 0 0 0 0     UID                                                 8 octets<br>
782      *                        0 0 0 0 | 0 0 0 0     UID Counter                                         2 octets<br>
783      * @param[in] buffer The buffer of the frame.
784      * @return The result of the method execution.
785      * @retval true  The packet is valid.
786      * @retval false The packet is invalid.
787      */
788     bool DisassembleParameters(uint8_t *buffer) override;
789 
790     /**
791      * @brief Gets the number of the packets.
792      *
793      * @return The number of the packets.
794      */
795     uint16_t GetNumberOfPackets(void) override;
796 
797     /**
798      * @brief Gets the unique media player id.
799      *
800      * @return The value of the "Player Id".
801      */
GetPlayerId(void)802     uint16_t GetPlayerId(void) const
803     {
804         return playerId_;
805     }
806 
807 private:
808     uint16_t playerId_ {AVRC_TG_SAP_PLAYER_ID};  // The value of the "Player Id".
809 
810     /**
811      * @brief A constructor used to create an <b>AvrcTgSapPacket</b> instance.
812      */
813     AvrcTgSapPacket() = delete;
814 };
815 
816 /******************************************************************
817  * PlayItem                                                       *
818  ******************************************************************/
819 
820 /**
821  * @brief This enumeration declares a set of values of the <b>PlayItemResponse</b> command.
822  */
823 enum AvrcTgPi {
824     AVRC_TG_PI_PARAMETER_LENGTH = 0x0001,  // The value of the "Parameter Length".
825     AVRC_TG_PI_SCOPE_OFFSET = 0x0a,        // The offset of the "scope" in the frame.
826     AVRC_TG_PI_NUM_OF_PACKETS = 0x01,      // The packet num sent by "TG".
827 };
828 
829 class AvrcTgPiPacket : public AvrcTgVendorPacket {
830 public:
831     /**
832      * @brief A constructor used to create an <b>AvrcTgPiPacket</b> instance.
833      *
834      * @details You can use this constructor when wants to initialize the attributes [crCode], [status] and [label].
835      */
836     AvrcTgPiPacket(uint8_t crCode, uint8_t status, uint8_t label);
837 
838     /**
839      * @brief A constructor used to create an <b>AvrcTgPiPacket</b> instance.
840      *
841      * @details You can use this constructor when wants to disassemble the packet.
842      */
843     AvrcTgPiPacket(Packet *pkt, uint8_t label);
844 
845     /**
846      * @brief A destructor used to delete the <b>AvrcTgPiPacket</b> instance.
847      */
848     ~AvrcTgPiPacket(void);
849 
850     /**
851      * @brief Assembles the payload into the PLAYITEM response.
852      *
853      * @details Response frame:<br>
854      *                        msb           lsb<br>
855      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
856      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
857      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
858      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
859      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
860      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
861      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
862      *                        0 0 0 0 | 0 0 0 0     status                                              1 octets<br>
863      * @return The frame packet.
864      */
865     Packet *AssembleParameters(Packet *pkt) override;
866 
867     /**
868      * @brief Disassembles the payload from the PLAYITEM command.
869      *
870      * @details Command frame:<br>
871      *                        msb           lsb<br>
872      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
873      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
874      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
875      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
876      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
877      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
878      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
879      *                        0 0 0 0 | 0 0 0 0     Scope                                               1 octets<br>
880      *                        0 0 0 0 | 0 0 0 0     UID                                                 8 octets<br>
881      *                        0 0 0 0 | 0 0 0 0     UID Counter                                         1 octets<br>
882      * @param[in] pkt The packet of the frame.
883      * @return The result of the method execution.
884      * @retval true  The packet is valid.
885      * @retval false The packet is invalid.
886      */
887     bool DisassembleParameters(uint8_t *buffer) override;
888 
889     /**
890      * @brief Gets the number of the packets.
891      *
892      * @return The number of the packets.
893      */
894     uint16_t GetNumberOfPackets(void) override;
895 
896     /**
897      * @brief Sets the scope of the PLAYITEM command.
898      *
899      * @param[in] uid which media content navigation may take place.
900      */
GetScope()901     uint8_t GetScope() const
902     {
903         return scope_;
904     }
905 
906     /**
907      * @brief Gets the uid of the PLAYITEM command.
908      *
909      * @return uid which is the unique identification of a Media Element Item.
910      */
GetUid(void)911     uint64_t GetUid(void) const
912     {
913         return uid_;
914     }
915 
916     /**
917      * @brief Gets the uid counter of the PLAYITEM command.
918      *
919      * @return uid counter which is the count of uid change .
920      */
GetUidCounter(void)921     uint16_t GetUidCounter(void) const
922     {
923         return uidCounter_;
924     }
925 
926 private:
927     uint8_t scope_ {AVRC_MEDIA_SCOPE_INVALID};          // The scope in which media content navigation may take place.
928     uint64_t uid_ {AVRC_TG_VENDOR_UID};                 // The uid in the frame.
929     uint16_t uidCounter_ {AVRC_TG_VENDOR_UID_COUNTER};  // The uid counter in the frame.
930 
931     /**
932      * @brief A constructor used to create an <b>AvrcTgPiPacket</b> instance.
933 
934      */
935     AvrcTgPiPacket() = delete;
936 };
937 
938 /******************************************************************
939  * AddToNowPlaying                                                *
940  ******************************************************************/
941 
942 /**
943  * @brief This enumeration declares the values of the <b>AddToNowPlaying</b> command.
944  */
945 enum AvrcTgAtnp {
946     AVRC_TG_ATNP_PARAMETER_LENGTH = 0x0001,  // The value of the "Parameter Length".
947     AVRC_TG_ATNP_NUM_OF_PACKETS = 0x0001,    // The number of the packets.
948 };
949 
950 /**
951  * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>AddToNowPlaying</b>
952  * command.
953  * @see Audio/Video Remote Control 1.6.2 Section 6.12.2 AddToNowPlaying.
954  */
955 class AvrcTgAtnpPacket : public AvrcTgVendorPacket {
956 public:
957     /**
958      * @brief A constructor used to create an <b>AvrcTgAtnpPacket</b> instance.
959      *
960      * @details You can use this constructor when wants to initialize the attributes [label].
961      */
962     AvrcTgAtnpPacket(uint8_t crCode, uint8_t status, uint8_t label);
963 
964     /**
965      * @brief A constructor used to create an <b>AvrcTgAtnpPacket</b> instance.
966      *
967      * @details You can use this constructor when wants to disassemble the packet.
968      */
969     AvrcTgAtnpPacket(Packet *pkt, uint8_t label);
970 
971     /**
972      * @brief A destructor used to delete the <b>AvrcTgAtnpPacket</b> instance.
973      */
974     ~AvrcTgAtnpPacket();
975 
976     /**
977      * @brief Assembles the operands behind the "PDU ID" of the frame.
978      *
979      * @details Response frame:<br>
980      *                        msb           lsb<br>
981      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
982      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
983      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
984      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
985      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
986      *
987      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
988      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
989      *                        0 0 0 0 | 0 0 0 0     Status                                              1 octets<br>
990      * @return The frame packet.
991      */
992     Packet *AssembleParameters(Packet *pkt) override;
993 
994     /**
995      * @brief Disassembles the operands behind the "Packet Type" of the frame.
996      *
997      * @details Command frame:<br>
998      *                        msb           lsb<br>
999      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
1000      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
1001      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
1002      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
1003      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
1004      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
1005      *
1006      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
1007      *                        0 0 0 0 | 0 0 0 0     Scope                                               1 octets<br>
1008      *                        0 0 0 0 | 0 0 0 0     UID                                                 8 octets<br>
1009      *                        0 0 0 0 | 0 0 0 0     UID Counter                                         2 octets<br>
1010      * @param[in] buffer The buffer of the frame.
1011      * @return The result of the method execution.
1012      * @retval true  The packet is valid.
1013      * @retval false The packet is invalid.
1014      */
1015     bool DisassembleParameters(uint8_t *buffer) override;
1016 
1017     /**
1018      * @brief Gets the number of the packets.
1019      *
1020      * @return The number of the packets.
1021      */
1022     uint16_t GetNumberOfPackets(void) override;
1023 
1024     /**
1025      * @brief Gets the scope in which the UID of the media element item or folder item.
1026      *
1027      * @return The value of the "Scope".
1028      */
GetScope(void)1029     uint8_t GetScope(void) const
1030     {
1031         return scope_;
1032     }
1033 
1034     /**
1035      * @brief Gets the UID of the media element item or folder item.
1036      *
1037      * @return The value of the "UID".
1038      */
GetUid(void)1039     uint64_t GetUid(void) const
1040     {
1041         return uid_;
1042     }
1043 
1044     /**
1045      * @brief Gets the UID Counter.
1046      *
1047      * @return The value of the "UID Counter".
1048      */
GetUidCounter(void)1049     uint16_t GetUidCounter(void) const
1050     {
1051         return uidCounter_;
1052     }
1053 
1054 private:
1055     uint8_t scope_ {AVRC_MEDIA_SCOPE_INVALID};          // The value of the "Scope".
1056     uint64_t uid_ {AVRC_TG_VENDOR_UID};                 // The value of the "UID".
1057     uint16_t uidCounter_ {AVRC_TG_VENDOR_UID_COUNTER};  // The value of the "UID Counter".
1058 
1059     /**
1060      * @brief A constructor used to create an <b>AvrcTgAtnpPacket</b> instance.
1061      */
1062     AvrcTgAtnpPacket() = delete;
1063 };
1064 
1065 /******************************************************************
1066  * SetAbsoluteVolume                                              *
1067  ******************************************************************/
1068 
1069 /**
1070  * @brief This enumeration declares the values of the <b>SetAbsoluteVolume</b> command.
1071  */
1072 enum AvrcTgSav {
1073     AVRC_TG_SAV_NUM_OF_PACKETS = 0x0001,  // The number of the packets.
1074     AVRC_TG_SAV_VOLUME_SIZE = 0x01,       // The size of the "Absolute Volume".
1075 };
1076 
1077 /**
1078  * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>SetAbsoluteVolume</b>
1079  * command.
1080  * @see Audio/Video Remote Control 1.6.2 Section 6.13.2 SetAbsoluteVolume.
1081  */
1082 class AvrcTgSavPacket : public AvrcTgVendorPacket {
1083 public:
1084     /**
1085      * @brief A constructor used to create an <b>AvrcTgSavPacket</b> instance.
1086      *
1087      * @details You can use this constructor when wants to initialize the attributes [volume] and [label].
1088      */
1089     AvrcTgSavPacket(uint8_t crCode, uint8_t volume, uint8_t label);
1090 
1091     /**
1092      * @brief A constructor used to create an <b>AvrcTgSavPacket</b> instance.
1093      *
1094      * @details You can use this constructor when wants to disassemble the packet.
1095      */
1096     AvrcTgSavPacket(Packet *pkt, uint8_t label);
1097 
1098     /**
1099      * @brief A destructor used to delete the <b>AvrcTgSavPacket</b> instance.
1100      */
1101     ~AvrcTgSavPacket();
1102 
1103     /**
1104      * @brief Assembles the operands behind the "PDU ID" of the frame.
1105      *
1106      * @details Response frame:<br>
1107      *                        msb           lsb<br>
1108      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
1109      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
1110      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
1111      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
1112      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
1113      *
1114      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
1115      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
1116      *                        0 0 0 0 | 0 0 0 0     Absolute Volume                                     1 octets<br>
1117      * @return The frame packet.
1118      */
1119     Packet *AssembleParameters(Packet *pkt) override;
1120 
1121     /**
1122      * @brief Disassembles the operands behind the "Packet Type" of the frame.
1123      *
1124      * @details Command frame:<br>
1125      *                        msb           lsb<br>
1126      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
1127      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
1128      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
1129      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
1130      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
1131      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
1132      *
1133      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
1134      *                        0 0 0 0 | 0 0 0 0     Absolute Volume                                     1 octets<br>
1135      * @param[in] buffer The buffer of the frame.
1136      * @return The result of the method execution.
1137      * @retval true  The packet is valid.
1138      * @retval false The packet is invalid.
1139      */
1140     bool DisassembleParameters(uint8_t *buffer) override;
1141 
1142     /**
1143      * @brief Gets the number of the packets.
1144      *
1145      * @return The number of the packets.
1146      */
1147     uint16_t GetNumberOfPackets(void) override;
1148 
1149     /**
1150      * @brief Gets the absolute volume.
1151      *
1152      * @return The value of the "Absolute Volume".
1153      */
GetAbsoluteVolume(void)1154     uint8_t GetAbsoluteVolume(void) const
1155     {
1156         return volume_;
1157     }
1158 
1159 private:
1160     uint8_t volume_ {AVRC_ABSOLUTE_VOLUME_INVALID};  // The value of the "Absolute Volume".
1161 
1162     /**
1163      * @brief A constructor used to create an <b>AvrcTgSavPacket</b> instance.
1164      */
1165     AvrcTgSavPacket() = delete;
1166 };
1167 }  // namespace bluetooth
1168 }  // namespace OHOS
1169 
1170 #endif  // !AVRCP_TG_VENDOR_H