Paul Jensen | f21b4dc | 2016-03-18 12:22:09 -0400 | [diff] [blame] | 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 | |
Remi NGUYEN VAN | a4bcc86 | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.annotation.TestApi; |
Remi NGUYEN VAN | 53b0314 | 2019-01-23 23:11:12 +0900 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | |
| 23 | import com.android.internal.R; |
Remi NGUYEN VAN | a4bcc86 | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 24 | |
Paul Jensen | f21b4dc | 2016-03-18 12:22:09 -0400 | [diff] [blame] | 25 | /** |
| 26 | * APF program support capabilities. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
Remi NGUYEN VAN | a4bcc86 | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 30 | @SystemApi |
| 31 | @TestApi |
Paul Jensen | f21b4dc | 2016-03-18 12:22:09 -0400 | [diff] [blame] | 32 | public 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 VAN | 6b0b2b7 | 2019-01-18 18:49:16 +0900 | [diff] [blame] | 49 | public ApfCapabilities( |
| 50 | int apfVersionSupported, int maximumApfProgramSize, int apfPacketFormat) { |
Paul Jensen | f21b4dc | 2016-03-18 12:22:09 -0400 | [diff] [blame] | 51 | this.apfVersionSupported = apfVersionSupported; |
| 52 | this.maximumApfProgramSize = maximumApfProgramSize; |
| 53 | this.apfPacketFormat = apfPacketFormat; |
| 54 | } |
Lorenzo Colitti | 37127f8 | 2016-03-28 15:22:30 +0900 | [diff] [blame] | 55 | |
Remi NGUYEN VAN | 6b0b2b7 | 2019-01-18 18:49:16 +0900 | [diff] [blame] | 56 | @Override |
Lorenzo Colitti | 37127f8 | 2016-03-28 15:22:30 +0900 | [diff] [blame] | 57 | public String toString() { |
Erik Kline | af579eb | 2017-04-21 17:56:55 +0900 | [diff] [blame] | 58 | return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(), |
Lorenzo Colitti | 37127f8 | 2016-03-28 15:22:30 +0900 | [diff] [blame] | 59 | apfVersionSupported, maximumApfProgramSize, apfPacketFormat); |
| 60 | } |
Bernie Innocenti | ab30db7 | 2018-04-24 01:25:42 +0900 | [diff] [blame] | 61 | |
Remi NGUYEN VAN | 6b0b2b7 | 2019-01-18 18:49:16 +0900 | [diff] [blame] | 62 | @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 Innocenti | ab30db7 | 2018-04-24 01:25:42 +0900 | [diff] [blame] | 71 | /** |
| 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 VAN | 53b0314 | 2019-01-23 23:11:12 +0900 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames. |
| 83 | */ |
Remi NGUYEN VAN | 5c5f1ba | 2019-01-29 12:08:43 +0900 | [diff] [blame] | 84 | public static boolean getApfDrop8023Frames(Context context) { |
Remi NGUYEN VAN | 53b0314 | 2019-01-23 23:11:12 +0900 | [diff] [blame] | 85 | 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 VAN | 5c5f1ba | 2019-01-29 12:08:43 +0900 | [diff] [blame] | 91 | public static int[] getApfEthTypeBlackList(Context context) { |
Remi NGUYEN VAN | 53b0314 | 2019-01-23 23:11:12 +0900 | [diff] [blame] | 92 | return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList); |
| 93 | } |
Lorenzo Colitti | 37127f8 | 2016-03-28 15:22:30 +0900 | [diff] [blame] | 94 | } |