command_packet.cc revision 99195bc17fe1f7c4a7e43590d9bce550b177a931
1// 2// Copyright 2015 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#define LOG_TAG "command_packet" 18 19#include "vendor_libs/test_vendor_lib/include/command_packet.h" 20 21extern "C" { 22#include "hci/include/hci_hal.h" 23#include "osi/include/log.h" 24#include "stack/include/hcidefs.h" 25} // extern "C" 26 27namespace test_vendor_lib { 28 29CommandPacket::CommandPacket(vector<uint8_t> header) 30 : Packet(DATA_TYPE_COMMAND, std::move(header)) {} 31 32CommandPacket::CommandPacket(uint16_t opcode) 33 : Packet( 34 DATA_TYPE_COMMAND, 35 {static_cast<uint8_t>(opcode), static_cast<uint8_t>(opcode >> 8)}) {} 36 37CommandPacket::CommandPacket(vector<uint8_t> header, vector<uint8_t> payload) 38 : Packet(DATA_TYPE_COMMAND, std::move(header)) { 39 AddPayloadOctets(payload.size(), std::move(payload)); 40} 41 42uint16_t CommandPacket::GetOpcode() const { 43 return 0 | (GetHeader()[0] | (GetHeader()[1] << 8)); 44} 45 46uint8_t CommandPacket::GetOGF() const { 47 return HCI_OGF(GetOpcode()); 48} 49 50uint16_t CommandPacket::GetOCF() const { 51 return HCI_OCF(GetOpcode()); 52} 53 54} // namespace test_vendor_lib 55