diff --git a/wifi/1.0/default/Android.mk b/wifi/1.0/default/Android.mk index ecb16e2549..3fd5fbae4c 100644 --- a/wifi/1.0/default/Android.mk +++ b/wifi/1.0/default/Android.mk @@ -25,6 +25,7 @@ LOCAL_SRC_FILES := \ wifi_legacy_hal.cpp \ wifi_nan_iface.cpp \ wifi_p2p_iface.cpp \ + wifi_rtt_controller.cpp \ wifi_sta_iface.cpp LOCAL_SHARED_LIBRARIES := \ android.hardware.wifi@1.0 \ diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp index d0bdd39c50..82dce942d0 100644 --- a/wifi/1.0/default/wifi_chip.cpp +++ b/wifi/1.0/default/wifi_chip.cpp @@ -346,11 +346,30 @@ Return WifiChip::getStaIface(const hidl_string& ifname, return Void(); } +Return WifiChip::createRttController(const sp& bound_iface, + createRttController_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + sp rtt = new WifiRttController(bound_iface, legacy_hal_); + rtt_controllers_.emplace_back(rtt); + cb(rtt); + return Void(); +} + void WifiChip::invalidateAndRemoveAllIfaces() { invalidateAndClear(ap_iface_); invalidateAndClear(nan_iface_); invalidateAndClear(p2p_iface_); invalidateAndClear(sta_iface_); + // Since all the ifaces are invalid now, all RTT controller objects + // using those ifaces also need to be invalidated. + for (const auto& rtt : rtt_controllers_) { + rtt->invalidate(); + } + rtt_controllers_.clear(); } } // namespace implementation diff --git a/wifi/1.0/default/wifi_chip.h b/wifi/1.0/default/wifi_chip.h index d191e8f007..94ffa63ec2 100644 --- a/wifi/1.0/default/wifi_chip.h +++ b/wifi/1.0/default/wifi_chip.h @@ -26,6 +26,7 @@ #include "wifi_legacy_hal.h" #include "wifi_nan_iface.h" #include "wifi_p2p_iface.h" +#include "wifi_rtt_controller.h" #include "wifi_sta_iface.h" namespace android { @@ -82,6 +83,8 @@ class WifiChip : public IWifiChip { Return getStaIfaceNames(getStaIfaceNames_cb cb) override; Return getStaIface(const hidl_string& ifname, getStaIface_cb cb) override; + Return createRttController(const sp& bound_iface, + createRttController_cb cb) override; private: void invalidateAndRemoveAllIfaces(); @@ -93,6 +96,7 @@ class WifiChip : public IWifiChip { sp nan_iface_; sp p2p_iface_; sp sta_iface_; + std::vector> rtt_controllers_; bool is_valid_; DISALLOW_COPY_AND_ASSIGN(WifiChip); diff --git a/wifi/1.0/default/wifi_rtt_controller.cpp b/wifi/1.0/default/wifi_rtt_controller.cpp new file mode 100644 index 0000000000..e2df1a85f7 --- /dev/null +++ b/wifi/1.0/default/wifi_rtt_controller.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wifi_rtt_controller.h" + +#include + +#include "failure_reason_util.h" + +namespace android { +namespace hardware { +namespace wifi { +namespace V1_0 { +namespace implementation { + +WifiRttController::WifiRttController( + const sp& bound_iface, + const std::weak_ptr legacy_hal) + : bound_iface_(bound_iface), legacy_hal_(legacy_hal), is_valid_(true) {} + +void WifiRttController::invalidate() { + legacy_hal_.reset(); + is_valid_ = false; +} + +Return WifiRttController::getBoundIface(getBoundIface_cb cb) { + cb(bound_iface_); + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace wifi +} // namespace hardware +} // namespace android diff --git a/wifi/1.0/default/wifi_rtt_controller.h b/wifi/1.0/default/wifi_rtt_controller.h new file mode 100644 index 0000000000..8d78b93e2f --- /dev/null +++ b/wifi/1.0/default/wifi_rtt_controller.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WIFI_RTT_CONTROLLER_H_ +#define WIFI_RTT_CONTROLLER_H_ + +#include +#include +#include + +#include "wifi_legacy_hal.h" + +namespace android { +namespace hardware { +namespace wifi { +namespace V1_0 { +namespace implementation { + +/** + * HIDL interface object used to control all RTT operations. + */ +class WifiRttController : public IWifiRttController { + public: + WifiRttController(const sp& bound_iface, + const std::weak_ptr legacy_hal); + // Refer to |WifiChip::invalidate()|. + void invalidate(); + + // HIDL methods exposed. + Return getBoundIface(getBoundIface_cb cb) override; + + private: + sp bound_iface_; + std::weak_ptr legacy_hal_; + bool is_valid_; + + DISALLOW_COPY_AND_ASSIGN(WifiRttController); +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace wifi +} // namespace hardware +} // namespace android + +#endif // WIFI_RTT_CONTROLLER_H_