Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 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 "common/callback.h" |
Martin Brabham | 94db40c | 2019-03-29 10:24:52 -0700 | [diff] [blame] | 20 | #include "hci/address.h" |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 21 | #include "hci/hci_packets.h" |
| 22 | #include "module.h" |
| 23 | #include "os/handler.h" |
| 24 | |
| 25 | namespace bluetooth { |
| 26 | namespace hci { |
| 27 | |
| 28 | class Controller : public Module { |
| 29 | public: |
| 30 | Controller(); |
| 31 | virtual ~Controller(); |
| 32 | DISALLOW_COPY_AND_ASSIGN(Controller); |
| 33 | |
| 34 | virtual void RegisterCompletedAclPacketsCallback( |
| 35 | common::Callback<void(uint16_t /* handle */, uint16_t /* num_packets */)> cb, os::Handler* handler); |
| 36 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 37 | virtual std::string GetControllerLocalName() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 38 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 39 | virtual LocalVersionInformation GetControllerLocalVersionInformation() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 40 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 41 | virtual std::array<uint8_t, 64> GetControllerLocalSupportedCommands() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 42 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 43 | virtual uint64_t GetControllerLocalSupportedFeatures() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 44 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 45 | virtual uint8_t GetControllerLocalExtendedFeaturesMaxPageNumber() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 46 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 47 | virtual uint64_t GetControllerLocalExtendedFeatures(uint8_t page_number) const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 48 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 49 | virtual uint16_t GetControllerAclPacketLength() const; |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 50 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 51 | virtual uint16_t GetControllerNumAclPacketBuffers() const; |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 52 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 53 | virtual uint8_t GetControllerScoPacketLength() const; |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 54 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 55 | virtual uint16_t GetControllerNumScoPacketBuffers() const; |
Hansong Zhang | c443be7 | 2019-06-18 16:04:01 -0700 | [diff] [blame] | 56 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 57 | virtual Address GetControllerMacAddress() const; |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 58 | |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 59 | virtual void SetEventMask(uint64_t event_mask); |
| 60 | |
| 61 | virtual void Reset(); |
| 62 | |
| 63 | virtual void SetEventFilterClearAll(); |
| 64 | |
| 65 | virtual void SetEventFilterInquiryResultAllDevices(); |
| 66 | |
| 67 | virtual void SetEventFilterInquiryResultClassOfDevice(ClassOfDevice class_of_device, |
| 68 | ClassOfDevice class_of_device_mask); |
| 69 | |
| 70 | virtual void SetEventFilterInquiryResultAddress(Address address); |
| 71 | |
| 72 | virtual void SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag); |
| 73 | |
| 74 | virtual void SetEventFilterConnectionSetupClassOfDevice(ClassOfDevice class_of_device, |
| 75 | ClassOfDevice class_of_device_mask, |
| 76 | AutoAcceptFlag auto_accept_flag); |
| 77 | |
| 78 | virtual void SetEventFilterConnectionSetupAddress(Address address, AutoAcceptFlag auto_accept_flag); |
| 79 | |
| 80 | virtual void WriteLocalName(std::string local_name); |
| 81 | |
| 82 | virtual void HostBufferSize(uint16_t host_acl_data_packet_length, uint8_t host_synchronous_data_packet_length, |
| 83 | uint16_t host_total_num_acl_data_packets, |
| 84 | uint16_t host_total_num_synchronous_data_packets); |
| 85 | |
| 86 | // LE controller commands |
| 87 | virtual void LeSetEventMask(uint64_t le_event_mask); |
| 88 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 89 | virtual LeBufferSize GetControllerLeBufferSize() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 90 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 91 | virtual uint64_t GetControllerLeLocalSupportedFeatures() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 92 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 93 | virtual uint64_t GetControllerLeSupportedStates() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 94 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 95 | virtual LeMaximumDataLength GetControllerLeMaximumDataLength() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 96 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 97 | virtual uint16_t GetControllerLeMaximumAdvertisingDataLength() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 98 | |
Chris Manton | 9809f87 | 2019-12-09 21:53:45 -0800 | [diff] [blame] | 99 | virtual uint8_t GetControllerLeNumberOfSupportedAdverisingSets() const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 100 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 101 | virtual VendorCapabilities GetControllerVendorCapabilities() const; |
Chienyuan | 1beb9f8 | 2019-09-03 14:24:26 +0800 | [diff] [blame] | 102 | |
Myles Watson | f3916a0 | 2019-11-07 10:26:54 -0800 | [diff] [blame] | 103 | virtual bool IsSupported(OpCode op_code) const; |
Chienyuan | a7ad3fb | 2019-08-15 18:04:32 +0800 | [diff] [blame] | 104 | |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 105 | static const ModuleFactory Factory; |
| 106 | |
Myles Watson | d739905 | 2020-02-12 08:53:39 -0800 | [diff] [blame] | 107 | static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff; |
| 108 | |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 109 | protected: |
| 110 | void ListDependencies(ModuleList* list) override; |
| 111 | |
| 112 | void Start() override; |
| 113 | |
| 114 | void Stop() override; |
| 115 | |
Zongheng Wang | 6fd349a | 2019-11-12 16:14:01 -0800 | [diff] [blame] | 116 | std::string ToString() const override; |
| 117 | |
Myles Watson | b79d5ea | 2019-06-03 16:33:59 -0700 | [diff] [blame] | 118 | private: |
| 119 | struct impl; |
| 120 | std::unique_ptr<impl> impl_; |
| 121 | }; |
| 122 | |
| 123 | } // namespace hci |
| 124 | } // namespace bluetooth |