1 /*
2  * Copyright (C) 2019 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 package android.net.ipsec.ike.exceptions;
17 
18 import android.net.ipsec.ike.ChildSessionCallback;
19 import android.net.ipsec.ike.IkeSessionCallback;
20 
21 import com.android.internal.net.ipsec.ike.utils.IkeMetrics;
22 
23 /**
24  * This exception is thrown if Traffic Selectors negotiation failed.
25  *
26  * <p>This exception indicates either proposed Traffic Selectors by callers is not acceptable or the
27  * negotiated Traffic Selectors from the remote server is invalid.
28  *
29  * @hide
30  */
31 // If remote server is the exchange initiator, IKE library should respond with a TS_UNACCEPTABLE
32 // Notify message. If the remote server is the exchange responder, IKE library should initiate a
33 // Delete IKE exchange and close the IKE Session.
34 public final class TsUnacceptableException extends IkeProtocolException {
35     private static final int EXPECTED_ERROR_DATA_LEN = 0;
36 
37     /**
38      * Construct an instance of TsUnacceptableException.
39      *
40      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
41      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
42      */
TsUnacceptableException()43     public TsUnacceptableException() {
44         super(ERROR_TYPE_TS_UNACCEPTABLE);
45     }
46 
47     /**
48      * Construct a instance of TsUnacceptableException from a notify payload.
49      *
50      * @param notifyData the notify data included in the payload.
51      * @hide
52      */
TsUnacceptableException(byte[] notifyData)53     public TsUnacceptableException(byte[] notifyData) {
54         super(ERROR_TYPE_TS_UNACCEPTABLE, notifyData);
55     }
56 
57     /** @hide */
58     @Override
isValidDataLength(int dataLen)59     protected boolean isValidDataLength(int dataLen) {
60         return EXPECTED_ERROR_DATA_LEN == dataLen;
61     }
62 
63     /**
64      * Returns the error code for metrics
65      *
66      * @hide
67      */
68     @Override
getMetricsErrorCode()69     public int getMetricsErrorCode() {
70         return IkeMetrics.IKE_ERROR_PROTOCOL_TS_UNACCEPTABLE;
71     }
72 }
73