Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 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 | |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 19 | #include "os/log.h" |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 20 | |
| 21 | using std::vector; |
| 22 | |
| 23 | namespace test_vendor_lib { |
| 24 | namespace packets { |
| 25 | |
| 26 | CommandPacketView::CommandPacketView(std::shared_ptr<std::vector<uint8_t>> packet) : PacketView<true>(packet) {} |
| 27 | |
| 28 | CommandPacketView CommandPacketView::Create(std::shared_ptr<std::vector<uint8_t>> packet) { |
| 29 | return CommandPacketView(packet); |
| 30 | } |
| 31 | |
| 32 | uint16_t CommandPacketView::GetOpcode() const { |
| 33 | return begin().extract<uint16_t>(); |
| 34 | } |
| 35 | |
| 36 | PacketView<true> CommandPacketView::GetPayload() const { |
| 37 | uint8_t payload_size = (begin() + sizeof(uint16_t)).extract<uint8_t>(); |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 38 | 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 Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 41 | return SubViewLittleEndian(sizeof(uint16_t) + sizeof(uint8_t), size()); |
| 42 | } |
| 43 | |
| 44 | } // namespace packets |
| 45 | } // namespace test_vendor_lib |