• 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 #include "hril_data.h"
17 
18 #include "hril_notification.h"
19 #include "hril_request.h"
20 
21 namespace OHOS {
22 namespace Telephony {
HRilData(int32_t slotId,IHRilReporter & hrilReporter)23 HRilData::HRilData(int32_t slotId, IHRilReporter &hrilReporter) : HRilBase(slotId, hrilReporter)
24 {
25     AddHandlerToMap();
26 }
27 
~HRilData()28 HRilData::~HRilData()
29 {
30     dataFuncs_ = nullptr;
31 }
32 
IsDataResponse(uint32_t code)33 bool HRilData::IsDataResponse(uint32_t code)
34 {
35     return ((code >= HREQ_DATA_BASE) && (code < HREQ_NETWORK_BASE));
36 }
37 
IsDataNotification(uint32_t code)38 bool HRilData::IsDataNotification(uint32_t code)
39 {
40     return ((code >= HNOTI_DATA_BASE) && (code < HNOTI_NETWORK_BASE));
41 }
42 
IsDataRespOrNotify(uint32_t code)43 bool HRilData::IsDataRespOrNotify(uint32_t code)
44 {
45     return IsDataResponse(code) || IsDataNotification(code);
46 }
47 
AddHandlerToMap()48 void HRilData::AddHandlerToMap()
49 {
50     // Notification
51     notiMemberFuncMap_[HNOTI_DATA_PDP_CONTEXT_LIST_UPDATED] = &HRilData::PdpContextListUpdated;
52     // response
53     respMemberFuncMap_[HREQ_DATA_SET_INIT_APN_INFO] = &HRilData::SetInitApnInfoResponse;
54     respMemberFuncMap_[HREQ_DATA_SET_DATA_PROFILE_INFO] = &HRilData::SetDataProfileInfoResponse;
55     respMemberFuncMap_[HREQ_DATA_ACTIVATE_PDP_CONTEXT] = &HRilData::ActivatePdpContextResponse;
56     respMemberFuncMap_[HREQ_DATA_DEACTIVATE_PDP_CONTEXT] = &HRilData::DeactivatePdpContextResponse;
57     respMemberFuncMap_[HREQ_DATA_GET_PDP_CONTEXT_LIST] = &HRilData::GetPdpContextListResponse;
58     respMemberFuncMap_[HREQ_DATA_GET_LINK_BANDWIDTH_INFO] = &HRilData::GetLinkBandwidthInfoResponse;
59     respMemberFuncMap_[HREQ_DATA_SET_LINK_BANDWIDTH_REPORTING_RULE] = &HRilData::SetLinkBandwidthReportingRuleResponse;
60     respMemberFuncMap_[HREQ_DATA_SET_DATA_PERMITTED] = &HRilData::SetDataPermittedResponse;
61 }
62 
SwitchRilDataToHal(const HRilDataCallResponse * response,HDI::Ril::V1_0::SetupDataCallResultInfo & result)63 void HRilData::SwitchRilDataToHal(const HRilDataCallResponse *response, HDI::Ril::V1_0::SetupDataCallResultInfo &result)
64 {
65     if (response == nullptr) {
66         TELEPHONY_LOGE("SwitchRilDataToHal response is null!!!");
67         return;
68     }
69     result.active = response->active;
70     result.reason = response->reason;
71     result.retryTime = response->retryTime;
72     result.cid = response->cid;
73     result.pduSessionId = response->pduSessionId;
74     result.maxTransferUnit = response->maxTransferUnit;
75     result.address = (response->address == nullptr) ? "" : response->address;
76     result.type = (response->type == nullptr) ? "" : response->type;
77     result.dns = (response->dns == nullptr) ? "" : response->dns;
78     result.dnsSec = (response->dnsSec == nullptr) ? "" : response->dnsSec;
79     result.netPortName = (response->netPortName == nullptr) ? "" : response->netPortName;
80     result.gateway = (response->gateway == nullptr) ? "" : response->gateway;
81     result.pCscfPrimAddr = (response->pCscfPrimAddr == nullptr) ? "" : response->pCscfPrimAddr;
82     result.pCscfSecAddr = (response->pCscfSecAddr == nullptr) ? "" : response->pCscfSecAddr;
83 }
84 
SwitchHRilDataListToHal(const void * response,size_t responseLen,std::vector<HDI::Ril::V1_0::SetupDataCallResultInfo> & dcResultList)85 void HRilData::SwitchHRilDataListToHal(
86     const void *response, size_t responseLen, std::vector<HDI::Ril::V1_0::SetupDataCallResultInfo> &dcResultList)
87 {
88     if (response == nullptr) {
89         TELEPHONY_LOGE("SwitchHRilDataListToHal response is null!!!");
90         return;
91     }
92     size_t dataNum = responseLen / sizeof(HRilDataCallResponse);
93     const HRilDataCallResponse *dataCallResponse = (const HRilDataCallResponse *)response;
94     dcResultList.resize(dataNum);
95 
96     size_t i = 0;
97     while (i < dataNum) {
98         SwitchRilDataToHal(&dataCallResponse[i], dcResultList[i]);
99         i++;
100     }
101 }
102 
DeactivatePdpContext(int32_t serialId,const OHOS::HDI::Ril::V1_0::UniInfo & uniInfo)103 int32_t HRilData::DeactivatePdpContext(int32_t serialId, const OHOS::HDI::Ril::V1_0::UniInfo &uniInfo)
104 {
105     HRilDataInfo dataInfo = {};
106     dataInfo.cid = uniInfo.gsmIndex;
107     dataInfo.reason = uniInfo.arg1;
108     return RequestVendor(
109         serialId, HREQ_DATA_DEACTIVATE_PDP_CONTEXT, dataFuncs_, &HRilDataReq::DeactivatePdpContext, &dataInfo);
110 }
111 
ActivatePdpContext(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataCallInfo & dataCallInfo)112 int32_t HRilData::ActivatePdpContext(int32_t serialId, const OHOS::HDI::Ril::V1_0::DataCallInfo &dataCallInfo)
113 {
114     HRilDataInfo dataInfo;
115     dataInfo.apn = StringToCString(dataCallInfo.dataProfileInfo.apn);
116     dataInfo.type = StringToCString(dataCallInfo.dataProfileInfo.protocol);
117     dataInfo.roamingType = StringToCString(dataCallInfo.dataProfileInfo.roamingProtocol);
118     dataInfo.userName = StringToCString(dataCallInfo.dataProfileInfo.userName);
119     dataInfo.password = StringToCString(dataCallInfo.dataProfileInfo.password);
120     dataInfo.verType = dataCallInfo.dataProfileInfo.authenticationType;
121     dataInfo.rat = dataCallInfo.radioTechnology;
122     dataInfo.roamingEnable = dataCallInfo.roamingAllowed ? 1 : 0;
123     return RequestVendor(
124         serialId, HREQ_DATA_ACTIVATE_PDP_CONTEXT, dataFuncs_, &HRilDataReq::ActivatePdpContext, &dataInfo);
125 }
126 
GetPdpContextList(int32_t serialId,const OHOS::HDI::Ril::V1_0::UniInfo & uniInfo)127 int32_t HRilData::GetPdpContextList(int32_t serialId, const OHOS::HDI::Ril::V1_0::UniInfo &uniInfo)
128 {
129     TELEPHONY_LOGD("serial %{public}d on %{public}d", uniInfo.serial, uniInfo.flag);
130     return RequestVendor(serialId, HREQ_DATA_GET_PDP_CONTEXT_LIST, dataFuncs_, &HRilDataReq::GetPdpContextList);
131 }
132 
SetInitApnInfo(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataProfileDataInfo & dataProfileDataInfo)133 int32_t HRilData::SetInitApnInfo(int32_t serialId, const OHOS::HDI::Ril::V1_0::DataProfileDataInfo &dataProfileDataInfo)
134 {
135     HRilDataInfo dataInfo = BuildDataInfo(dataProfileDataInfo);
136     return RequestVendor(serialId, HREQ_DATA_SET_INIT_APN_INFO, dataFuncs_, &HRilDataReq::SetInitApnInfo, &dataInfo);
137 }
138 
SendDataPerformanceMode(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataPerformanceInfo & dataPerformanceInfo)139 int32_t HRilData::SendDataPerformanceMode(
140     int32_t serialId, const OHOS::HDI::Ril::V1_0::DataPerformanceInfo &dataPerformanceInfo)
141 {
142     HRilDataPerformanceInfo hrilDataPerformanceInfo;
143     hrilDataPerformanceInfo.performanceEnable = dataPerformanceInfo.performanceEnable;
144     hrilDataPerformanceInfo.enforce = dataPerformanceInfo.enforce;
145     TELEPHONY_LOGI("SendDataPerformanceMode: performanceEnable=%{public}d enforce=%{public}d",
146         hrilDataPerformanceInfo.performanceEnable, hrilDataPerformanceInfo.enforce);
147     return RequestVendor(serialId, HREQ_DATA_SEND_DATA_PERFORMANCE_MODE, dataFuncs_,
148         &HRilDataReq::SendDataPerformanceMode, &hrilDataPerformanceInfo);
149 }
150 
SendDataSleepMode(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataSleepInfo & dataSleepInfo)151 int32_t HRilData::SendDataSleepMode(int32_t serialId, const OHOS::HDI::Ril::V1_0::DataSleepInfo &dataSleepInfo)
152 {
153     HRilDataSleepInfo hrilDataSleepInfo;
154     hrilDataSleepInfo.sleepEnable = dataSleepInfo.sleepEnable;
155     TELEPHONY_LOGI("SendDataSleepMode: sleepEnable=%{public}d", hrilDataSleepInfo.sleepEnable);
156     return RequestVendor(
157         serialId, HREQ_DATA_SEND_DATA_SLEEP_MODE, dataFuncs_, &HRilDataReq::SendDataSleepMode, &hrilDataSleepInfo);
158 }
159 
SetDataProfileInfo(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataProfilesInfo & dataProfilesInfo)160 int32_t HRilData::SetDataProfileInfo(int32_t serialId, const OHOS::HDI::Ril::V1_0::DataProfilesInfo &dataProfilesInfo)
161 {
162     int32_t size = dataProfilesInfo.profilesSize;
163     if (size <= 0 || size != static_cast<int32_t>(dataProfilesInfo.profiles.size())) {
164         TELEPHONY_LOGE("RilAdapter failed to do ReadFromParcel!");
165         return HRIL_ERR_INVALID_PARAMETER;
166     }
167     std::unique_ptr<HRilDataInfo[]> dataInfos = std::make_unique<HRilDataInfo[]>(size);
168     for (int32_t i = 0; i < size; i++) {
169         dataInfos[i] = BuildDataInfo(dataProfilesInfo.profiles[i]);
170     }
171     return RequestVendor(
172         serialId, HREQ_DATA_SET_DATA_PROFILE_INFO, dataFuncs_, &HRilDataReq::SetDataProfileInfo, dataInfos.get(), size);
173 }
174 
BuildDataInfo(const OHOS::HDI::Ril::V1_0::DataProfileDataInfo & dataProfileInfo)175 HRilDataInfo HRilData::BuildDataInfo(const OHOS::HDI::Ril::V1_0::DataProfileDataInfo &dataProfileInfo)
176 {
177     HRilDataInfo dataInfo;
178     dataInfo.cid = dataProfileInfo.profileId;
179     dataInfo.apn = StringToCString(dataProfileInfo.apn);
180     dataInfo.type = StringToCString(dataProfileInfo.protocol);
181     dataInfo.roamingType = StringToCString(dataProfileInfo.roamingProtocol);
182     dataInfo.userName = StringToCString(dataProfileInfo.userName);
183     dataInfo.password = StringToCString(dataProfileInfo.password);
184     dataInfo.verType = dataProfileInfo.authenticationType;
185     return dataInfo;
186 }
187 
GetLinkBandwidthInfo(int32_t serialId,int32_t cid)188 int32_t HRilData::GetLinkBandwidthInfo(int32_t serialId, int32_t cid)
189 {
190     return RequestVendor(
191         serialId, HREQ_DATA_GET_LINK_BANDWIDTH_INFO, dataFuncs_, &HRilDataReq::GetLinkBandwidthInfo, cid);
192 }
193 
SetLinkBandwidthReportingRule(int32_t serialId,const OHOS::HDI::Ril::V1_0::DataLinkBandwidthReportingRule & linkBandwidthRule)194 int32_t HRilData::SetLinkBandwidthReportingRule(
195     int32_t serialId, const OHOS::HDI::Ril::V1_0::DataLinkBandwidthReportingRule &linkBandwidthRule)
196 {
197     HRilLinkBandwidthReportingRule hLinkBandwidthRule;
198     hLinkBandwidthRule.rat = (RatType)linkBandwidthRule.rat;
199     hLinkBandwidthRule.delayMs = linkBandwidthRule.delayMs;
200     hLinkBandwidthRule.delayUplinkKbps = linkBandwidthRule.delayUplinkKbps;
201     hLinkBandwidthRule.delayDownlinkKbps = linkBandwidthRule.delayDownlinkKbps;
202     hLinkBandwidthRule.maximumUplinkKbpsSize = linkBandwidthRule.maximumUplinkKbpsSize;
203     hLinkBandwidthRule.maximumDownlinkKbpsSize = linkBandwidthRule.maximumDownlinkKbpsSize;
204     hLinkBandwidthRule.maximumUplinkKbps = new int32_t[linkBandwidthRule.maximumUplinkKbpsSize];
205     hLinkBandwidthRule.maximumDownlinkKbps = new int32_t[linkBandwidthRule.maximumDownlinkKbpsSize];
206     TELEPHONY_LOGI("maximumUplinkKbpsSize:%{public}d, maximumDownlinkKbpsSize:%{public}d",
207         linkBandwidthRule.maximumUplinkKbpsSize, linkBandwidthRule.maximumDownlinkKbpsSize);
208     for (int32_t i = 0; i < hLinkBandwidthRule.maximumUplinkKbpsSize; i++) {
209         hLinkBandwidthRule.maximumUplinkKbps[i] = linkBandwidthRule.maximumUplinkKbps[i];
210     }
211     for (int32_t i = 0; i < hLinkBandwidthRule.maximumDownlinkKbpsSize; i++) {
212         hLinkBandwidthRule.maximumDownlinkKbps[i] = linkBandwidthRule.maximumDownlinkKbps[i];
213     }
214     int32_t resutlt = RequestVendor(serialId, HREQ_DATA_SET_LINK_BANDWIDTH_REPORTING_RULE, dataFuncs_,
215         &HRilDataReq::SetLinkBandwidthReportingRule, &hLinkBandwidthRule);
216     delete[] hLinkBandwidthRule.maximumUplinkKbps;
217     delete[] hLinkBandwidthRule.maximumDownlinkKbps;
218     return resutlt;
219 }
220 
SetDataPermitted(int32_t serialId,int32_t dataPermitted)221 int32_t HRilData::SetDataPermitted(int32_t serialId, int32_t dataPermitted)
222 {
223     return RequestVendor(
224         serialId, HREQ_DATA_SET_DATA_PERMITTED, dataFuncs_, &HRilDataReq::SetDataPermitted, dataPermitted);
225 }
226 
DeactivatePdpContextResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)227 int32_t HRilData::DeactivatePdpContextResponse(
228     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
229 {
230     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::DeactivatePdpContextResponse);
231 }
232 
ActivatePdpContextResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)233 int32_t HRilData::ActivatePdpContextResponse(
234     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
235 {
236     if ((response == nullptr && responseLen != 0) || (responseLen % sizeof(HRilDataCallResponse)) != 0) {
237         TELEPHONY_LOGE("Invalid parameter, responseLen:%{public}zu", responseLen);
238         return HRIL_ERR_INVALID_PARAMETER;
239     }
240     HDI::Ril::V1_0::SetupDataCallResultInfo result = {};
241     result.reason = HRIL_ERROR_UNSPECIFIED_RSN;
242     result.cid = -1;
243     if (response != nullptr) {
244         SwitchRilDataToHal((HRilDataCallResponse *)response, result);
245     }
246     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::ActivatePdpContextResponse, result);
247 }
248 
GetPdpContextListResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)249 int32_t HRilData::GetPdpContextListResponse(
250     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
251 {
252     if ((response == nullptr && responseLen != 0) || (responseLen % sizeof(HRilDataCallResponse)) != 0) {
253         TELEPHONY_LOGE("Invalid parameter, responseLen:%{public}zu", responseLen);
254         return HRIL_ERR_INVALID_PARAMETER;
255     }
256     HDI::Ril::V1_0::DataCallResultList dataCallResultList = {};
257     if (response != nullptr) {
258         SwitchHRilDataListToHal(response, responseLen, dataCallResultList.dcList);
259     }
260     dataCallResultList.size = dataCallResultList.dcList.size();
261     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetPdpContextListResponse, dataCallResultList);
262 }
263 
SetInitApnInfoResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)264 int32_t HRilData::SetInitApnInfoResponse(
265     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
266 {
267     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetInitApnInfoResponse);
268 }
269 
SetDataProfileInfoResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)270 int32_t HRilData::SetDataProfileInfoResponse(
271     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
272 {
273     return HRIL_ERR_SUCCESS;
274 }
275 
SetLinkBandwidthReportingRuleResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)276 int32_t HRilData::SetLinkBandwidthReportingRuleResponse(
277     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
278 {
279     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetLinkBandwidthReportingRuleResponse);
280 }
281 
PdpContextListUpdated(int32_t notifyType,const HRilErrNumber error,const void * response,size_t responseLen)282 int32_t HRilData::PdpContextListUpdated(
283     int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
284 {
285     if ((response == nullptr) || (responseLen % sizeof(HRilDataCallResponse)) != 0) {
286         TELEPHONY_LOGE("Invalid parameter, responseLen:%{public}zu", responseLen);
287         return HRIL_ERR_INVALID_PARAMETER;
288     }
289     HDI::Ril::V1_0::DataCallResultList dataCallResultList = {};
290     if (response != nullptr) {
291         SwitchHRilDataListToHal(response, responseLen, dataCallResultList.dcList);
292     }
293     dataCallResultList.size = dataCallResultList.dcList.size();
294     return Notify(notifyType, error, &HDI::Ril::V1_0::IRilCallback::PdpContextListUpdated, dataCallResultList);
295 }
296 
GetLinkBandwidthInfoResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)297 int32_t HRilData::GetLinkBandwidthInfoResponse(
298     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
299 {
300     if ((response == nullptr && responseLen != 0) || (responseLen % sizeof(HRilLinkBandwidthInfo)) != 0) {
301         TELEPHONY_LOGE("Invalid parameter, responseLen:%{public}zu", responseLen);
302         return HRIL_ERR_INVALID_PARAMETER;
303     }
304     HDI::Ril::V1_0::DataLinkBandwidthInfo uplinkAndDownlinkBandwidthInfo = {};
305     if (response != nullptr) {
306         const HRilLinkBandwidthInfo *result = static_cast<const HRilLinkBandwidthInfo *>(response);
307         uplinkAndDownlinkBandwidthInfo.cid = result->cid;
308         uplinkAndDownlinkBandwidthInfo.qi = result->qi;
309         uplinkAndDownlinkBandwidthInfo.dlGfbr = result->dlGfbr;
310         uplinkAndDownlinkBandwidthInfo.ulGfbr = result->ulGfbr;
311         uplinkAndDownlinkBandwidthInfo.dlMfbr = result->dlMfbr;
312         uplinkAndDownlinkBandwidthInfo.ulMfbr = result->ulMfbr;
313         uplinkAndDownlinkBandwidthInfo.ulSambr = result->ulSambr;
314         uplinkAndDownlinkBandwidthInfo.dlSambr = result->dlSambr;
315         uplinkAndDownlinkBandwidthInfo.averagingWindow = result->averagingWindow;
316     }
317     return Response(
318         responseInfo, &HDI::Ril::V1_0::IRilCallback::GetLinkBandwidthInfoResponse, uplinkAndDownlinkBandwidthInfo);
319 }
320 
SetDataPermittedResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)321 int32_t HRilData::SetDataPermittedResponse(
322     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
323 {
324     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetDataPermittedResponse);
325 }
326 
RegisterDataFuncs(const HRilDataReq * dataFuncs)327 void HRilData::RegisterDataFuncs(const HRilDataReq *dataFuncs)
328 {
329     dataFuncs_ = dataFuncs;
330 }
331 } // namespace Telephony
332 } // namespace OHOS
333