From 3c86852a2e0d9ef8696cf87f2bd0f067862f4e80 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 27 Oct 2016 12:43:49 -0700 Subject: [PATCH] wifi: Use hidl_return_util functions in WifiChip Modify the WifiChip methods to the use the new helper functions. Also, 1. Modify the WifiLegacyHal.requestDriverMemoryDump & WifiLegacyHal.requestDriverMemoryDump to return a vector of |uint8_t| instead of |char| to avoid unnecessary typecasting in the HIDL methods. 2. Remove |createHidlVecOfIfaceNames| helper function as most of the necessary conversion should be handled by hidl_vec/hidl_string constructors. Bug: 32337072 Test: Compiles Change-Id: Ic0b7aa2a5a078e53d5bc5bef18995a3cc0f548a1 --- wifi/1.0/default/wifi_chip.cpp | 590 +++++++++++++-------------- wifi/1.0/default/wifi_chip.h | 32 ++ wifi/1.0/default/wifi_legacy_hal.cpp | 16 +- wifi/1.0/default/wifi_legacy_hal.h | 4 +- 4 files changed, 338 insertions(+), 304 deletions(-) diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp index 4f8545ff48..bc46eec333 100644 --- a/wifi/1.0/default/wifi_chip.cpp +++ b/wifi/1.0/default/wifi_chip.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "wifi_chip.h" - #include +#include "hidl_return_util.h" +#include "wifi_chip.h" #include "wifi_status_util.h" namespace { @@ -25,14 +25,6 @@ using android::sp; using android::hardware::hidl_vec; using android::hardware::hidl_string; -std::vector createHidlVecOfIfaceNames(const std::string& ifname) { - std::vector ifnames; - if (!ifname.empty()) { - ifnames.emplace_back(ifname); - } - return ifnames; -} - template void invalidateAndClear(sp& iface) { if (iface.get()) { @@ -47,6 +39,7 @@ namespace hardware { namespace wifi { namespace V1_0 { namespace implementation { +using hidl_return_util::validateAndCall; WifiChip::WifiChip(ChipId chip_id, const std::weak_ptr legacy_hal) @@ -59,363 +52,173 @@ void WifiChip::invalidate() { is_valid_ = false; } +bool WifiChip::isValid() { + return is_valid_; +} + Return WifiChip::getId(getId_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - UINT32_MAX); - return Void(); - } - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), chip_id_); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getIdInternal, + hidl_status_cb); } Return WifiChip::registerEventCallback( const sp& event_callback, registerEventCallback_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID)); - return Void(); - } - // TODO(b/31632518): remove the callback when the client is destroyed - event_callbacks_.emplace_back(event_callback); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::registerEventCallbackInternal, + hidl_status_cb, + event_callback); } Return WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - // TODO add implementation - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), - hidl_vec()); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getAvailableModesInternal, + hidl_status_cb); } -Return WifiChip::configureChip(uint32_t /*mode_id*/, +Return WifiChip::configureChip(uint32_t mode_id, configureChip_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID)); - return Void(); - } - - invalidateAndRemoveAllIfaces(); - // TODO add implementation - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::configureChipInternal, + hidl_status_cb, + mode_id); } Return WifiChip::getMode(getMode_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - UINT32_MAX); - return Void(); - } - // TODO add implementation - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), 0); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getModeInternal, + hidl_status_cb); } Return WifiChip::requestChipDebugInfo( requestChipDebugInfo_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - IWifiChip::ChipDebugInfo()); - return Void(); - } - - IWifiChip::ChipDebugInfo result; - - wifi_error legacy_status; - std::string driver_desc; - std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(); - if (legacy_status != WIFI_SUCCESS) { - LOG(ERROR) << "Failed to get driver version: " - << legacyErrorToString(legacy_status); - WifiStatus status = createWifiStatusFromLegacyError( - legacy_status, "failed to get driver version"); - hidl_status_cb(status, result); - return Void(); - } - result.driverDescription = driver_desc.c_str(); - - std::string firmware_desc; - std::tie(legacy_status, firmware_desc) = - legacy_hal_.lock()->getFirmwareVersion(); - if (legacy_status != WIFI_SUCCESS) { - LOG(ERROR) << "Failed to get firmware version: " - << legacyErrorToString(legacy_status); - WifiStatus status = createWifiStatusFromLegacyError( - legacy_status, "failed to get firmware version"); - hidl_status_cb(status, result); - return Void(); - } - result.firmwareDescription = firmware_desc.c_str(); - - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), result); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::requestChipDebugInfoInternal, + hidl_status_cb); } Return WifiChip::requestDriverDebugDump( requestDriverDebugDump_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - wifi_error legacy_status; - std::vector driver_dump; - std::tie(legacy_status, driver_dump) = - legacy_hal_.lock()->requestDriverMemoryDump(); - if (legacy_status != WIFI_SUCCESS) { - LOG(ERROR) << "Failed to get driver debug dump: " - << legacyErrorToString(legacy_status); - hidl_status_cb(createWifiStatusFromLegacyError(legacy_status), - hidl_vec()); - return Void(); - } - - hidl_vec hidl_data; - hidl_data.setToExternal(reinterpret_cast(driver_dump.data()), - driver_dump.size()); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), hidl_data); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::requestDriverDebugDumpInternal, + hidl_status_cb); } Return WifiChip::requestFirmwareDebugDump( requestFirmwareDebugDump_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - wifi_error legacy_status; - std::vector firmware_dump; - std::tie(legacy_status, firmware_dump) = - legacy_hal_.lock()->requestFirmwareMemoryDump(); - if (legacy_status != WIFI_SUCCESS) { - LOG(ERROR) << "Failed to get firmware debug dump: " - << legacyErrorToString(legacy_status); - hidl_status_cb(createWifiStatusFromLegacyError(legacy_status), - hidl_vec()); - return Void(); - } - - hidl_vec hidl_data; - hidl_data.setToExternal(reinterpret_cast(firmware_dump.data()), - firmware_dump.size()); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), hidl_data); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::requestFirmwareDebugDumpInternal, + hidl_status_cb); } Return WifiChip::createApIface(createApIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - 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_); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createApIfaceInternal, + hidl_status_cb); } Return WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - std::string ifname; - if (ap_iface_.get()) { - ifname = legacy_hal_.lock()->getApIfaceName().c_str(); - } - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), - createHidlVecOfIfaceNames(ifname)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getApIfaceNamesInternal, + hidl_status_cb); } Return WifiChip::getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - nullptr); - return Void(); - } - - if (ap_iface_.get() && - (ifname.c_str() == legacy_hal_.lock()->getApIfaceName())) { - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_); - } else { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), - nullptr); - } - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getApIfaceInternal, + hidl_status_cb, + ifname); } Return WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - 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_); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createNanIfaceInternal, + hidl_status_cb); } Return WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - std::string ifname; - if (nan_iface_.get()) { - ifname = legacy_hal_.lock()->getNanIfaceName().c_str(); - } - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), - createHidlVecOfIfaceNames(ifname)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getNanIfaceNamesInternal, + hidl_status_cb); } Return WifiChip::getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - nullptr); - return Void(); - } - - if (nan_iface_.get() && - (ifname.c_str() == legacy_hal_.lock()->getNanIfaceName())) { - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_); - } else { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), - nullptr); - } - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getNanIfaceInternal, + hidl_status_cb, + ifname); } Return WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - 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_); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createP2pIfaceInternal, + hidl_status_cb); } Return WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - std::string ifname; - if (p2p_iface_.get()) { - ifname = legacy_hal_.lock()->getP2pIfaceName().c_str(); - } - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), - createHidlVecOfIfaceNames(ifname)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getP2pIfaceNamesInternal, + hidl_status_cb); } Return WifiChip::getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - nullptr); - return Void(); - } - - if (p2p_iface_.get() && - (ifname.c_str() == legacy_hal_.lock()->getP2pIfaceName())) { - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_); - } else { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), - nullptr); - } - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getP2pIfaceInternal, + hidl_status_cb, + ifname); } Return WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - 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_); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createStaIfaceInternal, + hidl_status_cb); } Return WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - hidl_vec()); - return Void(); - } - - std::string ifname; - if (sta_iface_.get()) { - ifname = legacy_hal_.lock()->getStaIfaceName().c_str(); - } - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), - createHidlVecOfIfaceNames(ifname)); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getStaIfaceNamesInternal, + hidl_status_cb); } Return WifiChip::getStaIface(const hidl_string& ifname, getStaIface_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - nullptr); - return Void(); - } - - if (sta_iface_.get() && - (ifname.c_str() == legacy_hal_.lock()->getStaIfaceName())) { - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_); - } else { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), - nullptr); - } - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::getStaIfaceInternal, + hidl_status_cb, + ifname); } Return WifiChip::createRttController( const sp& bound_iface, createRttController_cb hidl_status_cb) { - if (!is_valid_) { - hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), - nullptr); - return Void(); - } - - sp rtt = new WifiRttController(bound_iface, legacy_hal_); - rtt_controllers_.emplace_back(rtt); - hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), rtt); - return Void(); + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createRttControllerInternal, + hidl_status_cb, + bound_iface); } void WifiChip::invalidateAndRemoveAllIfaces() { @@ -431,6 +234,201 @@ void WifiChip::invalidateAndRemoveAllIfaces() { rtt_controllers_.clear(); } +std::pair WifiChip::getIdInternal() { + return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; +} + +WifiStatus WifiChip::registerEventCallbackInternal( + const sp& event_callback) { + // TODO(b/31632518): remove the callback when the client is destroyed + event_callbacks_.emplace_back(event_callback); + return createWifiStatus(WifiStatusCode::SUCCESS); +} + +std::pair> +WifiChip::getAvailableModesInternal() { + // TODO add implementation + return {createWifiStatus(WifiStatusCode::SUCCESS), + std::vector()}; +} + +WifiStatus WifiChip::configureChipInternal(uint32_t /* mode_id */) { + invalidateAndRemoveAllIfaces(); + // TODO add implementation + return createWifiStatus(WifiStatusCode::SUCCESS); +} + +std::pair WifiChip::getModeInternal() { + // TODO add implementation + return {createWifiStatus(WifiStatusCode::SUCCESS), 0}; +} + +std::pair +WifiChip::requestChipDebugInfoInternal() { + IWifiChip::ChipDebugInfo result; + wifi_error legacy_status; + std::string driver_desc; + std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(); + if (legacy_status != WIFI_SUCCESS) { + LOG(ERROR) << "Failed to get driver version: " + << legacyErrorToString(legacy_status); + WifiStatus status = createWifiStatusFromLegacyError( + legacy_status, "failed to get driver version"); + return {status, result}; + } + result.driverDescription = driver_desc.c_str(); + + std::string firmware_desc; + std::tie(legacy_status, firmware_desc) = + legacy_hal_.lock()->getFirmwareVersion(); + if (legacy_status != WIFI_SUCCESS) { + LOG(ERROR) << "Failed to get firmware version: " + << legacyErrorToString(legacy_status); + WifiStatus status = createWifiStatusFromLegacyError( + legacy_status, "failed to get firmware version"); + return {status, result}; + } + result.firmwareDescription = firmware_desc.c_str(); + + return {createWifiStatus(WifiStatusCode::SUCCESS), result}; +} + +std::pair> +WifiChip::requestDriverDebugDumpInternal() { + wifi_error legacy_status; + std::vector driver_dump; + std::tie(legacy_status, driver_dump) = + legacy_hal_.lock()->requestDriverMemoryDump(); + if (legacy_status != WIFI_SUCCESS) { + LOG(ERROR) << "Failed to get driver debug dump: " + << legacyErrorToString(legacy_status); + return {createWifiStatusFromLegacyError(legacy_status), + std::vector()}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; +} + +std::pair> +WifiChip::requestFirmwareDebugDumpInternal() { + wifi_error legacy_status; + std::vector firmware_dump; + std::tie(legacy_status, firmware_dump) = + legacy_hal_.lock()->requestFirmwareMemoryDump(); + if (legacy_status != WIFI_SUCCESS) { + LOG(ERROR) << "Failed to get firmware debug dump: " + << legacyErrorToString(legacy_status); + return {createWifiStatusFromLegacyError(legacy_status), + std::vector()}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; +} + +std::pair> WifiChip::createApIfaceInternal() { + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getApIfaceName(); + ap_iface_ = new WifiApIface(ifname, legacy_hal_); + return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; +} + +std::pair> +WifiChip::getApIfaceNamesInternal() { + if (!ap_iface_.get()) { + return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), + {legacy_hal_.lock()->getApIfaceName()}}; +} + +std::pair> WifiChip::getApIfaceInternal( + const hidl_string& ifname) { + if (!ap_iface_.get() || + (ifname.c_str() != legacy_hal_.lock()->getApIfaceName())) { + return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; +} + +std::pair> WifiChip::createNanIfaceInternal() { + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getNanIfaceName(); + nan_iface_ = new WifiNanIface(ifname, legacy_hal_); + return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; +} + +std::pair> +WifiChip::getNanIfaceNamesInternal() { + if (!nan_iface_.get()) { + return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), + {legacy_hal_.lock()->getNanIfaceName()}}; +} + +std::pair> WifiChip::getNanIfaceInternal( + const hidl_string& ifname) { + if (!nan_iface_.get() || + (ifname.c_str() != legacy_hal_.lock()->getNanIfaceName())) { + return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; +} + +std::pair> WifiChip::createP2pIfaceInternal() { + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getP2pIfaceName(); + p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_); + return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; +} + +std::pair> +WifiChip::getP2pIfaceNamesInternal() { + if (!p2p_iface_.get()) { + return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), + {legacy_hal_.lock()->getP2pIfaceName()}}; +} + +std::pair> WifiChip::getP2pIfaceInternal( + const hidl_string& ifname) { + if (!p2p_iface_.get() || + (ifname.c_str() != legacy_hal_.lock()->getP2pIfaceName())) { + return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; +} + +std::pair> WifiChip::createStaIfaceInternal() { + // TODO(b/31997422): Disallow this based on the chip combination. + std::string ifname = legacy_hal_.lock()->getStaIfaceName(); + sta_iface_ = new WifiStaIface(ifname, legacy_hal_); + return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; +} + +std::pair> +WifiChip::getStaIfaceNamesInternal() { + if (!sta_iface_.get()) { + return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), + {legacy_hal_.lock()->getStaIfaceName()}}; +} + +std::pair> WifiChip::getStaIfaceInternal( + const hidl_string& ifname) { + if (!sta_iface_.get() || + (ifname.c_str() != legacy_hal_.lock()->getStaIfaceName())) { + return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; +} + +std::pair> +WifiChip::createRttControllerInternal(const sp& bound_iface) { + sp rtt = new WifiRttController(bound_iface, legacy_hal_); + rtt_controllers_.emplace_back(rtt); + return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; +} } // 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 dd9117e63e..47b4d7a2ee 100644 --- a/wifi/1.0/default/wifi_chip.h +++ b/wifi/1.0/default/wifi_chip.h @@ -57,6 +57,7 @@ class WifiChip : public IWifiChip { // All HIDL method implementations should check if the object is still marked // valid before processing them. void invalidate(); + bool isValid(); // HIDL methods exposed. Return getId(getId_cb hidl_status_cb) override; @@ -96,6 +97,37 @@ class WifiChip : public IWifiChip { private: void invalidateAndRemoveAllIfaces(); + // Corresponding worker functions for the HIDL methods. + std::pair getIdInternal(); + WifiStatus registerEventCallbackInternal( + const sp& event_callback); + std::pair> getAvailableModesInternal(); + WifiStatus configureChipInternal(uint32_t mode_id); + std::pair getModeInternal(); + std::pair + requestChipDebugInfoInternal(); + std::pair> requestDriverDebugDumpInternal(); + std::pair> + requestFirmwareDebugDumpInternal(); + std::pair> createApIfaceInternal(); + std::pair> getApIfaceNamesInternal(); + std::pair> getApIfaceInternal( + const hidl_string& ifname); + std::pair> createNanIfaceInternal(); + std::pair> getNanIfaceNamesInternal(); + std::pair> getNanIfaceInternal( + const hidl_string& ifname); + std::pair> createP2pIfaceInternal(); + std::pair> getP2pIfaceNamesInternal(); + std::pair> getP2pIfaceInternal( + const hidl_string& ifname); + std::pair> createStaIfaceInternal(); + std::pair> getStaIfaceNamesInternal(); + std::pair> getStaIfaceInternal( + const hidl_string& ifname); + std::pair> createRttControllerInternal( + const sp& bound_iface); + ChipId chip_id_; std::weak_ptr legacy_hal_; std::vector> event_callbacks_; diff --git a/wifi/1.0/default/wifi_legacy_hal.cpp b/wifi/1.0/default/wifi_legacy_hal.cpp index 65c078287a..5bd2454a99 100644 --- a/wifi/1.0/default/wifi_legacy_hal.cpp +++ b/wifi/1.0/default/wifi_legacy_hal.cpp @@ -154,12 +154,14 @@ std::pair WifiLegacyHal::getFirmwareVersion() { return std::make_pair(status, buffer.data()); } -std::pair> +std::pair> WifiLegacyHal::requestDriverMemoryDump() { - std::vector driver_dump; + std::vector driver_dump; on_driver_memory_dump_internal_callback = [&driver_dump](char* buffer, int buffer_size) { - driver_dump.insert(driver_dump.end(), buffer, buffer + buffer_size); + driver_dump.insert(driver_dump.end(), + reinterpret_cast(buffer), + reinterpret_cast(buffer) + buffer_size); }; wifi_error status = global_func_table_.wifi_get_driver_memory_dump( wlan_interface_handle_, {onDriverMemoryDump}); @@ -167,12 +169,14 @@ WifiLegacyHal::requestDriverMemoryDump() { return std::make_pair(status, std::move(driver_dump)); } -std::pair> +std::pair> WifiLegacyHal::requestFirmwareMemoryDump() { - std::vector firmware_dump; + std::vector firmware_dump; on_firmware_memory_dump_internal_callback = [&firmware_dump]( char* buffer, int buffer_size) { - firmware_dump.insert(firmware_dump.end(), buffer, buffer + buffer_size); + firmware_dump.insert(firmware_dump.end(), + reinterpret_cast(buffer), + reinterpret_cast(buffer) + buffer_size); }; wifi_error status = global_func_table_.wifi_get_firmware_memory_dump( wlan_interface_handle_, {onFirmwareMemoryDump}); diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h index 367ff15d24..21acb92621 100644 --- a/wifi/1.0/default/wifi_legacy_hal.h +++ b/wifi/1.0/default/wifi_legacy_hal.h @@ -49,8 +49,8 @@ class WifiLegacyHal { // Wrappers for all the functions in the legacy HAL function table. std::pair getDriverVersion(); std::pair getFirmwareVersion(); - std::pair> requestDriverMemoryDump(); - std::pair> requestFirmwareMemoryDump(); + std::pair> requestDriverMemoryDump(); + std::pair> requestFirmwareMemoryDump(); private: static const uint32_t kMaxVersionStringLength;