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
diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp
index 4f8545f..bc46eec 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 <android-base/logging.h>
+#include "hidl_return_util.h"
+#include "wifi_chip.h"
#include "wifi_status_util.h"
namespace {
@@ -25,14 +25,6 @@
using android::hardware::hidl_vec;
using android::hardware::hidl_string;
-std::vector<hidl_string> createHidlVecOfIfaceNames(const std::string& ifname) {
- std::vector<hidl_string> ifnames;
- if (!ifname.empty()) {
- ifnames.emplace_back(ifname);
- }
- return ifnames;
-}
-
template <typename Iface>
void invalidateAndClear(sp<Iface>& iface) {
if (iface.get()) {
@@ -47,6 +39,7 @@
namespace wifi {
namespace V1_0 {
namespace implementation {
+using hidl_return_util::validateAndCall;
WifiChip::WifiChip(ChipId chip_id,
const std::weak_ptr<WifiLegacyHal> legacy_hal)
@@ -59,363 +52,173 @@
is_valid_ = false;
}
+bool WifiChip::isValid() {
+ return is_valid_;
+}
+
Return<void> 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<void> WifiChip::registerEventCallback(
const sp<IWifiChipEventCallback>& 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<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<ChipMode>());
- return Void();
- }
- // TODO add implementation
- hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS),
- hidl_vec<ChipMode>());
- return Void();
+ return validateAndCall(this,
+ WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
+ &WifiChip::getAvailableModesInternal,
+ hidl_status_cb);
}
-Return<void> WifiChip::configureChip(uint32_t /*mode_id*/,
+Return<void> 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<void> 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<void> 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<void> WifiChip::requestDriverDebugDump(
requestDriverDebugDump_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<uint8_t>());
- return Void();
- }
-
- wifi_error legacy_status;
- std::vector<char> 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<uint8_t>());
- return Void();
- }
-
- hidl_vec<uint8_t> hidl_data;
- hidl_data.setToExternal(reinterpret_cast<uint8_t*>(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<void> WifiChip::requestFirmwareDebugDump(
requestFirmwareDebugDump_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<uint8_t>());
- return Void();
- }
-
- wifi_error legacy_status;
- std::vector<char> 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<uint8_t>());
- return Void();
- }
-
- hidl_vec<uint8_t> hidl_data;
- hidl_data.setToExternal(reinterpret_cast<uint8_t*>(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<void> 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<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<hidl_string>());
- 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<void> 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<void> 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<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<hidl_string>());
- 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<void> 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<void> 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<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<hidl_string>());
- 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<void> 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<void> 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<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- hidl_vec<hidl_string>());
- 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<void> 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<void> WifiChip::createRttController(
const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) {
- if (!is_valid_) {
- hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID),
- nullptr);
- return Void();
- }
-
- sp<WifiRttController> 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 @@
rtt_controllers_.clear();
}
+std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() {
+ return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_};
+}
+
+WifiStatus WifiChip::registerEventCallbackInternal(
+ const sp<IWifiChipEventCallback>& 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<WifiStatus, std::vector<IWifiChip::ChipMode>>
+WifiChip::getAvailableModesInternal() {
+ // TODO add implementation
+ return {createWifiStatus(WifiStatusCode::SUCCESS),
+ std::vector<IWifiChip::ChipMode>()};
+}
+
+WifiStatus WifiChip::configureChipInternal(uint32_t /* mode_id */) {
+ invalidateAndRemoveAllIfaces();
+ // TODO add implementation
+ return createWifiStatus(WifiStatusCode::SUCCESS);
+}
+
+std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
+ // TODO add implementation
+ return {createWifiStatus(WifiStatusCode::SUCCESS), 0};
+}
+
+std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
+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<WifiStatus, std::vector<uint8_t>>
+WifiChip::requestDriverDebugDumpInternal() {
+ wifi_error legacy_status;
+ std::vector<uint8_t> 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<uint8_t>()};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump};
+}
+
+std::pair<WifiStatus, std::vector<uint8_t>>
+WifiChip::requestFirmwareDebugDumpInternal() {
+ wifi_error legacy_status;
+ std::vector<uint8_t> 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<uint8_t>()};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump};
+}
+
+std::pair<WifiStatus, sp<IWifiApIface>> 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<WifiStatus, std::vector<hidl_string>>
+WifiChip::getApIfaceNamesInternal() {
+ if (!ap_iface_.get()) {
+ return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS),
+ {legacy_hal_.lock()->getApIfaceName()}};
+}
+
+std::pair<WifiStatus, sp<IWifiApIface>> 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<WifiStatus, sp<IWifiNanIface>> 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<WifiStatus, std::vector<hidl_string>>
+WifiChip::getNanIfaceNamesInternal() {
+ if (!nan_iface_.get()) {
+ return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS),
+ {legacy_hal_.lock()->getNanIfaceName()}};
+}
+
+std::pair<WifiStatus, sp<IWifiNanIface>> 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<WifiStatus, sp<IWifiP2pIface>> 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<WifiStatus, std::vector<hidl_string>>
+WifiChip::getP2pIfaceNamesInternal() {
+ if (!p2p_iface_.get()) {
+ return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS),
+ {legacy_hal_.lock()->getP2pIfaceName()}};
+}
+
+std::pair<WifiStatus, sp<IWifiP2pIface>> 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<WifiStatus, sp<IWifiStaIface>> 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<WifiStatus, std::vector<hidl_string>>
+WifiChip::getStaIfaceNamesInternal() {
+ if (!sta_iface_.get()) {
+ return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
+ }
+ return {createWifiStatus(WifiStatusCode::SUCCESS),
+ {legacy_hal_.lock()->getStaIfaceName()}};
+}
+
+std::pair<WifiStatus, sp<IWifiStaIface>> 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<WifiStatus, sp<IWifiRttController>>
+WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) {
+ sp<WifiRttController> rtt = new WifiRttController(bound_iface, legacy_hal_);
+ rtt_controllers_.emplace_back(rtt);
+ return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
+}
} // namespace implementation
} // namespace V1_0
} // namespace wifi