1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.apf; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * APF program support capabilities. APF stands for Android Packet Filtering and it is a flexible 27 * way to drop unwanted network packets to save power. 28 * 29 * See documentation at hardware/google/apf/apf.h 30 * 31 * This class is immutable. 32 * @hide 33 */ 34 @SystemApi 35 public final class ApfCapabilities implements Parcelable { 36 /** 37 * Version of APF instruction set supported for packet filtering. 0 indicates no support for 38 * packet filtering using APF programs. 39 */ 40 public final int apfVersionSupported; 41 42 /** 43 * Maximum size of APF program allowed. 44 */ 45 public final int maximumApfProgramSize; 46 47 /** 48 * Format of packets passed to APF filter. Should be one of ARPHRD_* 49 */ 50 public final int apfPacketFormat; 51 ApfCapabilities( int apfVersionSupported, int maximumApfProgramSize, int apfPacketFormat)52 public ApfCapabilities( 53 int apfVersionSupported, int maximumApfProgramSize, int apfPacketFormat) { 54 this.apfVersionSupported = apfVersionSupported; 55 this.maximumApfProgramSize = maximumApfProgramSize; 56 this.apfPacketFormat = apfPacketFormat; 57 } 58 ApfCapabilities(Parcel in)59 private ApfCapabilities(Parcel in) { 60 apfVersionSupported = in.readInt(); 61 maximumApfProgramSize = in.readInt(); 62 apfPacketFormat = in.readInt(); 63 } 64 65 @Override describeContents()66 public int describeContents() { 67 return 0; 68 } 69 70 @Override writeToParcel(Parcel dest, int flags)71 public void writeToParcel(Parcel dest, int flags) { 72 dest.writeInt(apfVersionSupported); 73 dest.writeInt(maximumApfProgramSize); 74 dest.writeInt(apfPacketFormat); 75 } 76 77 public static final Creator<ApfCapabilities> CREATOR = new Creator<ApfCapabilities>() { 78 @Override 79 public ApfCapabilities createFromParcel(Parcel in) { 80 return new ApfCapabilities(in); 81 } 82 83 @Override 84 public ApfCapabilities[] newArray(int size) { 85 return new ApfCapabilities[size]; 86 } 87 }; 88 89 @NonNull 90 @Override toString()91 public String toString() { 92 return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(), 93 apfVersionSupported, maximumApfProgramSize, apfPacketFormat); 94 } 95 96 @Override equals(@ullable Object obj)97 public boolean equals(@Nullable Object obj) { 98 if (!(obj instanceof ApfCapabilities)) return false; 99 final ApfCapabilities other = (ApfCapabilities) obj; 100 return apfVersionSupported == other.apfVersionSupported 101 && maximumApfProgramSize == other.maximumApfProgramSize 102 && apfPacketFormat == other.apfPacketFormat; 103 } 104 105 /** 106 * Determines whether the APF interpreter advertises support for the data buffer access opcodes 107 * LDDW (LoaD Data Word) and STDW (STore Data Word). Full LDDW (LoaD Data Word) and 108 * STDW (STore Data Word) support is present from APFv4 on. 109 * 110 * @return {@code true} if the IWifiStaIface#readApfPacketFilterData is supported. 111 */ hasDataAccess()112 public boolean hasDataAccess() { 113 return apfVersionSupported >= 4; 114 } 115 116 /** 117 * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames. 118 */ getApfDrop8023Frames()119 public static boolean getApfDrop8023Frames() { 120 // TODO: deprecate/remove this method (now unused in the platform), as the resource was 121 // moved to NetworkStack. 122 return true; 123 } 124 125 /** 126 * @return An array of denylisted EtherType, packets with EtherTypes within it will be dropped. 127 */ getApfEtherTypeBlackList()128 public static @NonNull int[] getApfEtherTypeBlackList() { 129 // TODO: deprecate/remove this method (now unused in the platform), as the resource was 130 // moved to NetworkStack. 131 return new int[] { 0x88a2, 0x88a4, 0x88b8, 0x88cd, 0x88e3 }; 132 } 133 } 134