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 android.annotation.IntDef; 20 import android.annotation.SuppressLint; 21 import android.annotation.SystemApi; 22 import android.util.ArraySet; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.util.Set; 27 28 /** 29 * Ike3gppBackoffTimer represents the data provided by the peer/remote endpoint for a BACKOFF_TIMER 30 * Notify payload. 31 * 32 * @see 3GPP TS 24.302 Section 8.2.9.1 BACKOFF_TIMER Notify Payload 33 * @hide 34 */ 35 @SystemApi 36 public final class Ike3gppBackoffTimer extends Ike3gppData { 37 /** 38 * Error-Notify indicating that access is not authorized because no subscription was found for 39 * the specified APN. 40 * 41 * <p>NOTE: PRIVATE-USE VALUE; not IANA specified. This value MAY conflict with other private 42 * use values from other extensions. 43 * 44 * <p>Corresponds to DIAMETER_ERROR_USER_NO_APN_SUBSCRIPTION Result code as specified in 3GPP TS 45 * 29.273 Section 10.3.7 46 * 47 * @see 3GPP TS 24.302 Section 8.1.2.2 48 */ 49 public static final int ERROR_TYPE_NO_APN_SUBSCRIPTION = 9002; 50 51 /** 52 * Error-Notify indicating that the procedure could not be completed due to network failure. 53 * 54 * <p>NOTE: PRIVATE-USE VALUE; not IANA specified. This value MAY conflict with other private 55 * use values from other extensions. 56 * 57 * <p>Corresponds to DIAMETER_UNABLE_TO_COMPLY Result code as specified in 3GPP TS 29.273 58 * 59 * @see 3GPP TS 24.302 Section 8.1.2.2 60 */ 61 public static final int ERROR_TYPE_NETWORK_FAILURE = 10500; 62 63 /** @hide */ 64 @Retention(RetentionPolicy.SOURCE) 65 @IntDef({ERROR_TYPE_NO_APN_SUBSCRIPTION, ERROR_TYPE_NETWORK_FAILURE}) 66 public @interface ErrorType {} 67 68 private static final Set<Integer> VALID_BACKOFF_TIMER_CAUSES; 69 70 static { 71 VALID_BACKOFF_TIMER_CAUSES = new ArraySet<>(); 72 VALID_BACKOFF_TIMER_CAUSES.add(ERROR_TYPE_NO_APN_SUBSCRIPTION); 73 VALID_BACKOFF_TIMER_CAUSES.add(ERROR_TYPE_NETWORK_FAILURE); 74 } 75 76 private final byte mBackoffTimer; 77 private final int mBackoffCause; 78 79 /** 80 * Constructs an Ike3gppBackoffTimer with the specified parameters. 81 * 82 * @param backoffTimer the backoff timer indicated by the peer 83 * @param backoffCause the cause for this backoff timer, indicated by the peer 84 * @hide 85 */ 86 // NoByteOrShort: using byte to be consistent with the Backoff Timer specification 87 @SystemApi Ike3gppBackoffTimer( @uppressLint"NoByteOrShort") byte backoffTimer, @ErrorType int backoffCause)88 public Ike3gppBackoffTimer( 89 @SuppressLint("NoByteOrShort") byte backoffTimer, @ErrorType int backoffCause) { 90 mBackoffTimer = backoffTimer; 91 mBackoffCause = backoffCause; 92 } 93 94 @Override getDataType()95 public @DataType int getDataType() { 96 return DATA_TYPE_NOTIFY_BACKOFF_TIMER; 97 } 98 99 /** 100 * Returns the Backoff Timer specified by the peer. 101 * 102 * <p>The Backoff Timer is coded as the value part (as specified in 3GPP TS 24.007 for type 4 103 * IE) of the GPRS timer 3 information element defined in 3GPP TS 24.008 subclause 10.5.7.4a. 104 */ 105 // NoByteOrShort: using byte to be consistent with the Backoff Timer specification 106 @SuppressLint("NoByteOrShort") getBackoffTimer()107 public byte getBackoffTimer() { 108 return mBackoffTimer; 109 } 110 111 /** Returns the cause for this Backoff Timer specified by the peer. */ getBackoffCause()112 public @ErrorType int getBackoffCause() { 113 return mBackoffCause; 114 } 115 116 /** @hide */ isValidErrorNotifyCause(int notifyType)117 public static boolean isValidErrorNotifyCause(int notifyType) { 118 return VALID_BACKOFF_TIMER_CAUSES.contains(notifyType); 119 } 120 } 121