1 /*
2  * Copyright (C) 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.net.ipsec.ike.ike3gpp;
18 
19 import static com.android.internal.net.ipsec.ike.message.IkeNotifyPayload.ERROR_NOTIFY_TYPE_MAX;
20 
21 import android.annotation.IntRange;
22 import android.annotation.SuppressLint;
23 import android.annotation.SystemApi;
24 
25 import com.android.internal.net.ipsec.ike.message.IkeNotifyPayload;
26 
27 /**
28  * Ike3gppBackoffTimer represents the data provided by the peer/remote endpoint for a BACKOFF_TIMER
29  * Notify payload.
30  *
31  * @see 3GPP TS 24.302 Section 8.2.9.1 BACKOFF_TIMER Notify Payload
32  * @hide
33  */
34 @SystemApi
35 public final class Ike3gppBackoffTimer extends Ike3gppData {
36     /**
37      * Error-Notify indicating that access is not authorized because no subscription was found for
38      * the specified APN.
39      *
40      * <p>NOTE: PRIVATE-USE VALUE; not IANA specified. This value MAY conflict with other private
41      * use values from other extensions.
42      *
43      * <p>Corresponds to DIAMETER_ERROR_USER_NO_APN_SUBSCRIPTION Result code as specified in 3GPP TS
44      * 29.273 Section 10.3.7
45      *
46      * @see 3GPP TS 24.302 Section 8.1.2.2
47      * @deprecated This API is no longer used to distinguish back off timer support. As per TS24.302
48      *     section 8.2.9.1, the BACK_OFF timer can be used with any ERROR_NOTIFY type.
49      */
50     @Deprecated public static final int ERROR_TYPE_NO_APN_SUBSCRIPTION = 9002;
51 
52     /**
53      * Error-Notify indicating that the procedure could not be completed due to network failure.
54      *
55      * <p>NOTE: PRIVATE-USE VALUE; not IANA specified. This value MAY conflict with other private
56      * use values from other extensions.
57      *
58      * <p>Corresponds to DIAMETER_UNABLE_TO_COMPLY Result code as specified in 3GPP TS 29.273
59      *
60      * @see 3GPP TS 24.302 Section 8.1.2.2
61      * @deprecated This API is no longer used to distinguish back off timer support. As per TS24.302
62      *     section 8.2.9.1, the BACK_OFF timer can be used with any ERROR_NOTIFY type.
63      */
64     @Deprecated public static final int ERROR_TYPE_NETWORK_FAILURE = 10500;
65 
66     private final byte mBackoffTimer;
67     private final int mBackoffCause;
68 
69     /**
70      * Constructs an Ike3gppBackoffTimer with the specified parameters.
71      *
72      * @param backoffTimer the backoff timer indicated by the peer
73      * @param backoffCause the cause for this backoff timer, indicated by the peer
74      * @hide
75      */
76     // NoByteOrShort: using byte to be consistent with the Backoff Timer specification
77     @SystemApi
Ike3gppBackoffTimer( @uppressLint"NoByteOrShort") byte backoffTimer, @IntRange(from = 0, to = ERROR_NOTIFY_TYPE_MAX) int backoffCause)78     public Ike3gppBackoffTimer(
79             @SuppressLint("NoByteOrShort") byte backoffTimer,
80             @IntRange(from = 0, to = ERROR_NOTIFY_TYPE_MAX) int backoffCause) {
81         mBackoffTimer = backoffTimer;
82         mBackoffCause = backoffCause;
83     }
84 
85     @Override
getDataType()86     public @DataType int getDataType() {
87         return DATA_TYPE_NOTIFY_BACKOFF_TIMER;
88     }
89 
90     /**
91      * Returns the Backoff Timer specified by the peer.
92      *
93      * <p>The Backoff Timer is coded as the value part (as specified in 3GPP TS 24.007 for type 4
94      * IE) of the GPRS timer 3 information element defined in 3GPP TS 24.008 subclause 10.5.7.4a.
95      */
96     // NoByteOrShort: using byte to be consistent with the Backoff Timer specification
97     @SuppressLint("NoByteOrShort")
getBackoffTimer()98     public byte getBackoffTimer() {
99         return mBackoffTimer;
100     }
101 
102     /** Returns the cause for this Backoff Timer specified by the peer. */
getBackoffCause()103     public @IntRange(from = 0, to = ERROR_NOTIFY_TYPE_MAX) int getBackoffCause() {
104         return mBackoffCause;
105     }
106 
107     /** @hide */
isValidErrorNotifyCause(IkeNotifyPayload notifyPayload)108     public static boolean isValidErrorNotifyCause(IkeNotifyPayload notifyPayload) {
109         return notifyPayload.isErrorNotify();
110     }
111 }
112