• 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_HRIL_MANAGER_H
17 #define OHOS_HRIL_MANAGER_H
18 
19 #include <list>
20 #include <mutex>
21 #include <unordered_map>
22 
23 #include "hril_call.h"
24 #include "hril_data.h"
25 #include "hril_modem.h"
26 #include "hril_network.h"
27 #include "hril_sim.h"
28 #include "hril_sms.h"
29 #include "hril_timer_callback.h"
30 #include "v1_0/ipower_interface.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 typedef enum : int32_t {
35     RIL_REGISTER_IS_NONE = 0,
36     RIL_REGISTER_IS_RUNNING,
37 } RegisterState;
38 
39 class HRilManager : public IHRilReporter {
40 public:
41     HRilManager();
42     virtual ~HRilManager();
43 
44     int32_t GetMaxSimSlotCount();
45 
46     virtual ReqDataInfo *CreateHRilRequest(int32_t serial, int32_t slotId, int32_t request) override;
47     virtual void ReleaseHRilRequest(int32_t request, ReqDataInfo *requestInfo) override;
48 
49     void RegisterCallFuncs(int32_t slotId, const HRilCallReq *callFuncs);
50     void RegisterDataFuncs(int32_t slotId, const HRilDataReq *dataFuncs);
51     void RegisterModemFuncs(int32_t slotId, const HRilModemReq *modemFuncs);
52     void RegisterNetworkFuncs(int32_t slotId, const HRilNetworkReq *networkFuncs);
53     void RegisterSimFuncs(int32_t slotId, const HRilSimReq *simFuncs);
54     void RegisterSmsFuncs(int32_t slotId, const HRilSmsReq *smsFuncs);
55     void ApplyRunningLock(void);
56     void ReleaseRunningLock(void);
57 
58     void OnCallReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
59     void OnDataReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
60     void OnModemReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
61     void OnNetworkReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
62     void OnSimReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
63     void OnSmsReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
64     void SetRilCallback(const sptr<OHOS::HDI::Ril::V1_0::IRilCallback> callback);
65 
66     // Call
67     int32_t SetEmergencyCallList(
68         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::EmergencyInfoList &emergencyInfoList);
69     int32_t GetEmergencyCallList(int32_t slotId, int32_t serialId);
70     int32_t GetCallList(int32_t slotId, int32_t serialId);
71     int32_t Dial(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DialInfo &dialInfo);
72     int32_t Reject(int32_t slotId, int32_t serialId);
73     int32_t Hangup(int32_t slotId, int32_t serialId, int32_t gsmIndex);
74     int32_t Answer(int32_t slotId, int32_t serialId);
75     int32_t HoldCall(int32_t slotId, int32_t serialId);
76     int32_t UnHoldCall(int32_t slotId, int32_t serialId);
77     int32_t SwitchCall(int32_t slotId, int32_t serialId);
78     int32_t CombineConference(int32_t slotId, int32_t serialId, int32_t callType);
79     int32_t SeparateConference(int32_t slotId, int32_t serialId, int32_t callIndex, int32_t callType);
80     int32_t GetCallWaiting(int32_t slotId, int32_t serialId);
81     int32_t SetCallWaiting(int32_t slotId, int32_t serialId, int32_t activate);
82     int32_t GetCallTransferInfo(int32_t slotId, int32_t serialId, int32_t reason);
83     int32_t SetCallTransferInfo(
84         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::CallForwardSetInfo &callForwardSetInfo);
85     int32_t GetCallRestriction(int32_t slotId, int32_t serialId, const std::string &fac);
86     int32_t SetCallRestriction(
87         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::CallRestrictionInfo &callRestrictionInfo);
88     int32_t GetClip(int32_t slotId, int32_t serialId);
89     int32_t SetClip(int32_t slotId, int32_t serialId, int32_t action);
90     int32_t GetClir(int32_t slotId, int32_t serialId);
91     int32_t SetClir(int32_t slotId, int32_t serialId, int32_t action);
92     int32_t GetCallPreferenceMode(int32_t slotId, int32_t serialId);
93     int32_t SetCallPreferenceMode(int32_t slotId, int32_t serialId, int32_t mode);
94     int32_t SetUssd(int32_t slotId, int32_t serialId, const std::string &str);
95     int32_t GetUssd(int32_t slotId, int32_t serialId);
96     int32_t SetMute(int32_t slotId, int32_t serialId, int32_t mute);
97     int32_t GetMute(int32_t slotId, int32_t serialId);
98     int32_t GetCallFailReason(int32_t slotId, int32_t serialId);
99     int32_t CallSupplement(int32_t slotId, int32_t serialId, int32_t type);
100     int32_t SendDtmf(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DtmfInfo &dtmfInfo);
101     int32_t StartDtmf(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DtmfInfo &dtmfInfo);
102     int32_t StopDtmf(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DtmfInfo &dtmfInfo);
103     int32_t SetBarringPassword(
104         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SetBarringInfo &setBarringInfo);
105 
106     // Data
107     int32_t ActivatePdpContext(
108         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DataCallInfo &dataCallInfo);
109     int32_t DeactivatePdpContext(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::UniInfo &uniInfo);
110     int32_t GetPdpContextList(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::UniInfo &uniInfo);
111     int32_t SetInitApnInfo(
112         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DataProfileDataInfo &dataProfileDataInfo);
113     int32_t GetLinkBandwidthInfo(int32_t slotId, int32_t serialId, int32_t cid);
114     int32_t SetLinkBandwidthReportingRule(int32_t slotId, int32_t serialId,
115         const OHOS::HDI::Ril::V1_0::DataLinkBandwidthReportingRule &dataLinkBandwidthReportingRule);
116     int32_t SetDataPermitted(int32_t slotId, int32_t serialId, int32_t dataPermitted);
117     int32_t SetDataProfileInfo(
118         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DataProfilesInfo &dataProfilesInfo);
119     int32_t SendDataPerformanceMode(
120         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DataPerformanceInfo &dataPerformanceInfo);
121     int32_t SendDataSleepMode(
122         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::DataSleepInfo &dataSleepInfo);
123 
124     int32_t SetRadioState(int32_t slotId, int32_t serialId, int32_t fun, int32_t rst);
125     int32_t GetRadioState(int32_t slotId, int32_t serialId);
126     int32_t GetImei(int32_t slotId, int32_t serialId);
127     int32_t GetMeid(int32_t slotId, int32_t serialId);
128     int32_t GetVoiceRadioTechnology(int32_t slotId, int32_t serialId);
129     int32_t GetBasebandVersion(int32_t slotId, int32_t serialId);
130     int32_t ShutDown(int32_t slotId, int32_t serialId);
131 
132     int32_t GetSimIO(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SimIoRequestInfo &simIO);
133     int32_t GetSimStatus(int32_t slotId, int32_t serialId);
134     int32_t GetImsi(int32_t slotId, int32_t serialId);
135     int32_t GetSimLockStatus(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SimLockInfo &simLockInfo);
136     int32_t SetSimLock(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SimLockInfo &simLockInfo);
137     int32_t ChangeSimPassword(
138         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SimPasswordInfo &simPassword);
139     int32_t UnlockPin(int32_t slotId, int32_t serialId, const std::string &pin);
140     int32_t UnlockPuk(int32_t slotId, int32_t serialId, const std::string &puk, const std::string &pin);
141     int32_t UnlockPin2(int32_t slotId, int32_t serialId, const std::string &pin2);
142     int32_t UnlockPuk2(int32_t slotId, int32_t serialId, const std::string &puk2, const std::string &pin2);
143     int32_t SetActiveSim(int32_t slotId, int32_t serialId, int32_t index, int32_t enable);
144     int32_t SimStkSendTerminalResponse(int32_t slotId, int32_t serialId, const std::string &strCmd);
145     int32_t SimStkSendEnvelope(int32_t slotId, int32_t serialId, const std::string &strCmd);
146     int32_t SimStkSendCallSetupRequestResult(int32_t slotId, int32_t serialId, int32_t accept);
147     int32_t SimStkIsReady(int32_t slotId, int32_t serialId);
148     int32_t GetRadioProtocol(int32_t slotId, int32_t serialId);
149     int32_t SetRadioProtocol(int32_t slotId, int32_t serialId, const HDI::Ril::V1_0::RadioProtocol &radioProtocol);
150     int32_t SimOpenLogicalChannel(int32_t slotId, int32_t serialId, const std::string &appID, int32_t p2);
151     int32_t SimCloseLogicalChannel(int32_t slotId, int32_t serialId, int32_t channelId);
152     int32_t SimTransmitApduLogicalChannel(
153         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::ApduSimIORequestInfo &apduSimIO);
154     int32_t SimTransmitApduBasicChannel(
155         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::ApduSimIORequestInfo &apduSimIO);
156     int32_t SimAuthentication(
157         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SimAuthenticationRequestInfo &simAuthInfo);
158     int32_t UnlockSimLock(int32_t slotId, int32_t serialId, int32_t lockType, const std::string &key);
159 
160     // Network
161     int32_t GetSignalStrength(int32_t slotId, int32_t serialId);
162     int32_t GetCsRegStatus(int32_t slotId, int32_t serialId);
163     int32_t GetPsRegStatus(int32_t slotId, int32_t serialId);
164     int32_t GetOperatorInfo(int32_t slotId, int32_t serialId);
165     int32_t GetNetworkSearchInformation(int32_t slotId, int32_t serialId);
166     int32_t GetNetworkSelectionMode(int32_t slotId, int32_t serialId);
167     int32_t SetNetworkSelectionMode(
168         int32_t slotId, int32_t serialId, const HDI::Ril::V1_0::SetNetworkModeInfo &networkModeInfo);
169     int32_t GetNeighboringCellInfoList(int32_t slotId, int32_t serialId);
170     int32_t GetCurrentCellInfo(int32_t slotId, int32_t serialId);
171     int32_t SetPreferredNetwork(int32_t slotId, int32_t serialId, int32_t preferredNetworkType);
172     int32_t GetPreferredNetwork(int32_t slotId, int32_t serialId);
173     int32_t GetPhysicalChannelConfig(int32_t slotId, int32_t serialId);
174     int32_t SetLocateUpdates(int32_t slotId, int32_t serialId, const HDI::Ril::V1_0::RilRegNotifyMode mode);
175     int32_t SetNotificationFilter(int32_t slotId, int32_t serialId, int32_t newFilter);
176     int32_t SetDeviceState(int32_t slotId, int32_t serialId, int32_t deviceStateType, int32_t deviceStateOn);
177 
178     // Sms
179     int32_t SendGsmSms(
180         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::GsmSmsMessageInfo &gsmSmsMessageInfo);
181     int32_t SendCdmaSms(
182         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SendCdmaSmsMessageInfo &cdmaSmsMessageInfo);
183     int32_t AddSimMessage(
184         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SmsMessageIOInfo &smsMessageIOInfo);
185     int32_t DelSimMessage(int32_t slotId, int32_t serialId, int32_t index);
186     int32_t UpdateSimMessage(
187         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SmsMessageIOInfo &smsMessageIOInfo);
188     int32_t AddCdmaSimMessage(
189         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SmsMessageIOInfo &smsMessageIOInfo);
190     int32_t DelCdmaSimMessage(int32_t slotId, int32_t serialId, int32_t index);
191     int32_t UpdateCdmaSimMessage(
192         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::SmsMessageIOInfo &smsMessageIOInfo);
193     int32_t SetSmscAddr(
194         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::ServiceCenterAddress &serviceCenterAddress);
195     int32_t GetSmscAddr(int32_t slotId, int32_t serialId);
196     int32_t SetCBConfig(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::CBConfigInfo &cellBroadcastInfo);
197     int32_t GetCBConfig(int32_t slotId, int32_t serialId);
198     int32_t SetCdmaCBConfig(
199         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::CdmaCBConfigInfoList &cdmaCBConfigInfoList);
200     int32_t GetCdmaCBConfig(int32_t slotId, int32_t serialId);
201     int32_t SendSmsMoreMode(
202         int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::GsmSmsMessageInfo &gsmSmsMessageInfo);
203     int32_t SendSmsAck(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_0::ModeData &modeData);
204 
205     int32_t SendRilAck();
206 
207 public:
208     sptr<OHOS::HDI::Power::V1_0::IPowerInterface> powerInterface_ { nullptr };
209     std::unique_ptr<HRilTimerCallback> timerCallback_ = nullptr;
210     std::unique_ptr<std::thread> eventLoop_ = nullptr;
211     static const uint32_t RUNNING_LOCK_DEFAULT_TIMEOUT_US = 200 * 1000; // 200ms
212     std::mutex mutexRunningLock_;
213     std::atomic_uint runningLockCount_ = 0;
214     std::atomic_int runningSerialNum_ = 0;
215     static std::shared_ptr<HRilManager> manager_;
216 
217 private:
218     template<typename T>
219     void OnReport(std::vector<std::unique_ptr<T>> &subModules, int32_t slotId, const ReportInfo *reportInfo,
220         const uint8_t *response, size_t responseLen);
221     template<typename ClassTypePtr, typename FuncType, typename... ParamTypes>
222     inline int32_t TaskSchedule(
223         const std::string _module, ClassTypePtr &_obj, FuncType &&_func, ParamTypes &&... _args);
224 
225 private:
226     const int32_t hrilSimSlotCount_;
227     std::vector<std::unique_ptr<HRilCall>> hrilCall_;
228     std::vector<std::unique_ptr<HRilModem>> hrilModem_;
229     std::vector<std::unique_ptr<HRilNetwork>> hrilNetwork_;
230     std::vector<std::unique_ptr<HRilSim>> hrilSim_;
231     std::vector<std::unique_ptr<HRilSms>> hrilSms_;
232     std::vector<std::unique_ptr<HRilData>> hrilData_;
233     std::unordered_map<int32_t, std::list<ReqDataInfo *>> requestList_;
234     static std::unordered_map<int32_t, int32_t> notificationMap_;
235     std::mutex requestListLock_;
236 };
237 
238 #ifdef __cplusplus
239 extern "C" {
240 #endif
241 
242 int32_t GetSimSlotCount(void);
243 void HRilRegOps(const HRilOps *hrilOps);
244 void OnCallReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
245 void OnDataReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
246 void OnModemReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
247 void OnNetworkReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
248 void OnSimReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
249 void OnSmsReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
250 void OnTimerCallback(HRilCallbackFun func, uint8_t *param, const struct timeval *tv);
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 } // namespace Telephony
256 } // namespace OHOS
257 #endif // OHOS_RIL_IMPL_H
258