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_CT_UNIT_INFO_H
17 #define AVRCP_CT_UNIT_INFO_H
18 
19 #include "avrcp_ct_packet.h"
20 #include "base_def.h"
21 #include "packet.h"
22 
23 namespace OHOS {
24 namespace bluetooth {
25 /**
26  * @brief This enumeration declares the values of the <b>UNIT INFO</b> command.
27  */
28 enum AvrcCtUnit {
29     AVRC_CT_UNIT_COMMAND_SIZE = 0x0008,     // The size of the command frame.
30     AVRC_CT_UNIT_RESPONSE_SIZE = 0x0008,    // The size of the response frame.
31     AVRC_CT_UNIT_SUBUNIT_TYPE_UNIT = 0x1F,  // The value of the "Subunit_type".
32     AVRC_CT_UNIT_SUBUNIT_ID_IGNORE = 0x07,  // The value of the "Subunit_ID".
33     AVRC_CT_UNIT_OCTET_3 = 0xFF,            // The fixed value and no name.
34     AVRC_CT_UNIT_COMPANY_ID_OFFSET = 0x05,  // The offset of the "Company ID".
35 };
36 
37 /**
38  * @brief This enumeration declares the values of the moving bit
39  */
40 enum AvrcCtUnitMoveBit {
41     AVRC_CT_UNIT_MOVE_BIT_3 = 0x03,
42 };
43 /**
44  * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>UNIT INFO</b>
45  * command.
46  * @see Audio/Video Remote Control 1.6.2 Section 4.2.1 UNIT INFO command / 25.1 UNIT INFO command.
47  */
48 class AvrcCtUnitPacket : public AvrcCtPacket {
49 public:
50     /**
51      * @brief A constructor used to create an <b>AvrcCtUnitPacket</b> instance.
52      */
53     AvrcCtUnitPacket();
54 
55     /**
56      * @brief A constructor used to create an <b>AvrcCtUnitPacket</b> instance.
57      *
58      * @details You can use this constructor when wants to disassemble the packet.
59      */
60     explicit AvrcCtUnitPacket(Packet *pkt);
61 
62     /**
63      * @brief A constructor used to create an <b>AvrcCtUnitPacket</b> instance.
64      */
65     virtual ~AvrcCtUnitPacket(void);
66 
67     /**
68      * @brief Assembles the frame packet.
69      *
70      * @details Command frame:<br>
71      *                        msb           lsb<br>
72      *                        0 0 0 0 | 0 0 0 0     ctype                           4 bits<br>
73      * subunit_type 5 bits    0 0 0 0 0 | 0 0 0     subunit_ID                      3 bits<br>
74      *                        0 0 0 0 | 0 0 0 0     opcode                          1 octets<br>
75      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<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      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
80      * @return The frame packet.
81      */
82     const Packet *AssemblePacket(void) override;
83 
84     /**
85      * @brief Disassembles the frame packet.
86      *
87      * @details Response frame:<br>
88      *                        msb           lsb<br>
89      *                        0 0 0 0 | 0 0 0 0     response                        4 bits<br>
90      * subunit_type 5 bits    0 0 0 0 0 | 0 0 0     subunit_ID                      3 bits<br>
91      *                        0 0 0 0 | 0 0 0 0     opcode                          1 octets<br>
92      *                        0 0 0 0 | 0 0 0 0     fixed value                     1 octets<br>
93      * uint_type    5 bits    0 0 0 0 0 | 0 0 0     unit                            2 bits<br>
94      *                        0 0 0 0 | 0 0 0 0     company_ID                      1 octets<br>
95      * @param[in] pkt The frame packet.
96      * @return The result of the method execution.
97      * @retval true  The packet is valid.
98      * @retval false The packet is invalid.
99      */
100     bool DisassemblePacket(Packet *pkt) override;
101 
102     /**
103      * @brief Gets the "ctype".
104      *
105      * @return The value of the "ctype".
106      */
GetCrCode(void)107     uint8_t GetCrCode(void) const
108     {
109         return crCode_;
110     };
111 
112     /**
113      * @brief Gets the "opcode".
114      *
115      * @return The value of the "opcode".
116      */
GetOpCode(void)117     uint8_t GetOpCode(void) const
118     {
119         return opCode_;
120     }
121 
122 protected:
123     uint8_t crCode_ {AVRC_CT_CMD_CODE_STATUS};                       // The value of the "ctype" or the "response".
124     uint8_t subunitType_ {AVRC_CT_UNIT_SUBUNIT_TYPE_UNIT};           // The value of the "Subunit_type".
125     uint8_t subunitId_ {AVRC_CT_UNIT_SUBUNIT_ID_IGNORE};             // The value of the "Subunit_ID".
126     uint8_t opCode_ {AVRC_CT_OP_CODE_UNIT_INFO};                     // The value of the "Opcode".
127     uint8_t unit_type_ {AVRC_CT_AVC_COMMON_SUBUNIT_TYPE};            // The value of the "Unit_type".
128     uint8_t unit_ {AVRC_CT_AVC_COMMON_SUBUNIT_ID};                   // The value of the "Unit".
129     uint32_t companyId_ {AVRC_CT_DEFAULT_BLUETOOTH_SIG_COMPANY_ID};  // The value of the "Company ID".
130     Packet *pkt_ {nullptr};                                          // The frame packet.
131     bool isValid_ {false};                                           // The packet is valid or not.
132 
133     BT_DISALLOW_COPY_AND_ASSIGN(AvrcCtUnitPacket);
134 };
135 }  // namespace bluetooth
136 }  // namespace OHOS
137 
138 #endif  // !AVRCP_CT_UNIT_INFO_H
139