• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_network.h"
17 
18 #include "hril_notification.h"
19 #include "hril_request.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 enum class NetworkParameter : int32_t {
24     RESPONSE_VALUE = 3,
25     INVALID_RESPONSE_VALUE = 11,
26 };
27 
HRilNetwork(int32_t slotId,IHRilReporter & hrilReporter)28 HRilNetwork::HRilNetwork(int32_t slotId, IHRilReporter &hrilReporter) : HRilBase(slotId, hrilReporter)
29 {
30     AddHandlerToMap();
31 }
32 
AddHandlerToMap()33 void HRilNetwork::AddHandlerToMap()
34 {
35     // indication
36     notiMemberFuncMap_[HNOTI_NETWORK_CS_REG_STATUS_UPDATED] = &HRilNetwork::NetworkCsRegStatusUpdated;
37     notiMemberFuncMap_[HNOTI_NETWORK_SIGNAL_STRENGTH_UPDATED] = &HRilNetwork::SignalStrengthUpdated;
38     notiMemberFuncMap_[HNOTI_NETWORK_TIME_UPDATED] = &HRilNetwork::NetworkTimeUpdated;
39     notiMemberFuncMap_[HNOTI_NETWORK_TIME_ZONE_UPDATED] = &HRilNetwork::NetworkTimeZoneUpdated;
40     notiMemberFuncMap_[HNOTI_NETWORK_PS_REG_STATUS_UPDATED] = &HRilNetwork::NetworkPsRegStatusUpdated;
41     notiMemberFuncMap_[HNOTI_NETWORK_PHY_CHNL_CFG_UPDATED] = &HRilNetwork::NetworkPhyChnlCfgUpdated;
42     notiMemberFuncMap_[HNOTI_NETWORK_CURRENT_CELL_UPDATED] = &HRilNetwork::NetworkCurrentCellUpdated;
43 
44     // Response
45     respMemberFuncMap_[HREQ_NETWORK_GET_SIGNAL_STRENGTH] = &HRilNetwork::GetSignalStrengthResponse;
46     respMemberFuncMap_[HREQ_NETWORK_GET_CS_REG_STATUS] = &HRilNetwork::GetCsRegStatusResponse;
47     respMemberFuncMap_[HREQ_NETWORK_GET_PS_REG_STATUS] = &HRilNetwork::GetPsRegStatusResponse;
48     respMemberFuncMap_[HREQ_NETWORK_GET_OPERATOR_INFO] = &HRilNetwork::GetOperatorInfoResponse;
49     respMemberFuncMap_[HREQ_NETWORK_GET_NETWORK_SEARCH_INFORMATION] = &HRilNetwork::GetNetworkSearchInformationResponse;
50     respMemberFuncMap_[HREQ_NETWORK_GET_NETWORK_SELECTION_MODE] = &HRilNetwork::GetNetworkSelectionModeResponse;
51     respMemberFuncMap_[HREQ_NETWORK_SET_NETWORK_SELECTION_MODE] = &HRilNetwork::SetNetworkSelectionModeResponse;
52     respMemberFuncMap_[HREQ_NETWORK_SET_PREFERRED_NETWORK] = &HRilNetwork::SetPreferredNetworkResponse;
53     respMemberFuncMap_[HREQ_NETWORK_GET_PREFERRED_NETWORK] = &HRilNetwork::GetPreferredNetworkResponse;
54     respMemberFuncMap_[HREQ_NETWORK_GET_NEIGHBORING_CELLINFO_LIST] = &HRilNetwork::GetNeighboringCellInfoListResponse;
55     respMemberFuncMap_[HREQ_NETWORK_GET_CURRENT_CELL_INFO] = &HRilNetwork::GetCurrentCellInfoResponse;
56     respMemberFuncMap_[HREQ_NETWORK_GET_PHYSICAL_CHANNEL_CONFIG] = &HRilNetwork::GetPhysicalChannelConfigResponse;
57     respMemberFuncMap_[HREQ_NETWORK_SET_LOCATE_UPDATES] = &HRilNetwork::SetLocateUpdatesResponse;
58     respMemberFuncMap_[HREQ_NETWORK_SET_NOTIFICATION_FILTER] = &HRilNetwork::SetNotificationFilterResponse;
59     respMemberFuncMap_[HREQ_NETWORK_SET_DEVICE_STATE] = &HRilNetwork::SetDeviceStateResponse;
60 }
61 
GetSignalStrength(int32_t serialId)62 int32_t HRilNetwork::GetSignalStrength(int32_t serialId)
63 {
64     return RequestVendor(serialId, HREQ_NETWORK_GET_SIGNAL_STRENGTH, networkFuncs_, &HRilNetworkReq::GetSignalStrength);
65 }
66 
GetCsRegStatus(int32_t serialId)67 int32_t HRilNetwork::GetCsRegStatus(int32_t serialId)
68 {
69     return RequestVendor(serialId, HREQ_NETWORK_GET_CS_REG_STATUS, networkFuncs_, &HRilNetworkReq::GetCsRegStatus);
70 }
71 
GetPsRegStatus(int32_t serialId)72 int32_t HRilNetwork::GetPsRegStatus(int32_t serialId)
73 {
74     return RequestVendor(serialId, HREQ_NETWORK_GET_PS_REG_STATUS, networkFuncs_, &HRilNetworkReq::GetPsRegStatus);
75 }
76 
GetOperatorInfo(int32_t serialId)77 int32_t HRilNetwork::GetOperatorInfo(int32_t serialId)
78 {
79     return RequestVendor(serialId, HREQ_NETWORK_GET_OPERATOR_INFO, networkFuncs_, &HRilNetworkReq::GetOperatorInfo);
80 }
81 
GetNeighboringCellInfoList(int32_t serialId)82 int32_t HRilNetwork::GetNeighboringCellInfoList(int32_t serialId)
83 {
84     return RequestVendor(serialId, HREQ_NETWORK_GET_NEIGHBORING_CELLINFO_LIST, networkFuncs_,
85         &HRilNetworkReq::GetNeighboringCellInfoList);
86 }
87 
GetCurrentCellInfo(int32_t serialId)88 int32_t HRilNetwork::GetCurrentCellInfo(int32_t serialId)
89 {
90     return RequestVendor(
91         serialId, HREQ_NETWORK_GET_CURRENT_CELL_INFO, networkFuncs_, &HRilNetworkReq::GetCurrentCellInfo);
92 }
93 
GetNetworkSearchInformation(int32_t serialId)94 int32_t HRilNetwork::GetNetworkSearchInformation(int32_t serialId)
95 {
96     return RequestVendor(serialId, HREQ_NETWORK_GET_NETWORK_SEARCH_INFORMATION, networkFuncs_,
97         &HRilNetworkReq::GetNetworkSearchInformation);
98 }
99 
GetNetworkSelectionMode(int32_t serialId)100 int32_t HRilNetwork::GetNetworkSelectionMode(int32_t serialId)
101 {
102     return RequestVendor(serialId, HREQ_NETWORK_GET_NETWORK_SELECTION_MODE, networkFuncs_,
103         &HRilNetworkReq::GetNetworkSelectionMode);
104 }
105 
SetNetworkSelectionMode(int32_t serialId,const HDI::Ril::V1_0::SetNetworkModeInfo & networkModeInfo)106 int32_t HRilNetwork::SetNetworkSelectionMode(
107     int32_t serialId, const HDI::Ril::V1_0::SetNetworkModeInfo &networkModeInfo)
108 {
109     HRilSetNetworkModeInfo setNetworkModeInfo = {};
110     setNetworkModeInfo.selectMode = networkModeInfo.selectMode;
111     ConvertToString(&setNetworkModeInfo.oper, networkModeInfo.oper);
112     TELEPHONY_LOGI("HRilNetwork::SetNetworkSelectionMode selectMode = %{public}d", setNetworkModeInfo.selectMode);
113     return RequestVendor(serialId, HREQ_NETWORK_SET_NETWORK_SELECTION_MODE, networkFuncs_,
114         &HRilNetworkReq::SetNetworkSelectionMode, &setNetworkModeInfo);
115 }
116 
SetPreferredNetwork(int32_t serialId,int32_t preferredNetworkType)117 int32_t HRilNetwork::SetPreferredNetwork(int32_t serialId, int32_t preferredNetworkType)
118 {
119     return RequestVendor(serialId, HREQ_NETWORK_SET_PREFERRED_NETWORK, networkFuncs_,
120         &HRilNetworkReq::SetPreferredNetwork, &preferredNetworkType);
121 }
122 
GetPreferredNetwork(int32_t serialId)123 int32_t HRilNetwork::GetPreferredNetwork(int32_t serialId)
124 {
125     return RequestVendor(serialId, HREQ_NETWORK_GET_PREFERRED_NETWORK, networkFuncs_,
126         &HRilNetworkReq::GetPreferredNetwork);
127 }
128 
GetPhysicalChannelConfig(int32_t serialId)129 int32_t HRilNetwork::GetPhysicalChannelConfig(int32_t serialId)
130 {
131     return RequestVendor(serialId, HREQ_NETWORK_GET_PHYSICAL_CHANNEL_CONFIG, networkFuncs_,
132         &HRilNetworkReq::GetPhysicalChannelConfig);
133 }
134 
SetLocateUpdates(int32_t serialId,const HDI::Ril::V1_0::RilRegNotifyMode mode)135 int32_t HRilNetwork::SetLocateUpdates(int32_t serialId, const HDI::Ril::V1_0::RilRegNotifyMode mode)
136 {
137     HRilRegNotifyMode regNotifyMode = static_cast<HRilRegNotifyMode>(mode);
138     if ((regNotifyMode < REG_NOT_NOTIFY) || (regNotifyMode > REG_NOTIFY_STAT_LAC_CELLID)) {
139         TELEPHONY_LOGE("SetLocateUpdates Invalid regNotifyMode parameter");
140         return HRIL_ERR_INVALID_PARAMETER;
141     }
142     return RequestVendor(serialId, HREQ_NETWORK_SET_LOCATE_UPDATES, networkFuncs_,
143         &HRilNetworkReq::SetLocateUpdates, static_cast<HRilRegNotifyMode>(mode));
144 }
145 
SetNotificationFilter(int32_t serialId,int32_t newFilter)146 int32_t HRilNetwork::SetNotificationFilter(int32_t serialId, int32_t newFilter)
147 {
148     return RequestVendor(serialId, HREQ_NETWORK_SET_NOTIFICATION_FILTER, networkFuncs_,
149         &HRilNetworkReq::SetNotificationFilter, &newFilter);
150 }
151 
SetDeviceState(int32_t serialId,int32_t deviceStateType,int32_t deviceStateOn)152 int32_t HRilNetwork::SetDeviceState(int32_t serialId, int32_t deviceStateType, int32_t deviceStateOn)
153 {
154     return RequestVendor(serialId, HREQ_NETWORK_SET_DEVICE_STATE, networkFuncs_,
155         &HRilNetworkReq::SetDeviceState, &deviceStateType, &deviceStateOn);
156 }
157 
GetSignalStrengthResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)158 int32_t HRilNetwork::GetSignalStrengthResponse(
159     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
160 {
161     HDI::Ril::V1_0::Rssi rssi = {};
162     if (response == nullptr || responseLen != sizeof(HRilRssi)) {
163         TELEPHONY_LOGE("GetSignalStrengthResponse response is invalid");
164         if (responseInfo.error == HRilErrType::NONE) {
165             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
166         }
167     } else {
168         ExchangeRilRssiToHdf(response, rssi);
169     }
170     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetSignalStrengthResponse, rssi);
171 }
172 
GetCsRegStatusResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)173 int32_t HRilNetwork::GetCsRegStatusResponse(
174     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
175 {
176     HDI::Ril::V1_0::CsRegStatusInfo csRegStatusInfo = {};
177     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
178         TELEPHONY_LOGE("GetCsRegStatusResponse response is invalid");
179         if (responseInfo.error == HRilErrType::NONE) {
180             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
181         }
182     } else {
183         const HRilRegStatusInfo *hrilRegStatusInfo = static_cast<const HRilRegStatusInfo *>(response);
184         csRegStatusInfo.notifyType = hrilRegStatusInfo->notifyMode;
185         csRegStatusInfo.regStatus = static_cast<HDI::Ril::V1_0::RilRegStatus>(hrilRegStatusInfo->regStatus);
186         csRegStatusInfo.lacCode = hrilRegStatusInfo->lacCode;
187         csRegStatusInfo.cellId = hrilRegStatusInfo->cellId;
188         csRegStatusInfo.radioTechnology = static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilRegStatusInfo->actType);
189         TELEPHONY_LOGI("GetCsRegStatusResponse notifyType:%{public}d, regStatus:%{public}d, "
190                        "lacCode:%{private}d, cellId:%{private}d, radioTechnology:%{public}d",
191             csRegStatusInfo.notifyType, csRegStatusInfo.regStatus, csRegStatusInfo.lacCode, csRegStatusInfo.cellId,
192             csRegStatusInfo.radioTechnology);
193     }
194     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetCsRegStatusResponse, csRegStatusInfo);
195 }
196 
GetPsRegStatusResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)197 int32_t HRilNetwork::GetPsRegStatusResponse(
198     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
199 {
200     HDI::Ril::V1_0::PsRegStatusInfo psRegStatusInfo = {};
201     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
202         TELEPHONY_LOGE("GetPsRegStatusResponse response is invalid");
203         if (responseInfo.error == HRilErrType::NONE) {
204             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
205         }
206     } else {
207         const HRilRegStatusInfo *hrilRegStatusInfo = static_cast<const HRilRegStatusInfo *>(response);
208         psRegStatusInfo.notifyType = hrilRegStatusInfo->notifyMode;
209         psRegStatusInfo.regStatus = static_cast<HDI::Ril::V1_0::RilRegStatus>(hrilRegStatusInfo->regStatus);
210         psRegStatusInfo.lacCode = hrilRegStatusInfo->lacCode;
211         psRegStatusInfo.cellId = hrilRegStatusInfo->cellId;
212         psRegStatusInfo.radioTechnology = static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilRegStatusInfo->actType);
213         psRegStatusInfo.isDcNrRestricted = hrilRegStatusInfo->isDcNrRestricted;
214         psRegStatusInfo.isNrAvailable = hrilRegStatusInfo->isNrAvailable;
215         psRegStatusInfo.isEnDcAvailable = hrilRegStatusInfo->isEnDcAvailable;
216         TELEPHONY_LOGI(
217             "GetPsRegStatusResponse notifyType:%{public}d, regStatus:%{public}d, lacCode:%{private}d, "
218             "cellId:%{private}d, technology:%{public}d, isDcNrRestricted:%{private}d, isNrAvailable:%{private}d, "
219             "isEnDcAvailable:%{private}d",
220             psRegStatusInfo.notifyType, psRegStatusInfo.regStatus, psRegStatusInfo.lacCode, psRegStatusInfo.cellId,
221             psRegStatusInfo.radioTechnology, psRegStatusInfo.isDcNrRestricted, psRegStatusInfo.isNrAvailable,
222             psRegStatusInfo.isEnDcAvailable);
223     }
224     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetPsRegStatusResponse, psRegStatusInfo);
225 }
226 
GetOperatorInfoResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)227 int32_t HRilNetwork::GetOperatorInfoResponse(
228     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
229 {
230     HDI::Ril::V1_0::OperatorInfo operatorInfoResult = {};
231     if (response == nullptr || responseLen == 0) {
232         TELEPHONY_LOGE("GetOperatorInfoResponse response is invalid");
233         if (responseInfo.error == HRilErrType::NONE) {
234             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
235         }
236     } else {
237         char **resp = static_cast<char **>(const_cast<void *>(response));
238         operatorInfoResult.longName = (resp[HRIL_LONE_NAME] == nullptr) ? "" : resp[HRIL_LONE_NAME];
239         operatorInfoResult.shortName = (resp[HRIL_SHORT_NAME] == nullptr) ? "" : resp[HRIL_SHORT_NAME];
240         operatorInfoResult.numeric = (resp[HRIL_NUMERIC] == nullptr) ? "" : resp[HRIL_NUMERIC];
241         TELEPHONY_LOGD("GetOperatorInfoResponse longName:%{public}s, shortName:%{public}s, numeric:%{public}s",
242             operatorInfoResult.longName.c_str(), operatorInfoResult.shortName.c_str(),
243             operatorInfoResult.numeric.c_str());
244     }
245     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetOperatorInfoResponse, operatorInfoResult);
246 }
247 
GetNetworkSearchInformationResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)248 int32_t HRilNetwork::GetNetworkSearchInformationResponse(
249     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
250 {
251     HDI::Ril::V1_0::AvailableNetworkList availableNetworkList = {};
252     if (response == nullptr || responseLen == 0) {
253         TELEPHONY_LOGE("GetNetworkSearchInformationResponse response is invalid");
254         if (responseInfo.error == HRilErrType::NONE) {
255             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
256         }
257     } else {
258         availableNetworkList.itemNum = 0;
259         BuildOperatorList(availableNetworkList, response, responseLen);
260     }
261     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetNetworkSearchInformationResponse,
262         availableNetworkList);
263 }
264 
GetNetworkSelectionModeResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)265 int32_t HRilNetwork::GetNetworkSelectionModeResponse(
266     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
267 {
268     HDI::Ril::V1_0::SetNetworkModeInfo selectModeInfo = {};
269     if (response == nullptr || responseLen != sizeof(int32_t)) {
270         TELEPHONY_LOGE("GetNetworkSelectionModeResponse response is invalid");
271         if (responseInfo.error == HRilErrType::NONE) {
272             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
273         }
274     } else {
275         int32_t *resp = static_cast<int32_t *>(const_cast<void *>(response));
276         selectModeInfo.selectMode = *resp;
277         TELEPHONY_LOGI("GetNetworkSelectionModeResponse selectMode: %{public}d", selectModeInfo.selectMode);
278     }
279     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetNetworkSelectionModeResponse, selectModeInfo);
280 }
281 
SetNetworkSelectionModeResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)282 int32_t HRilNetwork::SetNetworkSelectionModeResponse(
283     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
284 {
285     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetNetworkSelectionModeResponse);
286 }
287 
SetPreferredNetworkResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)288 int32_t HRilNetwork::SetPreferredNetworkResponse(
289     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
290 {
291     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetPreferredNetworkResponse);
292 }
293 
GetPreferredNetworkResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)294 int32_t HRilNetwork::GetPreferredNetworkResponse(
295     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
296 {
297     HDI::Ril::V1_0::PreferredNetworkTypeInfo preferredNetworkTypeInfo = {};
298     if (response == nullptr || responseLen != sizeof(int32_t)) {
299         TELEPHONY_LOGE("GetPreferredNetworkResponse response is invalid");
300         if (responseInfo.error == HRilErrType::NONE) {
301             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
302         }
303     } else {
304         int32_t *resp = static_cast<int32_t *>(const_cast<void *>(response));
305         preferredNetworkTypeInfo.preferredNetworkType = *resp;
306         TELEPHONY_LOGI("GetPreferredNetworkResponse preferredNetworkType: %{public}d", *resp);
307     }
308     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetPreferredNetworkResponse, preferredNetworkTypeInfo);
309 }
310 
GetNeighboringCellInfoListResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)311 int32_t HRilNetwork::GetNeighboringCellInfoListResponse(
312     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
313 {
314     HDI::Ril::V1_0::CellListNearbyInfo cellInfoList;
315     if (response == nullptr || responseLen != sizeof(CellInfoList)) {
316         TELEPHONY_LOGE("GetNeighboringCellInfoListResponse response is invalid");
317         if (responseInfo.error == HRilErrType::NONE) {
318             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
319         }
320     } else {
321         cellInfoList.itemNum = 0;
322         cellInfoList.cellNearbyInfo.clear();
323         if (BuildNeighboringCellList(cellInfoList, response, responseLen) != 0) {
324             TELEPHONY_LOGE("GetNeighboringCellInfoListResponse BuildNeighboringCellList failed");
325             return HRIL_ERR_GENERIC_FAILURE;
326         }
327     }
328     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetNeighboringCellInfoListResponse, cellInfoList);
329 }
330 
GetCurrentCellInfoResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)331 int32_t HRilNetwork::GetCurrentCellInfoResponse(
332     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
333 {
334     HDI::Ril::V1_0::CellListCurrentInfo cellList;
335     if (response == nullptr || responseLen != sizeof(CurrentCellInfoList)) {
336         TELEPHONY_LOGE("GetCurrentCellInfoResponse response is invalid");
337         if (responseInfo.error == HRilErrType::NONE) {
338             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
339         }
340     } else {
341         cellList.itemNum = 0;
342         cellList.cellCurrentInfo.clear();
343         if (BuildCurrentCellList(cellList, response, responseLen) != 0) {
344             TELEPHONY_LOGE("GetCurrentCellInfoResponse BuildCurrentCellList failed");
345             return HRIL_ERR_GENERIC_FAILURE;
346         }
347     }
348     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetCurrentCellInfoResponse, cellList);
349 }
350 
GetPhysicalChannelConfigResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)351 int32_t HRilNetwork::GetPhysicalChannelConfigResponse(
352     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
353 {
354     HDI::Ril::V1_0::ChannelConfigInfoList phyChnlCfgList = {};
355     if (response == nullptr || responseLen != sizeof(HRilChannelConfigList)) {
356         TELEPHONY_LOGE("GetPhysicalChannelConfigResponse response is invalid");
357         if (responseInfo.error == HRilErrType::NONE) {
358             responseInfo.error = HRilErrType::HRIL_ERR_INVALID_RESPONSE;
359         }
360     } else {
361         phyChnlCfgList.itemNum = 0;
362         phyChnlCfgList.channelConfigInfos.clear();
363         const HRilChannelConfigList *hrilChannelConfigList = static_cast<const HRilChannelConfigList *>(response);
364         phyChnlCfgList.itemNum = hrilChannelConfigList->itemNum;
365         for (int32_t i = 0; i < phyChnlCfgList.itemNum; i++) {
366             HDI::Ril::V1_0::PhysicalChannelConfig phyChnlCfg;
367             phyChnlCfg.cellConnStatus = static_cast<HDI::Ril::V1_0::RilCellConnectionStatus>(
368                 hrilChannelConfigList->channelConfigs[i].cellConnStatus);
369             phyChnlCfg.cellBandwidthDownlinkKhz = hrilChannelConfigList->channelConfigs[i].cellBandwidthDownlinkKhz;
370             phyChnlCfg.cellBandwidthUplinkKhz = hrilChannelConfigList->channelConfigs[i].cellBandwidthUplinkKhz;
371             phyChnlCfg.ratType =
372                 static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilChannelConfigList->channelConfigs[i].ratType);
373             phyChnlCfg.freqRange = hrilChannelConfigList->channelConfigs[i].freqRange;
374             phyChnlCfg.downlinkChannelNum = hrilChannelConfigList->channelConfigs[i].downlinkChannelNum;
375             phyChnlCfg.uplinkChannelNum = hrilChannelConfigList->channelConfigs[i].uplinkChannelNum;
376             phyChnlCfg.physicalCellId = hrilChannelConfigList->channelConfigs[i].physicalCellId;
377             phyChnlCfg.contextIdNum = hrilChannelConfigList->channelConfigs[i].contextIdNum;
378             TELEPHONY_LOGI(
379                 "GetPhysicalChannelConfigResponse cellConnStatus:%{private}d, "
380                 "cellBandwidthDownlinkKhz:%{private}d, cellBandwidthUplinkKhz:%{private}d, physicalCellId:%{private}d, "
381                 "ratType:%{private}d, freqRange:%{private}d, downlinkChannelNum:%{private}d, "
382                 "uplinkChannelNum:%{private}d, contextIdNum:%{private}d",
383                 phyChnlCfg.cellConnStatus, phyChnlCfg.cellBandwidthDownlinkKhz, phyChnlCfg.cellBandwidthUplinkKhz,
384                 phyChnlCfg.ratType, phyChnlCfg.freqRange, phyChnlCfg.downlinkChannelNum, phyChnlCfg.uplinkChannelNum,
385                 phyChnlCfg.physicalCellId, phyChnlCfg.contextIdNum);
386             for (int32_t j = 0; j < phyChnlCfg.contextIdNum; j++) {
387                 phyChnlCfg.contextIds.push_back(hrilChannelConfigList->channelConfigs[i].contextIds[j]);
388                 TELEPHONY_LOGI("contextIds:%{public}d---contextId:%{private}d", j, phyChnlCfg.contextIds[j]);
389             }
390             phyChnlCfgList.channelConfigInfos.push_back(phyChnlCfg);
391         }
392         TELEPHONY_LOGI("GetPhysicalChannelConfigResponse itemNum:%{public}d", phyChnlCfgList.itemNum);
393     }
394     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::GetPhysicalChannelConfigResponse, phyChnlCfgList);
395 }
396 
SetLocateUpdatesResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)397 int32_t HRilNetwork::SetLocateUpdatesResponse(
398     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
399 {
400     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetLocateUpdatesResponse);
401 }
402 
SetNotificationFilterResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)403 int32_t HRilNetwork::SetNotificationFilterResponse(
404     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
405 {
406     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetNotificationFilterResponse);
407 }
408 
SetDeviceStateResponse(int32_t requestNum,HRilRadioResponseInfo & responseInfo,const void * response,size_t responseLen)409 int32_t HRilNetwork::SetDeviceStateResponse(
410     int32_t requestNum, HRilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
411 {
412     return Response(responseInfo, &HDI::Ril::V1_0::IRilCallback::SetDeviceStateResponse);
413 }
414 
NetworkCsRegStatusUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)415 int32_t HRilNetwork::NetworkCsRegStatusUpdated(
416     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
417 {
418     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
419         TELEPHONY_LOGE("NetworkCsRegStatusUpdated response is invalid");
420         return HRIL_ERR_INVALID_PARAMETER;
421     }
422     HDI::Ril::V1_0::CsRegStatusInfo regStatusInfoNotify = {};
423     const HRilRegStatusInfo *hrilRegStatusInfo = static_cast<const HRilRegStatusInfo *>(response);
424     regStatusInfoNotify.notifyType = hrilRegStatusInfo->notifyMode;
425     regStatusInfoNotify.regStatus = static_cast<HDI::Ril::V1_0::RilRegStatus>(hrilRegStatusInfo->regStatus);
426     regStatusInfoNotify.lacCode = hrilRegStatusInfo->lacCode;
427     regStatusInfoNotify.cellId = hrilRegStatusInfo->cellId;
428     regStatusInfoNotify.radioTechnology = static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilRegStatusInfo->actType);
429     TELEPHONY_LOGI("NetworkCsRegStatusUpdated notifyType:%{public}d, regStatus:%{public}d, "
430                    "lacCode:%{private}d, cellId:%{private}d, radioTechnology:%{public}d",
431         regStatusInfoNotify.notifyType, regStatusInfoNotify.regStatus, regStatusInfoNotify.lacCode,
432         regStatusInfoNotify.cellId, regStatusInfoNotify.radioTechnology);
433     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkCsRegStatusUpdated, regStatusInfoNotify);
434 }
435 
NetworkPsRegStatusUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)436 int32_t HRilNetwork::NetworkPsRegStatusUpdated(
437     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
438 {
439     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
440         TELEPHONY_LOGE("NetworkPsRegStatusUpdated response is invalid");
441         return HRIL_ERR_INVALID_PARAMETER;
442     }
443     HDI::Ril::V1_0::PsRegStatusInfo regStatusInfoNotify = {};
444     const HRilRegStatusInfo *hrilRegStatusInfo = static_cast<const HRilRegStatusInfo *>(response);
445     regStatusInfoNotify.notifyType = hrilRegStatusInfo->notifyMode;
446     regStatusInfoNotify.regStatus = static_cast<HDI::Ril::V1_0::RilRegStatus>(hrilRegStatusInfo->regStatus);
447     regStatusInfoNotify.lacCode = hrilRegStatusInfo->lacCode;
448     regStatusInfoNotify.cellId = hrilRegStatusInfo->cellId;
449     regStatusInfoNotify.radioTechnology = static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilRegStatusInfo->actType);
450     regStatusInfoNotify.isDcNrRestricted = hrilRegStatusInfo->isDcNrRestricted;
451     regStatusInfoNotify.isNrAvailable = hrilRegStatusInfo->isNrAvailable;
452     regStatusInfoNotify.isEnDcAvailable = hrilRegStatusInfo->isEnDcAvailable;
453     TELEPHONY_LOGI(
454         "GetPsRegStatusResponse notifyType:%{public}d, regStatus:%{public}d, lacCode:%{private}d, cellId:%{private}d, "
455         "radioTechnology:%{public}d, isDcNrRestricted:%{private}d, isNrAvailable:%{private}d, "
456         "isEnDcAvailable:%{private}d",
457         regStatusInfoNotify.notifyType, regStatusInfoNotify.regStatus, regStatusInfoNotify.lacCode,
458         regStatusInfoNotify.cellId, regStatusInfoNotify.radioTechnology, regStatusInfoNotify.isDcNrRestricted,
459         regStatusInfoNotify.isNrAvailable, regStatusInfoNotify.isEnDcAvailable);
460     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkPsRegStatusUpdated, regStatusInfoNotify);
461 }
462 
SignalStrengthUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)463 int32_t HRilNetwork::SignalStrengthUpdated(
464     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
465 {
466     if (response == nullptr || responseLen != sizeof(HRilRssi)) {
467         TELEPHONY_LOGE("SignalStrengthUpdated response is invalid");
468         return HRIL_ERR_INVALID_PARAMETER;
469     }
470     HDI::Ril::V1_0::Rssi rssi = {};
471     ExchangeRilRssiToHdf(response, rssi);
472     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::SignalStrengthUpdated, rssi);
473 }
474 
NetworkTimeUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)475 int32_t HRilNetwork::NetworkTimeUpdated(
476     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
477 {
478     if (response == nullptr) {
479         TELEPHONY_LOGE("NetworkTimeUpdated response is invalid");
480         return HRIL_ERR_INVALID_PARAMETER;
481     }
482     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkTimeUpdated, (const char *)response);
483 }
484 
NetworkTimeZoneUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)485 int32_t HRilNetwork::NetworkTimeZoneUpdated(
486     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
487 {
488     if (response == nullptr) {
489         TELEPHONY_LOGE("NetworkTimeZoneUpdated response is invalid");
490         return HRIL_ERR_INVALID_PARAMETER;
491     }
492     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkTimeZoneUpdated, (const char *)response);
493 }
494 
NetworkPhyChnlCfgUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)495 int32_t HRilNetwork::NetworkPhyChnlCfgUpdated(
496     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
497 {
498     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
499         TELEPHONY_LOGE("NetworkPhyChnlCfgUpdated response is invalid");
500         return HRIL_ERR_INVALID_PARAMETER;
501     }
502     HDI::Ril::V1_0::ChannelConfigInfoList phyChnlCfgList = {};
503     phyChnlCfgList.itemNum = 0;
504     phyChnlCfgList.channelConfigInfos.clear();
505     const HRilChannelConfigList *hrilChannelConfigList = static_cast<const HRilChannelConfigList *>(response);
506     phyChnlCfgList.itemNum = hrilChannelConfigList->itemNum;
507     for (int32_t i = 0; i < phyChnlCfgList.itemNum; i++) {
508         HDI::Ril::V1_0::PhysicalChannelConfig phyChnlCfg;
509         phyChnlCfg.cellConnStatus = static_cast<HDI::Ril::V1_0::RilCellConnectionStatus>(
510             hrilChannelConfigList->channelConfigs[i].cellConnStatus);
511         phyChnlCfg.cellBandwidthDownlinkKhz = hrilChannelConfigList->channelConfigs[i].cellBandwidthDownlinkKhz;
512         phyChnlCfg.cellBandwidthUplinkKhz = hrilChannelConfigList->channelConfigs[i].cellBandwidthUplinkKhz;
513         phyChnlCfg.ratType =
514             static_cast<HDI::Ril::V1_0::RilRadioTech>(hrilChannelConfigList->channelConfigs[i].ratType);
515         phyChnlCfg.freqRange = hrilChannelConfigList->channelConfigs[i].freqRange;
516         phyChnlCfg.downlinkChannelNum = hrilChannelConfigList->channelConfigs[i].downlinkChannelNum;
517         phyChnlCfg.uplinkChannelNum = hrilChannelConfigList->channelConfigs[i].uplinkChannelNum;
518         phyChnlCfg.physicalCellId = hrilChannelConfigList->channelConfigs[i].physicalCellId;
519         phyChnlCfg.contextIdNum = hrilChannelConfigList->channelConfigs[i].contextIdNum;
520         for (int32_t j = 0; j < phyChnlCfg.contextIdNum; j++) {
521             phyChnlCfg.contextIds.push_back(hrilChannelConfigList->channelConfigs[i].contextIds[j]);
522         }
523         phyChnlCfgList.channelConfigInfos.push_back(phyChnlCfg);
524     }
525     TELEPHONY_LOGI("NetworkPhyChnlCfgUpdated itemNum:%{public}d", phyChnlCfgList.itemNum);
526     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkPhyChnlCfgUpdated, phyChnlCfgList);
527 }
528 
NetworkCurrentCellUpdated(int32_t indType,const HRilErrNumber error,const void * response,size_t responseLen)529 int32_t HRilNetwork::NetworkCurrentCellUpdated(
530     int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen)
531 {
532     if (response == nullptr || responseLen != sizeof(HRilRegStatusInfo)) {
533         TELEPHONY_LOGE("NetworkCurrentCellUpdated response is invalid");
534         return HRIL_ERR_INVALID_PARAMETER;
535     }
536     HDI::Ril::V1_0::CellListCurrentInfo cellList;
537     cellList.itemNum = 0;
538     cellList.cellCurrentInfo.clear();
539     if (BuildCurrentCellList(cellList, response, responseLen) != 0) {
540         TELEPHONY_LOGE("NetworkCurrentCellUpdated BuildCurrentCellList failed");
541         return HRIL_ERR_GENERIC_FAILURE;
542     }
543     return Notify(indType, error, &HDI::Ril::V1_0::IRilCallback::NetworkCurrentCellUpdated, cellList);
544 }
545 
ExchangeRilRssiToHdf(const void * response,HDI::Ril::V1_0::Rssi & rssi)546 void HRilNetwork::ExchangeRilRssiToHdf(const void *response, HDI::Ril::V1_0::Rssi &rssi)
547 {
548     HRilRssi *rilRssi = (HRilRssi *)response;
549     rssi.gw.rxlev = rilRssi->gsmRssi.rxlev;
550     rssi.gw.ber = rilRssi->gsmRssi.ber;
551     rssi.cdma.absoluteRssi = rilRssi->cdmaRssi.absoluteRssi;
552     rssi.cdma.ecno = rilRssi->cdmaRssi.ecno;
553     rssi.wcdma.rxlev = rilRssi->wcdmaRssi.rxlev;
554     rssi.wcdma.ber = rilRssi->wcdmaRssi.ber;
555     rssi.wcdma.ecio = rilRssi->wcdmaRssi.ecio;
556     rssi.wcdma.rscp = rilRssi->wcdmaRssi.rscp;
557     rssi.lte.rxlev = rilRssi->lteRssi.rxlev;
558     rssi.lte.rsrp = rilRssi->lteRssi.rsrp;
559     rssi.lte.rsrq = rilRssi->lteRssi.rsrq;
560     rssi.lte.snr = rilRssi->lteRssi.snr;
561     rssi.tdScdma.rscp = rilRssi->tdScdmaRssi.rscp;
562     rssi.nr.rsrp = rilRssi->nrRssi.rsrp;
563     rssi.nr.rsrq = rilRssi->nrRssi.rsrq;
564     rssi.nr.sinr = rilRssi->nrRssi.sinr;
565     TELEPHONY_LOGD("ExchangeRilRssiToHdf rxlev:%{public}d, rsrp:%{public}d", rssi.lte.rxlev, rssi.lte.rsrp);
566 }
567 
BuildOperatorList(HDI::Ril::V1_0::AvailableNetworkList & availableNetworkList,const void * response,size_t responseLen)568 void HRilNetwork::BuildOperatorList(
569     HDI::Ril::V1_0::AvailableNetworkList &availableNetworkList, const void *response, size_t responseLen)
570 {
571     size_t numStrings = responseLen / sizeof(AvailableOperInfo *);
572     HDI::Ril::V1_0::AvailableNetworkInfo operInfo = {};
573     availableNetworkList.itemNum = numStrings;
574     TELEPHONY_LOGI(
575         "BuildOperatorList availableNetworkList.itemNum: %{public}lu", static_cast<unsigned long>(numStrings));
576     for (size_t i = 0; i < numStrings; i++) {
577         AvailableOperInfo *curPtr = ((AvailableOperInfo **)response)[i];
578         if (curPtr != nullptr) {
579             operInfo.status = curPtr->status;
580             TELEPHONY_LOGI("operInfo.status:%{public}d", curPtr->status);
581             operInfo.longName = (curPtr->longName == nullptr) ? "" : curPtr->longName;
582             TELEPHONY_LOGI("operInfo.longName:%{public}s", curPtr->longName);
583             operInfo.numeric = (curPtr->numeric == nullptr) ? "" : curPtr->numeric;
584             TELEPHONY_LOGI("operInfo.numeric:%{public}s", curPtr->numeric);
585             operInfo.shortName = (curPtr->shortName == nullptr) ? "" : curPtr->shortName;
586             TELEPHONY_LOGI("operInfo.shortName:%{public}s", curPtr->shortName);
587             operInfo.rat = curPtr->rat;
588             TELEPHONY_LOGI("operInfo.rat:%{public}d", curPtr->rat);
589             availableNetworkList.availableNetworkInfo.push_back(operInfo);
590         }
591     }
592 }
593 
FillCellNearbyInfo(HDI::Ril::V1_0::CellNearbyInfo & cellInfo,const CellInfo * cellPtr)594 void HRilNetwork::FillCellNearbyInfo(HDI::Ril::V1_0::CellNearbyInfo &cellInfo, const CellInfo *cellPtr)
595 {
596     cellInfo.ratType = cellPtr->ratType;
597     switch (cellPtr->ratType) {
598         case NETWORK_TYPE_GSM:
599             cellInfo.serviceCells.gsm.band = cellPtr->ServiceCellParas.gsm.band;
600             cellInfo.serviceCells.gsm.arfcn = cellPtr->ServiceCellParas.gsm.arfcn;
601             cellInfo.serviceCells.gsm.bsic = cellPtr->ServiceCellParas.gsm.bsic;
602             cellInfo.serviceCells.gsm.cellId = cellPtr->ServiceCellParas.gsm.cellId;
603             cellInfo.serviceCells.gsm.lac = cellPtr->ServiceCellParas.gsm.lac;
604             cellInfo.serviceCells.gsm.rxlev = cellPtr->ServiceCellParas.gsm.rxlev;
605             break;
606         case NETWORK_TYPE_LTE:
607             cellInfo.serviceCells.lte.arfcn = cellPtr->ServiceCellParas.lte.arfcn;
608             cellInfo.serviceCells.lte.pci = cellPtr->ServiceCellParas.lte.pci;
609             cellInfo.serviceCells.lte.rsrp = cellPtr->ServiceCellParas.lte.rsrp;
610             cellInfo.serviceCells.lte.rsrq = cellPtr->ServiceCellParas.lte.rsrq;
611             cellInfo.serviceCells.lte.rxlev = cellPtr->ServiceCellParas.lte.rxlev;
612             break;
613         case NETWORK_TYPE_WCDMA:
614             cellInfo.serviceCells.wcdma.arfcn = cellPtr->ServiceCellParas.wcdma.arfcn;
615             cellInfo.serviceCells.wcdma.psc = cellPtr->ServiceCellParas.wcdma.psc;
616             cellInfo.serviceCells.wcdma.rscp = cellPtr->ServiceCellParas.wcdma.rscp;
617             cellInfo.serviceCells.wcdma.ecno = cellPtr->ServiceCellParas.wcdma.ecno;
618             break;
619         case NETWORK_TYPE_CDMA:
620             FillCellNearbyInfoCdma(cellInfo, cellPtr);
621             break;
622         case NETWORK_TYPE_TDSCDMA:
623             FillCellNearbyInfoTdscdma(cellInfo, cellPtr);
624             break;
625         case NETWORK_TYPE_NR:
626             cellInfo.serviceCells.nr.nrArfcn = cellPtr->ServiceCellParas.nr.nrArfcn;
627             cellInfo.serviceCells.nr.pci = cellPtr->ServiceCellParas.nr.pci;
628             cellInfo.serviceCells.nr.tac = cellPtr->ServiceCellParas.nr.tac;
629             cellInfo.serviceCells.nr.nci = cellPtr->ServiceCellParas.nr.nci;
630             break;
631         default:
632             cellInfo.serviceCells.gsm.band = 0;
633             cellInfo.serviceCells.gsm.arfcn = 0;
634             cellInfo.serviceCells.gsm.bsic = 0;
635             cellInfo.serviceCells.gsm.cellId = 0;
636             cellInfo.serviceCells.gsm.lac = 0;
637             cellInfo.serviceCells.gsm.rxlev = 0;
638             break;
639     }
640 }
641 
FillCellNearbyInfoTdscdma(HDI::Ril::V1_0::CellNearbyInfo & cellInfo,const CellInfo * hrilCellPtr)642 void HRilNetwork::FillCellNearbyInfoTdscdma(HDI::Ril::V1_0::CellNearbyInfo &cellInfo, const CellInfo *hrilCellPtr)
643 {
644     cellInfo.serviceCells.tdscdma.arfcn = hrilCellPtr->ServiceCellParas.tdscdma.arfcn;
645     cellInfo.serviceCells.tdscdma.syncId = hrilCellPtr->ServiceCellParas.tdscdma.syncId;
646     cellInfo.serviceCells.tdscdma.sc = hrilCellPtr->ServiceCellParas.tdscdma.sc;
647     cellInfo.serviceCells.tdscdma.cellId = hrilCellPtr->ServiceCellParas.tdscdma.cellId;
648     cellInfo.serviceCells.tdscdma.lac = hrilCellPtr->ServiceCellParas.tdscdma.lac;
649     cellInfo.serviceCells.tdscdma.rscp = hrilCellPtr->ServiceCellParas.tdscdma.rscp;
650     cellInfo.serviceCells.tdscdma.drx = hrilCellPtr->ServiceCellParas.tdscdma.drx;
651     cellInfo.serviceCells.tdscdma.rac = hrilCellPtr->ServiceCellParas.tdscdma.rac;
652     cellInfo.serviceCells.tdscdma.cpid = hrilCellPtr->ServiceCellParas.tdscdma.cpid;
653 }
654 
FillCellNearbyInfoCdma(HDI::Ril::V1_0::CellNearbyInfo & cellInfo,const CellInfo * hrilCellPtr)655 void HRilNetwork::FillCellNearbyInfoCdma(HDI::Ril::V1_0::CellNearbyInfo &cellInfo, const CellInfo *hrilCellPtr)
656 {
657     cellInfo.serviceCells.cdma.systemId = hrilCellPtr->ServiceCellParas.cdma.systemId;
658     cellInfo.serviceCells.cdma.networkId = hrilCellPtr->ServiceCellParas.cdma.networkId;
659     cellInfo.serviceCells.cdma.baseId = hrilCellPtr->ServiceCellParas.cdma.baseId;
660     cellInfo.serviceCells.cdma.zoneId = hrilCellPtr->ServiceCellParas.cdma.zoneId;
661     cellInfo.serviceCells.cdma.pilotPn = hrilCellPtr->ServiceCellParas.cdma.pilotPn;
662     cellInfo.serviceCells.cdma.pilotStrength = hrilCellPtr->ServiceCellParas.cdma.pilotStrength;
663     cellInfo.serviceCells.cdma.channel = hrilCellPtr->ServiceCellParas.cdma.channel;
664     cellInfo.serviceCells.cdma.longitude = hrilCellPtr->ServiceCellParas.cdma.longitude;
665     cellInfo.serviceCells.cdma.latitude = hrilCellPtr->ServiceCellParas.cdma.latitude;
666 }
667 
BuildNeighboringCellList(HDI::Ril::V1_0::CellListNearbyInfo & cellInfoList,const void * response,size_t responseLen)668 int32_t HRilNetwork::BuildNeighboringCellList(
669     HDI::Ril::V1_0::CellListNearbyInfo &cellInfoList, const void *response, size_t responseLen)
670 {
671     const CellInfoList *temp = reinterpret_cast<const CellInfoList *>(response);
672     cellInfoList.itemNum = temp->itemNum;
673     TELEPHONY_LOGI("BuildNeighboringCellList cellInfoList.itemNum = %{public}d", cellInfoList.itemNum);
674     for (int32_t i = 0; i < temp->itemNum; i++) {
675         HDI::Ril::V1_0::CellNearbyInfo cellInfo;
676         CellInfo *cell = temp->cellNearbyInfo + i;
677         if (cell == nullptr) {
678             TELEPHONY_LOGE("BuildNeighboringCellList cell is nullptr");
679             return HRIL_ERR_GENERIC_FAILURE;
680         }
681         FillCellNearbyInfo(cellInfo, cell);
682         cellInfoList.cellNearbyInfo.push_back(cellInfo);
683     }
684     return HRIL_ERR_SUCCESS;
685 }
686 
FillCellInfoType(HDI::Ril::V1_0::CurrentCellInfo & cellInfo,const CurrentCellInfoVendor * hrilCellInfoVendor)687 void HRilNetwork::FillCellInfoType(
688     HDI::Ril::V1_0::CurrentCellInfo &cellInfo, const CurrentCellInfoVendor *hrilCellInfoVendor)
689 {
690     if (hrilCellInfoVendor->ratType == NETWORK_TYPE_WCDMA) {
691         cellInfo.serviceCells.wcdma.arfcn = hrilCellInfoVendor->ServiceCellParas.wcdma.arfcn;
692         cellInfo.serviceCells.wcdma.cellId = hrilCellInfoVendor->ServiceCellParas.wcdma.cellId;
693         cellInfo.serviceCells.wcdma.psc = hrilCellInfoVendor->ServiceCellParas.wcdma.psc;
694         cellInfo.serviceCells.wcdma.lac = hrilCellInfoVendor->ServiceCellParas.wcdma.lac;
695         cellInfo.serviceCells.wcdma.rxlev = hrilCellInfoVendor->ServiceCellParas.wcdma.rxlev;
696         cellInfo.serviceCells.wcdma.rscp = hrilCellInfoVendor->ServiceCellParas.wcdma.rscp;
697         cellInfo.serviceCells.wcdma.ecno = hrilCellInfoVendor->ServiceCellParas.wcdma.ecno;
698         cellInfo.serviceCells.wcdma.ura = hrilCellInfoVendor->ServiceCellParas.wcdma.ura;
699         cellInfo.serviceCells.wcdma.drx = hrilCellInfoVendor->ServiceCellParas.wcdma.drx;
700     } else if (hrilCellInfoVendor->ratType == NETWORK_TYPE_CDMA) {
701         cellInfo.serviceCells.cdma.systemId = hrilCellInfoVendor->ServiceCellParas.cdma.systemId;
702         cellInfo.serviceCells.cdma.networkId = hrilCellInfoVendor->ServiceCellParas.cdma.networkId;
703         cellInfo.serviceCells.cdma.baseId = hrilCellInfoVendor->ServiceCellParas.cdma.baseId;
704         cellInfo.serviceCells.cdma.zoneId = hrilCellInfoVendor->ServiceCellParas.cdma.zoneId;
705         cellInfo.serviceCells.cdma.pilotPn = hrilCellInfoVendor->ServiceCellParas.cdma.pilotPn;
706         cellInfo.serviceCells.cdma.pilotStrength = hrilCellInfoVendor->ServiceCellParas.cdma.pilotStrength;
707         cellInfo.serviceCells.cdma.channel = hrilCellInfoVendor->ServiceCellParas.cdma.channel;
708         cellInfo.serviceCells.cdma.longitude = hrilCellInfoVendor->ServiceCellParas.cdma.longitude;
709         cellInfo.serviceCells.cdma.latitude = hrilCellInfoVendor->ServiceCellParas.cdma.latitude;
710     } else if (hrilCellInfoVendor->ratType == NETWORK_TYPE_TDSCDMA) {
711         cellInfo.serviceCells.tdscdma.arfcn = hrilCellInfoVendor->ServiceCellParas.tdscdma.arfcn;
712         cellInfo.serviceCells.tdscdma.syncId = hrilCellInfoVendor->ServiceCellParas.tdscdma.syncId;
713         cellInfo.serviceCells.tdscdma.sc = hrilCellInfoVendor->ServiceCellParas.tdscdma.sc;
714         cellInfo.serviceCells.tdscdma.cellId = hrilCellInfoVendor->ServiceCellParas.tdscdma.cellId;
715         cellInfo.serviceCells.tdscdma.lac = hrilCellInfoVendor->ServiceCellParas.tdscdma.lac;
716         cellInfo.serviceCells.tdscdma.rscp = hrilCellInfoVendor->ServiceCellParas.tdscdma.rscp;
717         cellInfo.serviceCells.tdscdma.drx = hrilCellInfoVendor->ServiceCellParas.tdscdma.drx;
718         cellInfo.serviceCells.tdscdma.rac = hrilCellInfoVendor->ServiceCellParas.tdscdma.rac;
719         cellInfo.serviceCells.tdscdma.cpid = hrilCellInfoVendor->ServiceCellParas.tdscdma.cpid;
720     }
721 }
722 
FillCurrentCellInfo(HDI::Ril::V1_0::CurrentCellInfo & cellInfo,const CurrentCellInfoVendor * cellInfoVendor)723 void HRilNetwork::FillCurrentCellInfo(
724     HDI::Ril::V1_0::CurrentCellInfo &cellInfo, const CurrentCellInfoVendor *cellInfoVendor)
725 {
726     cellInfo.ratType = cellInfoVendor->ratType;
727     cellInfo.mcc = cellInfoVendor->mcc;
728     cellInfo.mnc = cellInfoVendor->mnc;
729     switch (cellInfoVendor->ratType) {
730         case NETWORK_TYPE_GSM:
731             cellInfo.serviceCells.gsm.band = cellInfoVendor->ServiceCellParas.gsm.band;
732             cellInfo.serviceCells.gsm.arfcn = cellInfoVendor->ServiceCellParas.gsm.arfcn;
733             cellInfo.serviceCells.gsm.bsic = cellInfoVendor->ServiceCellParas.gsm.bsic;
734             cellInfo.serviceCells.gsm.cellId = cellInfoVendor->ServiceCellParas.gsm.cellId;
735             cellInfo.serviceCells.gsm.lac = cellInfoVendor->ServiceCellParas.gsm.lac;
736             cellInfo.serviceCells.gsm.rxlev = cellInfoVendor->ServiceCellParas.gsm.rxlev;
737             cellInfo.serviceCells.gsm.rxQuality = cellInfoVendor->ServiceCellParas.gsm.rxQuality;
738             cellInfo.serviceCells.gsm.ta = cellInfoVendor->ServiceCellParas.gsm.ta;
739             break;
740         case NETWORK_TYPE_LTE:
741             cellInfo.serviceCells.lte.arfcn = cellInfoVendor->ServiceCellParas.lte.arfcn;
742             cellInfo.serviceCells.lte.cellId = cellInfoVendor->ServiceCellParas.lte.cellId;
743             cellInfo.serviceCells.lte.pci = cellInfoVendor->ServiceCellParas.lte.pci;
744             cellInfo.serviceCells.lte.tac = cellInfoVendor->ServiceCellParas.lte.tac;
745             cellInfo.serviceCells.lte.rsrp = cellInfoVendor->ServiceCellParas.lte.rsrp;
746             cellInfo.serviceCells.lte.rsrq = cellInfoVendor->ServiceCellParas.lte.rsrq;
747             cellInfo.serviceCells.lte.rssi = cellInfoVendor->ServiceCellParas.lte.rssi;
748             break;
749         case NETWORK_TYPE_WCDMA:
750         case NETWORK_TYPE_CDMA:
751         case NETWORK_TYPE_TDSCDMA:
752             FillCellInfoType(cellInfo, cellInfoVendor);
753             break;
754         case NETWORK_TYPE_NR:
755             cellInfo.serviceCells.nr.nrArfcn = cellInfoVendor->ServiceCellParas.nr.nrArfcn;
756             cellInfo.serviceCells.nr.pci = cellInfoVendor->ServiceCellParas.nr.pci;
757             cellInfo.serviceCells.nr.tac = cellInfoVendor->ServiceCellParas.nr.tac;
758             cellInfo.serviceCells.nr.nci = cellInfoVendor->ServiceCellParas.nr.nci;
759             break;
760         default:
761             cellInfo.serviceCells.wcdma.arfcn = 0;
762             cellInfo.serviceCells.wcdma.cellId = 0;
763             cellInfo.serviceCells.wcdma.psc = 0;
764             cellInfo.serviceCells.wcdma.lac = 0;
765             cellInfo.serviceCells.wcdma.rxlev = 0;
766             cellInfo.serviceCells.wcdma.rscp = 0;
767             cellInfo.serviceCells.wcdma.ecno = 0;
768             cellInfo.serviceCells.wcdma.drx = 0;
769             cellInfo.serviceCells.wcdma.ura = 0;
770             break;
771     }
772 }
773 
BuildCurrentCellList(HDI::Ril::V1_0::CellListCurrentInfo & cellInfoList,const void * response,size_t responseLen)774 int32_t HRilNetwork::BuildCurrentCellList(HDI::Ril::V1_0::CellListCurrentInfo &cellInfoList,
775     const void *response, size_t responseLen)
776 {
777     const CurrentCellInfoList *temp = reinterpret_cast<const CurrentCellInfoList *>(response);
778     cellInfoList.itemNum = temp->itemNum;
779     TELEPHONY_LOGI("BuildCurrentCellList cellInfoList.itemNum = %{public}d", cellInfoList.itemNum);
780     for (int32_t i = 0; i < temp->itemNum; i++) {
781         HDI::Ril::V1_0::CurrentCellInfo cellInfo;
782         CurrentCellInfoVendor *cell = temp->currentCellInfo + i;
783         if (cell == nullptr) {
784             TELEPHONY_LOGE("BuildCurrentCellList cell is nullptr");
785             return HRIL_ERR_GENERIC_FAILURE;
786         }
787         FillCurrentCellInfo(cellInfo, cell);
788         cellInfoList.cellCurrentInfo.push_back(cellInfo);
789     }
790     return HRIL_ERR_SUCCESS;
791 }
792 
IsNetworkResponse(uint32_t code)793 bool HRilNetwork::IsNetworkResponse(uint32_t code)
794 {
795     return ((code >= HREQ_NETWORK_BASE) && (code < HREQ_COMMON_BASE));
796 }
797 
IsNetworkNotification(uint32_t code)798 bool HRilNetwork::IsNetworkNotification(uint32_t code)
799 {
800     return ((code >= HNOTI_NETWORK_BASE) && (code < HNOTI_COMMON_BASE));
801 }
802 
IsNetworkRespOrNotify(uint32_t code)803 bool HRilNetwork::IsNetworkRespOrNotify(uint32_t code)
804 {
805     return IsNetworkResponse(code) || IsNetworkNotification(code);
806 }
807 
RegisterNetworkFuncs(const HRilNetworkReq * networkFuncs)808 void HRilNetwork::RegisterNetworkFuncs(const HRilNetworkReq *networkFuncs)
809 {
810     networkFuncs_ = networkFuncs;
811 }
812 } // namespace Telephony
813 } // namespace OHOS
814