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