• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_SIM_STATE_TYPE_H
17 #define OHOS_SIM_STATE_TYPE_H
18 
19 #include <map>
20 #include <parcel.h>
21 #include <string>
22 #include <vector>
23 
24 namespace OHOS {
25 namespace Telephony {
26 /**
27  * @brief Icc card type
28  */
29 enum class CardType {
30     /**
31      * Icc card type: Unknow type Card.
32      */
33     UNKNOWN_CARD = -1,
34 
35     /**
36      * Icc card type: Single sim card type.
37      */
38     SINGLE_MODE_SIM_CARD = 10,
39 
40     /**
41      * Icc card type: Single usim card type.
42      */
43     SINGLE_MODE_USIM_CARD = 20,
44 
45     /**
46      * Icc card type: Single ruim card type.
47      */
48     SINGLE_MODE_RUIM_CARD = 30,
49 
50     /**
51      * Icc card type: Double card C+G.
52      */
53     DUAL_MODE_CG_CARD = 40,
54 
55     /**
56      * Icc card type: Roaming Card (Dual Mode).
57      */
58     CT_NATIONAL_ROAMING_CARD = 41,
59 
60     /**
61      * Icc card type: China Unicom Dual Mode Card.
62      */
63     CU_DUAL_MODE_CARD = 42,
64 
65     /**
66      * Icc card type: LTE Card (Dual Mode).
67      */
68     DUAL_MODE_TELECOM_LTE_CARD = 43,
69 
70     /**
71      * Icc card type: Double card U+G.
72      */
73     DUAL_MODE_UG_CARD = 50,
74 
75     /**
76      * Icc card type: Single isim card type.
77      */
78     SINGLE_MODE_ISIM_CARD = 60,
79 };
80 
81 /**
82  * @brief SIM card state
83  */
84 enum class SimState {
85     /**
86      * Indicates unknown SIM card state, that is, the accurate status cannot be obtained.
87      */
88     SIM_STATE_UNKNOWN,
89 
90     /**
91      * Indicates that the SIM card is in the <b>not present</b> state, that is, no SIM card is inserted
92      * into the card slot.
93      */
94     SIM_STATE_NOT_PRESENT,
95 
96     /**
97      * Indicates that the SIM card is in the <b>locked</b> state, that is, the SIM card is locked by the
98      * personal identification number (PIN)/PIN unblocking key (PUK) or network.
99      */
100     SIM_STATE_LOCKED,
101 
102     /**
103      * Indicates that the SIM card is in the <b>not ready</b> state, that is, the SIM card is in position
104      * but cannot work properly.
105      */
106     SIM_STATE_NOT_READY,
107 
108     /**
109      * Indicates that the SIM card is in the <b>ready</b> state, that is, the SIM card is in position and
110      * is working properly.
111      */
112     SIM_STATE_READY,
113 
114     /**
115      * Indicates that the SIM card is in the <b>loaded</b> state, that is, the SIM card is in position and
116      * is working properly.
117      */
118     SIM_STATE_LOADED
119 };
120 
121 /**
122  * @brief Lock reason
123  */
124 enum class LockReason {
125     SIM_NONE,
126     SIM_PIN,
127     SIM_PUK,
128     /**
129      * Network Personalization (refer 3GPP TS 22.022 [33])
130      */
131     SIM_PN_PIN,
132     SIM_PN_PUK,
133     /**
134      * Network sUbset Personalization (refer 3GPP TS 22.022 [33])
135      */
136     SIM_PU_PIN,
137     SIM_PU_PUK,
138     /**
139      * Service supplier Personalization (refer 3GPP TS 22.022 [33])
140      */
141     SIM_PP_PIN,
142     SIM_PP_PUK,
143     /**
144      * Corporate Personalization (refer 3GPP TS 22.022 [33])
145      */
146     SIM_PC_PIN,
147     SIM_PC_PUK,
148     /**
149      * SIM/USIM Personalisation (refer 3GPP TS 22.022 [33])
150      */
151     SIM_SIM_PIN,
152     SIM_SIM_PUK,
153 };
154 
155 /**
156  * @brief Personalization lock type
157  */
158 enum class PersoLockType {
159     /**
160      * Network Personalization (refer 3GPP TS 22.022 [33])
161      */
162     PN_PIN_LOCK,
163     PN_PUK_LOCK,
164     /**
165      * Network sUbset Personalization (refer 3GPP TS 22.022 [33])
166      */
167     PU_PIN_LOCK,
168     PU_PUK_LOCK,
169     /**
170      * Service supplier Personalization (refer 3GPP TS 22.022 [33])
171      */
172     PP_PIN_LOCK,
173     PP_PUK_LOCK,
174     /**
175      * Corporate Personalization (refer 3GPP TS 22.022 [33])
176      */
177     PC_PIN_LOCK,
178     PC_PUK_LOCK,
179     /**
180      * SIM/USIM Personalisation (refer 3GPP TS 22.022 [33])
181      */
182     SIM_PIN_LOCK,
183     SIM_PUK_LOCK,
184 };
185 
186 /**
187  * @brief Lock type
188  */
189 enum class LockType {
190     PIN_LOCK = 1,
191     FDN_LOCK = 2,
192 };
193 
194 /**
195  * @brief Authentication type
196  */
197 enum AuthType {
198     /**
199      * Authentication type is EAP-SIM. See RFC 4186
200      */
201     SIM_AUTH_EAP_SIM_TYPE = 128,
202     /**
203      * Authentication type is EAP-AKA. See RFC 4187
204      */
205     SIM_AUTH_EAP_AKA_TYPE = 129,
206 };
207 
208 /**
209  * @brief Lock state
210  */
211 enum class LockState {
212     /**
213      * Indicates that the lock state card is in the off state.
214      */
215     LOCK_OFF = 0,
216 
217     /**
218      * Indicates that the lock state card is in the open state.
219      */
220     LOCK_ON,
221 
222     /**
223      * Indicates that the lock state card is in the error state.
224      */
225     LOCK_ERROR,
226 };
227 
228 /**
229  * @brief icc sim status
230  */
231 enum class IccSimStatus {
232     ICC_CONTENT_UNKNOWN = -1,
233     ICC_CARD_ABSENT = 0,
234     ICC_CONTENT_READY,
235     ICC_CONTENT_PIN,
236     ICC_CONTENT_PUK,
237     ICC_CONTENT_PIN2,
238     ICC_CONTENT_PUK2,
239     ICC_CONTENT_PH_NET_PIN,
240     ICC_CONTENT_PH_NET_PUK,
241     ICC_CONTENT_PH_NET_SUB_PIN,
242     ICC_CONTENT_PH_NET_SUB_PUK,
243     ICC_CONTENT_PH_SP_PIN,
244     ICC_CONTENT_PH_SP_PUK,
245 };
246 
247 /**
248  * @brief Lock information
249  */
250 struct LockInfo {
251     LockType lockType = LockType::PIN_LOCK;
252     std::u16string password = u"";
253     LockState lockState = LockState::LOCK_ERROR;
254 };
255 
256 /**
257  * @brief Personalization lock information
258  */
259 struct PersoLockInfo {
260     PersoLockType lockType = PersoLockType::PN_PIN_LOCK;
261     std::u16string password = u"";
262 };
263 
264 /**
265  * @brief Unlock result
266  */
267 enum UnlockResult {
268     /**
269      * Unlock fail
270      */
271     UNLOCK_FAIL = -2,
272     /**
273      * Password error
274      */
275     UNLOCK_INCORRECT = -1,
276     /**
277      * Unlock successful
278      */
279     UNLOCK_OK = 0,
280 };
281 
282 /**
283  * @brief Lock status response
284  */
285 struct LockStatusResponse {
286     int32_t result = 0;
287     int32_t remain = 0;
288 };
289 
290 /**
291  * @brief SIM card Authentication response
292  */
293 struct SimAuthenticationResponse {
294     /**
295      * Status word 1 of the SIM card, which is returned by the SIM card after command execution
296      */
297     int32_t sw1 = 0;
298     /**
299      * Status word 2 of the SIM card, which is returned by the SIM card after command execution
300      */
301     int32_t sw2 = 0;
302     std::string response = "";
303 };
304 
305 /**
306  * @brief SIM card Authentication result
307  */
308 enum SimAuthResult {
309     /**
310      * Authentication fail
311      */
312     SIM_AUTH_FAIL = -1,
313     /**
314      * Authentication success
315      */
316     SIM_AUTH_SUCCESS = 0,
317 };
318 
319 /**
320  * @brief Dsds Mode
321  */
322 enum class DsdsMode {
323     DSDS_MODE_V2 = 0,
324     DSDS_MODE_V3 = 1,
325     DSDS_MODE_V5_TDM = 2,
326     DSDS_MODE_V5_DSDA = 3,
327 };
328 
329 /**
330  * @brief Icc Account Information
331  */
332 struct IccAccountInfo : public Parcelable {
333     /**
334      * SIM Id for card
335      */
336     int32_t simId = 0;
337     /**
338      * Slot index for card
339      */
340     int32_t slotIndex = 0;
341     /**
342      * Mark card is eSim or not
343      */
344     bool isEsim = false;
345     /**
346      * Active status for card
347      */
348     bool isActive = false;
349     /**
350      * IccId for card
351      */
352     std::u16string iccId = u"";
353     /**
354      * Show name for card
355      */
356     std::u16string showName = u"";
357     /**
358      * Show number for card
359      */
360     std::u16string showNumber = u"";
361     inline static const std::u16string DEFAULT_SHOW_NAME = u"Card";
362     inline static const std::u16string DEFAULT_SHOW_NUMBER = u"";
363     inline static const std::u16string DEFAULT_ICC_ID = u"";
364 
InitIccAccountInfo365     void Init(int32_t simCardId, int32_t slotId)
366     {
367         this->simId = simCardId;
368         this->slotIndex = slotId;
369         this->isEsim = false;
370         this->isActive = true;
371         this->iccId = DEFAULT_ICC_ID;
372         this->showName = DEFAULT_SHOW_NAME;
373         this->showNumber = DEFAULT_SHOW_NUMBER;
374     };
375 
SetIsEsimIccAccountInfo376     void SetIsEsim(bool isEsimType)
377     {
378         this->isEsim = isEsimType;
379     }
380 
SetIsActiveIccAccountInfo381     void SetIsActive(bool activeEnabled)
382     {
383         this->isActive = activeEnabled;
384     }
385 
SetIccIdIccAccountInfo386     void SetIccId(std::u16string id)
387     {
388         this->iccId = id;
389     }
390 
SetShowNameIccAccountInfo391     void SetShowName(std::u16string name)
392     {
393         this->showName = name;
394     }
395 
SetShowNumberIccAccountInfo396     void SetShowNumber(std::u16string number)
397     {
398         this->showNumber = number;
399     }
400 
MarshallingIccAccountInfo401     bool Marshalling(Parcel &parcel) const
402     {
403         if (!parcel.WriteInt32(simId)) {
404             return false;
405         }
406         if (!parcel.WriteInt32(slotIndex)) {
407             return false;
408         }
409         if (!parcel.WriteBool(isEsim)) {
410             return false;
411         }
412         if (!parcel.WriteBool(isActive)) {
413             return false;
414         }
415         if (!parcel.WriteString16(iccId)) {
416             return false;
417         }
418         if (!parcel.WriteString16(showName)) {
419             return false;
420         }
421         if (!parcel.WriteString16(showNumber)) {
422             return false;
423         }
424         return true;
425     };
426 
UnMarshallingIccAccountInfo427     std::shared_ptr<IccAccountInfo> UnMarshalling(Parcel &parcel)
428     {
429         std::shared_ptr<IccAccountInfo> param = std::make_shared<IccAccountInfo>();
430         if (param == nullptr || !param->ReadFromParcel(parcel)) {
431             param = nullptr;
432         }
433         return param;
434     };
435 
ReadFromParcelIccAccountInfo436     bool ReadFromParcel(Parcel &parcel)
437     {
438         parcel.ReadInt32(simId);
439         parcel.ReadInt32(slotIndex);
440         parcel.ReadBool(isEsim);
441         parcel.ReadBool(isActive);
442         parcel.ReadString16(iccId);
443         parcel.ReadString16(showName);
444         parcel.ReadString16(showNumber);
445         return true;
446     };
447 
448     bool operator==(const IccAccountInfo &p)
449     {
450         return (slotIndex == p.slotIndex && simId == p.simId);
451     }
452 };
453 } // namespace Telephony
454 } // namespace OHOS
455 #endif // OHOS_SIM_STATE_TYPE_H
456