1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <libradiocompat/RadioNetwork.h>
18
19 #include "commonStructs.h"
20 #include "debug.h"
21 #include "structs.h"
22 #include "utils.h"
23
24 #include "collections.h"
25
26 #define RADIO_MODULE "Network"
27
28 namespace android::hardware::radio::compat {
29
30 using ::aidl::android::hardware::radio::AccessNetwork;
31 using ::ndk::ScopedAStatus;
32 namespace aidl = ::aidl::android::hardware::radio::network;
33 constexpr auto ok = &ScopedAStatus::ok;
34
respond()35 std::shared_ptr<aidl::IRadioNetworkResponse> RadioNetwork::respond() {
36 return mCallbackManager->response().networkCb();
37 }
38
getAllowedNetworkTypesBitmap(int32_t serial)39 ScopedAStatus RadioNetwork::getAllowedNetworkTypesBitmap(int32_t serial) {
40 LOG_CALL << serial;
41 if (mHal1_6) {
42 mHal1_6->getAllowedNetworkTypesBitmap(serial);
43 } else {
44 mHal1_5->getPreferredNetworkType(serial);
45 }
46 return ok();
47 }
48
getAvailableBandModes(int32_t serial)49 ScopedAStatus RadioNetwork::getAvailableBandModes(int32_t serial) {
50 LOG_CALL << serial;
51 mHal1_5->getAvailableBandModes(serial);
52 return ok();
53 }
54
getAvailableNetworks(int32_t serial)55 ScopedAStatus RadioNetwork::getAvailableNetworks(int32_t serial) {
56 LOG_CALL << serial;
57 mHal1_5->getAvailableNetworks(serial);
58 return ok();
59 }
60
getBarringInfo(int32_t serial)61 ScopedAStatus RadioNetwork::getBarringInfo(int32_t serial) {
62 LOG_CALL << serial;
63 mHal1_5->getBarringInfo(serial);
64 return ok();
65 }
66
getCdmaRoamingPreference(int32_t serial)67 ScopedAStatus RadioNetwork::getCdmaRoamingPreference(int32_t serial) {
68 LOG_CALL << serial;
69 mHal1_5->getCdmaRoamingPreference(serial);
70 return ok();
71 }
72
getCellInfoList(int32_t serial)73 ScopedAStatus RadioNetwork::getCellInfoList(int32_t serial) {
74 LOG_CALL << serial;
75 if (mHal1_6) {
76 mHal1_6->getCellInfoList_1_6(serial);
77 } else {
78 mHal1_5->getCellInfoList(serial);
79 }
80 return ok();
81 }
82
getDataRegistrationState(int32_t serial)83 ScopedAStatus RadioNetwork::getDataRegistrationState(int32_t serial) {
84 LOG_CALL << serial;
85 if (mHal1_6) {
86 mHal1_6->getDataRegistrationState_1_6(serial);
87 } else {
88 mHal1_5->getDataRegistrationState_1_5(serial);
89 }
90 return ok();
91 }
92
getImsRegistrationState(int32_t serial)93 ScopedAStatus RadioNetwork::getImsRegistrationState(int32_t serial) {
94 LOG_CALL << serial;
95 mHal1_5->getImsRegistrationState(serial);
96 return ok();
97 }
98
getNetworkSelectionMode(int32_t serial)99 ScopedAStatus RadioNetwork::getNetworkSelectionMode(int32_t serial) {
100 LOG_CALL << serial;
101 mHal1_5->getNetworkSelectionMode(serial);
102 return ok();
103 }
104
getOperator(int32_t serial)105 ScopedAStatus RadioNetwork::getOperator(int32_t serial) {
106 LOG_CALL << serial;
107 mHal1_5->getOperator(serial);
108 return ok();
109 }
110
getSignalStrength(int32_t serial)111 ScopedAStatus RadioNetwork::getSignalStrength(int32_t serial) {
112 LOG_CALL << serial;
113 if (mHal1_6) {
114 mHal1_6->getSignalStrength_1_6(serial);
115 } else {
116 mHal1_5->getSignalStrength_1_4(serial);
117 }
118 return ok();
119 }
120
getSystemSelectionChannels(int32_t serial)121 ScopedAStatus RadioNetwork::getSystemSelectionChannels(int32_t serial) {
122 LOG_CALL << serial;
123 if (mHal1_6) {
124 mHal1_6->getSystemSelectionChannels(serial);
125 } else {
126 respond()->getSystemSelectionChannelsResponse(notSupported(serial), {});
127 }
128 return ok();
129 }
130
getVoiceRadioTechnology(int32_t serial)131 ScopedAStatus RadioNetwork::getVoiceRadioTechnology(int32_t serial) {
132 LOG_CALL << serial;
133 mHal1_5->getVoiceRadioTechnology(serial);
134 return ok();
135 }
136
getVoiceRegistrationState(int32_t serial)137 ScopedAStatus RadioNetwork::getVoiceRegistrationState(int32_t serial) {
138 LOG_CALL << serial;
139 if (mHal1_6) {
140 mHal1_6->getVoiceRegistrationState_1_6(serial);
141 } else {
142 mHal1_5->getVoiceRegistrationState_1_5(serial);
143 }
144 return ok();
145 }
146
isNrDualConnectivityEnabled(int32_t serial)147 ScopedAStatus RadioNetwork::isNrDualConnectivityEnabled(int32_t serial) {
148 LOG_CALL << serial;
149 if (mHal1_6) {
150 mHal1_6->isNrDualConnectivityEnabled(serial);
151 } else {
152 respond()->isNrDualConnectivityEnabledResponse(notSupported(serial), false);
153 }
154 return ok();
155 }
156
responseAcknowledgement()157 ScopedAStatus RadioNetwork::responseAcknowledgement() {
158 LOG_CALL;
159 mHal1_5->responseAcknowledgement();
160 return ok();
161 }
162
setAllowedNetworkTypesBitmap(int32_t serial,int32_t ntype)163 ScopedAStatus RadioNetwork::setAllowedNetworkTypesBitmap(int32_t serial, int32_t ntype) {
164 LOG_CALL << serial;
165 const auto raf = toHidlBitfield<V1_4::RadioAccessFamily>(ntype);
166 if (mHal1_6) {
167 mHal1_6->setAllowedNetworkTypesBitmap(serial, raf);
168 } else {
169 mHal1_5->setPreferredNetworkType(serial, getNetworkTypeFromRaf(raf));
170 }
171 return ok();
172 }
173
setBandMode(int32_t serial,aidl::RadioBandMode mode)174 ScopedAStatus RadioNetwork::setBandMode(int32_t serial, aidl::RadioBandMode mode) {
175 LOG_CALL << serial;
176 mHal1_5->setBandMode(serial, V1_0::RadioBandMode(mode));
177 return ok();
178 }
179
setBarringPassword(int32_t serial,const std::string & facility,const std::string & oldPw,const std::string & newPw)180 ScopedAStatus RadioNetwork::setBarringPassword(int32_t serial, const std::string& facility,
181 const std::string& oldPw, const std::string& newPw) {
182 LOG_CALL << serial;
183 mHal1_5->setBarringPassword(serial, facility, oldPw, newPw);
184 return ok();
185 }
186
setCdmaRoamingPreference(int32_t serial,aidl::CdmaRoamingType type)187 ScopedAStatus RadioNetwork::setCdmaRoamingPreference(int32_t serial, aidl::CdmaRoamingType type) {
188 LOG_CALL << serial;
189 mHal1_5->setCdmaRoamingPreference(serial, V1_0::CdmaRoamingType(type));
190 return ok();
191 }
192
setCellInfoListRate(int32_t serial,int32_t rate)193 ScopedAStatus RadioNetwork::setCellInfoListRate(int32_t serial, int32_t rate) {
194 LOG_CALL << serial;
195 mHal1_5->setCellInfoListRate(serial, rate);
196 return ok();
197 }
198
setIndicationFilter(int32_t serial,int32_t indFilter)199 ScopedAStatus RadioNetwork::setIndicationFilter(int32_t serial, int32_t indFilter) {
200 LOG_CALL << serial;
201 mHal1_5->setIndicationFilter_1_5(serial, toHidlBitfield<V1_5::IndicationFilter>(indFilter));
202 return ok();
203 }
204
setLinkCapacityReportingCriteria(int32_t serial,int32_t hysteresisMs,int32_t hysteresisDlKbps,int32_t hysteresisUlKbps,const std::vector<int32_t> & thrDownlinkKbps,const std::vector<int32_t> & thrUplinkKbps,AccessNetwork accessNetwork)205 ScopedAStatus RadioNetwork::setLinkCapacityReportingCriteria( //
206 int32_t serial, int32_t hysteresisMs, int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
207 const std::vector<int32_t>& thrDownlinkKbps, const std::vector<int32_t>& thrUplinkKbps,
208 AccessNetwork accessNetwork) {
209 LOG_CALL << serial;
210 mHal1_5->setLinkCapacityReportingCriteria_1_5( //
211 serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps, thrDownlinkKbps,
212 thrUplinkKbps, V1_5::AccessNetwork(accessNetwork));
213 return ok();
214 }
215
setLocationUpdates(int32_t serial,bool enable)216 ScopedAStatus RadioNetwork::setLocationUpdates(int32_t serial, bool enable) {
217 LOG_CALL << serial;
218 mHal1_5->setLocationUpdates(serial, enable);
219 return ok();
220 }
221
setNetworkSelectionModeAutomatic(int32_t serial)222 ScopedAStatus RadioNetwork::setNetworkSelectionModeAutomatic(int32_t serial) {
223 LOG_CALL << serial;
224 mHal1_5->setNetworkSelectionModeAutomatic(serial);
225 return ok();
226 }
227
setNetworkSelectionModeManual(int32_t serial,const std::string & opNumeric,AccessNetwork ran)228 ScopedAStatus RadioNetwork::setNetworkSelectionModeManual( //
229 int32_t serial, const std::string& opNumeric, AccessNetwork ran) {
230 LOG_CALL << serial;
231 mHal1_5->setNetworkSelectionModeManual_1_5(serial, opNumeric, toRadioAccessNetworks(ran));
232 return ok();
233 }
234
setNrDualConnectivityState(int32_t serial,aidl::NrDualConnectivityState st)235 ScopedAStatus RadioNetwork::setNrDualConnectivityState(int32_t serial,
236 aidl::NrDualConnectivityState st) {
237 LOG_CALL << serial;
238 if (mHal1_6) {
239 mHal1_6->setNrDualConnectivityState(serial, V1_6::NrDualConnectivityState(st));
240 } else {
241 respond()->setNrDualConnectivityStateResponse(notSupported(serial));
242 }
243 return ok();
244 }
245
setResponseFunctions(const std::shared_ptr<aidl::IRadioNetworkResponse> & response,const std::shared_ptr<aidl::IRadioNetworkIndication> & indication)246 ScopedAStatus RadioNetwork::setResponseFunctions(
247 const std::shared_ptr<aidl::IRadioNetworkResponse>& response,
248 const std::shared_ptr<aidl::IRadioNetworkIndication>& indication) {
249 LOG_CALL << response << ' ' << indication;
250 mCallbackManager->setResponseFunctions(response, indication);
251 return ok();
252 }
253
setSignalStrengthReportingCriteria(int32_t serial,const std::vector<aidl::SignalThresholdInfo> & infos)254 ScopedAStatus RadioNetwork::setSignalStrengthReportingCriteria(
255 int32_t serial, const std::vector<aidl::SignalThresholdInfo>& infos) {
256 LOG_CALL << serial;
257 if (infos.size() == 0) {
258 LOG(ERROR) << "Threshold info array is empty - dropping setSignalStrengthReportingCriteria";
259 return ok();
260 }
261 if (infos.size() > 1) {
262 LOG(WARNING) << "Multi-element reporting criteria are not supported with HIDL HAL";
263 }
264 if (infos[0].signalMeasurement == aidl::SignalThresholdInfo::SIGNAL_MEASUREMENT_TYPE_ECNO) {
265 LOG(WARNING) << "SIGNAL_MEASUREMENT_TYPE_ECNO are not supported with HIDL HAL";
266 respond()->setSignalStrengthReportingCriteriaResponse(notSupported(serial));
267 return ok();
268 }
269 mHal1_5->setSignalStrengthReportingCriteria_1_5(serial, toHidl(infos[0]),
270 V1_5::AccessNetwork(infos[0].ran));
271 return ok();
272 }
273
setSuppServiceNotifications(int32_t serial,bool enable)274 ScopedAStatus RadioNetwork::setSuppServiceNotifications(int32_t serial, bool enable) {
275 LOG_CALL << serial;
276 mHal1_5->setSuppServiceNotifications(serial, enable);
277 return ok();
278 }
279
setSystemSelectionChannels(int32_t serial,bool specifyCh,const std::vector<aidl::RadioAccessSpecifier> & specifiers)280 ScopedAStatus RadioNetwork::setSystemSelectionChannels( //
281 int32_t serial, bool specifyCh, const std::vector<aidl::RadioAccessSpecifier>& specifiers) {
282 LOG_CALL << serial;
283 mHal1_5->setSystemSelectionChannels_1_5(serial, specifyCh, toHidl(specifiers));
284 return ok();
285 }
286
startNetworkScan(int32_t serial,const aidl::NetworkScanRequest & req)287 ScopedAStatus RadioNetwork::startNetworkScan(int32_t serial, const aidl::NetworkScanRequest& req) {
288 LOG_CALL << serial;
289 mHal1_5->startNetworkScan_1_5(serial, toHidl(req));
290 return ok();
291 }
292
stopNetworkScan(int32_t serial)293 ScopedAStatus RadioNetwork::stopNetworkScan(int32_t serial) {
294 LOG_CALL << serial;
295 mHal1_5->stopNetworkScan(serial);
296 return ok();
297 }
298
supplyNetworkDepersonalization(int32_t ser,const std::string & nPin)299 ScopedAStatus RadioNetwork::supplyNetworkDepersonalization(int32_t ser, const std::string& nPin) {
300 LOG_CALL << ser;
301 mHal1_5->supplyNetworkDepersonalization(ser, nPin);
302 return ok();
303 }
304
setUsageSetting(int32_t serial,aidl::UsageSetting)305 ScopedAStatus RadioNetwork::setUsageSetting(int32_t serial, aidl::UsageSetting) {
306 LOG_CALL << serial;
307 LOG(ERROR) << "setUsageSetting is unsupported by HIDL HALs";
308 respond()->setUsageSettingResponse(notSupported(serial));
309 return ok();
310 }
311
getUsageSetting(int32_t serial)312 ScopedAStatus RadioNetwork::getUsageSetting(int32_t serial) {
313 LOG_CALL << serial;
314 LOG(ERROR) << "getUsageSetting is unsupported by HIDL HALs";
315 respond()->getUsageSettingResponse(notSupported(serial), {}); // {} = neither voice nor data
316 return ok();
317 }
318
setEmergencyMode(int32_t serial,aidl::EmergencyMode)319 ScopedAStatus RadioNetwork::setEmergencyMode(int32_t serial, aidl::EmergencyMode) {
320 LOG_CALL << serial;
321 LOG(ERROR) << " setEmergencyMode is unsupported by HIDL HALs";
322 respond()->setEmergencyModeResponse(notSupported(serial), {});
323 return ok();
324 }
325
triggerEmergencyNetworkScan(int32_t serial,const aidl::EmergencyNetworkScanTrigger &)326 ScopedAStatus RadioNetwork::triggerEmergencyNetworkScan(int32_t serial,
327 const aidl::EmergencyNetworkScanTrigger&) {
328 LOG_CALL << serial;
329 LOG(ERROR) << " triggerEmergencyNetworkScan is unsupported by HIDL HALs";
330 respond()->triggerEmergencyNetworkScanResponse(notSupported(serial));
331 return ok();
332 }
333
cancelEmergencyNetworkScan(int32_t serial,bool)334 ScopedAStatus RadioNetwork::cancelEmergencyNetworkScan(int32_t serial, bool) {
335 LOG_CALL << serial;
336 LOG(ERROR) << " cancelEmergencyNetworkScan is unsupported by HIDL HALs";
337 respond()->cancelEmergencyNetworkScanResponse(notSupported(serial));
338 return ok();
339 }
340
exitEmergencyMode(int32_t serial)341 ScopedAStatus RadioNetwork::exitEmergencyMode(int32_t serial) {
342 LOG_CALL << serial;
343 LOG(ERROR) << " exitEmergencyMode is unsupported by HIDL HALs";
344 respond()->exitEmergencyModeResponse(notSupported(serial));
345 return ok();
346 }
347
setNullCipherAndIntegrityEnabled(int32_t serial,bool)348 ScopedAStatus RadioNetwork::setNullCipherAndIntegrityEnabled(int32_t serial, bool) {
349 LOG_CALL << serial;
350 LOG(ERROR) << " setNullCipherAndIntegrityEnabled is unsupported by HIDL HALs";
351 respond()->setNullCipherAndIntegrityEnabledResponse(notSupported(serial));
352 return ok();
353 }
354
isNullCipherAndIntegrityEnabled(int32_t serial)355 ScopedAStatus RadioNetwork::isNullCipherAndIntegrityEnabled(int32_t serial) {
356 LOG_CALL << serial;
357 LOG(ERROR) << " isNullCipherAndIntegrityEnabled is unsupported by HIDL HALs";
358 respond()->isNullCipherAndIntegrityEnabledResponse(notSupported(serial), true);
359 return ok();
360 }
361
isN1ModeEnabled(int32_t serial)362 ScopedAStatus RadioNetwork::isN1ModeEnabled(int32_t serial) {
363 LOG_CALL << serial;
364 LOG(ERROR) << " isN1ModeEnabled is unsupported by HIDL HALs";
365 respond()->isN1ModeEnabledResponse(notSupported(serial), false);
366 return ok();
367 }
368
setN1ModeEnabled(int32_t serial,bool)369 ScopedAStatus RadioNetwork::setN1ModeEnabled(int32_t serial, bool /*enable*/) {
370 LOG_CALL << serial;
371 LOG(ERROR) << " setN1ModeEnabled is unsupported by HIDL HALs";
372 respond()->setN1ModeEnabledResponse(notSupported(serial));
373 return ok();
374 }
375
isCellularIdentifierTransparencyEnabled(int32_t serial)376 ScopedAStatus RadioNetwork::isCellularIdentifierTransparencyEnabled(int32_t serial) {
377 LOG_CALL << serial;
378 LOG(ERROR) << " isCellularIdentifierTransparencyEnabled is unsupported by HIDL HALs";
379 respond()->isCellularIdentifierTransparencyEnabledResponse(notSupported(serial), false);
380 return ok();
381 }
382
setCellularIdentifierTransparencyEnabled(int32_t serial,bool)383 ScopedAStatus RadioNetwork::setCellularIdentifierTransparencyEnabled(int32_t serial,
384 bool /*enabled*/) {
385 LOG_CALL << serial;
386 LOG(ERROR) << " setCellularIdentifierTransparencyEnabled is unsupported by HIDL HALs";
387 respond()->setCellularIdentifierTransparencyEnabledResponse(notSupported(serial));
388 return ok();
389 }
390
isSecurityAlgorithmsUpdatedEnabled(int32_t serial)391 ScopedAStatus RadioNetwork::isSecurityAlgorithmsUpdatedEnabled(int32_t serial) {
392 LOG_CALL << serial;
393 LOG(ERROR) << " isSecurityAlgorithmsUpdatedEnabled is unsupported by HIDL HALs";
394 respond()->isSecurityAlgorithmsUpdatedEnabledResponse(notSupported(serial), false);
395 return ok();
396 }
397
setSecurityAlgorithmsUpdatedEnabled(int32_t serial,bool)398 ScopedAStatus RadioNetwork::setSecurityAlgorithmsUpdatedEnabled(int32_t serial, bool /*enable*/) {
399 LOG_CALL << serial;
400 LOG(ERROR) << " setSecurityAlgorithmsUpdatedEnabled is unsupported by HIDL HALs";
401 respond()->setSecurityAlgorithmsUpdatedEnabledResponse(notSupported(serial));
402 return ok();
403 }
404
405 } // namespace android::hardware::radio::compat
406