wifi: Add chip level callbacks
The following new notifications are added:
1. onChipReconfigureFailre - Invoked if there is an error during
configuration.
2. onIfaceAdded - Invoked on addition of an iface.
3. onIfaceRemoved - Invoked on removal of an iface.
Bug: 33679304
Bug: 33038823
Test: Gtests
Change-Id: Id3fa19420d1e1e8d209ec88a1fbd36a64afb5252
diff --git a/wifi/1.0/IWifiChipEventCallback.hal b/wifi/1.0/IWifiChipEventCallback.hal
index 1501029..aff1e43 100644
--- a/wifi/1.0/IWifiChipEventCallback.hal
+++ b/wifi/1.0/IWifiChipEventCallback.hal
@@ -20,7 +20,7 @@
/**
* Callback indicating that the chip has been reconfigured successfully. At
* this point the interfaces available in the mode must be able to be
- * configured. When this is called any previous interface indexes will be
+ * configured. When this is called any previous iface objects must be
* considered invalid.
*
* @param modeId The mode that the chip switched to, corresponding to the id
@@ -29,6 +29,32 @@
oneway onChipReconfigured(ChipModeId modeId);
/**
+ * Callback indicating that a chip reconfiguration failed. This is a fatal
+ * error and any iface objects available previously must be considered
+ * invalid. The client can attempt to recover by trying to reconfigure the
+ * chip again using |IWifiChip.configureChip|.
+ *
+ * @param status Failure reason code.
+ */
+ oneway onChipReconfigureFailure(WifiStatus status);
+
+ /**
+ * Callback indicating that a new iface has been added to the chip.
+ *
+ * @param type Type of iface added.
+ * @param name Name of iface added.
+ */
+ oneway onIfaceAdded(IfaceType type, string name);
+
+ /**
+ * Callback indicating that an existing iface has been removed from the chip.
+ *
+ * @param type Type of iface removed.
+ * @param name Name of iface removed.
+ */
+ oneway onIfaceRemoved(IfaceType type, string name);
+
+ /**
* Callbacks for reporting debug ring buffer data.
*
* The ring buffer data collection is event based:
diff --git a/wifi/1.0/default/wifi_chip.cpp b/wifi/1.0/default/wifi_chip.cpp
index d64dea6..87b47cb 100644
--- a/wifi/1.0/default/wifi_chip.cpp
+++ b/wifi/1.0/default/wifi_chip.cpp
@@ -25,12 +25,13 @@
using android::sp;
using android::hardware::hidl_vec;
using android::hardware::hidl_string;
+using android::hardware::wifi::V1_0::ChipModeId;
using android::hardware::wifi::V1_0::IWifiChip;
using android::hardware::wifi::V1_0::IfaceType;
-constexpr uint32_t kStaChipModeId = 0;
-constexpr uint32_t kApChipModeId = 1;
-constexpr uint32_t kInvalidModeId = UINT32_MAX;
+constexpr ChipModeId kStaChipModeId = 0;
+constexpr ChipModeId kApChipModeId = 1;
+constexpr ChipModeId kInvalidModeId = UINT32_MAX;
template <typename Iface>
void invalidateAndClear(sp<Iface>& iface) {
@@ -104,7 +105,7 @@
hidl_status_cb);
}
-Return<void> WifiChip::configureChip(uint32_t mode_id,
+Return<void> WifiChip::configureChip(ChipModeId mode_id,
configureChip_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
@@ -402,7 +403,7 @@
{sta_chip_mode, ap_chip_mode}};
}
-WifiStatus WifiChip::configureChipInternal(uint32_t mode_id) {
+WifiStatus WifiChip::configureChipInternal(ChipModeId mode_id) {
if (mode_id != kStaChipModeId && mode_id != kApChipModeId) {
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
@@ -410,40 +411,18 @@
LOG(DEBUG) << "Already in the specified mode " << mode_id;
return createWifiStatus(WifiStatusCode::SUCCESS);
}
- // If the chip is already configured in a different mode, stop
- // the legacy HAL and then start it after firmware mode change.
- if (current_mode_id_ != kInvalidModeId) {
- invalidateAndRemoveAllIfaces();
- legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop([]() {});
- if (legacy_status != legacy_hal::WIFI_SUCCESS) {
- LOG(ERROR) << "Failed to stop legacy HAL: "
- << legacyErrorToString(legacy_status);
- // TODO(b/33038823): Need to invoke onChipReconfigureFailure()
- return createWifiStatusFromLegacyError(legacy_status);
+ WifiStatus status = handleChipConfiguration(mode_id);
+ if (status.code != WifiStatusCode::SUCCESS) {
+ for (const auto& callback : event_callbacks_) {
+ callback->onChipReconfigureFailure(status);
}
- }
- bool success;
- if (mode_id == kStaChipModeId) {
- success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
- } else {
- success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
- }
- if (!success) {
- // TODO(b/33038823): Need to invoke onChipReconfigureFailure()
- return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
- }
- legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
- if (legacy_status != legacy_hal::WIFI_SUCCESS) {
- LOG(ERROR) << "Failed to start legacy HAL: "
- << legacyErrorToString(legacy_status);
- // TODO(b/33038823): Need to invoke onChipReconfigureFailure()
- return createWifiStatusFromLegacyError(legacy_status);
+ return status;
}
for (const auto& callback : event_callbacks_) {
callback->onChipReconfigured(mode_id);
}
current_mode_id_ = mode_id;
- return createWifiStatus(WifiStatusCode::SUCCESS);
+ return status;
}
std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
@@ -519,6 +498,9 @@
}
std::string ifname = legacy_hal_.lock()->getApIfaceName();
ap_iface_ = new WifiApIface(ifname, legacy_hal_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceAdded(IfaceType::AP, ifname);
+ }
return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_};
}
@@ -544,6 +526,9 @@
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
invalidateAndClear(ap_iface_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceRemoved(IfaceType::AP, ifname);
+ }
return createWifiStatus(WifiStatusCode::SUCCESS);
}
@@ -555,6 +540,9 @@
}
std::string ifname = legacy_hal_.lock()->getNanIfaceName();
nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceAdded(IfaceType::NAN, ifname);
+ }
return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
}
@@ -580,6 +568,9 @@
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
invalidateAndClear(nan_iface_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceRemoved(IfaceType::NAN, ifname);
+ }
return createWifiStatus(WifiStatusCode::SUCCESS);
}
@@ -591,6 +582,9 @@
}
std::string ifname = legacy_hal_.lock()->getP2pIfaceName();
p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceAdded(IfaceType::P2P, ifname);
+ }
return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_};
}
@@ -616,6 +610,9 @@
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
invalidateAndClear(p2p_iface_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceRemoved(IfaceType::P2P, ifname);
+ }
return createWifiStatus(WifiStatusCode::SUCCESS);
}
@@ -625,6 +622,9 @@
}
std::string ifname = legacy_hal_.lock()->getStaIfaceName();
sta_iface_ = new WifiStaIface(ifname, legacy_hal_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceAdded(IfaceType::STA, ifname);
+ }
return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_};
}
@@ -650,6 +650,9 @@
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
invalidateAndClear(sta_iface_);
+ for (const auto& callback : event_callbacks_) {
+ callback->onIfaceRemoved(IfaceType::STA, ifname);
+ }
return createWifiStatus(WifiStatusCode::SUCCESS);
}
@@ -741,6 +744,36 @@
}
return createWifiStatusFromLegacyError(legacy_status);
}
+
+WifiStatus WifiChip::handleChipConfiguration(ChipModeId mode_id) {
+ // If the chip is already configured in a different mode, stop
+ // the legacy HAL and then start it after firmware mode change.
+ if (current_mode_id_ != kInvalidModeId) {
+ invalidateAndRemoveAllIfaces();
+ legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop([]() {});
+ if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+ LOG(ERROR) << "Failed to stop legacy HAL: "
+ << legacyErrorToString(legacy_status);
+ return createWifiStatusFromLegacyError(legacy_status);
+ }
+ }
+ bool success;
+ if (mode_id == kStaChipModeId) {
+ success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
+ } else {
+ success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
+ }
+ if (!success) {
+ return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
+ }
+ legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
+ if (legacy_status != legacy_hal::WIFI_SUCCESS) {
+ LOG(ERROR) << "Failed to start legacy HAL: "
+ << legacyErrorToString(legacy_status);
+ return createWifiStatusFromLegacyError(legacy_status);
+ }
+ return createWifiStatus(WifiStatusCode::SUCCESS);
+}
} // 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 cfe2ed2..373712c 100644
--- a/wifi/1.0/default/wifi_chip.h
+++ b/wifi/1.0/default/wifi_chip.h
@@ -71,7 +71,7 @@
registerEventCallback_cb hidl_status_cb) override;
Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override;
Return<void> getAvailableModes(getAvailableModes_cb hidl_status_cb) override;
- Return<void> configureChip(uint32_t mode_id,
+ Return<void> configureChip(ChipModeId mode_id,
configureChip_cb hidl_status_cb) override;
Return<void> getMode(getMode_cb hidl_status_cb) override;
Return<void> requestChipDebugInfo(
@@ -132,7 +132,7 @@
const sp<IWifiChipEventCallback>& event_callback);
std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal();
- WifiStatus configureChipInternal(uint32_t mode_id);
+ WifiStatus configureChipInternal(ChipModeId mode_id);
std::pair<WifiStatus, uint32_t> getModeInternal();
std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
requestChipDebugInfoInternal();
@@ -173,6 +173,8 @@
getDebugHostWakeReasonStatsInternal();
WifiStatus enableDebugErrorAlertsInternal(bool enable);
+ WifiStatus handleChipConfiguration(ChipModeId mode_id);
+
ChipId chip_id_;
std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
std::weak_ptr<mode_controller::WifiModeController> mode_controller_;