1 /*
2  * Copyright (C) 2023 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;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import java.util.Objects;
27 
28 /**
29  * A single occurrence of a cellular identifier being disclosed in the clear before a security
30  * context is established.
31  *
32  * @hide
33  */
34 public final class CellularIdentifierDisclosure implements Parcelable {
35     private static final String TAG = "CellularIdentifierDisclosure";
36 
37     private @NasProtocolMessage int mNasProtocolMessage;
38     private @CellularIdentifier int mCellularIdentifier;
39     private String mPlmn;
40     private boolean mIsEmergency;
41 
CellularIdentifierDisclosure(@asProtocolMessage int nasProtocolMessage, @CellularIdentifier int cellularIdentifier, String plmn, boolean isEmergency)42     public CellularIdentifierDisclosure(@NasProtocolMessage int nasProtocolMessage,
43             @CellularIdentifier int cellularIdentifier, String plmn, boolean isEmergency) {
44         mNasProtocolMessage = nasProtocolMessage;
45         mCellularIdentifier = cellularIdentifier;
46         mPlmn = plmn;
47         mIsEmergency = isEmergency;
48     }
49 
CellularIdentifierDisclosure(Parcel in)50     private CellularIdentifierDisclosure(Parcel in) {
51         readFromParcel(in);
52     }
53 
getNasProtocolMessage()54     public @NasProtocolMessage int getNasProtocolMessage() {
55         return mNasProtocolMessage;
56     }
57 
getCellularIdentifier()58     public @CellularIdentifier int getCellularIdentifier() {
59         return mCellularIdentifier;
60     }
61 
getPlmn()62     public String getPlmn() {
63         return mPlmn;
64     }
65 
isEmergency()66     public boolean isEmergency() {
67         return mIsEmergency;
68     }
69 
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     @Override
writeToParcel(Parcel out, int flags)76     public void writeToParcel(Parcel out, int flags) {
77         out.writeInt(mNasProtocolMessage);
78         out.writeInt(mCellularIdentifier);
79         out.writeBoolean(mIsEmergency);
80         out.writeString8(mPlmn);
81     }
82 
83     public static final Parcelable.Creator<CellularIdentifierDisclosure> CREATOR =
84             new Parcelable.Creator<CellularIdentifierDisclosure>() {
85                 public CellularIdentifierDisclosure createFromParcel(Parcel in) {
86                     return new CellularIdentifierDisclosure(in);
87                 }
88 
89                 public CellularIdentifierDisclosure[] newArray(int size) {
90                     return new CellularIdentifierDisclosure[size];
91                 }
92             };
93 
94     @Override
toString()95     public String toString() {
96         return TAG + ":{ mNasProtocolMessage = " + mNasProtocolMessage
97                 + " mCellularIdentifier = " + mCellularIdentifier + " mIsEmergency = "
98                 + mIsEmergency + " mPlmn = " + mPlmn;
99     }
100 
101     @Override
equals(Object o)102     public boolean equals(Object o) {
103         if (this == o) return true;
104         if (!(o instanceof CellularIdentifierDisclosure)) return false;
105         CellularIdentifierDisclosure that = (CellularIdentifierDisclosure) o;
106         return mNasProtocolMessage == that.mNasProtocolMessage
107                 && mCellularIdentifier == that.mCellularIdentifier
108                 && mIsEmergency == that.mIsEmergency && mPlmn.equals(that.mPlmn);
109     }
110 
111     @Override
hashCode()112     public int hashCode() {
113         return Objects.hash(mNasProtocolMessage, mCellularIdentifier, mIsEmergency,
114                 mPlmn);
115     }
116 
readFromParcel(@onNull Parcel in)117     private void readFromParcel(@NonNull Parcel in) {
118         mNasProtocolMessage = in.readInt();
119         mCellularIdentifier = in.readInt();
120         mIsEmergency = in.readBoolean();
121         mPlmn = in.readString8();
122     }
123 
124     public static final int NAS_PROTOCOL_MESSAGE_UNKNOWN = 0;
125     public static final int NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST = 1;
126     public static final int NAS_PROTOCOL_MESSAGE_IDENTITY_RESPONSE = 2;
127     public static final int NAS_PROTOCOL_MESSAGE_DETACH_REQUEST = 3;
128     public static final int NAS_PROTOCOL_MESSAGE_TRACKING_AREA_UPDATE_REQUEST = 4;
129     public static final int NAS_PROTOCOL_MESSAGE_LOCATION_UPDATE_REQUEST = 5;
130     public static final int NAS_PROTOCOL_MESSAGE_AUTHENTICATION_AND_CIPHERING_RESPONSE = 6;
131     public static final int NAS_PROTOCOL_MESSAGE_REGISTRATION_REQUEST = 7;
132     public static final int NAS_PROTOCOL_MESSAGE_DEREGISTRATION_REQUEST = 8;
133     public static final int NAS_PROTOCOL_MESSAGE_CM_REESTABLISHMENT_REQUEST = 9;
134     public static final int NAS_PROTOCOL_MESSAGE_CM_SERVICE_REQUEST = 10;
135     public static final int NAS_PROTOCOL_MESSAGE_IMSI_DETACH_INDICATION = 11;
136 
137     /** @hide */
138     @Retention(RetentionPolicy.SOURCE)
139     @IntDef(prefix = {"NAS_PROTOCOL_MESSAGE_"}, value = {NAS_PROTOCOL_MESSAGE_UNKNOWN,
140             NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST, NAS_PROTOCOL_MESSAGE_IDENTITY_RESPONSE,
141             NAS_PROTOCOL_MESSAGE_DETACH_REQUEST, NAS_PROTOCOL_MESSAGE_TRACKING_AREA_UPDATE_REQUEST,
142             NAS_PROTOCOL_MESSAGE_LOCATION_UPDATE_REQUEST,
143             NAS_PROTOCOL_MESSAGE_AUTHENTICATION_AND_CIPHERING_RESPONSE,
144             NAS_PROTOCOL_MESSAGE_REGISTRATION_REQUEST, NAS_PROTOCOL_MESSAGE_DEREGISTRATION_REQUEST,
145             NAS_PROTOCOL_MESSAGE_CM_REESTABLISHMENT_REQUEST,
146             NAS_PROTOCOL_MESSAGE_CM_SERVICE_REQUEST, NAS_PROTOCOL_MESSAGE_IMSI_DETACH_INDICATION})
147     public @interface NasProtocolMessage {
148     }
149 
150     public static final int CELLULAR_IDENTIFIER_UNKNOWN = 0;
151     public static final int CELLULAR_IDENTIFIER_IMSI = 1;
152     public static final int CELLULAR_IDENTIFIER_IMEI = 2;
153     public static final int CELLULAR_IDENTIFIER_SUCI = 3;
154 
155     /** @hide */
156     @Retention(RetentionPolicy.SOURCE)
157     @IntDef(prefix = {"CELLULAR_IDENTIFIER_"}, value = {CELLULAR_IDENTIFIER_UNKNOWN,
158             CELLULAR_IDENTIFIER_IMSI, CELLULAR_IDENTIFIER_IMEI, CELLULAR_IDENTIFIER_SUCI})
159     public @interface CellularIdentifier {
160     }
161 }
162