Home | History | Annotate | Download | only in src
      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 
     25 using std::vector;
     26 
     27 namespace test_vendor_lib {
     28 
     29 CommandPacket::CommandPacket(vector<uint8_t> header)
     30     : Packet(DATA_TYPE_COMMAND, std::move(header)) {}
     31 
     32 CommandPacket::CommandPacket(uint16_t opcode)
     33     : Packet(DATA_TYPE_COMMAND, {static_cast<uint8_t>(opcode),
     34                                  static_cast<uint8_t>(opcode >> 8)}) {}
     35 
     36 CommandPacket::CommandPacket(vector<uint8_t> header, vector<uint8_t> payload)
     37     : Packet(DATA_TYPE_COMMAND, std::move(header)) {
     38   AddPayloadOctets(payload.size(), std::move(payload));
     39 }
     40 
     41 uint16_t CommandPacket::GetOpcode() const {
     42   return 0 | (GetHeader()[0] | (GetHeader()[1] << 8));
     43 }
     44 
     45 uint8_t CommandPacket::GetOGF() const { return HCI_OGF(GetOpcode()); }
     46 
     47 uint16_t CommandPacket::GetOCF() const { return HCI_OCF(GetOpcode()); }
     48 
     49 }  // namespace test_vendor_lib
     50