From 35d958c43f48377db80b0ad70731b9e3d8400f39 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 6 Oct 2016 16:47:38 -0700 Subject: [PATCH] wifi: Add Iface related method implementations in WifiChip Add the iface creation/retrieval/list method implementations in WifiChip. WifiChip does not yet support the chip mode configuration. So, all |createIface| method calls succeed today. Once the mode configuration changes are in place, we will deny iface creation requests depending on the iface combination supported in the current mode. The iface objects are all invalidated and deleted on mode switches and when HAL is stopped. While there, Change the |callbacks_| member to std::vector instead of std::set. We don't really need a set to store the list of callbacks. Bug: 31943042 Test: Compiles Change-Id: Ic94864c8b11aabbe569b5157d68d6056364a3c4c --- wifi/1.0/default/wifi_chip.cpp | 226 +++++++++++++++++++++++++++++++-- wifi/1.0/default/wifi_chip.h | 30 ++++- 2 files changed, 245 insertions(+), 11 deletions(-) diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp index 719a6b93c4..d0bdd39c50 100644 --- a/wifi/1.0/default/wifi_chip.cpp +++ b/wifi/1.0/default/wifi_chip.cpp @@ -20,6 +20,32 @@ #include "failure_reason_util.h" +namespace { +using android::sp; +using android::hardware::hidl_vec; +using android::hardware::hidl_string; + +hidl_vec createHidlVecOfIfaceNames(const std::string& ifname) { + std::vector ifnames; + if (!ifname.empty()) { + hidl_string hidl_ifname; + hidl_ifname = ifname.c_str(); + ifnames.emplace_back(hidl_ifname); + } + hidl_vec hidl_ifnames; + hidl_ifnames.setToExternal(ifnames.data(), ifnames.size()); + return hidl_ifnames; +} + +template +void invalidateAndClear(sp& iface) { + if (iface.get()) { + iface->invalidate(); + iface.clear(); + } +} +} // namepsace + namespace android { namespace hardware { namespace wifi { @@ -28,11 +54,13 @@ namespace implementation { WifiChip::WifiChip(ChipId chip_id, const std::weak_ptr legacy_hal) - : chip_id_(chip_id), legacy_hal_(legacy_hal) {} + : chip_id_(chip_id), legacy_hal_(legacy_hal), is_valid_(true) {} void WifiChip::invalidate() { + invalidateAndRemoveAllIfaces(); legacy_hal_.reset(); callbacks_.clear(); + is_valid_ = false; } Return WifiChip::getId() { @@ -41,15 +69,15 @@ Return WifiChip::getId() { Return WifiChip::registerEventCallback( const sp& callback) { - if (!legacy_hal_.lock()) + if (!is_valid_) return Void(); // TODO(b/31632518): remove the callback when the client is destroyed - callbacks_.insert(callback); + callbacks_.emplace_back(callback); return Void(); } Return WifiChip::getAvailableModes(getAvailableModes_cb cb) { - if (!legacy_hal_.lock()) { + if (!is_valid_) { cb(hidl_vec()); return Void(); } else { @@ -59,21 +87,23 @@ Return WifiChip::getAvailableModes(getAvailableModes_cb cb) { } Return WifiChip::configureChip(uint32_t /*mode_id*/) { - if (!legacy_hal_.lock()) + if (!is_valid_) return Void(); + + invalidateAndRemoveAllIfaces(); // TODO add implementation return Void(); } Return WifiChip::getMode() { - if (!legacy_hal_.lock()) + if (!is_valid_) return 0; // TODO add implementation return 0; } Return WifiChip::requestChipDebugInfo() { - if (!legacy_hal_.lock()) + if (!is_valid_) return Void(); IWifiChipEventCallback::ChipDebugInfo result; @@ -102,7 +132,7 @@ Return WifiChip::requestChipDebugInfo() { } Return WifiChip::requestDriverDebugDump() { - if (!legacy_hal_.lock()) + if (!is_valid_) return Void(); std::pair> ret = @@ -124,7 +154,7 @@ Return WifiChip::requestDriverDebugDump() { } Return WifiChip::requestFirmwareDebugDump() { - if (!legacy_hal_.lock()) + if (!is_valid_) return Void(); std::pair> ret = @@ -145,6 +175,184 @@ Return WifiChip::requestFirmwareDebugDump() { return Void(); } +Return WifiChip::createApIface(createApIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getApIfaceName(); + ap_iface_ = new WifiApIface(ifname, legacy_hal_); + cb(ap_iface_); + return Void(); +} + +Return WifiChip::getApIfaceNames(getApIfaceNames_cb cb) { + if (!is_valid_) { + cb(hidl_vec()); + return Void(); + } + + std::string ifname; + if (ap_iface_.get()) { + ifname = legacy_hal_.lock()->getApIfaceName().c_str(); + } + cb(createHidlVecOfIfaceNames(ifname)); + return Void(); +} + +Return WifiChip::getApIface(const hidl_string& ifname, getApIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + if (ap_iface_.get() && + (ifname.c_str() == legacy_hal_.lock()->getApIfaceName())) { + cb(ap_iface_); + } else { + cb(nullptr); + } + return Void(); +} + +Return WifiChip::createNanIface(createNanIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getNanIfaceName(); + nan_iface_ = new WifiNanIface(ifname, legacy_hal_); + cb(nan_iface_); + return Void(); +} + +Return WifiChip::getNanIfaceNames(getNanIfaceNames_cb cb) { + if (!is_valid_) { + cb(hidl_vec()); + return Void(); + } + + std::string ifname; + if (nan_iface_.get()) { + ifname = legacy_hal_.lock()->getNanIfaceName().c_str(); + } + cb(createHidlVecOfIfaceNames(ifname)); + return Void(); +} + +Return WifiChip::getNanIface(const hidl_string& ifname, + getNanIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + if (nan_iface_.get() && + (ifname.c_str() == legacy_hal_.lock()->getNanIfaceName())) { + cb(nan_iface_); + } else { + cb(nullptr); + } + return Void(); +} + +Return WifiChip::createP2pIface(createP2pIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getP2pIfaceName(); + p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_); + cb(p2p_iface_); + return Void(); +} + +Return WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb cb) { + if (!is_valid_) { + cb(hidl_vec()); + return Void(); + } + + std::string ifname; + if (p2p_iface_.get()) { + ifname = legacy_hal_.lock()->getP2pIfaceName().c_str(); + } + cb(createHidlVecOfIfaceNames(ifname)); + return Void(); +} + +Return WifiChip::getP2pIface(const hidl_string& ifname, + getP2pIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + if (p2p_iface_.get() && + (ifname.c_str() == legacy_hal_.lock()->getP2pIfaceName())) { + cb(p2p_iface_); + } else { + cb(nullptr); + } + return Void(); +} + +Return WifiChip::createStaIface(createStaIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getStaIfaceName(); + sta_iface_ = new WifiStaIface(ifname, legacy_hal_); + cb(sta_iface_); + return Void(); +} + +Return WifiChip::getStaIfaceNames(getStaIfaceNames_cb cb) { + if (!is_valid_) { + cb(hidl_vec()); + return Void(); + } + + std::string ifname; + if (sta_iface_.get()) { + ifname = legacy_hal_.lock()->getStaIfaceName().c_str(); + } + cb(createHidlVecOfIfaceNames(ifname)); + return Void(); +} + +Return WifiChip::getStaIface(const hidl_string& ifname, + getStaIface_cb cb) { + if (!is_valid_) { + cb(nullptr); + return Void(); + } + + if (sta_iface_.get() && + (ifname.c_str() == legacy_hal_.lock()->getStaIfaceName())) { + cb(sta_iface_); + } else { + cb(nullptr); + } + return Void(); +} + +void WifiChip::invalidateAndRemoveAllIfaces() { + invalidateAndClear(ap_iface_); + invalidateAndClear(nan_iface_); + invalidateAndClear(p2p_iface_); + invalidateAndClear(sta_iface_); +} + } // namespace implementation } // namespace V1_0 } // namespace wifi diff --git a/wifi/1.0/default/wifi_chip.h b/wifi/1.0/default/wifi_chip.h index 84e5470376..d191e8f007 100644 --- a/wifi/1.0/default/wifi_chip.h +++ b/wifi/1.0/default/wifi_chip.h @@ -17,12 +17,16 @@ #ifndef WIFI_CHIP_H_ #define WIFI_CHIP_H_ -#include +#include #include #include +#include "wifi_ap_iface.h" #include "wifi_legacy_hal.h" +#include "wifi_nan_iface.h" +#include "wifi_p2p_iface.h" +#include "wifi_sta_iface.h" namespace android { namespace hardware { @@ -63,11 +67,33 @@ class WifiChip : public IWifiChip { Return requestChipDebugInfo() override; Return requestDriverDebugDump() override; Return requestFirmwareDebugDump() override; + Return createApIface(createApIface_cb cb) override; + Return getApIfaceNames(getApIfaceNames_cb cb) override; + Return getApIface(const hidl_string& ifname, getApIface_cb cb) override; + Return createNanIface(createNanIface_cb cb) override; + Return getNanIfaceNames(getNanIfaceNames_cb cb) override; + Return getNanIface(const hidl_string& ifname, + getNanIface_cb cb) override; + Return createP2pIface(createP2pIface_cb cb) override; + Return getP2pIfaceNames(getP2pIfaceNames_cb cb) override; + Return getP2pIface(const hidl_string& ifname, + getP2pIface_cb cb) override; + Return createStaIface(createStaIface_cb cb) override; + Return getStaIfaceNames(getStaIfaceNames_cb cb) override; + Return getStaIface(const hidl_string& ifname, + getStaIface_cb cb) override; private: + void invalidateAndRemoveAllIfaces(); + ChipId chip_id_; std::weak_ptr legacy_hal_; - std::set> callbacks_; + std::vector> callbacks_; + sp ap_iface_; + sp nan_iface_; + sp p2p_iface_; + sp sta_iface_; + bool is_valid_; DISALLOW_COPY_AND_ASSIGN(WifiChip); };