1 /* 2 * Copyright 2019 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 <chrono> 20 #include <map> 21 22 #include "address.h" 23 #include "class_of_device.h" 24 #include "common/bidi_queue.h" 25 #include "common/callback.h" 26 #include "hal/hci_hal.h" 27 #include "hci/hci_packets.h" 28 #include "hci/le_advertising_interface.h" 29 #include "hci/le_scanning_interface.h" 30 #include "hci/le_security_interface.h" 31 #include "hci/security_interface.h" 32 #include "module.h" 33 #include "os/utils.h" 34 35 namespace bluetooth { 36 namespace hci { 37 38 class HciLayer : public Module { 39 public: 40 HciLayer(); 41 virtual ~HciLayer(); 42 DISALLOW_COPY_AND_ASSIGN(HciLayer); 43 44 virtual void EnqueueCommand(std::unique_ptr<CommandPacketBuilder> command, 45 common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler); 46 47 virtual void EnqueueCommand(std::unique_ptr<CommandPacketBuilder> command, 48 common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler); 49 50 virtual common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* GetAclQueueEnd(); 51 52 virtual void RegisterEventHandler(EventCode event_code, common::Callback<void(EventPacketView)> event_handler, 53 os::Handler* handler); 54 55 virtual void UnregisterEventHandler(EventCode event_code); 56 57 virtual void RegisterLeEventHandler(SubeventCode subevent_code, common::Callback<void(LeMetaEventView)> event_handler, 58 os::Handler* handler); 59 60 virtual void UnregisterLeEventHandler(SubeventCode subevent_code); 61 62 SecurityInterface* GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler, os::Handler* handler); 63 64 LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler, 65 os::Handler* handler); 66 67 LeAdvertisingInterface* GetLeAdvertisingInterface(common::Callback<void(LeMetaEventView)> event_handler, 68 os::Handler* handler); 69 70 LeScanningInterface* GetLeScanningInterface(common::Callback<void(LeMetaEventView)> event_handler, 71 os::Handler* handler); 72 73 static const ModuleFactory Factory; 74 75 void ListDependencies(ModuleList* list) override; 76 77 void Start() override; 78 79 void Stop() override; 80 81 std::string ToString() const override; 82 static constexpr std::chrono::milliseconds kHciTimeoutMs = std::chrono::milliseconds(2000); 83 84 private: 85 struct impl; 86 std::unique_ptr<impl> impl_; 87 }; 88 } // namespace hci 89 } // namespace bluetooth 90