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_ICC_FILE_CONTROLLER_H 17 #define OHOS_ICC_FILE_CONTROLLER_H 18 19 #include <cstring> 20 #include <string> 21 22 #include "i_tel_ril_manager.h" 23 #include "sim_constant.h" 24 #include "sim_data_type.h" 25 #include "sim_utils.h" 26 #include "tel_event_handler.h" 27 #include "telephony_log_wrapper.h" 28 29 namespace OHOS { 30 namespace Telephony { 31 // 3GPP TS 51.011 V4.1.0 section 10.7 files of gsm 32 const std::string MASTER_FILE_SIM = "3F00"; 33 const std::string DEDICATED_FILE_TELECOM = "7F10"; 34 const std::string DEDICATED_FILE_GSM = "7F20"; 35 const std::string DEDICATED_FILE_GRAPHICS = "5F50"; 36 // ETSI TS 102 221 V3.3.0 section 8.6 reservation of file IDs 37 const std::string DEDICATED_FILE_DIALLING_NUMBERS = "5F3A"; 38 const std::string DEDICATED_FILE_DF5GS = "5FC0"; // TS 131 102 DF5GS 39 const std::string DEDICATED_FILE_ADF = "7FFF"; 40 41 class IccFileController : public TelEventHandler { 42 public: 43 explicit IccFileController(const std::string &name, int slotId); 44 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 45 virtual ~IccFileController(); 46 void ObtainBinaryFile(int fileId, const AppExecFwk::InnerEvent::Pointer &event); 47 void ObtainBinaryFile(int fileId, int size, const AppExecFwk::InnerEvent::Pointer &event); 48 49 void ObtainLinearFixedFile( 50 int fileId, const std::string &path, int fileNum, const AppExecFwk::InnerEvent::Pointer &event); 51 void ObtainLinearFixedFile(int fileId, int fileNum, const AppExecFwk::InnerEvent::Pointer &event); 52 53 void ObtainAllLinearFixedFile( 54 int fileId, const std::string &path, const AppExecFwk::InnerEvent::Pointer &event); 55 void ObtainAllLinearFixedFile(int fileId, const AppExecFwk::InnerEvent::Pointer &event); 56 void ObtainLinearFileSize(int fileId, const std::string &path, const AppExecFwk::InnerEvent::Pointer &event); 57 void ObtainLinearFileSize(int fileId, const AppExecFwk::InnerEvent::Pointer &event); 58 59 void UpdateLinearFixedFile(int fileId, const std::string &path, int fileNum, const std::string data, 60 int dataLength, const std::string pin2, const AppExecFwk::InnerEvent::Pointer &onComplete); 61 void UpdateLinearFixedFile(int fileId, int fileNum, const std::string data, int dataLength, 62 const std::string pin2, const AppExecFwk::InnerEvent::Pointer &onComplete); 63 void UpdateBinaryFile( 64 int fileId, const std::string data, int dataLength, const AppExecFwk::InnerEvent::Pointer &onComplete); 65 void SetRilManager(std::shared_ptr<ITelRilManager> ril); 66 inline const static std::string NULLSTR = ""; 67 68 protected: 69 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 70 int slotId_ = 0; 71 virtual std::string ObtainElementFilePath(int efId) = 0; 72 std::string ObtainElementFileForPublic(int efId); 73 void SendResponse(std::shared_ptr<IccControllerHolder> holder, const IccFileData *fd); 74 void SendEfLinearResult(const AppExecFwk::InnerEvent::Pointer &response, const int val[], int len); 75 void SendMultiRecordResult(const AppExecFwk::InnerEvent::Pointer &response, std::vector<std::string> &strValue); 76 AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId, std::shared_ptr<IccControllerHolder> &holderObject); 77 AppExecFwk::InnerEvent::Pointer BuildCallerInfo( 78 int eventId, int arg1, int arg2, std::shared_ptr<IccControllerHolder> &holderObject); 79 AppExecFwk::InnerEvent::Pointer BuildCallerInfo( 80 int eventId, int arg1, int arg2, const AppExecFwk::InnerEvent::Pointer &msg); 81 void ProcessBinarySize(const AppExecFwk::InnerEvent::Pointer &event); 82 void ProcessRecordSize(const AppExecFwk::InnerEvent::Pointer &event); 83 void ProcessLinearRecordSize(const AppExecFwk::InnerEvent::Pointer &event); 84 void ProcessReadRecord(const AppExecFwk::InnerEvent::Pointer &event); 85 void ProcessReadBinary(const AppExecFwk::InnerEvent::Pointer &event); 86 void SendEvent(std::shared_ptr<AppExecFwk::EventHandler> handler, uint32_t id, bool needShare, 87 std::shared_ptr<ControllerToFileMsg> objectShare, std::unique_ptr<ControllerToFileMsg> &objectUnique); 88 89 private: 90 const int RECORD_NUM = 3; 91 const uint32_t OFFSET = 8; 92 const uint8_t BYTE_NUM = 0xff; 93 const int MAX_FILE_INDEX = 2; 94 const int ICC_FILE_CURRENT_MODE = 4; 95 void ParseFileSize(int val[], int len, const unsigned char *data); 96 bool IsValidRecordSizeData(const unsigned char *data); 97 bool IsValidBinarySizeData(const unsigned char *data); 98 void GetFileAndDataSize(const unsigned char *data, int &dataSize, int &fileSize); 99 void GetDataSize(const unsigned char *data, int &dataSize); 100 std::string CheckRightPath(const std::string &path, int fileId); 101 bool ProcessErrorResponse(const AppExecFwk::InnerEvent::Pointer &event); 102 bool IsFixedNumberType(int); 103 }; 104 } // namespace Telephony 105 } // namespace OHOS 106 107 #endif 108