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 #ifndef AVRCP_TG_SUB_UNIT_INFO_H
17 #define AVRCP_TG_SUB_UNIT_INFO_H
18 
19 #include "avrcp_tg_internal.h"
20 #include "avrcp_tg_packet.h"
21 #include "avrcp_tg_unit_info.h"
22 #include "packet.h"
23 
24 /**
25  * @brief The bluetooth subsystem.
26  */
27 namespace OHOS {
28 namespace bluetooth {
29 /**
30  * @brief This enumeration declares the values of the SUB UNIT INFO command.
31  */
32 using AvrcTgSubUnit = enum {
33     AVRC_TG_SUB_UNIT_COMMAND_SIZE = 0x0008,     // The size of the command frame.
34     AVRC_TG_SUB_UNIT_RESPONSE_SIZE = 0x0008,    // The size of the response frame.
35     AVRC_TG_SUB_UNIT_SUBUNIT_TYPE_UNIT = 0x1F,  // The value of the "Subunit_type".
36     AVRC_TG_SUB_UNIT_SUBUNIT_ID_IGNORE = 0x07,  // The value of the "Subunit_ID".
37     AVRC_TG_SUB_UNIT_PAGE = 0x00,               // The value of the "Page".
38     AVRC_TG_SUB_UNIT_EXTENTION_CODE = 0x07,     // The value of the "Extention_code".
39     AVRC_TG_SUB_UNIT_OCTET_4 = 0xFF,            // The fixed value and no name.
40 };
41 
42 /**
43  * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>SUB UNIT INFO</b>
44  * command.
45  * @see Audio/Video Remote Control 1.6.2 Section 4.2.1 SUB UNIT INFO command / 25.1 SUB UNIT INFO command.
46  */
47 class AvrcTgSubUnitPacket : public AvrcTgUnitPacket {
48 public:
49     /**
50      * @brief A constructor used to create an <b>AvrcTgSubUnitPacket</b> instance.
51      */
52     AvrcTgSubUnitPacket(void);
53 
54     /**
55      * @brief A constructor used to create an <b>AvrcTgSubUnitPacket</b> instance.
56      *
57      * @details You can use this constructor when wants to disassemble the packet.
58      */
59     AvrcTgSubUnitPacket(Packet *pkt, uint8_t label);
60 
61     /**
62      * @brief A destructor used to delete the <b>AvrcTgSubUnitPacket</b> instance.
63      */
64     ~AvrcTgSubUnitPacket(void);
65 
66     /**
67      * @brief Assembles the frame packet.
68      *
69      * @details Response frame:<br>
70      *                        msb           lsb<br>
71      *                        0 0 0 0 | 0 0 0 0     response                        4 bits<br>
72      * subunit_type 5 bits    0 0 0 0 0 | 0 0 0     subunit_ID                      3 bits<br>
73      *                        0 0 0 0 | 0 0 0 0     opcode                          1 octets<br>
74      * page         3 bits    0 0 0 0 | 0 0 0 0     extention_code                  3 bits<br>
75      * subunit_type 5 bits    0 0 0 0 0 | 0 0 0     max_subunit_ID                  3 bits<br>
76      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
77      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
78      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
79      * @return The frame packet.
80      */
81     const Packet *AssemblePacket(void) override;
82 
83     /**
84      * @brief Disassembles the frame packet.
85      *
86      * @details Command frame:<br>
87      *                        msb           lsb<br>
88      *                        0 0 0 0 | 0 0 0 0     ctype                           4 bits<br>
89      * subunit_type 5 bits    0 0 0 0 0 | 0 0 0     subunit_ID                      3 bits<br>
90      *                        0 0 0 0 | 0 0 0 0     opcode                          1 octets<br>
91      * page         3 bits    0 0 0 0 | 0 0 0 0     extention_code                  3 bits<br>
92      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
93      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
94      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
95      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
96      * @param[in] pkt The frame packet.
97      * @return The result of the method execution.
98      * @retval true  The packet is valid.
99      * @retval false The packet is invalid.
100      */
101     bool DisassemblePacket(Packet *pkt) override;
102 
103 private:
104     uint8_t page_ {AVRC_TG_SUB_UNIT_PAGE};                     // The value of the "Page".
105     uint8_t extentionCode_ {AVRC_TG_SUB_UNIT_EXTENTION_CODE};  // The value of the "Extention_code".
106 
107     BT_DISALLOW_COPY_AND_ASSIGN(AvrcTgSubUnitPacket);
108 };
109 }  // namespace bluetooth
110 }  // namespace OHOS
111 
112 #endif  // !AVRCP_TG_SUB_UNIT_INFO_H
113