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.NonNull; 20 import android.annotation.SuppressLint; 21 import android.annotation.SystemApi; 22 23 import java.util.Objects; 24 25 /** 26 * Ike3gppParams is used to configure 3GPP-specific parameters to be used during an IKE Session. 27 * 28 * @see 3GPP ETSI TS 24.302: Access to the 3GPP Evolved Packet Core (EPC) via non-3GPP access 29 * networks 30 * @hide 31 */ 32 @SystemApi 33 public final class Ike3gppParams { 34 /** If the PDU Session ID is not set, it will be reported as 0. */ 35 // NoByteOrShort: using byte to be consistent with the PDU Session ID specification 36 @SuppressLint("NoByteOrShort") 37 public static final byte PDU_SESSION_ID_UNSET = 0; 38 39 private final byte mPduSessionId; 40 Ike3gppParams(byte pduSessionId)41 private Ike3gppParams(byte pduSessionId) { 42 mPduSessionId = pduSessionId; 43 } 44 45 /** 46 * Retrieves the PDU Session ID for this Ike3gppParams. 47 * 48 * <p>If the PDU Session ID was not set and this method is called, {@link PDU_SESSION_ID_UNSET} 49 * will be returned. 50 */ 51 // NoByteOrShort: using byte to be consistent with the PDU Session ID specification 52 @SuppressLint("NoByteOrShort") getPduSessionId()53 public byte getPduSessionId() { 54 return mPduSessionId; 55 } 56 57 /** 58 * Returns true if the PDU Session ID is set for this instance. 59 * 60 * @hide 61 */ hasPduSessionId()62 public boolean hasPduSessionId() { 63 return mPduSessionId != PDU_SESSION_ID_UNSET; 64 } 65 66 @Override hashCode()67 public int hashCode() { 68 return Objects.hash(mPduSessionId); 69 } 70 71 @Override equals(Object o)72 public boolean equals(Object o) { 73 if (!(o instanceof Ike3gppParams)) { 74 return false; 75 } 76 77 return mPduSessionId == ((Ike3gppParams) o).mPduSessionId; 78 } 79 80 @Override toString()81 public String toString() { 82 return new StringBuilder() 83 .append("Ike3gppParams={ ") 84 .append("pduSessionId=") 85 .append(String.format("%02X", mPduSessionId)) 86 .append(" }") 87 .toString(); 88 } 89 90 /** This class can be used to incrementally construct an {@link Ike3gppParams}. */ 91 public static final class Builder { 92 private byte mPduSessionId = PDU_SESSION_ID_UNSET; 93 94 /** 95 * Sets the PDU Session ID to be used for the 3GPP N1_MODE_CAPABILITY payload. 96 * 97 * <p>Setting the PDU Session ID will configure the IKE Session to notify the server that it 98 * supports N1_MODE. 99 * 100 * <p>{@link PDU_SESSION_ID_UNSET} will clear the previously-set PDU Session ID. 101 * 102 * @see TS 24.007 Section 11.2.3.1b for the definition of PDU Session ID encoding 103 * @see TS 24.302 Section 7.2.2 for context on PDU Session ID usage 104 * @see TS 24.302 Section 8.2.9.15 for a description of the N1_MODE_CAPABILITY payload 105 * @param pduSessionId the PDU Session ID value to be used in this IKE Session 106 * @return Builder this, to facilitate chaining 107 */ 108 // NoByteOrShort: using byte to be consistent with the PDU Session ID specification 109 @NonNull setPduSessionId(@uppressLint"NoByteOrShort") byte pduSessionId)110 public Builder setPduSessionId(@SuppressLint("NoByteOrShort") byte pduSessionId) { 111 mPduSessionId = pduSessionId; 112 return this; 113 } 114 115 /** 116 * Validates and builds the {@link Ike3gppParams}. 117 * 118 * @return Ike3gppParams the validated Ike3gppParams 119 */ 120 @NonNull build()121 public Ike3gppParams build() { 122 return new Ike3gppParams(mPduSessionId); 123 } 124 } 125 } 126