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 enum class PinOperationType { 291 SIM_ABSENT, 292 PIN_ENABLE, 293 PIN_DISABLE, 294 PIN_ALTER, 295 }; 296 297 /** 298 * @brief SIM card Authentication response 299 */ 300 struct SimAuthenticationResponse { 301 /** 302 * Status word 1 of the SIM card, which is returned by the SIM card after command execution 303 */ 304 int32_t sw1 = 0; 305 /** 306 * Status word 2 of the SIM card, which is returned by the SIM card after command execution 307 */ 308 int32_t sw2 = 0; 309 std::string response = ""; 310 }; 311 312 /** 313 * @brief SIM card Authentication result 314 */ 315 enum SimAuthResult { 316 /** 317 * Authentication fail 318 */ 319 SIM_AUTH_FAIL = -1, 320 /** 321 * Authentication success 322 */ 323 SIM_AUTH_SUCCESS = 0, 324 }; 325 326 /** 327 * @brief Dsds Mode 328 */ 329 enum class DsdsMode { 330 DSDS_MODE_V2 = 0, 331 DSDS_MODE_V3 = 1, 332 DSDS_MODE_V5_TDM = 2, 333 DSDS_MODE_V5_DSDA = 3, 334 }; 335 336 enum class SimType { 337 PSIM, 338 ESIM, 339 }; 340 341 struct SimLabel { 342 SimType simType = SimType::PSIM; 343 int32_t index = 0; 344 345 bool operator==(const SimLabel &p)const 346 { 347 return (this->simType == p.simType && (p.simType ==SimType::ESIM || this->index == p.index)); 348 } 349 }; 350 351 /** 352 * @brief Icc Account Information 353 */ 354 struct IccAccountInfo : public Parcelable { 355 /** 356 * SIM Id for card 357 */ 358 int32_t simId = 0; 359 /** 360 * Slot index for card 361 */ 362 int32_t slotIndex = 0; 363 /** 364 * Mark card is eSim or not 365 */ 366 bool isEsim = false; 367 /** 368 * Active status for card 369 */ 370 bool isActive = false; 371 /** 372 * IccId for card 373 */ 374 std::u16string iccId = u""; 375 /** 376 * Show name for card 377 */ 378 std::u16string showName = u""; 379 /** 380 * Show number for card 381 */ 382 std::u16string showNumber = u""; 383 /** 384 * sim label index for card 385 */ 386 int32_t simLabelIndex = 0; 387 /** 388 * operator name for esim card 389 */ 390 std::string operatorName = ""; 391 392 inline static const std::u16string DEFAULT_SHOW_NAME = u"Card"; 393 inline static const std::u16string DEFAULT_SHOW_NUMBER = u""; 394 inline static const std::u16string DEFAULT_ICC_ID = u""; 395 InitIccAccountInfo396 void Init(int32_t simCardId, int32_t slotId) 397 { 398 this->simId = simCardId; 399 this->slotIndex = slotId; 400 this->isEsim = false; 401 this->isActive = true; 402 this->iccId = DEFAULT_ICC_ID; 403 this->showName = DEFAULT_SHOW_NAME; 404 this->showNumber = DEFAULT_SHOW_NUMBER; 405 }; 406 SetIsEsimIccAccountInfo407 void SetIsEsim(bool isEsimType) 408 { 409 this->isEsim = isEsimType; 410 } 411 SetIsActiveIccAccountInfo412 void SetIsActive(bool activeEnabled) 413 { 414 this->isActive = activeEnabled; 415 } 416 SetIccIdIccAccountInfo417 void SetIccId(std::u16string id) 418 { 419 this->iccId = id; 420 } 421 SetShowNameIccAccountInfo422 void SetShowName(std::u16string name) 423 { 424 this->showName = name; 425 } 426 SetShowNumberIccAccountInfo427 void SetShowNumber(std::u16string number) 428 { 429 this->showNumber = number; 430 } 431 SetSimLabelIndexIccAccountInfo432 void SetSimLabelIndex(int32_t labelIndex) 433 { 434 this->simLabelIndex = labelIndex; 435 } 436 SetOpoeratorNameIccAccountInfo437 void SetOpoeratorName(std::string esimOperatorName) 438 { 439 this->operatorName = esimOperatorName; 440 } 441 MarshallingIccAccountInfo442 bool Marshalling(Parcel &parcel) const 443 { 444 if (!parcel.WriteInt32(simId)) { 445 return false; 446 } 447 if (!parcel.WriteInt32(slotIndex)) { 448 return false; 449 } 450 if (!parcel.WriteBool(isEsim)) { 451 return false; 452 } 453 if (!parcel.WriteBool(isActive)) { 454 return false; 455 } 456 if (!parcel.WriteString16(iccId)) { 457 return false; 458 } 459 if (!parcel.WriteString16(showName)) { 460 return false; 461 } 462 if (!parcel.WriteString16(showNumber)) { 463 return false; 464 } 465 if (!parcel.WriteInt32(simLabelIndex)) { 466 return false; 467 } 468 if (!parcel.WriteString(operatorName)) { 469 return false; 470 } 471 return true; 472 }; 473 UnMarshallingIccAccountInfo474 std::shared_ptr<IccAccountInfo> UnMarshalling(Parcel &parcel) 475 { 476 std::shared_ptr<IccAccountInfo> param = std::make_shared<IccAccountInfo>(); 477 if (param == nullptr || !param->ReadFromParcel(parcel)) { 478 param = nullptr; 479 } 480 return param; 481 }; 482 ReadFromParcelIccAccountInfo483 bool ReadFromParcel(Parcel &parcel) 484 { 485 parcel.ReadInt32(simId); 486 parcel.ReadInt32(slotIndex); 487 parcel.ReadBool(isEsim); 488 parcel.ReadBool(isActive); 489 parcel.ReadString16(iccId); 490 parcel.ReadString16(showName); 491 parcel.ReadString16(showNumber); 492 parcel.ReadInt32(simLabelIndex); 493 parcel.ReadString(operatorName); 494 return true; 495 }; 496 497 bool operator==(const IccAccountInfo &p) 498 { 499 return (slotIndex == p.slotIndex && simId == p.simId); 500 } 501 }; 502 } // namespace Telephony 503 } // namespace OHOS 504 #endif // OHOS_SIM_STATE_TYPE_H 505