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_unit_info.h 18 * 19 * @brief Declares the class of the UNIT INFO command, including attributes and methods. 20 */ 21 22 #ifndef AVRCP_TG_UNIT_INFO_H 23 #define AVRCP_TG_UNIT_INFO_H 24 25 #include "avrcp_tg_internal.h" 26 #include "avrcp_tg_packet.h" 27 28 namespace OHOS { 29 namespace bluetooth { 30 /** 31 * @brief This enumeration declares the values of the <b>UNIT INFO</b> command. 32 */ 33 enum AvrcTgUnit { 34 AVRC_TG_UNIT_COMMAND_SIZE = 0x0008, // The size of the command frame. 35 AVRC_TG_UNIT_RESPONSE_SIZE = 0x0008, // The size of the response frame. 36 AVRC_TG_UNIT_SUBUNIT_TYPE_UNIT = 0x1F, // The value of the "Subunit_type". 37 AVRC_TG_UNIT_SUBUNIT_ID_IGNORE = 0x07, // The value of the "Subunit_ID". 38 AVRC_TG_UNIT_OCTET_3 = 0x07, // The fixed value and no name. 39 AVRC_TG_UNIT_COMPANY_ID_OFFSET = 0x05, // The offset of the "Company ID". 40 }; 41 42 /** 43 * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>UNIT INFO</b> 44 * command. 45 * @see Audio/Video Remote Control 1.6.2 Section 4.2.1 UNIT INFO command / 25.1 UNIT INFO command. 46 */ 47 class AvrcTgUnitPacket : public AvrcTgPacket { 48 public: 49 /** 50 * @brief A constructor used to create an <b>AvrcTgUnitPacket</b> instance. 51 */ 52 AvrcTgUnitPacket(); 53 54 /** 55 * @brief A constructor used to create an <b>AvrcTgUnitPacket</b> instance. 56 * 57 * @details You can use this constructor when wants to disassemble the packet. 58 */ 59 AvrcTgUnitPacket(Packet *pkt, uint8_t label); 60 61 /** 62 * @brief A constructor used to create an <b>AvrcTgUnitPacket</b> instance. 63 */ 64 virtual ~AvrcTgUnitPacket(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 * 0 0 0 0 | 0 0 0 0 fixed value 1 octets<br> 75 * uint_type 5 bits 0 0 0 0 0 | 0 0 0 unit 2 bits<br> 76 * 0 0 0 0 | 0 0 0 0 company_ID 1 octets<br> 77 * @return The frame packet. 78 */ 79 const Packet *AssemblePacket(void) override; 80 81 /** 82 * @brief Disassembles the frame packet. 83 * 84 * @details Command frame:<br> 85 * msb lsb<br> 86 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 87 * subunit_type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 88 * 0 0 0 0 | 0 0 0 0 opcode 1 octets<br> 89 * 0 0 0 0 | 0 0 0 0 fixed value 1 octets<br> 90 * 0 0 0 0 | 0 0 0 0 fixed value 1 octets<br> 91 * 0 0 0 0 | 0 0 0 0 fixed value 1 octets<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 * @param[in] pkt The frame packet. 95 * @return The result of the method execution. 96 * @retval true The packet is valid. 97 * @retval false The packet is invalid. 98 */ 99 bool DisassemblePacket(Packet *pkt) override; 100 101 /** 102 * @brief Gets the "opcode". 103 * 104 * @return The value of the "opcode". 105 */ GetOpCode(void)106 uint8_t GetOpCode(void) const 107 { 108 return opCode_; 109 } 110 111 /** 112 * @brief Gets the label. 113 * 114 * @return The value of the label. 115 */ GetLabel(void)116 uint8_t GetLabel(void) const 117 { 118 return label_; 119 } 120 121 protected: 122 uint8_t crCode_ {AVRC_TG_RSP_CODE_STABLE}; // The value of the "ctype" or the "response". 123 uint8_t subunitType_ {AVRC_TG_UNIT_SUBUNIT_TYPE_UNIT}; // The value of the "Subunit_type". 124 uint8_t subunitId_ {AVRC_TG_UNIT_SUBUNIT_ID_IGNORE}; // The value of the "Subunit_ID". 125 uint8_t opCode_ {AVRC_TG_OP_CODE_UNIT_INFO}; // The value of the "Opcode". 126 uint8_t unit_type_ {AVRC_TG_AVC_COMMON_SUBUNIT_TYPE}; // The value of the "Unit_type". 127 uint8_t unit_ {AVRC_TG_AVC_COMMON_SUBUNIT_ID}; // The value of the "Unit". 128 uint32_t companyId_ {AVRC_TG_DEFAULT_BLUETOOTH_SIG_COMPANY_ID}; // The value of the "Company ID". 129 Packet *pkt_ {nullptr}; // The frame packet. 130 uint8_t label_ {AVRC_DEFAULT_LABEL}; // The label which is used to distinguish different call. 131 bool isValid_ {false}; // The packet is valid or not. 132 133 BT_DISALLOW_COPY_AND_ASSIGN(AvrcTgUnitPacket); 134 }; 135 } // namespace bluetooth 136 } // namespace OHOS 137 138 #endif // !AVRCP_TG_UNIT_INFO_H 139