1 /*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 * Not a Contribution
4 */
5 /*
6 * Copyright (C) 2016 The Android Open Source Project
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 #define LOG_TAG "LocSvc_GnssConfigurationInterface"
22
23 #include <log_util.h>
24 #include "Gnss.h"
25 #include "GnssConfiguration.h"
26
27 namespace android {
28 namespace hardware {
29 namespace gnss {
30 namespace V1_0 {
31 namespace implementation {
32
GnssConfiguration(Gnss * gnss)33 GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
34 }
35
36 // Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
setSuplEs(bool enabled)37 Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
38 if (mGnss == nullptr) {
39 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
40 return false;
41 }
42
43 GnssConfig config;
44 memset(&config, 0, sizeof(GnssConfig));
45 config.size = sizeof(GnssConfig);
46 config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
47 config.suplEmergencyServices = (enabled ?
48 GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES :
49 GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO);
50
51 return mGnss->updateConfiguration(config);
52 }
53
setSuplVersion(uint32_t version)54 Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
55 if (mGnss == nullptr) {
56 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
57 return false;
58 }
59
60 GnssConfig config;
61 memset(&config, 0, sizeof(GnssConfig));
62 config.size = sizeof(GnssConfig);
63 config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
64 switch (version) {
65 case 0x00020002:
66 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
67 break;
68 case 0x00020000:
69 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
70 break;
71 case 0x00010000:
72 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
73 break;
74 default:
75 LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
76 return false;
77 break;
78 }
79
80 return mGnss->updateConfiguration(config);
81 }
82
setSuplMode(uint8_t mode)83 Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
84 if (mGnss == nullptr) {
85 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
86 return false;
87 }
88
89 GnssConfig config;
90 memset(&config, 0, sizeof(GnssConfig));
91 config.size = sizeof(GnssConfig);
92 config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
93 switch (mode) {
94 case 0:
95 config.suplModeMask = 0; // STANDALONE ONLY
96 break;
97 case 1:
98 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
99 break;
100 case 2:
101 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
102 break;
103 case 3:
104 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
105 break;
106 default:
107 LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
108 return false;
109 break;
110 }
111
112 return mGnss->updateConfiguration(config);
113 }
114
setLppProfile(uint8_t lppProfile)115 Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfile) {
116 if (mGnss == nullptr) {
117 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
118 return false;
119 }
120
121 GnssConfig config;
122 memset(&config, 0, sizeof(GnssConfig));
123 config.size = sizeof(GnssConfig);
124 config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
125 switch (lppProfile) {
126 case 0:
127 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE;
128 break;
129 case 1:
130 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE;
131 break;
132 case 2:
133 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE;
134 break;
135 case 3:
136 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE;
137 break;
138 default:
139 LOC_LOGE("%s]: invalid lppProfile: %d.", __FUNCTION__, lppProfile);
140 return false;
141 break;
142 }
143
144 return mGnss->updateConfiguration(config);
145 }
146
setGlonassPositioningProtocol(uint8_t protocol)147 Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
148 if (mGnss == nullptr) {
149 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
150 return false;
151 }
152
153 GnssConfig config;
154 memset(&config, 0, sizeof(GnssConfig));
155 config.size = sizeof(GnssConfig);
156
157 config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
158 if (protocol & (1<<0)) {
159 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
160 }
161 if (protocol & (1<<1)) {
162 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
163 }
164 if (protocol & (1<<2)) {
165 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
166 }
167 if (protocol & (1<<3)) {
168 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
169 }
170
171 return mGnss->updateConfiguration(config);
172 }
173
setGpsLock(uint8_t lock)174 Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
175 if (mGnss == nullptr) {
176 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
177 return false;
178 }
179
180 GnssConfig config;
181 memset(&config, 0, sizeof(GnssConfig));
182 config.size = sizeof(GnssConfig);
183 config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
184 switch (lock) {
185 case 0:
186 config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE;
187 break;
188 case 1:
189 config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO;
190 break;
191 case 2:
192 config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI;
193 break;
194 case 3:
195 config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
196 break;
197 default:
198 LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock);
199 return false;
200 break;
201 }
202
203 return mGnss->updateConfiguration(config);
204 }
205
setEmergencySuplPdn(bool enabled)206 Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
207 if (mGnss == nullptr) {
208 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
209 return false;
210 }
211
212 GnssConfig config;
213 memset(&config, 0, sizeof(GnssConfig));
214 config.size = sizeof(GnssConfig);
215 config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
216 config.emergencyPdnForEmergencySupl = (enabled ?
217 GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
218 GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
219
220 return mGnss->updateConfiguration(config);
221 }
222
223 } // namespace implementation
224 } // namespace V1_0
225 } // namespace gnss
226 } // namespace hardware
227 } // namespace android
228