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_VENDOR_H 17 #define AVRCP_CT_VENDOR_H 18 19 #include "avrcp_ct_packet.h" 20 #include "packet.h" 21 22 namespace OHOS { 23 namespace bluetooth { 24 /** 25 * @brief This enumeration declares the values of the <b>VENDOR DEPENDENT</b> command. 26 */ 27 enum AvrcCtVendor { 28 AVRC_CT_VENDOR_MIN_COMMAND_SIZE = 0x08, // The min size of the command frame. 29 AVRC_CT_VENDOR_FIXED_OPERAND_SIZE = 0x0A, // The size of the fixed operand in the frame. 30 AVRC_CT_VENDOR_PARAMETER_LENGTH_SIZE = 0x0002, // The size of the "Parameter Length". 31 AVRC_CT_VENDOR_SUBUNIT_TYPE = 0x09, // The value of the "Subunit_type". 32 AVRC_CT_VENDOR_SUBUNIT_ID = 0x00, // The value of the "Subunit_ID". 33 AVRC_CT_VENDOR_PACKET_TYPE = 0x00, // The value of the "Packet type". 34 AVRC_CT_VENDOR_PACKET_TYPE_START = 0x01, // The value of the "Packet type - Start(01)". 35 AVRC_CT_VENDOR_PACKET_TYPE_CONTINUE = 0x02, // The value of the "Packet type - Continue(10)". 36 AVRC_CT_VENDOR_PACKET_TYPE_END = 0x03, // The value of the "Packet type - End(11)". 37 AVRC_CT_VENDOR_PARAMETER_LENGTH = 0x0000, // The value of the "Parameter Length". 38 AVRC_TG_VENDOR_REJECT_PARAMETER_LENGTH = 0x0001, // The value of the "Parameter Length". 39 AVRC_CT_VENDOR_UID = 0xFFFFFFFFFFFFFFFF, // The value of the "UID". 40 AVRC_CT_VENDOR_UID_COUNTER = 0x0000, // The value of the "UID Counter". 41 AVRC_CT_VENDOR_CTYPE_OFFSET = 0x00, // The offset of the "Ctype". 42 AVRC_CT_VENDOR_OPCODE_OFFSET = 0x02, // The offset of the "Opcode". 43 AVRC_CT_VENDOR_COMPANY_ID_OFFSET = 0x03, // The offset of the "Company ID". 44 AVRC_CT_VENDOR_PDU_ID_OFFSET = 0x06, // The offset of the "PDU ID". 45 AVRC_CT_VENDOR_PACKET_TYPE_OFFSET = 0x07, // The offset of the "Packet Type". 46 AVRC_CT_VENDOR_PARAMETER_LENGTH_OFFSET = 0x08, // The offset of the "Parameter Length". 47 AVRC_CT_VENDOR_STATUS_OFFSET = 0x0A, // The offset of the "Error Code". 48 AVRC_CT_VENDOR_RECEIVED_FRAGMENTS = 0x00, // The value of the received fragments. 49 }; 50 51 /** 52 * @brief This enumeration declares the values of the moving bit 53 */ 54 enum AvrcCtVendorMoveBit { 55 AVRC_CT_VENDOR_MOVE_BIT_3 = 0x03, 56 }; 57 58 /** 59 * @brief This class provides a set of methods of assemble / disassemble the packet of the <b>VENDOR DEPENDENT</b> 60 * command. 61 */ 62 class AvrcCtVendorPacket : public AvrcCtPacket { 63 public: 64 /** 65 * @brief A constructor used to create an <b>AvrcCtVendorPacket</b> instance. 66 */ 67 AvrcCtVendorPacket(); 68 69 /** 70 * @brief A destructor used to delete the <b>AvrcCtVendorPacket</b> instance. 71 */ 72 virtual ~AvrcCtVendorPacket(); 73 74 /** 75 * @brief Assembles the operands behind the "Packet Type" of the frame. 76 * 77 * @details Response frame:<br> 78 * msb lsb<br> 79 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 80 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 81 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 82 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 83 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 84 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 85 * 86 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 87 * 0 0 0 0 | 0 0 0 0 other operands n octets<br> 88 * @return The frame packet. 89 */ 90 virtual Packet *AssembleParameters(Packet *pkt) = 0; 91 92 /** 93 * @brief Assembles the packet of the frame. 94 * 95 * @retval nullptr Always return nullptr. 96 */ 97 const Packet *AssemblePacket(void) override; 98 99 /** 100 * @brief Disassembles the packet of the frame. 101 * 102 * @details Command frame:<br> 103 * msb lsb<br> 104 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 105 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 106 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 107 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 108 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 109 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 110 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 111 * @return The result of the method execution. 112 * @retval true The packet is valid. 113 * @retval false The packet is invalid. 114 */ 115 bool DisassemblePacket(Packet *pkt) override; 116 117 /** 118 * @brief Disassembles the operands behind the "Packet Type" of the frame. 119 * 120 * @param[in] buffer The buffer of the frame. 121 * @return The result of the method execution. 122 * @retval true The parameters is valid. 123 * @retval false The parameters is invalid. 124 */ 125 virtual bool DisassembleParameters(uint8_t *buffer) = 0; 126 127 /** 128 * @brief Gets the "ctype". 129 * 130 * @return The value of the "ctype". 131 */ 132 GetCrCode(void)133 uint8_t GetCrCode(void) const 134 { 135 return crCode_; 136 }; 137 138 /** 139 * @brief Sets the "ctype". 140 * 141 * @param[in] crCode The value the "ctype". 142 */ SetCrCode(uint8_t crCode)143 void SetCrCode(uint8_t crCode) 144 { 145 crCode_ = crCode; 146 } 147 148 /** 149 * @brief Gets the "PDU ID". 150 * 151 * @return The value of the "PDU ID". 152 */ GetPduId(void)153 uint8_t GetPduId(void) const 154 { 155 return pduId_; 156 } 157 158 /** 159 * @brief Gets the received fragments. 160 * 161 * @return The value of the received fragments. 162 */ GetReceivedFragments(void)163 uint8_t GetReceivedFragments(void) const 164 { 165 return receivedFragments_; 166 } 167 168 /** 169 * @brief Checks the frame packet is valid or not. 170 * 171 * @return The result of the method execution. 172 * @retval true The packet is valid. 173 * @retval false The packet is invalid. 174 */ IsValid(void)175 bool IsValid(void) const 176 { 177 return isValid_; 178 } 179 180 protected: 181 uint8_t crCode_ {AVRC_CT_CMD_CODE_STATUS}; // The value of the "ctype" or the "response". 182 uint8_t subunitType_ {AVRC_CT_VENDOR_SUBUNIT_TYPE}; // The value of the "Subunit_type". 183 uint8_t subunitId_ {AVRC_CT_VENDOR_SUBUNIT_ID}; // The value of the "Subunit_ID". 184 uint8_t opCode_ {AVRC_CT_OP_CODE_VENDOR}; // The value of the "Opcode". 185 uint32_t companyId_ {AVRC_CT_DEFAULT_BLUETOOTH_SIG_COMPANY_ID}; // The value of the "Company ID". 186 uint8_t pduId_ {AVRC_CT_PDU_ID_INVALID}; // The value of the "PDU ID". 187 uint8_t packetType_ {AVRC_CT_VENDOR_PACKET_TYPE}; // The value of the "Packet type". 188 uint16_t parameterLength_ {AVRC_CT_VENDOR_PARAMETER_LENGTH}; // The value of the "Parameter Length". 189 uint8_t status_ {AVRC_ES_CODE_INVALID}; // The value of the "Status". 190 uint8_t receivedFragments_ {AVRC_CT_VENDOR_RECEIVED_FRAGMENTS}; // The value of the received fragments. 191 Packet *pkt_ {nullptr}; // The frame packet. 192 bool isValid_ {false}; // The frame packet is valid or not. 193 194 /** 195 * @brief Assembles the operands in the front of the "Packet Type" of the frame. 196 * 197 * @details Response frame:<br> 198 * msb lsb<br> 199 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 200 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 201 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 202 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 203 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 204 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 205 * @return The frame packet. 206 */ 207 Packet *AssembleFixedOperands(void); 208 209 /** 210 * @brief Checks the "Parameter Length" is valid or not. 211 * 212 * @param[in] pkt The frame packet. 213 * @return The result of the method execution. 214 * @retval true The "Parameter Length" is valid. 215 * @retval false The "Parameter Length" is invalid. 216 */ 217 bool IsValidParameterLength(Packet *pkt); 218 219 BT_DISALLOW_COPY_AND_ASSIGN(AvrcCtVendorPacket); 220 }; 221 222 /****************************************************************** 223 * GetCapability * 224 ******************************************************************/ 225 226 /** 227 * @brief This enumeration declares a set of values associated with the <b>GetCapability<b> 228 */ 229 enum AvrcCtGc { 230 AVRC_CT_GC_PARAMETER_LENGTH = 0x01, // The Length of each "Parameter". 231 AVRC_CT_GC_CAPABILITY_COUT = 0x00, // The Init value of "CapabilityID". 232 }; 233 234 /** 235 * @brief This class provides a set of methods associated with assemble / disassemble the packet of the 236 * <b>GetCapability<b> command. 237 * @see Audio/Video Remote Control 1.6.2 Section 6.5.1 GetCapability. 238 */ 239 240 class AvrcCtGcPacket : public AvrcCtVendorPacket { 241 public: 242 /** 243 * @brief A constructor used to create an <b>GetCapability</b> instance. 244 */ 245 explicit AvrcCtGcPacket(uint8_t capabilityId); 246 247 /** 248 * @brief A constructor used to create an <b>GetCapability</b> instance. 249 */ 250 explicit AvrcCtGcPacket(Packet *pkt); 251 252 /** 253 * @brief A destructor used to delete the <b>GetCapability</b> instance. 254 */ 255 ~AvrcCtGcPacket(); 256 257 /** 258 * @brief Assembles the operands behind the "Packet Type" of the frame. 259 * 260 * @details Command frame: 261 * msb lsb 262 * 0 0 0 0 | 0 0 0 0 ctype 4 bits 263 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits 264 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets 265 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets 266 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets 267 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits 268 * 269 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets 270 * 0 0 0 0 | 0 0 0 0 Capability ID 0x2 (CompanyID)/0x3 (EventsID) 1 octets 271 * @return The packet of the frame. 272 */ 273 Packet *AssembleParameters(Packet *pkt) override; 274 275 /** 276 * @brief Disassembles the operands behind the "Parameter Length" of the frame. 277 * 278 * @details Response frame: 279 * msb lsb 280 * 0 0 0 0 | 0 0 0 0 response 4 bits 281 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits 282 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets 283 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets 284 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets 285 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits 286 * 287 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets 288 * 0 0 0 0 | 0 0 0 0 Capability ID 1 octets 289 * 0 0 0 0 | 0 0 0 0 Capability Count 1 octets 290 * 0 0 0 0 | 0 0 0 0 Capability ID or EVENT 3*3n octets or n octets 291 * @param[in] buffer The buffer of the frame. 292 * @return @c true : The packet is valid. 293 * @c false : The packet is invalid. 294 */ 295 bool DisassembleParameters(uint8_t *buffer) override; 296 297 /** 298 * @brief Gets the capabilities. 299 * 300 * @return The companyId of the packets. 301 */ GetCompanies(void)302 const std::vector<uint32_t> &GetCompanies(void) const 303 { 304 return companies_; 305 } 306 307 /** 308 * @brief Gets the capabilities. 309 * 310 * @return The eventId of the packets. 311 */ GetEvents(void)312 const std::vector<uint8_t> &GetEvents(void) const 313 { 314 return events_; 315 } 316 317 private: 318 uint8_t capabilityId_ {AVRC_CT_GC_CAPABILITY_INVALID}; // Specific capability requested. 319 uint8_t capabilityCount_ {AVRC_CT_GC_CAPABILITY_COUT}; // Specifies the number of CompanyID returned. 320 std::vector<uint32_t> companies_ {}; // List of CompanyID. 321 std::vector<uint8_t> events_ {}; // Minimum of two mandatory EventIDs. 322 323 /** 324 * @brief A constructor used to create an <b>GetCapability</b> instance. 325 */ 326 AvrcCtGcPacket() = delete; 327 }; 328 329 /****************************************************************** 330 * GetElementAttribute * 331 ******************************************************************/ 332 333 /** 334 * @brief This enumeration declares a set of values associated with the <b>GetElementAttribute<b> frame. 335 */ 336 enum AvrcCtGea { 337 AVRC_CT_GEA_IDENTIFIER_SIZE = 0x08, // The length of the "Identifier" size. 338 AVRC_CT_GEA_PARAMETER_LENGTH_SIZE = 0x0002, // The length of the "Parameter Length" size. 339 AVRC_CT_GEA_ATTRIBUTE_COUNT_SIZE = 0x01, // The length of the "Attribute Count" size. 340 AVRC_CT_GEA_ATTRIBUTE_SIZE = 0x04, // The length of the "Attribute" size. 341 AVRC_CT_GEA_INITIALIZATION = 0x00, // The value of initialization. 342 AVRC_CT_GEA_MTU = 0x0200, // The "mtu" of the packet. 343 }; 344 345 /** 346 * @brief This class provides a set of methods associated with assemble / disassemble the packet of the 347 * <b>GetElementAttribute<b> command. 348 * @see Audio/Video Remote Control 1.6.2 Section 6.6.1 GetElementAttribute. 349 */ 350 class AvrcCtGeaPacket : public AvrcCtVendorPacket { 351 public: 352 /** 353 * @brief A constructor used to create an <b>AvrcCtGeaPacket</b> instance. 354 */ 355 AvrcCtGeaPacket(uint64_t identifier, std::vector<uint32_t> attributes); 356 357 /** 358 * @brief A constructor used to create an <b>AvrcCtGeaPacket</b> instance. 359 */ 360 explicit AvrcCtGeaPacket(Packet *pkt); 361 362 /** 363 * @brief A destructor used to delete the <b>AvrcCtGeaPacket</b> instance. 364 */ 365 ~AvrcCtGeaPacket(); 366 367 /** 368 * @brief Assembles the operands behind the "Packet Type" of the frame. 369 * 370 * @details Command frame: 371 * msb lsb 372 * 0 0 0 0 | 0 0 0 0 ctype 4 bits 373 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits 374 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets 375 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets 376 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets 377 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits 378 * 379 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets 380 * 0 0 0 0 | 0 0 0 0 Identifier 8 octets 381 * 0 0 0 0 | 0 0 0 0 AttributeCount 4 octets 382 * 0 0 0 0 | 0 0 0 0 Attribute1 N 1 octets 383 * @return The packet of the frame. 384 */ 385 Packet *AssembleParameters(Packet *pkt) override; 386 387 /** 388 * @brief Disassembles the operands behind the "Parameter Length" of the frame. 389 * 390 * @details Response frame: 391 * msb lsb 392 * 0 0 0 0 | 0 0 0 0 response 4 bits 393 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits 394 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets 395 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets 396 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets 397 * 398 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits 399 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets 400 * 0 0 0 0 | 0 0 0 0 Number of Attributes 1 octets 401 * 402 * 0 0 0 0 | 0 0 0 0 Attribute ID1 4 octets 403 * 0 0 0 0 | 0 0 0 0 CharacterSetID1 2 octets 404 * 0 0 0 0 | 0 0 0 0 AttributeValueLength1 2 octets 405 * 0 0 0 0 | 0 0 0 0 AttributeValue1 AttributeValueLength octets 406 * @param[in] buffer The buffer of the frame. 407 * @return @c true : The packet is valid. 408 * @c false : The packet is invalid. 409 */ 410 bool DisassembleParameters(uint8_t *buffer) override; 411 412 /** 413 * @brief Gets the "Packet Type" of the frame. 414 * 415 * @return The "Packet Type" of the frame. 416 */ GetPacketType(void)417 uint8_t GetPacketType(void) const 418 { 419 return packetType_; 420 } 421 422 /** 423 * @brief Gets the number of Attribute. 424 * 425 * @return The number of Attribute. 426 */ 427 GetNumberOfAttribute(void)428 uint8_t GetNumberOfAttribute(void) const 429 { 430 return attributes_.size(); 431 } 432 433 /** 434 * @brief Specifies the attribute ID for the attributes to be retrieved. 435 * 436 * @return Specifies the attribute ID for the attributes to be retrieved. 437 */ GetAttributes(void)438 const std::vector<uint32_t> &GetAttributes(void) const 439 { 440 return attributes_; 441 } 442 443 /** 444 * @brief Clears the "ElementAttributeID". 445 * 446 * @return The ID of the "ElementAttributeID". 447 */ ClearAttributes(void)448 void ClearAttributes(void) 449 { 450 attributes_.clear(); 451 } 452 453 /** 454 * @brief Clears the "PlayerApplicationSettingValueID". 455 * 456 * @return The values of the "PlayerApplicationSettingValueID". 457 */ ClearValues(void)458 void ClearValues(void) 459 { 460 values_.clear(); 461 } 462 463 /** 464 * @brief Gets the "ElementAttributes". 465 * 466 * @return The values of the "ElementAttributesValueID". 467 */ GetValues(void)468 const std::vector<std::string> &GetValues(void) const 469 { 470 return values_; 471 } 472 473 private: 474 uint64_t identifier_ {AVRC_CT_VENDOR_UID}; // Unique identifier to identify an element on TG. 475 uint8_t number_ {AVRC_CT_GEA_INITIALIZATION}; // The num of the "Element Attribute" of one packet. 476 uint16_t numOfAttributes_ {AVRC_CT_GEA_INITIALIZATION}; // The num of the "AttributeNum". 477 std::vector<uint32_t> attributes_ {}; // Specifies the attribute ID for the attributes to be retrieved. 478 uint16_t AttributeValueLength_ {AVRC_CT_GEA_INITIALIZATION}; // Length of the value of the attribute. 479 uint16_t numOfValues_ {AVRC_CT_GEA_INITIALIZATION}; // The num of the "ValueNum". 480 std::vector<std::string> values_ {}; // The values of the "ElementAttributesID". 481 482 bool DisassemblePacketAttributes(uint8_t *buffer, uint16_t offset); 483 484 /** 485 * @brief A constructor used to create an <b>AvrcCtGeaPacket</b> instance. 486 */ 487 AvrcCtGeaPacket() = delete; 488 }; 489 490 /****************************************************************** 491 * GetPlayStatus * 492 ******************************************************************/ 493 494 /** 495 * @brief This enumeration declares the values of the <b>GetPlayStatus</b> command. 496 */ 497 enum AvrcCtGps { 498 AVRC_CT_GPS_PARAMETER_LENGTH = 0x0001, // The value of the "Parameter Length". 499 AVRC_CT_GPS_SONG_LENGTH_OFFSET = 0x0A, // The offset of the "Song length". 500 }; 501 502 /** 503 * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>GetPlayStatus</b> 504 * command. 505 * @see Audio/Video Remote Control 1.6.2 Section 6.7.1 GetPlayStatus. 506 */ 507 class AvrcCtGpsPacket : public AvrcCtVendorPacket { 508 public: 509 /** 510 * @brief A constructor used to create an <b>AvrcCtGpsPacket</b> instance. 511 */ 512 AvrcCtGpsPacket(); 513 514 /** 515 * @brief A constructor used to create an <b>AvrcCtGpsPacket</b> instance. 516 * 517 * @details You can use this constructor when wants to disassemble the packet. 518 */ 519 explicit AvrcCtGpsPacket(Packet *pkt); 520 521 /** 522 * @brief A destructor used to delete the <b>AvrcCtGpsPacket</b> instance. 523 */ 524 ~AvrcCtGpsPacket(); 525 526 /** 527 * @brief Assembles the operands behind the "Packet Type" of the frame. 528 * 529 * @details Command frame:<br> 530 * msb lsb<br> 531 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 532 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 533 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 534 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 535 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 536 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 537 * 538 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 539 * @return The frame packet. 540 */ 541 Packet *AssembleParameters(Packet *pkt) override; 542 543 /** 544 * @brief Disassembles the operands behind the "Packet Type" of the frame. 545 * 546 * @details Response frame:<br> 547 * msb lsb<br> 548 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 549 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 550 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 551 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 552 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 553 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 554 * 555 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 556 * 0 0 0 0 | 0 0 0 0 Song Length 4 octets<br> 557 * 0 0 0 0 | 0 0 0 0 Song Position 4 octets<br> 558 * 0 0 0 0 | 0 0 0 0 Play Status 1 octets<br> 559 * @param[in] buffer The buffer of the frame. 560 * @return The result of the method execution. 561 * @retval true The packet is valid. 562 * @retval false The packet is invalid. 563 */ 564 bool DisassembleParameters(uint8_t *buffer) override; 565 566 /** 567 * @brief Gets the total length of the playing song in milliseconds. 568 * 569 * @return The total length of the playing song in milliseconds. 570 */ GetSongLength()571 uint32_t GetSongLength() const 572 { 573 return songLength_; 574 } 575 576 /** 577 * @brief Gets the current position of the playing in milliseconds elapsed. 578 * 579 * @return The current position of the playing in milliseconds elapsed. 580 */ GetSongPosition(void)581 uint32_t GetSongPosition(void) const 582 { 583 return songPosition_; 584 } 585 586 /** 587 * @brief Gets the current status of playing. 588 * 589 * @return The current status of playing. 590 */ GetPlayStatus(void)591 uint8_t GetPlayStatus(void) const 592 { 593 return playStatus_; 594 } 595 596 private: 597 uint32_t songLength_ {AVRC_PLAY_STATUS_INVALID_SONG_LENGTH}; // The value of the "SongLength". 598 uint32_t songPosition_ {AVRC_PLAY_STATUS_INVALID_SONG_POSITION}; // The value of the "SongPosition". 599 uint8_t playStatus_ {AVRC_PLAY_STATUS_ERROR}; // The value of the "PlayStatus". 600 }; 601 602 /****************************************************************** 603 * SetAddressedPlayer * 604 ******************************************************************/ 605 606 /** 607 * @brief This enumeration declares the values of the <b>SetAddressedPlayer</b> command. 608 */ 609 enum AvrcCtSap { 610 AVRC_CT_SAP_PARAMETER_LENGTH = 0x0002, // The value of the "Parameter Length". 611 AVRC_CT_SAP_PLAYER_ID = 0xFFFF, // The value of the "Player Id". 612 }; 613 614 /** 615 * @brief This class provides a set of methods for assembling / disassembling the packet of the 616 * <b>SetAddressedPlayer</b> command. 617 * @see Audio/Video Remote Control 1.6.2 Section 6.9.1 SetAddressedPlayer. 618 */ 619 class AvrcCtSapPacket : public AvrcCtVendorPacket { 620 public: 621 /** 622 * @brief A constructor used to create an <b>AvrcCtSapPacket</b> instance. 623 */ 624 explicit AvrcCtSapPacket(uint16_t playerId); 625 626 /** 627 * @brief A constructor used to create an <b>AvrcCtSapPacket</b> instance. 628 * 629 * @details You can use this constructor when wants to disassemble the packet. 630 */ 631 explicit AvrcCtSapPacket(Packet *pkt); 632 633 /** 634 * @brief A destructor used to delete the <b>AvrcCtSapPacket</b> instance. 635 */ 636 ~AvrcCtSapPacket(); 637 638 /** 639 * @brief Assembles the operands behind the "Packet Type" of the frame. 640 * 641 * @details Command frame:<br> 642 * msb lsb<br> 643 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 644 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 645 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 646 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 647 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 648 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 649 * 650 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 651 * 0 0 0 0 | 0 0 0 0 Player Id 2 octets<br> 652 * @return The frame packet. 653 */ 654 Packet *AssembleParameters(Packet *pkt) override; 655 656 /** 657 * @brief Disassembles the operands behind the "Packet Type" of the frame. 658 * 659 * @details Response frame:<br> 660 * msb lsb<br> 661 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 662 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 663 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 664 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 665 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 666 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 667 * 668 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 669 * 0 0 0 0 | 0 0 0 0 Status 1 octets<br> 670 * @param[in] buffer The buffer of the frame. 671 * @return The result of the method execution. 672 * @retval true The packet is valid. 673 * @retval false The packet is invalid. 674 */ 675 bool DisassembleParameters(uint8_t *buffer) override; 676 677 /** 678 * @brief Gets the result of the operation. 679 * 680 * @return The value of the "Status". 681 */ GetStatus(void)682 uint8_t GetStatus(void) const 683 { 684 return status_; 685 } 686 687 private: 688 uint16_t playerId_ {AVRC_CT_SAP_PLAYER_ID}; // The value of the "Player Id". 689 690 /** 691 * @brief A constructor used to create an <b>AvrcCtSapPacket</b> instance. 692 */ 693 AvrcCtSapPacket() = delete; 694 }; 695 696 /****************************************************************** 697 * PlayItem * 698 ******************************************************************/ 699 700 /** 701 * @brief This enumeration declares a set of values associated with the PlayItem frame. 702 */ 703 using AvrcCtPi = enum { 704 AVRC_CT_PI_PARAMETER_LENGTH = 0x000B, // The value of the "Parameter Length". 705 AVRC_CT_PI_STATUS_OFFSET = 0x0A, // The offset of the frame body. 706 }; 707 708 class AvrcCtPiPacket : public AvrcCtVendorPacket { 709 public: 710 /** 711 * @brief A constructor used to create an <b>AvrcCtPiPacket</b> instance. 712 */ 713 AvrcCtPiPacket(uint8_t scope, uint64_t uid, uint16_t uidCounter); 714 715 /** 716 * @brief A constructor used to create an <b>AvrcCtPiPacket</b> instance. 717 */ 718 explicit AvrcCtPiPacket(Packet *pkt); 719 720 /** 721 * @brief A destructor used to delete the <b>AvrcCtAtnpPacket</b> instance. 722 */ 723 ~AvrcCtPiPacket(void); 724 725 /** 726 * @brief Assembles the payload into the PlayItem response. 727 * 728 * @details Command frame:<br> 729 * msb lsb<br> 730 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 731 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 732 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 733 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 734 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 735 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 736 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 737 * 0 0 0 0 | 0 0 0 0 Scope 1 octets<br> 738 * 0 0 0 0 | 0 0 0 0 UID 8 octets<br> 739 * 0 0 0 0 | 0 0 0 0 UID Counter 1 octets<br> 740 * @return The frame packet. 741 */ 742 Packet *AssembleParameters(Packet *pkt) override; 743 744 /** 745 * @brief Disassembles the payload from the PlayItem command. 746 * 747 * @details Response frame:<br> 748 * msb lsb<br> 749 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 750 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 751 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 752 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 753 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 754 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 755 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 756 * 0 0 0 0 | 0 0 0 0 status 1 octets<br> 757 * @param[in] pkt The packet of the frame. 758 * @return The result of the method execution. 759 * @retval true The packet is valid. 760 * @retval false The packet is invalid. 761 */ 762 bool DisassembleParameters(uint8_t *buffer) override; 763 764 /** 765 * @brief Gets the status of the PlayItem response. 766 * 767 * @return status which is the result of the PlayItem operation . 768 */ GetStatus(void)769 uint8_t GetStatus(void) const 770 { 771 return status_; 772 } 773 774 private: 775 uint8_t scope_ {AVRC_MEDIA_SCOPE_INVALID}; // The scope in which media content navigation may take place. 776 uint64_t uid_ {AVRC_CT_VENDOR_UID}; // The uid in the frame. 777 uint16_t uidCounter_ {AVRC_CT_VENDOR_UID_COUNTER}; // The uid counter in the frame. 778 779 /** 780 * @brief A constructor used to create an <b>AvrcCtPiPacket</b> instance. 781 */ 782 AvrcCtPiPacket() = delete; 783 }; 784 785 /****************************************************************** 786 * AddToNowPlaying * 787 ******************************************************************/ 788 789 /** 790 * @brief This enumeration declares the values of the <b>AddToNowPlaying</b> command. 791 */ 792 enum AvrcCtAtnp { 793 AVRC_CT_ATNP_PARAMETER_LENGTH = 0x000B, // The value of the "Parameter Length". 794 }; 795 796 /** 797 * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>AddToNowPlaying</b> 798 * command. 799 * @see Audio/Video Remote Control 1.6.2 Section 6.12.2 AddToNowPlaying. 800 */ 801 class AvrcCtAtnpPacket : public AvrcCtVendorPacket { 802 public: 803 /** 804 * @brief A constructor used to create an <b>AvrcCtAtnpPacket</b> instance. 805 */ 806 AvrcCtAtnpPacket(uint8_t scope, uint64_t uid, uint16_t uidCounter); 807 808 /** 809 * @brief A constructor used to create an <b>AvrcCtAtnpPacket</b> instance. 810 * 811 * @details You can use this constructor when wants to disassemble the packet. 812 */ 813 explicit AvrcCtAtnpPacket(Packet *pkt); 814 815 /** 816 * @brief A destructor used to delete the <b>AvrcCtAtnpPacket</b> instance. 817 */ 818 ~AvrcCtAtnpPacket(); 819 820 /** 821 * @brief Assembles the operands behind the "Packet Type" of the frame. 822 * 823 * @details Command frame:<br> 824 * msb lsb<br> 825 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 826 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 827 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 828 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 829 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 830 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 831 * 832 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 833 * 0 0 0 0 | 0 0 0 0 Scope 1 octets<br> 834 * 0 0 0 0 | 0 0 0 0 UID 8 octets<br> 835 * 0 0 0 0 | 0 0 0 0 UID Counter 2 octets<br> 836 * @return The frame packet. 837 */ 838 Packet *AssembleParameters(Packet *pkt) override; 839 840 /** 841 * @brief Disassembles the operands behind the "Packet Type" of the frame. 842 * 843 * @details Response frame:<br> 844 * msb lsb<br> 845 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 846 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 847 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 848 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 849 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 850 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 851 * 852 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 853 * 0 0 0 0 | 0 0 0 0 Status 1 octets<br> 854 * @param[in] buffer The buffer of the frame. 855 * @return The result of the method execution. 856 * @retval true The packet is valid. 857 * @retval false The packet is invalid. 858 */ 859 bool DisassembleParameters(uint8_t *buffer) override; 860 861 /** 862 * @brief Gets the result of the operation. 863 * 864 * @return The value of the "Status". 865 */ GetStatus(void)866 uint8_t GetStatus(void) const 867 { 868 return status_; 869 } 870 871 private: 872 uint8_t scope_ {AVRC_MEDIA_SCOPE_INVALID}; // The value of the "Scope". 873 uint64_t uid_ {AVRC_CT_VENDOR_UID}; // The value of the "UID". 874 uint16_t uidCounter_ {AVRC_CT_VENDOR_UID_COUNTER}; // The value of the "UID Counter". 875 876 /** 877 * @brief A constructor used to create an <b>AvrcCtAtnpPacket</b> instance. 878 */ 879 AvrcCtAtnpPacket() = delete; 880 }; 881 882 /****************************************************************** 883 * SetAbsoluteVolume * 884 ******************************************************************/ 885 886 /** 887 * @brief This enumeration declares the values of the <b>SetAbsoluteVolume</b> command. 888 */ 889 enum AvrcCtSav { 890 AVRC_CT_SAV_PARAMETER_LENGTH = 0x0001, // The value of the "Parameter Length". 891 }; 892 893 /** 894 * @brief This class provides a set of methods for assembling / disassembling the packet of the <b>SetAbsoluteVolume</b> 895 * command. 896 * @see Audio/Video Remote Control 1.6.2 Section 6.13.2 SetAbsoluteVolume. 897 */ 898 class AvrcCtSavPacket : public AvrcCtVendorPacket { 899 public: 900 /** 901 * @brief A constructor used to create an <b>AvrcCtSavPacket</b> instance. 902 */ 903 explicit AvrcCtSavPacket(uint8_t volume); 904 905 /** 906 * @brief A constructor used to create an <b>AvrcCtAtnpPacket</b> instance. 907 * 908 * @details You can use this constructor when wants to disassemble the packet. 909 */ 910 explicit AvrcCtSavPacket(Packet *pkt); 911 912 /** 913 * @brief A destructor used to delete the <b>AvrcCtGpsPacket</b> instance. 914 */ 915 ~AvrcCtSavPacket(); 916 917 /** 918 * @brief Assembles the operands behind the "Packet Type" of the frame. 919 * 920 * @details Command frame:<br> 921 * msb lsb<br> 922 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 923 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 924 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 925 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 926 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 927 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 928 * 929 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 930 * 0 0 0 0 | 0 0 0 0 Absolute Volume 1 octets<br> 931 * @return The frame packet. 932 */ 933 Packet *AssembleParameters(Packet *pkt) override; 934 935 /** 936 * @brief Disassembles the operands behind the "Packet Type" of the frame. 937 * 938 * @details Response frame:<br> 939 * msb lsb<br> 940 * 0 0 0 0 | 0 0 0 0 response 4 bits<br> 941 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 942 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 943 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 944 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 945 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 946 * 947 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 948 * 0 0 0 0 | 0 0 0 0 Absolute Volume 1 octets<br> 949 * @param[in] buffer The buffer of the frame. 950 * @return The result of the method execution. 951 * @retval true The packet is valid. 952 * @retval false The packet is invalid. 953 */ 954 bool DisassembleParameters(uint8_t *buffer) override; 955 956 /** 957 * @brief Gets the absolute volume. 958 * 959 * @return The value of the "Absolute Volume". 960 */ GetAbsoluteVolume(void)961 uint8_t GetAbsoluteVolume(void) const 962 { 963 return volume_; 964 } 965 966 private: 967 uint8_t volume_ {AVRC_ABSOLUTE_VOLUME_INVALID}; // The value of the "Absolute Volume". 968 969 /** 970 * @brief A constructor used to create an <b>AvrcCtSavPacket</b> instance. 971 */ 972 AvrcCtSavPacket() = delete; 973 }; 974 } // namespace bluetooth 975 } // namespace OHOS 976 977 #endif // !AVRCP_CT_VENDOR_H