Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fc6d170 authored by Roshan Pius's avatar Roshan Pius
Browse files

wifi(implementation): Load wifi driver on IWifi.start()

The current implementation loads the wifi driver only when the chip is
configured, but the HAL is initialized on IWifi.start(). This seems to
be wrong semantically. The driver needs to be loaded before the HAL is
initialized.

This may have worked previously because the driver was loaded in
init.rc, but may stop working when we move to proper DLKM model in 2018.

Bug: 65671875
Test: Device boots up and connects to wifi networks.
Change-Id: I017d3528bf0b42a6a59af43203ecc9d0d027f60d
parent 8e3c7ef1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ namespace mode_controller {
class MockWifiModeController : public WifiModeController {
   public:
    MockWifiModeController();
    MOCK_METHOD0(initialize, bool());
    MOCK_METHOD1(changeFirmwareMode, bool(IfaceType));
    MOCK_METHOD1(isFirmwareModeChangeNeeded, bool(IfaceType));
    MOCK_METHOD0(deinitialize, bool());
+6 −2
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ WifiStatus Wifi::startInternal() {
        return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
                                "HAL is stopping");
    }
    WifiStatus wifi_status = initializeLegacyHal();
    WifiStatus wifi_status = initializeModeControllerAndLegacyHal();
    if (wifi_status.code == WifiStatusCode::SUCCESS) {
        // Create the chip instance once the HAL is started.
        chip_ = new WifiChip(kChipId, legacy_hal_, mode_controller_,
@@ -166,7 +166,11 @@ std::pair<WifiStatus, sp<IWifiChip>> Wifi::getChipInternal(ChipId chip_id) {
    return {createWifiStatus(WifiStatusCode::SUCCESS), chip_};
}

WifiStatus Wifi::initializeLegacyHal() {
WifiStatus Wifi::initializeModeControllerAndLegacyHal() {
    if (!mode_controller_->initialize()) {
        LOG(ERROR) << "Failed to initialize firmware mode controller";
        return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
    }
    legacy_hal::wifi_error legacy_status = legacy_hal_->initialize();
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        LOG(ERROR) << "Failed to initialize legacy HAL: "
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class Wifi : public V1_2::IWifi {
    std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
    std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id);

    WifiStatus initializeLegacyHal();
    WifiStatus initializeModeControllerAndLegacyHal();
    WifiStatus stopLegacyHalAndDeinitializeModeController(
        std::unique_lock<std::recursive_mutex>* lock);

+5 −1
Original line number Diff line number Diff line
@@ -59,11 +59,15 @@ bool WifiModeController::isFirmwareModeChangeNeeded(IfaceType type) {
        convertIfaceTypeToFirmwareMode(type));
}

bool WifiModeController::changeFirmwareMode(IfaceType type) {
bool WifiModeController::initialize() {
    if (!driver_tool_->LoadDriver()) {
        LOG(ERROR) << "Failed to load WiFi driver";
        return false;
    }
    return true;
}

bool WifiModeController::changeFirmwareMode(IfaceType type) {
    if (!driver_tool_->ChangeFirmwareMode(
            convertIfaceTypeToFirmwareMode(type))) {
        LOG(ERROR) << "Failed to change firmware mode";
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class WifiModeController {
    // Checks if a firmware mode change is necessary to support the specified
    // iface type operations.
    virtual bool isFirmwareModeChangeNeeded(IfaceType type);
    virtual bool initialize();
    // Change the firmware mode to support the specified iface type operations.
    virtual bool changeFirmwareMode(IfaceType type);
    // Unload the driver. This should be invoked whenever |IWifi.stop()| is