1 /* 2 * Copyright (C) 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 #ifndef WIFI_RTT_CONTROLLER_H_ 18 #define WIFI_RTT_CONTROLLER_H_ 19 20 #include <aidl/android/hardware/wifi/BnWifiRttController.h> 21 #include <aidl/android/hardware/wifi/IWifiRttControllerEventCallback.h> 22 #include <aidl/android/hardware/wifi/IWifiStaIface.h> 23 #include <android-base/macros.h> 24 25 #include "wifi_legacy_hal.h" 26 27 namespace aidl { 28 namespace android { 29 namespace hardware { 30 namespace wifi { 31 32 /** 33 * AIDL interface object used to control all RTT operations. 34 */ 35 class WifiRttController : public BnWifiRttController { 36 public: 37 WifiRttController(const std::string& iface_name, 38 const std::shared_ptr<IWifiStaIface>& bound_iface, 39 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal); 40 // Factory method - use instead of default constructor. 41 static std::shared_ptr<WifiRttController> create( 42 const std::string& iface_name, const std::shared_ptr<IWifiStaIface>& bound_iface, 43 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal); 44 45 // Refer to |WifiChip::invalidate()|. 46 void invalidate(); 47 bool isValid(); 48 std::vector<std::shared_ptr<IWifiRttControllerEventCallback>> getEventCallbacks(); 49 std::string getIfaceName(); 50 51 // AIDL methods exposed. 52 ndk::ScopedAStatus getBoundIface(std::shared_ptr<IWifiStaIface>* _aidl_return) override; 53 ndk::ScopedAStatus registerEventCallback( 54 const std::shared_ptr<IWifiRttControllerEventCallback>& callback) override; 55 ndk::ScopedAStatus rangeRequest(int32_t in_cmdId, 56 const std::vector<RttConfig>& in_rttConfigs) override; 57 ndk::ScopedAStatus rangeCancel(int32_t in_cmdId, 58 const std::vector<MacAddress>& in_addrs) override; 59 ndk::ScopedAStatus getCapabilities(RttCapabilities* _aidl_return) override; 60 ndk::ScopedAStatus setLci(int32_t in_cmdId, const RttLciInformation& in_lci) override; 61 ndk::ScopedAStatus setLcr(int32_t in_cmdId, const RttLcrInformation& in_lcr) override; 62 ndk::ScopedAStatus getResponderInfo(RttResponder* _aidl_return) override; 63 ndk::ScopedAStatus enableResponder(int32_t in_cmdId, const WifiChannelInfo& in_channelHint, 64 int32_t in_maxDurationInSeconds, 65 const RttResponder& in_info) override; 66 ndk::ScopedAStatus disableResponder(int32_t in_cmdId) override; 67 68 private: 69 // Corresponding worker functions for the AIDL methods. 70 std::pair<std::shared_ptr<IWifiStaIface>, ndk::ScopedAStatus> getBoundIfaceInternal(); 71 ndk::ScopedAStatus registerEventCallbackInternal( 72 const std::shared_ptr<IWifiRttControllerEventCallback>& callback); 73 ndk::ScopedAStatus rangeRequestInternal(int32_t cmd_id, 74 const std::vector<RttConfig>& rtt_configs); 75 ndk::ScopedAStatus rangeCancelInternal(int32_t cmd_id, const std::vector<MacAddress>& addrs); 76 std::pair<RttCapabilities, ndk::ScopedAStatus> getCapabilitiesInternal(); 77 ndk::ScopedAStatus setLciInternal(int32_t cmd_id, const RttLciInformation& lci); 78 ndk::ScopedAStatus setLcrInternal(int32_t cmd_id, const RttLcrInformation& lcr); 79 std::pair<RttResponder, ndk::ScopedAStatus> getResponderInfoInternal(); 80 ndk::ScopedAStatus enableResponderInternal(int32_t cmd_id, const WifiChannelInfo& channel_hint, 81 int32_t max_duration_seconds, 82 const RttResponder& info); 83 ndk::ScopedAStatus disableResponderInternal(int32_t cmd_id); 84 85 void setWeakPtr(std::weak_ptr<WifiRttController> ptr); 86 87 std::string ifname_; 88 std::shared_ptr<IWifiStaIface> bound_iface_; 89 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; 90 std::vector<std::shared_ptr<IWifiRttControllerEventCallback>> event_callbacks_; 91 std::weak_ptr<WifiRttController> weak_ptr_this_; 92 bool is_valid_; 93 94 DISALLOW_COPY_AND_ASSIGN(WifiRttController); 95 }; 96 97 } // namespace wifi 98 } // namespace hardware 99 } // namespace android 100 } // namespace aidl 101 102 #endif // WIFI_RTT_CONTROLLER_H_ 103