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