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