1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 #include "fake_l2cap.h" 17 #include "pw_bluetooth_sapphire/internal/host/common/byte_buffer.h" 18 #include "pw_bluetooth_sapphire/internal/host/common/packet_view.h" 19 #include "pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h" 20 #include "pw_bluetooth_sapphire/internal/host/l2cap/fake_l2cap.h" 21 #include "pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h" 22 #include "pw_bluetooth_sapphire/internal/host/sdp/server.h" 23 #include "pw_bluetooth_sapphire/internal/host/testing/fake_dynamic_channel.h" 24 25 namespace bt::testing { 26 27 // Emulate Sdp Server capability leveraging the production SDP server to 28 // generate response packets as necessary. 29 class FakeSdpServer { 30 public: 31 // Initialize a FakeSdpServer instance and create an associated instance of 32 // the production SDP server. 33 explicit FakeSdpServer(pw::async::Dispatcher& pw_dispatcher); 34 35 // Register this FakeSdpServer as a service on PSM l2cap::kSDP on |l2cap|. 36 // Any channel registered with this service will have its packet handler 37 // calllback set to FakeSdpServer::HandleSdu() 38 void RegisterWithL2cap(FakeL2cap* l2cap); 39 40 // Handle an inbound packet |sdu| using the production SDP server instance, 41 // and then respond using the |channel| send_packet_callback. 42 void HandleSdu(FakeDynamicChannel::WeakPtr channel, const ByteBuffer& sdu); 43 44 // Return the production SDP server associated with this FakeSdpServer. server()45 sdp::Server* server() { return &server_; } 46 47 private: 48 std::unique_ptr<l2cap::testing::FakeL2cap> l2cap_; 49 50 // The production SDP server associated with this FakeSdpServer, 51 sdp::Server server_; 52 53 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(FakeSdpServer); 54 }; 55 56 } // namespace bt::testing 57