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

Commit da62c38e authored by Kumar Anand's avatar Kumar Anand
Browse files

Wifi: Chip level API to set the country code

Country code is global setting across the Wifi chip
and not really Wifi interface (STA or AP) specific.
Framework should have the ability to set the country
code on a chip level without requiring supplicant
instance to be running. As long as there is at least
one active interface to communicate to kernel driver,
country code can be set and driver should apply the
setting globally.

Bug: 149936939
Test: VTS - VtsHalWifiV1_5TargetTest
Change-Id: I1be5dae34b216a6152d09605d055872d5345507c
parent f86c2c3c
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -216,4 +216,22 @@ interface IWifiChip extends @1.4::IWifiChip {
    setCoexUnsafeChannels(
        vec<CoexUnsafeChannel> unsafeChannels, bitfield<CoexRestriction> restrictions)
            generates (WifiStatus status);

    /**
     * Set country code for this Wifi chip.
     *
     * Country code is global setting across the Wifi chip and not Wifi
     * interface (STA or AP) specific. Legacy HAL API's for country code in
     * @1.0::ISupplicantStaIface::setCountryCode &
     * @1.0::IWifiApIface:setCountryCode are deprecated in favor of this
     * chip level API.
     *
     * @param code 2 byte country code (as defined in ISO 3166) to set.
     * @return status Status of the operation.
     *         Possible status codes:
     *         |WifiStatusCode.SUCCESS|,
     *         |WifiStatusCode.FAILURE_UNKNOWN|,
     *         |WifiStatusCode.FAILURE_IFACE_INVALID|
     */
    setCountryCode(int8_t[2] code) generates (WifiStatus status);
};
+13 −0
Original line number Diff line number Diff line
@@ -731,6 +731,13 @@ Return<void> WifiChip::setCoexUnsafeChannels(
                           hidl_status_cb, unsafeChannels, restrictions);
}

Return<void> WifiChip::setCountryCode(const hidl_array<int8_t, 2>& code,
                                      setCountryCode_cb hidl_status_cb) {
    return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
                           &WifiChip::setCountryCodeInternal, hidl_status_cb,
                           code);
}

void WifiChip::invalidateAndRemoveAllIfaces() {
    invalidateAndClearBridgedApAll();
    invalidateAndClearAll(ap_ifaces_);
@@ -1478,6 +1485,12 @@ WifiStatus WifiChip::setCoexUnsafeChannelsInternal(
    return createWifiStatusFromLegacyError(legacy_status);
}

WifiStatus WifiChip::setCountryCodeInternal(const std::array<int8_t, 2>& code) {
    auto legacy_status =
        legacy_hal_.lock()->setCountryCode(getFirstActiveWlanIfaceName(), code);
    return createWifiStatusFromLegacyError(legacy_status);
}

WifiStatus WifiChip::handleChipConfiguration(
    /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
    ChipModeId mode_id) {
+3 −1
Original line number Diff line number Diff line
@@ -178,6 +178,8 @@ class WifiChip : public V1_5::IWifiChip {
        const hidl_vec<CoexUnsafeChannel>& unsafe_channels,
        hidl_bitfield<IfaceType> restrictions,
        setCoexUnsafeChannels_cb hidl_status_cb) override;
    Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,
                                setCountryCode_cb _hidl_cb) override;

   private:
    void invalidateAndRemoveAllIfaces();
@@ -258,7 +260,7 @@ class WifiChip : public V1_5::IWifiChip {
    WifiStatus setMultiStaUseCaseInternal(MultiStaUseCase use_case);
    WifiStatus setCoexUnsafeChannelsInternal(
        std::vector<CoexUnsafeChannel> unsafe_channels, uint32_t restrictions);

    WifiStatus setCountryCodeInternal(const std::array<int8_t, 2>& code);
    WifiStatus handleChipConfiguration(
        std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
    WifiStatus registerDebugRingBufferCallback();
+14 −0
Original line number Diff line number Diff line
@@ -173,6 +173,20 @@ TEST_P(WifiChipHidlTest, setCoexUnsafeChannels) {
    }
}

/*
 * SetCountryCode:
 * Ensures that a call to set the country code will return with a success
 * status code.
 */
TEST_P(WifiChipHidlTest, setCountryCode) {
    const android::hardware::hidl_array<int8_t, 2> kCountryCode{
        std::array<int8_t, 2>{{0x55, 0x53}}};

    configureChipForIfaceType(IfaceType::STA, true);
    EXPECT_EQ(WifiStatusCode::SUCCESS,
              HIDL_INVOKE(wifi_chip_, setCountryCode, kCountryCode).code);
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);
INSTANTIATE_TEST_SUITE_P(
    PerInstance, WifiChipHidlTest,