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_1/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_1::IRilCallback> callback); 65 66 // Call 67 int32_t SetEmergencyCallList( 68 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::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_1::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_1::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_1::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_1::DtmfInfo &dtmfInfo); 101 int32_t StartDtmf(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DtmfInfo &dtmfInfo); 102 int32_t StopDtmf(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DtmfInfo &dtmfInfo); 103 int32_t SetBarringPassword( 104 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SetBarringInfo &setBarringInfo); 105 int32_t CloseUnFinishedUssd(int32_t slotId, int32_t serialId); 106 int32_t SetVonrSwitch(int32_t slotId, int32_t serialId, int32_t status); 107 108 // Data 109 int32_t ActivatePdpContext( 110 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DataCallInfo &dataCallInfo); 111 int32_t DeactivatePdpContext(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::UniInfo &uniInfo); 112 int32_t GetPdpContextList(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::UniInfo &uniInfo); 113 int32_t SetInitApnInfo( 114 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DataProfileDataInfo &dataProfileDataInfo); 115 int32_t GetLinkBandwidthInfo(int32_t slotId, int32_t serialId, int32_t cid); 116 int32_t SetLinkBandwidthReportingRule(int32_t slotId, int32_t serialId, 117 const OHOS::HDI::Ril::V1_1::DataLinkBandwidthReportingRule &dataLinkBandwidthReportingRule); 118 int32_t SetDataPermitted(int32_t slotId, int32_t serialId, int32_t dataPermitted); 119 int32_t SetDataProfileInfo( 120 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DataProfilesInfo &dataProfilesInfo); 121 int32_t SendDataPerformanceMode( 122 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DataPerformanceInfo &dataPerformanceInfo); 123 int32_t SendDataSleepMode( 124 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::DataSleepInfo &dataSleepInfo); 125 int32_t GetLinkCapability(int32_t slotId, int32_t serialId); 126 127 int32_t SetRadioState(int32_t slotId, int32_t serialId, int32_t fun, int32_t rst); 128 int32_t GetRadioState(int32_t slotId, int32_t serialId); 129 int32_t GetImei(int32_t slotId, int32_t serialId); 130 int32_t GetMeid(int32_t slotId, int32_t serialId); 131 int32_t GetVoiceRadioTechnology(int32_t slotId, int32_t serialId); 132 int32_t GetBasebandVersion(int32_t slotId, int32_t serialId); 133 int32_t ShutDown(int32_t slotId, int32_t serialId); 134 135 int32_t GetSimIO(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SimIoRequestInfo &simIO); 136 int32_t GetSimStatus(int32_t slotId, int32_t serialId); 137 int32_t GetImsi(int32_t slotId, int32_t serialId); 138 int32_t GetSimLockStatus(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SimLockInfo &simLockInfo); 139 int32_t SetSimLock(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SimLockInfo &simLockInfo); 140 int32_t ChangeSimPassword( 141 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SimPasswordInfo &simPassword); 142 int32_t UnlockPin(int32_t slotId, int32_t serialId, const std::string &pin); 143 int32_t UnlockPuk(int32_t slotId, int32_t serialId, const std::string &puk, const std::string &pin); 144 int32_t UnlockPin2(int32_t slotId, int32_t serialId, const std::string &pin2); 145 int32_t UnlockPuk2(int32_t slotId, int32_t serialId, const std::string &puk2, const std::string &pin2); 146 int32_t SetActiveSim(int32_t slotId, int32_t serialId, int32_t index, int32_t enable); 147 int32_t SimStkSendTerminalResponse(int32_t slotId, int32_t serialId, const std::string &strCmd); 148 int32_t SimStkSendEnvelope(int32_t slotId, int32_t serialId, const std::string &strCmd); 149 int32_t SimStkSendCallSetupRequestResult(int32_t slotId, int32_t serialId, int32_t accept); 150 int32_t SimStkIsReady(int32_t slotId, int32_t serialId); 151 int32_t GetRadioProtocol(int32_t slotId, int32_t serialId); 152 int32_t SetRadioProtocol(int32_t slotId, int32_t serialId, const HDI::Ril::V1_1::RadioProtocol &radioProtocol); 153 int32_t SimOpenLogicalChannel(int32_t slotId, int32_t serialId, const std::string &appID, int32_t p2); 154 int32_t SimCloseLogicalChannel(int32_t slotId, int32_t serialId, int32_t channelId); 155 int32_t SimTransmitApduLogicalChannel( 156 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &apduSimIO); 157 int32_t SimTransmitApduBasicChannel( 158 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &apduSimIO); 159 int32_t SimAuthentication( 160 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SimAuthenticationRequestInfo &simAuthInfo); 161 int32_t UnlockSimLock(int32_t slotId, int32_t serialId, int32_t lockType, const std::string &key); 162 163 // Network 164 int32_t GetSignalStrength(int32_t slotId, int32_t serialId); 165 int32_t GetCsRegStatus(int32_t slotId, int32_t serialId); 166 int32_t GetPsRegStatus(int32_t slotId, int32_t serialId); 167 int32_t GetOperatorInfo(int32_t slotId, int32_t serialId); 168 int32_t GetNetworkSearchInformation(int32_t slotId, int32_t serialId); 169 int32_t GetNetworkSelectionMode(int32_t slotId, int32_t serialId); 170 int32_t SetNetworkSelectionMode( 171 int32_t slotId, int32_t serialId, const HDI::Ril::V1_1::SetNetworkModeInfo &networkModeInfo); 172 int32_t GetNeighboringCellInfoList(int32_t slotId, int32_t serialId); 173 int32_t GetCurrentCellInfo(int32_t slotId, int32_t serialId); 174 int32_t SetPreferredNetwork(int32_t slotId, int32_t serialId, int32_t preferredNetworkType); 175 int32_t GetPreferredNetwork(int32_t slotId, int32_t serialId); 176 int32_t GetPhysicalChannelConfig(int32_t slotId, int32_t serialId); 177 int32_t SetLocateUpdates(int32_t slotId, int32_t serialId, const HDI::Ril::V1_1::RilRegNotifyMode mode); 178 int32_t SetNotificationFilter(int32_t slotId, int32_t serialId, int32_t newFilter); 179 int32_t SetDeviceState(int32_t slotId, int32_t serialId, int32_t deviceStateType, int32_t deviceStateOn); 180 int32_t SetNrOptionMode(int32_t slotId, int32_t serialId, int32_t mode); 181 int32_t GetNrOptionMode(int32_t slotId, int32_t serialId); 182 int32_t GetRrcConnectionState(int32_t slotId, int32_t serialId); 183 184 // Sms 185 int32_t SendGsmSms( 186 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::GsmSmsMessageInfo &gsmSmsMessageInfo); 187 int32_t SendCdmaSms( 188 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SendCdmaSmsMessageInfo &cdmaSmsMessageInfo); 189 int32_t AddSimMessage( 190 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &smsMessageIOInfo); 191 int32_t DelSimMessage(int32_t slotId, int32_t serialId, int32_t index); 192 int32_t UpdateSimMessage( 193 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &smsMessageIOInfo); 194 int32_t AddCdmaSimMessage( 195 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &smsMessageIOInfo); 196 int32_t DelCdmaSimMessage(int32_t slotId, int32_t serialId, int32_t index); 197 int32_t UpdateCdmaSimMessage( 198 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &smsMessageIOInfo); 199 int32_t SetSmscAddr( 200 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::ServiceCenterAddress &serviceCenterAddress); 201 int32_t GetSmscAddr(int32_t slotId, int32_t serialId); 202 int32_t SetCBConfig(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::CBConfigInfo &cellBroadcastInfo); 203 int32_t GetCBConfig(int32_t slotId, int32_t serialId); 204 int32_t SetCdmaCBConfig( 205 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::CdmaCBConfigInfoList &cdmaCBConfigInfoList); 206 int32_t GetCdmaCBConfig(int32_t slotId, int32_t serialId); 207 int32_t SendSmsMoreMode( 208 int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::GsmSmsMessageInfo &gsmSmsMessageInfo); 209 int32_t SendSmsAck(int32_t slotId, int32_t serialId, const OHOS::HDI::Ril::V1_1::ModeData &modeData); 210 211 int32_t SendRilAck(); 212 213 public: 214 sptr<OHOS::HDI::Power::V1_1::IPowerInterface> powerInterface_ { nullptr }; 215 std::unique_ptr<HRilTimerCallback> timerCallback_ = nullptr; 216 std::unique_ptr<std::thread> eventLoop_ = nullptr; 217 static const uint32_t RUNNING_LOCK_DEFAULT_TIMEOUT_US = 200 * 1000; // 200ms 218 std::mutex mutexRunningLock_; 219 std::atomic_uint runningLockCount_ = 0; 220 std::atomic_int runningSerialNum_ = 0; 221 static std::shared_ptr<HRilManager> manager_; 222 223 private: 224 template<typename T> 225 void OnReport(std::vector<std::unique_ptr<T>> &subModules, int32_t slotId, const ReportInfo *reportInfo, 226 const uint8_t *response, size_t responseLen); 227 template<typename ClassTypePtr, typename FuncType, typename... ParamTypes> 228 inline int32_t TaskSchedule( 229 const std::string _module, ClassTypePtr &_obj, FuncType &&_func, ParamTypes &&... _args); 230 231 private: 232 const int32_t hrilSimSlotCount_; 233 std::vector<std::unique_ptr<HRilCall>> hrilCall_; 234 std::vector<std::unique_ptr<HRilModem>> hrilModem_; 235 std::vector<std::unique_ptr<HRilNetwork>> hrilNetwork_; 236 std::vector<std::unique_ptr<HRilSim>> hrilSim_; 237 std::vector<std::unique_ptr<HRilSms>> hrilSms_; 238 std::vector<std::unique_ptr<HRilData>> hrilData_; 239 std::unordered_map<int32_t, std::list<ReqDataInfo *>> requestList_; 240 static std::unordered_map<int32_t, int32_t> notificationMap_; 241 std::mutex requestListLock_; 242 }; 243 244 #ifdef __cplusplus 245 extern "C" { 246 #endif 247 248 int32_t GetSimSlotCount(void); 249 void HRilRegOps(const HRilOps *hrilOps); 250 void OnCallReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 251 void OnDataReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 252 void OnModemReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 253 void OnNetworkReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 254 void OnSimReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 255 void OnSmsReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen); 256 void OnTimerCallback(HRilCallbackFun func, uint8_t *param, const struct timeval *tv); 257 258 #ifdef __cplusplus 259 } 260 #endif 261 } // namespace Telephony 262 } // namespace OHOS 263 #endif // OHOS_RIL_IMPL_H 264