• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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.telephony.data;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.net.LinkAddress;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Objects;
31 
32 /**
33  * Class that stores QOS filter parameters as defined in
34  * 3gpp 24.008 10.5.6.12 and 3gpp 24.501 9.11.4.13.
35  *
36  * @hide
37  */
38 public final class QosBearerFilter implements Parcelable {
39     private @NonNull List<LinkAddress> localAddresses;
40     private @NonNull List<LinkAddress> remoteAddresses;
41     private @Nullable PortRange localPort;
42     private @Nullable PortRange remotePort;
43 
44     /** @hide */
45     @Retention(RetentionPolicy.SOURCE)
46     @IntDef(prefix = "QOS_PROTOCOL_",
47             value = {QOS_PROTOCOL_UNSPECIFIED, QOS_PROTOCOL_TCP, QOS_PROTOCOL_UDP,
48                     QOS_PROTOCOL_ESP, QOS_PROTOCOL_AH})
49     public @interface QosProtocol {}
50 
51     public static final int QOS_PROTOCOL_UNSPECIFIED =
52             android.hardware.radio.V1_6.QosProtocol.UNSPECIFIED;
53     public static final int QOS_PROTOCOL_TCP = android.hardware.radio.V1_6.QosProtocol.TCP;
54     public static final int QOS_PROTOCOL_UDP = android.hardware.radio.V1_6.QosProtocol.UDP;
55     public static final int QOS_PROTOCOL_ESP = android.hardware.radio.V1_6.QosProtocol.ESP;
56     public static final int QOS_PROTOCOL_AH = android.hardware.radio.V1_6.QosProtocol.AH;
57     public static final int QOS_MIN_PORT = android.hardware.radio.V1_6.QosPortRange.MIN;
58     /**
59      * Hardcoded in place of android.hardware.radio.V1_6.QosPortRange.MAX as it
60      * returns -1 due to uint16_t to int conversion in java. (TODO: Fix the HAL)
61      */
62     public static final int QOS_MAX_PORT = 65535; // android.hardware.radio.V1_6.QosPortRange.MIN;
63 
64     private @QosProtocol int protocol;
65 
66     private int typeOfServiceMask;
67 
68     private long flowLabel;
69 
70     /** IPSec security parameter index */
71     private long securityParameterIndex;
72 
73     /** @hide */
74     @Retention(RetentionPolicy.SOURCE)
75     @IntDef(prefix = "QOS_FILTER_DIRECTION_",
76             value = {QOS_FILTER_DIRECTION_DOWNLINK, QOS_FILTER_DIRECTION_UPLINK,
77                     QOS_FILTER_DIRECTION_BIDIRECTIONAL})
78     public @interface QosBearerFilterDirection {}
79 
80     public static final int QOS_FILTER_DIRECTION_DOWNLINK =
81             android.hardware.radio.V1_6.QosFilterDirection.DOWNLINK;
82     public static final int QOS_FILTER_DIRECTION_UPLINK =
83             android.hardware.radio.V1_6.QosFilterDirection.UPLINK;
84     public static final int QOS_FILTER_DIRECTION_BIDIRECTIONAL =
85             android.hardware.radio.V1_6.QosFilterDirection.BIDIRECTIONAL;
86 
87     private @QosBearerFilterDirection int filterDirection;
88 
89     /**
90      * Specified the order in which the filter needs to be matched.
91      * A Lower numerical value has a higher precedence.
92      */
93     private int precedence;
94 
QosBearerFilter(@onNull List<LinkAddress> localAddresses, @NonNull List<LinkAddress> remoteAddresses, @Nullable PortRange localPort, @Nullable PortRange remotePort, @QosProtocol int protocol, int tos, long flowLabel, long spi, @QosBearerFilterDirection int direction, int precedence)95     public QosBearerFilter(@NonNull List<LinkAddress> localAddresses,
96             @NonNull List<LinkAddress> remoteAddresses, @Nullable PortRange localPort,
97             @Nullable PortRange remotePort, @QosProtocol int protocol, int tos, long flowLabel,
98             long spi, @QosBearerFilterDirection int direction, int precedence) {
99         this.localAddresses = new ArrayList<>();
100         this.localAddresses.addAll(localAddresses);
101         this.remoteAddresses = new ArrayList<>();
102         this.remoteAddresses.addAll(remoteAddresses);
103         this.localPort = localPort;
104         this.remotePort = remotePort;
105         this.protocol = protocol;
106         this.typeOfServiceMask = tos;
107         this.flowLabel = flowLabel;
108         this.securityParameterIndex = spi;
109         this.filterDirection = direction;
110         this.precedence = precedence;
111     }
112 
getLocalAddresses()113     public @NonNull List<LinkAddress> getLocalAddresses() {
114         return localAddresses;
115     }
116 
getRemoteAddresses()117     public @NonNull List<LinkAddress> getRemoteAddresses() {
118         return remoteAddresses;
119     }
120 
getLocalPortRange()121     public @Nullable PortRange getLocalPortRange() {
122         return localPort;
123     }
124 
getRemotePortRange()125     public @Nullable PortRange getRemotePortRange() {
126         return remotePort;
127     }
128 
getPrecedence()129     public int getPrecedence() {
130         return precedence;
131     }
132 
133     public static class PortRange implements Parcelable {
134         int start;
135         int end;
136 
PortRange(Parcel source)137         private PortRange(Parcel source) {
138             start = source.readInt();
139             end = source.readInt();
140         }
141 
PortRange(int start, int end)142         public PortRange(int start, int end) {
143             this.start = start;
144             this.end = end;
145         }
146 
getStart()147         public int getStart() {
148             return start;
149         }
150 
getEnd()151         public int getEnd() {
152             return end;
153         }
154 
isValid()155         public boolean isValid() {
156             return start >= QOS_MIN_PORT && start <= QOS_MAX_PORT
157                     && end >= QOS_MIN_PORT && end <= QOS_MAX_PORT
158                     && start <= end;
159         }
160 
161         @Override
writeToParcel(@onNull Parcel dest, int flags)162         public void writeToParcel(@NonNull Parcel dest, int flags) {
163             dest.writeInt(start);
164             dest.writeInt(end);
165         }
166 
167         @Override
describeContents()168         public int describeContents() {
169             return 0;
170         }
171 
172         public static final @NonNull Parcelable.Creator<PortRange> CREATOR =
173                 new Parcelable.Creator<PortRange>() {
174                     @Override
175                     public PortRange createFromParcel(Parcel source) {
176                         return new PortRange(source);
177                     }
178 
179                     @Override
180                     public PortRange[] newArray(int size) {
181                         return new PortRange[size];
182                     }
183                 };
184 
185         @Override
toString()186         public String toString() {
187             return "PortRange {"
188                     + " start=" + start
189                     + " end=" + end + "}";
190         }
191 
192         @Override
equals(Object o)193         public boolean equals(Object o) {
194             if (this == o) return true;
195 
196             if (o == null || !(o instanceof PortRange)) {
197               return false;
198             }
199 
200             PortRange other = (PortRange) o;
201             return start == other.start
202                     && end == other.end;
203         }
204 
205         @Override
hashCode()206         public int hashCode() {
207             return Objects.hash(start, end);
208         }
209     };
210 
211     @Override
toString()212     public String toString() {
213         return "QosBearerFilter {"
214                 + " localAddresses=" + localAddresses
215                 + " remoteAddresses=" + remoteAddresses
216                 + " localPort=" + localPort
217                 + " remotePort=" + remotePort
218                 + " protocol=" + protocol
219                 + " typeOfServiceMask=" + typeOfServiceMask
220                 + " flowLabel=" + flowLabel
221                 + " securityParameterIndex=" + securityParameterIndex
222                 + " filterDirection=" + filterDirection
223                 + " precedence=" + precedence + "}";
224     }
225 
226     @Override
hashCode()227     public int hashCode() {
228         return Objects.hash(localAddresses, remoteAddresses, localPort,
229                 remotePort, protocol, typeOfServiceMask, flowLabel,
230                 securityParameterIndex, filterDirection, precedence);
231     }
232 
233     @Override
equals(Object o)234     public boolean equals(Object o) {
235         if (this == o) return true;
236 
237         if (o == null || !(o instanceof QosBearerFilter)) {
238             return false;
239         }
240 
241         QosBearerFilter other = (QosBearerFilter) o;
242 
243         return localAddresses.size() == other.localAddresses.size()
244                 && localAddresses.containsAll(other.localAddresses)
245                 && remoteAddresses.size() == other.remoteAddresses.size()
246                 && remoteAddresses.containsAll(other.remoteAddresses)
247                 && Objects.equals(localPort, other.localPort)
248                 && Objects.equals(remotePort, other.remotePort)
249                 && protocol == other.protocol
250                 && typeOfServiceMask == other.typeOfServiceMask
251                 && flowLabel == other.flowLabel
252                 && securityParameterIndex == other.securityParameterIndex
253                 && filterDirection == other.filterDirection
254                 && precedence == other.precedence;
255     }
256 
QosBearerFilter(Parcel source)257     private QosBearerFilter(Parcel source) {
258         localAddresses = new ArrayList<>();
259         source.readList(localAddresses, LinkAddress.class.getClassLoader(), android.net.LinkAddress.class);
260         remoteAddresses = new ArrayList<>();
261         source.readList(remoteAddresses, LinkAddress.class.getClassLoader(), android.net.LinkAddress.class);
262         localPort = source.readParcelable(PortRange.class.getClassLoader(), android.telephony.data.QosBearerFilter.PortRange.class);
263         remotePort = source.readParcelable(PortRange.class.getClassLoader(), android.telephony.data.QosBearerFilter.PortRange.class);
264         protocol = source.readInt();
265         typeOfServiceMask = source.readInt();
266         flowLabel = source.readLong();
267         securityParameterIndex = source.readLong();
268         filterDirection = source.readInt();
269         precedence = source.readInt();
270     }
271 
272     @Override
writeToParcel(@onNull Parcel dest, int flags)273     public void writeToParcel(@NonNull Parcel dest, int flags) {
274         dest.writeList(localAddresses);
275         dest.writeList(remoteAddresses);
276         dest.writeParcelable(localPort, flags);
277         dest.writeParcelable(remotePort, flags);
278         dest.writeInt(protocol);
279         dest.writeInt(typeOfServiceMask);
280         dest.writeLong(flowLabel);
281         dest.writeLong(securityParameterIndex);
282         dest.writeInt(filterDirection);
283         dest.writeInt(precedence);
284     }
285 
286     @Override
describeContents()287     public int describeContents() {
288         return 0;
289     }
290 
291     public static final @NonNull Parcelable.Creator<QosBearerFilter> CREATOR =
292             new Parcelable.Creator<QosBearerFilter>() {
293                 @Override
294                 public QosBearerFilter createFromParcel(Parcel source) {
295                     return new QosBearerFilter(source);
296                 }
297 
298                 @Override
299                 public QosBearerFilter[] newArray(int size) {
300                     return new QosBearerFilter[size];
301                 }
302             };
303 }
304