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 #pragma once 18 19 #include <cstdint> 20 21 #include <log/log.h> 22 23 #include "include/link.h" 24 #include "packets/link_layer/link_layer_packet_view.h" 25 #include "packets/packet_view.h" 26 27 namespace test_vendor_lib { 28 namespace packets { 29 30 class LeAdvertisementView : public PacketView<true>, public LeAdvertisement { 31 public: 32 LeAdvertisementView(const LeAdvertisementView&) = default; 33 virtual ~LeAdvertisementView() = default; 34 GetLeAdvertisementView(const LinkLayerPacketView & view)35 static LeAdvertisementView GetLeAdvertisementView(const LinkLayerPacketView& view) { 36 CHECK(view.GetType() == Link::PacketType::LE_ADVERTISEMENT || view.GetType() == Link::PacketType::LE_SCAN_RESPONSE); 37 return LeAdvertisementView(view.GetPayload()); 38 } 39 GetAddressType()40 AddressType GetAddressType() { 41 return static_cast<AddressType>(at(0)); 42 } GetAdvertisementType()43 AdvertisementType GetAdvertisementType() { 44 return static_cast<AdvertisementType>(at(1)); 45 } GetData()46 Iterator<true> GetData() { 47 return begin() + 2 * sizeof(uint8_t); 48 } 49 50 private: 51 LeAdvertisementView() = delete; LeAdvertisementView(const PacketView<true> & view)52 LeAdvertisementView(const PacketView<true>& view) : PacketView(view) {} 53 }; 54 55 } // namespace packets 56 } // namespace test_vendor_lib 57