/* * Copyright (C) 2022 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.net.wifi; import static android.net.wifi.WifiScanner.WIFI_BAND_24_GHZ; import static android.net.wifi.WifiScanner.WIFI_BAND_5_GHZ; import static android.net.wifi.WifiScanner.WIFI_BAND_6_GHZ; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.net.MacAddress; import android.net.NetworkCapabilities; import android.os.Parcel; import android.os.Parcelable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Objects; /** * Data structure class representing a Wi-Fi Multi-Link Operation (MLO) link * This is only used by 802.11be capable devices */ public final class MloLink implements Parcelable { /** * Invalid link id. Used in {link #getLinkId()} */ public static final int INVALID_MLO_LINK_ID = -1; /** * Lower limit for MLO link id * As described in IEEE 802.11be Specification, section 9.4.2.295b.2. * * @hide */ public static final int MIN_MLO_LINK_ID = 0; /** * Upper limit for MLO link id * As described in IEEE 802.11be Specification, section 9.4.2.295b.2. * * @hide */ public static final int MAX_MLO_LINK_ID = 15; /** * MLO link state: Invalid link state. Used in {link #getState()} */ public static final int MLO_LINK_STATE_INVALID = 0; /** * MLO link state: Link is not associated with the access point. Used in {link #getState()} */ public static final int MLO_LINK_STATE_UNASSOCIATED = 1; /** * MLO link state: Link is associated to the access point but not mapped to any traffic stream. * Used in {link #getState()} */ public static final int MLO_LINK_STATE_IDLE = 2; /** * MLO link state: Link is associated to the access point and mapped to at least one traffic * stream. {link #getState()} * Note that an MLO link could be in that state but in power save mode. */ public static final int MLO_LINK_STATE_ACTIVE = 3; /** * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"MLO_LINK_STATE_"}, value = { MLO_LINK_STATE_INVALID, MLO_LINK_STATE_UNASSOCIATED, MLO_LINK_STATE_IDLE, MLO_LINK_STATE_ACTIVE}) public @interface MloLinkState {}; private int mLinkId; private MacAddress mApMacAddress; private MacAddress mStaMacAddress; private @MloLinkState int mState; private @WifiAnnotations.WifiBandBasic int mBand; private int mChannel; /** * Constructor for a MloLInk. */ public MloLink() { mBand = WifiScanner.WIFI_BAND_UNSPECIFIED; mChannel = 0; mState = MLO_LINK_STATE_UNASSOCIATED; mApMacAddress = null; mStaMacAddress = null; mLinkId = INVALID_MLO_LINK_ID; } /** * Copy Constructor * * @hide */ public MloLink(MloLink source, long redactions) { mBand = source.mBand; mChannel = source.mChannel; mLinkId = source.mLinkId; mState = source.mState; mStaMacAddress = ((redactions & NetworkCapabilities.REDACT_FOR_LOCAL_MAC_ADDRESS) != 0) || source.mStaMacAddress == null ? null : MacAddress.fromString(source.mStaMacAddress.toString()); mApMacAddress = ((redactions & NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION) != 0) || source.mApMacAddress == null ? null : MacAddress.fromString(source.mApMacAddress.toString()); } /** Returns the Wi-Fi band of this link as one of: * {@link WifiScanner#WIFI_BAND_UNSPECIFIED}, * {@link WifiScanner#WIFI_BAND_24_GHZ}, * {@link WifiScanner#WIFI_BAND_5_GHZ}, * {@link WifiScanner#WIFI_BAND_6_GHZ} */ public @WifiAnnotations.WifiBandBasic int getBand() { return mBand; } /** * Returns the channel number of this link. * A valid value is based on the 802.11 specification in sections 19.3.15 and 27.3.23 */ @IntRange(from = 1) public int getChannel() { return mChannel; } /** * Returns the link id of this link. * Valid values are 0-15, as described in IEEE 802.11be Specification, section 9.4.2.295b.2. * * @return {@link #INVALID_MLO_LINK_ID} or a valid value (0-15). */ @IntRange(from = INVALID_MLO_LINK_ID, to = MAX_MLO_LINK_ID) public int getLinkId() { return mLinkId; } /** Returns the state of this link as one of: * {@link #MLO_LINK_STATE_INVALID} * {@link #MLO_LINK_STATE_UNASSOCIATED} * {@link #MLO_LINK_STATE_IDLE} * {@link #MLO_LINK_STATE_ACTIVE} */ public @MloLinkState int getState() { return mState; } /** * Returns the AP MAC address of this link. * * @return AP MAC address for this link or null when the caller has insufficient * permissions to access the access point MAC Address. */ public @Nullable MacAddress getApMacAddress() { return mApMacAddress; } /** * Returns the STA MAC address of this link. * * @return STA MAC address assigned for this link, or null in the following cases: *