1 /* 2 * Copyright 2022 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 <memory> 20 #include <string> 21 #include <utility> 22 23 #include "common/contextual_callback.h" 24 #include "hci/hci_packets.h" 25 #include "module.h" 26 27 namespace bluetooth { 28 namespace hci { 29 30 // The RemoteNameRequestModule handles Remote Name Requests, which produce both Remote Name Request 31 // Completed events, and Remote Host Supported Features Notification events. 32 33 using CompletionCallback = common::ContextualOnceCallback<void(ErrorCode)>; 34 using RemoteHostSupportedFeaturesCallback = common::ContextualOnceCallback<void(uint64_t)>; 35 using RemoteNameCallback = 36 common::ContextualOnceCallback<void(ErrorCode, std::array<uint8_t, 248>)>; 37 38 // Historical note: This class is intended to provide a shim at the *HCI* layer, so legacy Remote 39 // Name Requests can interoperate with the GD ACL scheduler. Thus, we intentionally do not merge 40 // identical requests, cache responses, or handle request timeouts - we leave this to our callers. 41 // When GD clients start to use this module, richer functionality should be added. 42 class RemoteNameRequestModule : public bluetooth::Module { 43 public: 44 // Dispatch a Remote Name Request 45 void StartRemoteNameRequest( 46 Address address, 47 std::unique_ptr<RemoteNameRequestBuilder> request, 48 CompletionCallback on_completion, 49 RemoteHostSupportedFeaturesCallback on_remote_host_supported_features_notification, 50 RemoteNameCallback on_remote_name_complete); 51 52 // Cancel a Remote Name Request 53 void CancelRemoteNameRequest(Address address); 54 55 // Due to controller bugs (b/184239841), an ACL connection completion is sometimes reported in 56 // place of an RNR completion This method lets the ACL manager inform the RNR module if this 57 // happens, since we don't get the appropriate HCI event. 58 void ReportRemoteNameRequestCancellation(Address address); 59 60 private: 61 struct impl; 62 std::unique_ptr<impl> pimpl_; 63 64 protected: 65 void ListDependencies(ModuleList* list) const override; 66 void Start() override; 67 void Stop() override; ToString()68 std::string ToString() const override { 69 return std::string("RemoteNameRequestModule"); 70 } 71 72 public: 73 static const ModuleFactory Factory; 74 RemoteNameRequestModule(); 75 ~RemoteNameRequestModule(); 76 }; 77 78 } // namespace hci 79 } // namespace bluetooth