blob: b0d27e694774c5f6721457e145f71a1bce3dd0c5 [file] [log] [blame]
Myles Watsone22dde22019-01-18 11:42:33 -08001/*
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
Myles Watson1a0a0da2019-10-17 11:36:33 -070019#include "os/log.h"
Myles Watsone22dde22019-01-18 11:42:33 -080020
21using std::vector;
22
23namespace test_vendor_lib {
24namespace packets {
25
26CommandPacketView::CommandPacketView(std::shared_ptr<std::vector<uint8_t>> packet) : PacketView<true>(packet) {}
27
28CommandPacketView CommandPacketView::Create(std::shared_ptr<std::vector<uint8_t>> packet) {
29 return CommandPacketView(packet);
30}
31
32uint16_t CommandPacketView::GetOpcode() const {
33 return begin().extract<uint16_t>();
34}
35
36PacketView<true> CommandPacketView::GetPayload() const {
37 uint8_t payload_size = (begin() + sizeof(uint16_t)).extract<uint8_t>();
Myles Watson1a0a0da2019-10-17 11:36:33 -070038 ASSERT_LOG(static_cast<uint8_t>(size() - sizeof(uint16_t) - sizeof(uint8_t)) == payload_size,
39 "Malformed Command packet payload_size %d + 2 != %d", static_cast<int>(payload_size),
40 static_cast<int>(size()));
Myles Watsone22dde22019-01-18 11:42:33 -080041 return SubViewLittleEndian(sizeof(uint16_t) + sizeof(uint8_t), size());
42}
43
44} // namespace packets
45} // namespace test_vendor_lib