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 <fstream> 21 #include <memory> 22 #include <string> 23 24 #include "hci/address.h" 25 #include "model/devices/device.h" 26 #include "packets/link_layer_packets.h" 27 #include "phy.h" 28 29 namespace rootcanal { 30 31 namespace bredr_bb { 32 class BaseBandPacketBuilder; 33 } // namespace bredr_bb 34 35 using ::bluetooth::hci::Address; 36 37 class BaseBandSniffer : public Device { 38 public: 39 BaseBandSniffer(const std::string& filename); 40 ~BaseBandSniffer() = default; 41 Create(const std::string & filename)42 static std::shared_ptr<BaseBandSniffer> Create(const std::string& filename) { 43 return std::make_shared<BaseBandSniffer>(filename); 44 } 45 46 // Return a string representation of the type of device. GetTypeString()47 virtual std::string GetTypeString() const override { 48 return "baseband_sniffer"; 49 } 50 51 virtual void ReceiveLinkLayerPacket( 52 model::packets::LinkLayerPacketView packet, Phy::Type type, 53 int8_t rssi) override; 54 55 private: 56 void AppendRecord(std::unique_ptr<bredr_bb::BaseBandPacketBuilder> packet); 57 std::ofstream output_; 58 }; 59 60 } // namespace rootcanal 61