command_packet.cc revision 265316f78ca1077216c9d87b2de096894fdd5ee5
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 "command_packet.h" 20 21#include "hci/include/hci_hal.h" 22#include "osi/include/log.h" 23#include "stack/include/hcidefs.h" 24 25namespace test_vendor_lib { 26 27CommandPacket::CommandPacket(vector<uint8_t> header) 28 : Packet(DATA_TYPE_COMMAND, std::move(header)) {} 29 30CommandPacket::CommandPacket(uint16_t opcode) 31 : Packet( 32 DATA_TYPE_COMMAND, 33 {static_cast<uint8_t>(opcode), static_cast<uint8_t>(opcode >> 8)}) {} 34 35CommandPacket::CommandPacket(vector<uint8_t> header, vector<uint8_t> payload) 36 : Packet(DATA_TYPE_COMMAND, std::move(header)) { 37 AddPayloadOctets(payload.size(), std::move(payload)); 38} 39 40uint16_t CommandPacket::GetOpcode() const { 41 return 0 | (GetHeader()[0] | (GetHeader()[1] << 8)); 42} 43 44uint8_t CommandPacket::GetOGF() const { 45 return HCI_OGF(GetOpcode()); 46} 47 48uint16_t CommandPacket::GetOCF() const { 49 return HCI_OCF(GetOpcode()); 50} 51 52} // namespace test_vendor_lib 53