1 /*
2  * Copyright (C) 2022 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 "RefRadioNetwork.h"
18 
19 namespace cf::ril {
20 
21 using ::ndk::ScopedAStatus;
22 using namespace ::aidl::android::hardware::radio;
23 constexpr auto ok = &ScopedAStatus::ok;
24 
responseInfo(int32_t serial,RadioError error=RadioError::NONE)25 static RadioResponseInfo responseInfo(int32_t serial, RadioError error = RadioError::NONE) {
26     return {
27             .type = RadioResponseType::SOLICITED,
28             .serial = serial,
29             .error = error,
30     };
31 }
32 
setUsageSetting(int32_t serial,network::UsageSetting usageSetting)33 ScopedAStatus RefRadioNetwork::setUsageSetting(int32_t serial, network::UsageSetting usageSetting) {
34     if (usageSetting != network::UsageSetting::VOICE_CENTRIC &&
35         usageSetting != network::UsageSetting::DATA_CENTRIC) {
36         respond()->setUsageSettingResponse(responseInfo(serial, RadioError::INVALID_ARGUMENTS));
37         return ok();
38     }
39 
40     mUsageSetting = usageSetting;
41     respond()->setUsageSettingResponse(responseInfo(serial));
42     return ok();
43 }
44 
getUsageSetting(int32_t serial)45 ScopedAStatus RefRadioNetwork::getUsageSetting(int32_t serial) {
46     respond()->getUsageSettingResponse(responseInfo(serial), mUsageSetting);
47     return ok();
48 }
49 
setEmergencyMode(int32_t serial,network::EmergencyMode emergencyMode)50 ScopedAStatus RefRadioNetwork::setEmergencyMode(int32_t serial,
51                                                 network::EmergencyMode emergencyMode) {
52     network::EmergencyRegResult regState;
53     regState.accessNetwork = AccessNetwork::EUTRAN;
54     regState.regState = network::RegState::REG_HOME;
55     regState.emcDomain = network::Domain(3);  // CS_PS
56     respond()->setEmergencyModeResponse(responseInfo(serial), regState);
57     return ok();
58 }
59 
triggerEmergencyNetworkScan(int32_t serial,const network::EmergencyNetworkScanTrigger & request)60 ScopedAStatus RefRadioNetwork::triggerEmergencyNetworkScan(
61         int32_t serial, const network::EmergencyNetworkScanTrigger& request) {
62     respond()->triggerEmergencyNetworkScanResponse(responseInfo(serial));
63     return ok();
64 }
65 
exitEmergencyMode(int32_t serial)66 ScopedAStatus RefRadioNetwork::exitEmergencyMode(int32_t serial) {
67     respond()->exitEmergencyModeResponse(responseInfo(serial));
68     return ok();
69 }
70 
cancelEmergencyNetworkScan(int32_t serial,bool resetScan)71 ScopedAStatus RefRadioNetwork::cancelEmergencyNetworkScan(int32_t serial, bool resetScan) {
72     respond()->cancelEmergencyNetworkScanResponse(responseInfo(serial));
73     return ok();
74 }
75 
isN1ModeEnabled(int32_t serial)76 ScopedAStatus RefRadioNetwork::isN1ModeEnabled(int32_t serial) {
77     respond()->isN1ModeEnabledResponse(responseInfo(serial), false);
78     return ok();
79 }
80 
setN1ModeEnabled(int32_t serial,bool enable)81 ScopedAStatus RefRadioNetwork::setN1ModeEnabled(int32_t serial, bool enable) {
82     respond()->setN1ModeEnabledResponse(responseInfo(serial));
83     return ok();
84 }
85 
setNullCipherAndIntegrityEnabled(int32_t serial,bool enabled)86 ScopedAStatus RefRadioNetwork::setNullCipherAndIntegrityEnabled(int32_t serial, bool enabled) {
87     respond()->setNullCipherAndIntegrityEnabledResponse(responseInfo(serial));
88     return ok();
89 }
90 
isNullCipherAndIntegrityEnabled(int32_t serial)91 ScopedAStatus RefRadioNetwork::isNullCipherAndIntegrityEnabled(int32_t serial) {
92     respond()->isNullCipherAndIntegrityEnabledResponse(responseInfo(serial), true);
93     return ok();
94 }
95 
setCellularIdentifierTransparencyEnabled(int32_t serial,bool enabled)96 ScopedAStatus RefRadioNetwork::setCellularIdentifierTransparencyEnabled(int32_t serial, bool enabled) {
97     mIsCellularIdentifierTransparencyEnabled = enabled;
98     respond()->setCellularIdentifierTransparencyEnabledResponse(responseInfo(serial));
99     return ok();
100 }
101 
isCellularIdentifierTransparencyEnabled(int32_t serial)102 ScopedAStatus RefRadioNetwork::isCellularIdentifierTransparencyEnabled(int32_t serial) {
103     respond()->isCellularIdentifierTransparencyEnabledResponse(
104             responseInfo(serial), mIsCellularIdentifierTransparencyEnabled);
105     return ok();
106 }
107 
setSecurityAlgorithmsUpdatedEnabled(int32_t serial,bool enabled)108 ScopedAStatus RefRadioNetwork::setSecurityAlgorithmsUpdatedEnabled(int32_t serial, bool enabled) {
109     mIsCipheringTransparencyEnabled = enabled;
110     respond()->setSecurityAlgorithmsUpdatedEnabledResponse(responseInfo(serial));
111     return ok();
112 }
113 
isSecurityAlgorithmsUpdatedEnabled(int32_t serial)114 ScopedAStatus RefRadioNetwork::isSecurityAlgorithmsUpdatedEnabled(int32_t serial) {
115     respond()->isSecurityAlgorithmsUpdatedEnabledResponse(responseInfo(serial),
116                                                           mIsCipheringTransparencyEnabled);
117     return ok();
118 }
119 }  // namespace cf::ril
120