blob: e09fa8fd9e7729c4f6891f5a9f3a5dfe141370ec [file] [log] [blame]
Paul Jensenf21b4dc2016-03-18 12:22:09 -04001/*
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
17package android.net.apf;
18
Remi NGUYEN VANa4bcc862019-01-28 13:28:35 +090019import android.annotation.SystemApi;
20import android.annotation.TestApi;
Remi NGUYEN VAN53b03142019-01-23 23:11:12 +090021import android.content.Context;
22
23import com.android.internal.R;
Remi NGUYEN VANa4bcc862019-01-28 13:28:35 +090024
Paul Jensenf21b4dc2016-03-18 12:22:09 -040025/**
26 * APF program support capabilities.
27 *
28 * @hide
29 */
Remi NGUYEN VANa4bcc862019-01-28 13:28:35 +090030@SystemApi
31@TestApi
Paul Jensenf21b4dc2016-03-18 12:22:09 -040032public class ApfCapabilities {
33 /**
34 * Version of APF instruction set supported for packet filtering. 0 indicates no support for
35 * packet filtering using APF programs.
36 */
37 public final int apfVersionSupported;
38
39 /**
40 * Maximum size of APF program allowed.
41 */
42 public final int maximumApfProgramSize;
43
44 /**
45 * Format of packets passed to APF filter. Should be one of ARPHRD_*
46 */
47 public final int apfPacketFormat;
48
Remi NGUYEN VAN6b0b2b72019-01-18 18:49:16 +090049 public ApfCapabilities(
50 int apfVersionSupported, int maximumApfProgramSize, int apfPacketFormat) {
Paul Jensenf21b4dc2016-03-18 12:22:09 -040051 this.apfVersionSupported = apfVersionSupported;
52 this.maximumApfProgramSize = maximumApfProgramSize;
53 this.apfPacketFormat = apfPacketFormat;
54 }
Lorenzo Colitti37127f82016-03-28 15:22:30 +090055
Remi NGUYEN VAN6b0b2b72019-01-18 18:49:16 +090056 @Override
Lorenzo Colitti37127f82016-03-28 15:22:30 +090057 public String toString() {
Erik Klineaf579eb2017-04-21 17:56:55 +090058 return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
Lorenzo Colitti37127f82016-03-28 15:22:30 +090059 apfVersionSupported, maximumApfProgramSize, apfPacketFormat);
60 }
Bernie Innocentiab30db72018-04-24 01:25:42 +090061
Remi NGUYEN VAN6b0b2b72019-01-18 18:49:16 +090062 @Override
63 public boolean equals(Object obj) {
64 if (!(obj instanceof ApfCapabilities)) return false;
65 final ApfCapabilities other = (ApfCapabilities) obj;
66 return apfVersionSupported == other.apfVersionSupported
67 && maximumApfProgramSize == other.maximumApfProgramSize
68 && apfPacketFormat == other.apfPacketFormat;
69 }
70
Bernie Innocentiab30db72018-04-24 01:25:42 +090071 /**
72 * Returns true if the APF interpreter advertises support for the data buffer access opcodes
73 * LDDW and STDW.
74 *
75 * Full LDDW and STDW support is present from APFv4 on.
76 */
77 public boolean hasDataAccess() {
78 return apfVersionSupported >= 4;
79 }
Remi NGUYEN VAN53b03142019-01-23 23:11:12 +090080
81 /**
82 * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
83 */
Remi NGUYEN VAN5c5f1ba2019-01-29 12:08:43 +090084 public static boolean getApfDrop8023Frames(Context context) {
Remi NGUYEN VAN53b03142019-01-23 23:11:12 +090085 return context.getResources().getBoolean(R.bool.config_apfDrop802_3Frames);
86 }
87
88 /**
89 * @return An array of blacklisted EtherType, packets with EtherTypes within it will be dropped.
90 */
Remi NGUYEN VAN5c5f1ba2019-01-29 12:08:43 +090091 public static int[] getApfEthTypeBlackList(Context context) {
Remi NGUYEN VAN53b03142019-01-23 23:11:12 +090092 return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList);
93 }
Lorenzo Colitti37127f82016-03-28 15:22:30 +090094}