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 <string> 20 #include <map> 21 22 #include "parcel.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 enum class CardType { 27 /** Icc card type: Unknow type Card. */ 28 UNKNOWN_CARD = -1, 29 30 /** Icc card type: Single sim card type. */ 31 SINGLE_MODE_SIM_CARD = 10, 32 33 /** Icc card type: Single usim card type. */ 34 SINGLE_MODE_USIM_CARD = 20, 35 36 /** Icc card type: Single ruim card type. */ 37 SINGLE_MODE_RUIM_CARD = 30, 38 39 /** Icc card type: Double card C+G. */ 40 DUAL_MODE_CG_CARD = 40, 41 42 /** Icc card type: Roaming Card (Dual Mode). */ 43 CT_NATIONAL_ROAMING_CARD = 41, 44 45 /** Icc card type: China Unicom Dual Mode Card. */ 46 CU_DUAL_MODE_CARD = 42, 47 48 /** Icc card type: LTE Card (Dual Mode). */ 49 DUAL_MODE_TELECOM_LTE_CARD = 43, 50 51 /** Icc card type: Double card U+G. */ 52 DUAL_MODE_UG_CARD = 50, 53 54 /** Icc card type: Single isim card type. */ 55 SINGLE_MODE_ISIM_CARD = 60, 56 }; 57 58 enum class SimState { 59 /** 60 * Indicates unknown SIM card state, that is, the accurate status cannot be obtained. 61 */ 62 SIM_STATE_UNKNOWN, 63 64 /** 65 * Indicates that the SIM card is in the <b>not present</b> state, that is, no SIM card is inserted 66 * into the card slot. 67 */ 68 SIM_STATE_NOT_PRESENT, 69 70 /** 71 * Indicates that the SIM card is in the <b>locked</b> state, that is, the SIM card is locked by the 72 * personal identification number (PIN)/PIN unblocking key (PUK) or network. 73 */ 74 SIM_STATE_LOCKED, 75 76 /** 77 * Indicates that the SIM card is in the <b>not ready</b> state, that is, the SIM card is in position 78 * but cannot work properly. 79 */ 80 SIM_STATE_NOT_READY, 81 82 /** 83 * Indicates that the SIM card is in the <b>ready</b> state, that is, the SIM card is in position and 84 * is working properly. 85 */ 86 SIM_STATE_READY, 87 88 /** 89 * Indicates that the SIM card is in the <b>loaded</b> state, that is, the SIM card is in position and 90 * is working properly. 91 */ 92 SIM_STATE_LOADED 93 }; 94 95 enum class LockReason { 96 SIM_NONE, 97 SIM_PIN, 98 SIM_PUK, 99 SIM_PN_PIN, // Network Personalization (refer 3GPP TS 22.022 [33]) 100 SIM_PN_PUK, 101 SIM_PU_PIN, // network sUbset Personalization (refer 3GPP TS 22.022 [33]) 102 SIM_PU_PUK, 103 SIM_PP_PIN, // service supplier Personalization (refer 3GPP TS 22.022 [33]) 104 SIM_PP_PUK, 105 SIM_PC_PIN, // Corporate Personalization (refer 3GPP TS 22.022 [33]) 106 SIM_PC_PUK, 107 SIM_SIM_PIN, // SIM/USIM personalisation (refer 3GPP TS 22.022 [33]) 108 SIM_SIM_PUK, 109 }; 110 111 enum class PersoLockType { 112 PN_PIN_LOCK, // Network Personalization (refer 3GPP TS 22.022 [33]) 113 PN_PUK_LOCK, 114 PU_PIN_LOCK, // network sUbset Personalization (refer 3GPP TS 22.022 [33]) 115 PU_PUK_LOCK, 116 PP_PIN_LOCK, // service supplier Personalization (refer 3GPP TS 22.022 [33]) 117 PP_PUK_LOCK, 118 PC_PIN_LOCK, // Corporate Personalization (refer 3GPP TS 22.022 [33]) 119 PC_PUK_LOCK, 120 SIM_PIN_LOCK, // SIM/USIM personalisation (refer 3GPP TS 22.022 [33]) 121 SIM_PUK_LOCK, 122 }; 123 124 enum class LockType { 125 PIN_LOCK = 1, 126 FDN_LOCK = 2, 127 }; 128 129 enum class LockState { 130 /**Indicates that the lock state card is in the <b>off</b> state. */ 131 LOCK_OFF = 0, 132 133 /**Indicates that the lock state card is in the <b>open</b> state. */ 134 LOCK_ON, 135 136 /**Indicates that the lock state card is in the <b>error</b> state. */ 137 LOCK_ERROR, 138 }; 139 140 struct LockInfo { 141 LockType lockType; 142 std::u16string password; 143 LockState lockState; 144 }; 145 146 struct PersoLockInfo { 147 PersoLockType lockType; 148 std::u16string password; 149 }; 150 151 enum UnlockResult { 152 UNLOCK_FAIL = -2, // unlock fail 153 UNLOCK_INCORRECT = -1, // password error 154 UNLOCK_OK = 0, // unlock sucessful 155 }; 156 157 struct LockStatusResponse { 158 int32_t result; 159 int32_t remain; 160 }; 161 162 struct OperatorConfig : public Parcelable { 163 std::map<std::u16string, std::u16string> configValue; 164 MarshallingOperatorConfig165 bool Marshalling(Parcel &parcel) const 166 { 167 if (!parcel.WriteInt32(configValue.size())) { 168 return false; 169 } 170 auto valueIt = configValue.begin(); 171 while (valueIt != configValue.end()) { 172 if (!parcel.WriteString16(valueIt->first)) { 173 return false; 174 } 175 if (!parcel.WriteString16(valueIt->second)) { 176 return false; 177 } 178 valueIt++; 179 } 180 return true; 181 }; 182 UnMarshallingOperatorConfig183 std::shared_ptr<OperatorConfig> UnMarshalling(Parcel &parcel) 184 { 185 std::shared_ptr<OperatorConfig> param = std::make_shared<OperatorConfig>(); 186 if (param == nullptr || !param->ReadFromParcel(parcel)) { 187 param = nullptr; 188 } 189 return param; 190 }; 191 ReadFromParcelOperatorConfig192 bool ReadFromParcel(Parcel &parcel) 193 { 194 configValue.clear(); 195 int32_t valueSize = parcel.ReadInt32(); 196 int32_t k = 0; 197 while (valueSize > k) { 198 std::u16string first = parcel.ReadString16(); 199 std::u16string second = parcel.ReadString16(); 200 configValue.emplace(std::pair<std::u16string, std::u16string>(first, second)); 201 k++; 202 } 203 return true; 204 }; 205 }; 206 207 struct IccAccountInfo : public Parcelable { 208 int32_t simId; // sim Id for card 209 int32_t slotIndex; // slot index for card 210 bool isEsim; // mark card is eSim or not 211 bool isActive; // active status for card 212 std::u16string iccId; // iccId for card 213 std::u16string showName; // show name for card 214 std::u16string showNumber; // show number for card 215 inline static const std::u16string DEFAULT_SHOW_NAME = u"Card"; 216 inline static const std::u16string DEFAULT_SHOW_NUMBER = u""; 217 inline static const std::u16string DEFAULT_ICC_ID = u""; 218 InitIccAccountInfo219 void Init(int32_t simCardId, int32_t slotId) 220 { 221 this->simId = simCardId; 222 this->slotIndex = slotId; 223 this->isEsim = false; 224 this->isActive = true; 225 this->iccId = DEFAULT_ICC_ID; 226 this->showName = DEFAULT_SHOW_NAME; 227 this->showNumber = DEFAULT_SHOW_NUMBER; 228 }; 229 SetIsEsimIccAccountInfo230 void SetIsEsim(bool isEsimType) 231 { 232 this->isEsim = isEsimType; 233 } 234 SetIsActiveIccAccountInfo235 void SetIsActive(bool activeEnabled) 236 { 237 this->isActive = activeEnabled; 238 } 239 SetIccIdIccAccountInfo240 void SetIccId(std::u16string id) 241 { 242 this->iccId = id; 243 } 244 SetShowNameIccAccountInfo245 void SetShowName(std::u16string name) 246 { 247 this->showName = name; 248 } 249 SetShowNumberIccAccountInfo250 void SetShowNumber(std::u16string number) 251 { 252 this->showNumber = number; 253 } 254 MarshallingIccAccountInfo255 bool Marshalling(Parcel &parcel) const 256 { 257 if (!parcel.WriteInt32(simId)) { 258 return false; 259 } 260 if (!parcel.WriteInt32(slotIndex)) { 261 return false; 262 } 263 if (!parcel.WriteBool(isEsim)) { 264 return false; 265 } 266 if (!parcel.WriteBool(isActive)) { 267 return false; 268 } 269 if (!parcel.WriteString16(iccId)) { 270 return false; 271 } 272 if (!parcel.WriteString16(showName)) { 273 return false; 274 } 275 if (!parcel.WriteString16(showNumber)) { 276 return false; 277 } 278 return true; 279 }; 280 UnMarshallingIccAccountInfo281 std::shared_ptr<IccAccountInfo> UnMarshalling(Parcel &parcel) 282 { 283 std::shared_ptr<IccAccountInfo> param = std::make_shared<IccAccountInfo>(); 284 if (param == nullptr || !param->ReadFromParcel(parcel)) { 285 param = nullptr; 286 } 287 return param; 288 }; 289 ReadFromParcelIccAccountInfo290 bool ReadFromParcel(Parcel &parcel) 291 { 292 parcel.ReadInt32(simId); 293 parcel.ReadInt32(slotIndex); 294 parcel.ReadBool(isEsim); 295 parcel.ReadBool(isActive); 296 parcel.ReadString16(iccId); 297 parcel.ReadString16(showName); 298 parcel.ReadString16(showNumber); 299 return true; 300 }; 301 302 bool operator==(const IccAccountInfo &p) 303 { 304 return (slotIndex == p.slotIndex && simId == p.simId); 305 } 306 }; 307 308 struct RadioProtocolResponse : public Parcelable { 309 bool result; 310 int32_t reason; 311 MarshallingRadioProtocolResponse312 bool Marshalling(Parcel &parcel) const 313 { 314 if (!parcel.WriteBool(result)) { 315 return false; 316 } 317 if (!parcel.WriteInt32(reason)) { 318 return false; 319 } 320 return true; 321 }; 322 UnMarshallingRadioProtocolResponse323 std::shared_ptr<RadioProtocolResponse> UnMarshalling(Parcel &parcel) 324 { 325 std::shared_ptr<RadioProtocolResponse> param = std::make_shared<RadioProtocolResponse>(); 326 if (param == nullptr || !param->ReadFromParcel(parcel)) { 327 param = nullptr; 328 } 329 return param; 330 }; 331 ReadFromParcelRadioProtocolResponse332 bool ReadFromParcel(Parcel &parcel) 333 { 334 parcel.ReadBool(result); 335 parcel.ReadInt32(reason); 336 return true; 337 }; 338 }; 339 } // namespace Telephony 340 } // namespace OHOS 341 #endif // OHOS_SIM_STATE_TYPE_H 342