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 Lock information 230 */ 231 struct LockInfo { 232 LockType lockType = LockType::PIN_LOCK; 233 std::u16string password = u""; 234 LockState lockState = LockState::LOCK_ERROR; 235 }; 236 237 /** 238 * @brief Personalization lock information 239 */ 240 struct PersoLockInfo { 241 PersoLockType lockType = PersoLockType::PN_PIN_LOCK; 242 std::u16string password = u""; 243 }; 244 245 /** 246 * @brief Unlock result 247 */ 248 enum UnlockResult { 249 /** 250 * Unlock fail 251 */ 252 UNLOCK_FAIL = -2, 253 /** 254 * Password error 255 */ 256 UNLOCK_INCORRECT = -1, 257 /** 258 * Unlock successful 259 */ 260 UNLOCK_OK = 0, 261 }; 262 263 /** 264 * @brief Lock status response 265 */ 266 struct LockStatusResponse { 267 int32_t result = 0; 268 int32_t remain = 0; 269 }; 270 271 /** 272 * @brief SIM card Authentication response 273 */ 274 struct SimAuthenticationResponse { 275 /** 276 * Status word 1 of the SIM card, which is returned by the SIM card after command execution 277 */ 278 int32_t sw1 = 0; 279 /** 280 * Status word 2 of the SIM card, which is returned by the SIM card after command execution 281 */ 282 int32_t sw2 = 0; 283 std::string response = ""; 284 }; 285 286 /** 287 * @brief SIM card Authentication result 288 */ 289 enum SimAuthResult { 290 /** 291 * Authentication fail 292 */ 293 SIM_AUTH_FAIL = -1, 294 /** 295 * Authentication success 296 */ 297 SIM_AUTH_SUCCESS = 0, 298 }; 299 300 /** 301 * @brief Dsds Mode 302 */ 303 enum class DsdsMode { 304 DSDS_MODE_V2 = 0, 305 DSDS_MODE_V3 = 1, 306 DSDS_MODE_V5_TDM = 2, 307 DSDS_MODE_V5_DSDA = 3, 308 }; 309 310 /** 311 * @brief Icc Account Information 312 */ 313 struct IccAccountInfo : public Parcelable { 314 /** 315 * SIM Id for card 316 */ 317 int32_t simId = 0; 318 /** 319 * Slot index for card 320 */ 321 int32_t slotIndex = 0; 322 /** 323 * Mark card is eSim or not 324 */ 325 bool isEsim = false; 326 /** 327 * Active status for card 328 */ 329 bool isActive = false; 330 /** 331 * IccId for card 332 */ 333 std::u16string iccId = u""; 334 /** 335 * Show name for card 336 */ 337 std::u16string showName = u""; 338 /** 339 * Show number for card 340 */ 341 std::u16string showNumber = u""; 342 inline static const std::u16string DEFAULT_SHOW_NAME = u"Card"; 343 inline static const std::u16string DEFAULT_SHOW_NUMBER = u""; 344 inline static const std::u16string DEFAULT_ICC_ID = u""; 345 InitIccAccountInfo346 void Init(int32_t simCardId, int32_t slotId) 347 { 348 this->simId = simCardId; 349 this->slotIndex = slotId; 350 this->isEsim = false; 351 this->isActive = true; 352 this->iccId = DEFAULT_ICC_ID; 353 this->showName = DEFAULT_SHOW_NAME; 354 this->showNumber = DEFAULT_SHOW_NUMBER; 355 }; 356 SetIsEsimIccAccountInfo357 void SetIsEsim(bool isEsimType) 358 { 359 this->isEsim = isEsimType; 360 } 361 SetIsActiveIccAccountInfo362 void SetIsActive(bool activeEnabled) 363 { 364 this->isActive = activeEnabled; 365 } 366 SetIccIdIccAccountInfo367 void SetIccId(std::u16string id) 368 { 369 this->iccId = id; 370 } 371 SetShowNameIccAccountInfo372 void SetShowName(std::u16string name) 373 { 374 this->showName = name; 375 } 376 SetShowNumberIccAccountInfo377 void SetShowNumber(std::u16string number) 378 { 379 this->showNumber = number; 380 } 381 MarshallingIccAccountInfo382 bool Marshalling(Parcel &parcel) const 383 { 384 if (!parcel.WriteInt32(simId)) { 385 return false; 386 } 387 if (!parcel.WriteInt32(slotIndex)) { 388 return false; 389 } 390 if (!parcel.WriteBool(isEsim)) { 391 return false; 392 } 393 if (!parcel.WriteBool(isActive)) { 394 return false; 395 } 396 if (!parcel.WriteString16(iccId)) { 397 return false; 398 } 399 if (!parcel.WriteString16(showName)) { 400 return false; 401 } 402 if (!parcel.WriteString16(showNumber)) { 403 return false; 404 } 405 return true; 406 }; 407 UnMarshallingIccAccountInfo408 std::shared_ptr<IccAccountInfo> UnMarshalling(Parcel &parcel) 409 { 410 std::shared_ptr<IccAccountInfo> param = std::make_shared<IccAccountInfo>(); 411 if (param == nullptr || !param->ReadFromParcel(parcel)) { 412 param = nullptr; 413 } 414 return param; 415 }; 416 ReadFromParcelIccAccountInfo417 bool ReadFromParcel(Parcel &parcel) 418 { 419 parcel.ReadInt32(simId); 420 parcel.ReadInt32(slotIndex); 421 parcel.ReadBool(isEsim); 422 parcel.ReadBool(isActive); 423 parcel.ReadString16(iccId); 424 parcel.ReadString16(showName); 425 parcel.ReadString16(showNumber); 426 return true; 427 }; 428 429 bool operator==(const IccAccountInfo &p) 430 { 431 return (slotIndex == p.slotIndex && simId == p.simId); 432 } 433 }; 434 } // namespace Telephony 435 } // namespace OHOS 436 #endif // OHOS_SIM_STATE_TYPE_H 437