• 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 "link_layer_packet_view.h"
18 #include "base/logging.h"
19 
20 namespace test_vendor_lib {
21 constexpr size_t Link::kSizeBytes;
22 constexpr size_t Link::kTypeBytes;
23 
24 namespace packets {
LinkLayerPacketView(std::shared_ptr<std::vector<uint8_t>> raw)25 LinkLayerPacketView::LinkLayerPacketView(std::shared_ptr<std::vector<uint8_t>> raw) : PacketView<true>(raw) {}
26 
Create(std::shared_ptr<std::vector<uint8_t>> raw)27 LinkLayerPacketView LinkLayerPacketView::Create(std::shared_ptr<std::vector<uint8_t>> raw) {
28   CHECK(raw->size() >= Link::kSizeBytes + Link::kTypeBytes + 2 * Address::kLength);
29   return LinkLayerPacketView(raw);
30 }
31 
GetType() const32 Link::PacketType LinkLayerPacketView::GetType() const {
33   return static_cast<Link::PacketType>(at(Link::kSizeBytes));
34 }
35 
GetSourceAddress() const36 Address LinkLayerPacketView::GetSourceAddress() const {
37   size_t offset = Link::kSizeBytes + Link::kTypeBytes;
38   return (begin() + offset).extract<Address>();
39 }
40 
GetDestinationAddress() const41 Address LinkLayerPacketView::GetDestinationAddress() const {
42   size_t offset = Link::kSizeBytes + Link::kTypeBytes + Address::kLength;
43   return (begin() + offset).extract<Address>();
44 }
45 
GetPayload() const46 PacketView<true> LinkLayerPacketView::GetPayload() const {
47   return SubViewLittleEndian(Link::kSizeBytes + Link::kTypeBytes + 2 * Address::kLength, size());
48 }
49 
50 }  // namespace packets
51 }  // namespace test_vendor_lib
52