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 #include <string> 21 #include <vector> 22 23 #include "link.h" 24 #include "packets/link_layer/command_builder.h" 25 #include "packets/link_layer/disconnect_builder.h" 26 #include "packets/link_layer/encrypt_connection_builder.h" 27 #include "packets/link_layer/inquiry_builder.h" 28 #include "packets/link_layer/inquiry_response_builder.h" 29 #include "packets/link_layer/io_capability_builder.h" 30 #include "packets/link_layer/io_capability_negative_response_builder.h" 31 #include "packets/link_layer/le_advertisement_builder.h" 32 #include "packets/link_layer/page_builder.h" 33 #include "packets/link_layer/page_response_builder.h" 34 #include "packets/link_layer/response_builder.h" 35 #include "packets/link_layer/view_forwarder_builder.h" 36 #include "packets/packet_builder.h" 37 #include "types/address.h" 38 39 namespace test_vendor_lib { 40 namespace packets { 41 42 // Link-layer packets are an abstraction of LMP PDUs. 43 class LinkLayerPacketBuilder : PacketBuilder<true> { 44 public: 45 virtual ~LinkLayerPacketBuilder() = default; 46 47 static std::shared_ptr<LinkLayerPacketBuilder> WrapAcl(std::unique_ptr<ViewForwarderBuilder> acl, 48 const Address& source, const Address& dest); 49 static std::shared_ptr<LinkLayerPacketBuilder> WrapCommand(std::unique_ptr<CommandBuilder> command, 50 const Address& source, const Address& dest); 51 static std::shared_ptr<LinkLayerPacketBuilder> WrapDisconnect(std::unique_ptr<DisconnectBuilder> disconnect, 52 const Address& source, const Address& dest); 53 static std::shared_ptr<LinkLayerPacketBuilder> WrapEncryptConnection( 54 std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest); 55 static std::shared_ptr<LinkLayerPacketBuilder> WrapEncryptConnectionResponse( 56 std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest); 57 static std::shared_ptr<LinkLayerPacketBuilder> WrapInquiry(std::unique_ptr<InquiryBuilder> inquiry, 58 const Address& source); 59 static std::shared_ptr<LinkLayerPacketBuilder> WrapInquiryResponse( 60 std::unique_ptr<InquiryResponseBuilder> inquiry_response, const Address& source, const Address& dest); 61 static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityRequest( 62 std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest); 63 static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityResponse( 64 std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest); 65 static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityNegativeResponse( 66 std::unique_ptr<IoCapabilityNegativeResponseBuilder> io_capability_negative_response, const Address& source, 67 const Address& dest); 68 static std::shared_ptr<LinkLayerPacketBuilder> WrapLeAdvertisement( 69 std::unique_ptr<LeAdvertisementBuilder> advertisement, const Address& source); 70 static std::shared_ptr<LinkLayerPacketBuilder> WrapLeScan(const Address& source, const Address& dest); 71 static std::shared_ptr<LinkLayerPacketBuilder> WrapLeScanResponse( 72 std::unique_ptr<LeAdvertisementBuilder> scan_response, const Address& source, const Address& dest); 73 static std::shared_ptr<LinkLayerPacketBuilder> WrapPage(std::unique_ptr<PageBuilder> page, const Address& source, 74 const Address& dest); 75 static std::shared_ptr<LinkLayerPacketBuilder> WrapPageResponse(std::unique_ptr<PageResponseBuilder> page_response, 76 const Address& source, const Address& dest); 77 static std::shared_ptr<LinkLayerPacketBuilder> WrapResponse(const std::unique_ptr<ResponseBuilder> response, 78 const Address& source, const Address& dest); 79 static std::shared_ptr<LinkLayerPacketBuilder> WrapSco(std::unique_ptr<ViewForwarderBuilder> sco, 80 const Address& source, const Address& dest); 81 static std::shared_ptr<LinkLayerPacketBuilder> ReWrap(const std::shared_ptr<std::vector<uint8_t>> raw_packet); 82 83 virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override; 84 85 virtual size_t size() const override; 86 87 private: 88 LinkLayerPacketBuilder(const LinkLayerPacketBuilder&) = delete; 89 LinkLayerPacketBuilder() = delete; 90 LinkLayerPacketBuilder(Link::PacketType type, const Address& source, const Address& dest); 91 LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> builder, const Address& source, 92 const Address& dest); 93 LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> builder, const Address& source); 94 Link::PacketType type_; 95 Address source_addr_; 96 Address dest_addr_; 97 std::unique_ptr<PacketBuilder> builder_; 98 }; 99 100 } // namespace packets 101 } // namespace test_vendor_lib 102