• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 #include "packets/hci/command_packet_view.h"
18 
19 #include <base/logging.h>
20 
21 using std::vector;
22 
23 namespace test_vendor_lib {
24 namespace packets {
25 
CommandPacketView(std::shared_ptr<std::vector<uint8_t>> packet)26 CommandPacketView::CommandPacketView(std::shared_ptr<std::vector<uint8_t>> packet) : PacketView<true>(packet) {}
27 
Create(std::shared_ptr<std::vector<uint8_t>> packet)28 CommandPacketView CommandPacketView::Create(std::shared_ptr<std::vector<uint8_t>> packet) {
29   return CommandPacketView(packet);
30 }
31 
GetOpcode() const32 uint16_t CommandPacketView::GetOpcode() const {
33   return begin().extract<uint16_t>();
34 }
35 
GetPayload() const36 PacketView<true> CommandPacketView::GetPayload() const {
37   uint8_t payload_size = (begin() + sizeof(uint16_t)).extract<uint8_t>();
38   CHECK(static_cast<uint8_t>(size() - sizeof(uint16_t) - sizeof(uint8_t)) == payload_size)
39       << "Malformed Command packet payload_size " << payload_size << " + 2 != " << size();
40   return SubViewLittleEndian(sizeof(uint16_t) + sizeof(uint8_t), size());
41 }
42 
43 }  // namespace packets
44 }  // namespace test_vendor_lib
45