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

Commit 420c4fc3 authored by lesl's avatar lesl
Browse files

wifi: Add resetFactoryMac support (AP+AP Part 3)

Support HAL API:resetToFactoryMacAddress to reset the MAC
to factory MAC on each instances in IWifiApIface.

AP+AP Part 3 includes:
1. Support resetToFactoryMac in IWifiApIface.Hal.
2. Vts support for non bridged API.
3. Framework support resetToFactoryMac in bridged Ap.

Test: atest -c VtsHalWifiApV1_5TargetTest
Test: atest -c VtsHalWifiApV1_4TargetTest
Test: atest -c VtsHalWifiApV1_0TargetTest
Bug: 162686273
Change-Id: Ic7f2c0d6f1d8bf46fabfbc874d5f2b74068e43cc
parent 94d2824a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ hidl_interface {
        "types.hal",
        "IWifi.hal",
        "IWifiChip.hal",
        "IWifiApIface.hal",
        "IWifiNanIface.hal",
        "IWifiNanIfaceEventCallback.hal",
        "IWifiStaIface.hal",
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.wifi@1.5;

import @1.4::IWifiApIface;
import @1.0::MacAddress;
import @1.0::WifiStatus;

/**
 * Represents a network interface in AP mode.
 *
 * This can be obtained through @1.0::IWifiChip.getApIface() and casting
 * IWifiApIface up to 1.5.
 */
interface IWifiApIface extends @1.4::IWifiApIface {
    /**
     * Reset all of the AP interfaces MAC address to the factory MAC address.
     *
     * @return status WifiStatus of the operation
     *         Possible status codes:
     *         |WifiStatusCode.SUCCESS|,
     *         |WifiStatusCode.ERROR_WIFI_IFACE_INVALID|,
     *         |WifiStatusCode.ERROR_UNKNOWN|
     */
    resetToFactoryMacAddress() generates (WifiStatus status);
};
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package android.hardware.wifi@1.5;

import @1.0::WifiStatus;
import @1.0::IWifiApIface;
import @1.5::IWifiApIface;
import @1.0::IWifiIface;
import @1.3::IWifiChip;
import @1.4::IWifiChip;
+55 −7
Original line number Diff line number Diff line
@@ -29,10 +29,11 @@ namespace implementation {
using hidl_return_util::validateAndCall;

WifiApIface::WifiApIface(
    const std::string& ifname,
    const std::string& ifname, const std::vector<std::string>& instances,
    const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
    const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
    : ifname_(ifname),
      instances_(instances),
      legacy_hal_(legacy_hal),
      iface_util_(iface_util),
      is_valid_(true) {}
@@ -81,6 +82,14 @@ Return<void> WifiApIface::getFactoryMacAddress(
    getFactoryMacAddress_cb hidl_status_cb) {
    return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
                           &WifiApIface::getFactoryMacAddressInternal,
                           hidl_status_cb,
                           instances_.size() > 0 ? instances_[0] : ifname_);
}

Return<void> WifiApIface::resetToFactoryMacAddress(
    resetToFactoryMacAddress_cb hidl_status_cb) {
    return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
                           &WifiApIface::resetToFactoryMacAddressInternal,
                           hidl_status_cb);
}

@@ -94,8 +103,8 @@ std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {

WifiStatus WifiApIface::setCountryCodeInternal(
    const std::array<int8_t, 2>& code) {
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->setCountryCode(ifname_, code);
    legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setCountryCode(
        instances_.size() > 0 ? instances_[0] : ifname_, code);
    return createWifiStatusFromLegacyError(legacy_status);
}

@@ -107,13 +116,30 @@ WifiApIface::getValidFrequenciesForBandInternal(V1_0::WifiBand band) {
    std::vector<uint32_t> valid_frequencies;
    std::tie(legacy_status, valid_frequencies) =
        legacy_hal_.lock()->getValidFrequenciesForBand(
            ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band));
            instances_.size() > 0 ? instances_[0] : ifname_,
            hidl_struct_util::convertHidlWifiBandToLegacy(band));
    return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies};
}

WifiStatus WifiApIface::setMacAddressInternal(
    const std::array<uint8_t, 6>& mac) {
    bool status = iface_util_.lock()->setMacAddress(ifname_, mac);
    bool status;
    // Support random MAC up to 2 interfaces
    if (instances_.size() == 2) {
        int rbyte = 1;
        for (auto const& intf : instances_) {
            std::array<uint8_t, 6> rmac = mac;
            // reverse the bits to avoid clision
            rmac[rbyte] = 0xff - rmac[rbyte];
            status = iface_util_.lock()->setMacAddress(intf, rmac);
            if (!status) {
                LOG(INFO) << "Failed to set random mac address on " << intf;
            }
            rbyte++;
        }
    } else {
        status = iface_util_.lock()->setMacAddress(ifname_, mac);
    }
    if (!status) {
        return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
    }
@@ -121,15 +147,37 @@ WifiStatus WifiApIface::setMacAddressInternal(
}

std::pair<WifiStatus, std::array<uint8_t, 6>>
WifiApIface::getFactoryMacAddressInternal() {
WifiApIface::getFactoryMacAddressInternal(const std::string& ifaceName) {
    std::array<uint8_t, 6> mac =
        iface_util_.lock()->getFactoryMacAddress(ifname_);
        iface_util_.lock()->getFactoryMacAddress(ifaceName);
    if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 &&
        mac[4] == 0 && mac[5] == 0) {
        return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), mac};
    }
    return {createWifiStatus(WifiStatusCode::SUCCESS), mac};
}

WifiStatus WifiApIface::resetToFactoryMacAddressInternal() {
    std::pair<WifiStatus, std::array<uint8_t, 6>> getMacResult;
    if (instances_.size() == 2) {
        for (auto const& intf : instances_) {
            getMacResult = getFactoryMacAddressInternal(intf);
            LOG(DEBUG) << "Reset MAC to factory MAC on " << intf;
            if (getMacResult.first.code != WifiStatusCode::SUCCESS ||
                !iface_util_.lock()->setMacAddress(intf, getMacResult.second)) {
                return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
            }
        }
    } else {
        getMacResult = getFactoryMacAddressInternal(ifname_);
        LOG(DEBUG) << "Reset MAC to factory MAC on " << ifname_;
        if (getMacResult.first.code != WifiStatusCode::SUCCESS ||
            !iface_util_.lock()->setMacAddress(ifname_, getMacResult.second)) {
            return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
        }
    }
    return createWifiStatus(WifiStatusCode::SUCCESS);
}
}  // namespace implementation
}  // namespace V1_5
}  // namespace wifi
+9 −4
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#define WIFI_AP_IFACE_H_

#include <android-base/macros.h>
#include <android/hardware/wifi/1.4/IWifiApIface.h>
#include <android/hardware/wifi/1.5/IWifiApIface.h>

#include "wifi_iface_util.h"
#include "wifi_legacy_hal.h"
@@ -33,9 +33,10 @@ using namespace android::hardware::wifi::V1_0;
/**
 * HIDL interface object used to control a AP Iface instance.
 */
class WifiApIface : public V1_4::IWifiApIface {
class WifiApIface : public V1_5::IWifiApIface {
   public:
    WifiApIface(const std::string& ifname,
                const std::vector<std::string>& instances,
                const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
                const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util);
    // Refer to |WifiChip::invalidate()|.
@@ -55,6 +56,8 @@ class WifiApIface : public V1_4::IWifiApIface {
                               setMacAddress_cb hidl_status_cb) override;
    Return<void> getFactoryMacAddress(
        getFactoryMacAddress_cb hidl_status_cb) override;
    Return<void> resetToFactoryMacAddress(
        resetToFactoryMacAddress_cb hidl_status_cb) override;

   private:
    // Corresponding worker functions for the HIDL methods.
@@ -64,10 +67,12 @@ class WifiApIface : public V1_4::IWifiApIface {
    std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
    getValidFrequenciesForBandInternal(V1_0::WifiBand band);
    WifiStatus setMacAddressInternal(const std::array<uint8_t, 6>& mac);
    std::pair<WifiStatus, std::array<uint8_t, 6>>
    getFactoryMacAddressInternal();
    std::pair<WifiStatus, std::array<uint8_t, 6>> getFactoryMacAddressInternal(
        const std::string& ifaceName);
    WifiStatus resetToFactoryMacAddressInternal();

    std::string ifname_;
    std::vector<std::string> instances_;
    std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
    std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_;
    bool is_valid_;
Loading