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 mHal1_5->setSignalStrengthReportingCriteria_1_5(serial, toHidl(infos[0]),
265 V1_5::AccessNetwork(infos[0].ran));
266 return ok();
267 }
268
setSuppServiceNotifications(int32_t serial,bool enable)269 ScopedAStatus RadioNetwork::setSuppServiceNotifications(int32_t serial, bool enable) {
270 LOG_CALL << serial;
271 mHal1_5->setSuppServiceNotifications(serial, enable);
272 return ok();
273 }
274
setSystemSelectionChannels(int32_t serial,bool specifyCh,const std::vector<aidl::RadioAccessSpecifier> & specifiers)275 ScopedAStatus RadioNetwork::setSystemSelectionChannels( //
276 int32_t serial, bool specifyCh, const std::vector<aidl::RadioAccessSpecifier>& specifiers) {
277 LOG_CALL << serial;
278 mHal1_5->setSystemSelectionChannels_1_5(serial, specifyCh, toHidl(specifiers));
279 return ok();
280 }
281
startNetworkScan(int32_t serial,const aidl::NetworkScanRequest & req)282 ScopedAStatus RadioNetwork::startNetworkScan(int32_t serial, const aidl::NetworkScanRequest& req) {
283 LOG_CALL << serial;
284 mHal1_5->startNetworkScan_1_5(serial, toHidl(req));
285 return ok();
286 }
287
stopNetworkScan(int32_t serial)288 ScopedAStatus RadioNetwork::stopNetworkScan(int32_t serial) {
289 LOG_CALL << serial;
290 mHal1_5->stopNetworkScan(serial);
291 return ok();
292 }
293
supplyNetworkDepersonalization(int32_t ser,const std::string & nPin)294 ScopedAStatus RadioNetwork::supplyNetworkDepersonalization(int32_t ser, const std::string& nPin) {
295 LOG_CALL << ser;
296 mHal1_5->supplyNetworkDepersonalization(ser, nPin);
297 return ok();
298 }
299
setUsageSetting(int32_t serial,aidl::UsageSetting)300 ScopedAStatus RadioNetwork::setUsageSetting(int32_t serial, aidl::UsageSetting) {
301 LOG_CALL << serial;
302 LOG(ERROR) << "setUsageSetting is unsupported by HIDL HALs";
303 respond()->setUsageSettingResponse(notSupported(serial));
304 return ok();
305 }
306
getUsageSetting(int32_t serial)307 ScopedAStatus RadioNetwork::getUsageSetting(int32_t serial) {
308 LOG_CALL << serial;
309 LOG(ERROR) << "getUsageSetting is unsupported by HIDL HALs";
310 respond()->getUsageSettingResponse(notSupported(serial), {}); // {} = neither voice nor data
311 return ok();
312 }
313
314 } // namespace android::hardware::radio::compat
315