1 /*
2 * Copyright (c) 2017-2018, 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 #include <android/hardware/gnss/1.0/types.h>
27
28 namespace android {
29 namespace hardware {
30 namespace gnss {
31 namespace V1_1 {
32 namespace implementation {
33
34 using ::android::hardware::gnss::V1_0::GnssConstellationType;
35
GnssConfiguration(Gnss * gnss)36 GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
37 }
38
39 // Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
setSuplEs(bool enabled)40 Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
41 if (mGnss == nullptr) {
42 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
43 return false;
44 }
45
46 GnssConfig config;
47 memset(&config, 0, sizeof(GnssConfig));
48 config.size = sizeof(GnssConfig);
49 config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
50 config.suplEmergencyServices = (enabled ?
51 GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES :
52 GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO);
53
54 return mGnss->updateConfiguration(config);
55 }
56
setSuplVersion(uint32_t version)57 Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
58 if (mGnss == nullptr) {
59 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
60 return false;
61 }
62
63 GnssConfig config;
64 memset(&config, 0, sizeof(GnssConfig));
65 config.size = sizeof(GnssConfig);
66 config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
67 switch (version) {
68 case 0x00020004:
69 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4;
70 break;
71 case 0x00020002:
72 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
73 break;
74 case 0x00020000:
75 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
76 break;
77 case 0x00010000:
78 config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
79 break;
80 default:
81 LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
82 return false;
83 break;
84 }
85
86 return mGnss->updateConfiguration(config);
87 }
88
setSuplMode(uint8_t mode)89 Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
90 if (mGnss == nullptr) {
91 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
92 return false;
93 }
94
95 GnssConfig config;
96 memset(&config, 0, sizeof(GnssConfig));
97 config.size = sizeof(GnssConfig);
98 config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
99 switch (mode) {
100 case 0:
101 config.suplModeMask = 0; // STANDALONE ONLY
102 break;
103 case 1:
104 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
105 break;
106 case 2:
107 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
108 break;
109 case 3:
110 config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
111 break;
112 default:
113 LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
114 return false;
115 break;
116 }
117
118 return mGnss->updateConfiguration(config);
119 }
120
setLppProfile(uint8_t lppProfile)121 Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfile) {
122 if (mGnss == nullptr) {
123 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
124 return false;
125 }
126
127 GnssConfig config;
128 memset(&config, 0, sizeof(GnssConfig));
129 config.size = sizeof(GnssConfig);
130 config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
131 switch (lppProfile) {
132 case 0:
133 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE;
134 break;
135 case 1:
136 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE;
137 break;
138 case 2:
139 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE;
140 break;
141 case 3:
142 config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE;
143 break;
144 default:
145 LOC_LOGE("%s]: invalid lppProfile: %d.", __FUNCTION__, lppProfile);
146 return false;
147 break;
148 }
149
150 return mGnss->updateConfiguration(config);
151 }
152
setGlonassPositioningProtocol(uint8_t protocol)153 Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
154 if (mGnss == nullptr) {
155 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
156 return false;
157 }
158
159 GnssConfig config;
160 memset(&config, 0, sizeof(GnssConfig));
161 config.size = sizeof(GnssConfig);
162
163 config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
164 if (protocol & (1<<0)) {
165 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
166 }
167 if (protocol & (1<<1)) {
168 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
169 }
170 if (protocol & (1<<2)) {
171 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
172 }
173 if (protocol & (1<<3)) {
174 config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
175 }
176
177 return mGnss->updateConfiguration(config);
178 }
179
setGpsLock(uint8_t lock)180 Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
181 if (mGnss == nullptr) {
182 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
183 return false;
184 }
185
186 GnssConfig config;
187 memset(&config, 0, sizeof(GnssConfig));
188 config.size = sizeof(GnssConfig);
189 config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
190 switch (lock) {
191 case 0:
192 config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE;
193 break;
194 case 1:
195 config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO;
196 break;
197 case 2:
198 config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI;
199 break;
200 case 3:
201 config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
202 break;
203 default:
204 LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock);
205 return false;
206 break;
207 }
208
209 return mGnss->updateConfiguration(config);
210 }
211
setEmergencySuplPdn(bool enabled)212 Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
213 if (mGnss == nullptr) {
214 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
215 return false;
216 }
217
218 GnssConfig config;
219 memset(&config, 0, sizeof(GnssConfig));
220 config.size = sizeof(GnssConfig);
221 config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
222 config.emergencyPdnForEmergencySupl = (enabled ?
223 GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
224 GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
225
226 return mGnss->updateConfiguration(config);
227 }
228
229 // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
setBlacklist(const hidl_vec<GnssConfiguration::BlacklistedSource> & blacklist)230 Return<bool> GnssConfiguration::setBlacklist(
231 const hidl_vec<GnssConfiguration::BlacklistedSource>& blacklist) {
232
233 ENTRY_LOG_CALLFLOW();
234 if (nullptr == mGnss) {
235 LOC_LOGe("mGnss is null");
236 return false;
237 }
238
239 // blValid is true if blacklist is empty, i.e. clearing the BL;
240 // if blacklist is not empty, blValid is initialied to false, and later
241 // updated in the for loop to become true only if there is at least
242 // one {constellation, svid} in the list that is valid.
243 bool blValid = (0 == blacklist.size());
244 GnssConfig config;
245 memset(&config, 0, sizeof(GnssConfig));
246 config.size = sizeof(GnssConfig);
247 config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
248 config.blacklistedSvIds.clear();
249
250 GnssSvIdSource source = {};
251 for (int idx = 0; idx < (int)blacklist.size(); idx++) {
252 // Set blValid true if any one source is valid
253 blValid = setBlacklistedSource(source, blacklist[idx]) || blValid;
254 config.blacklistedSvIds.push_back(source);
255 }
256
257 // Update configuration only if blValid is true
258 // i.e. only if atleast one source is valid for blacklisting
259 return (blValid && mGnss->updateConfiguration(config));
260 }
261
setBlacklistedSource(GnssSvIdSource & copyToSource,const GnssConfiguration::BlacklistedSource & copyFromSource)262 bool GnssConfiguration::setBlacklistedSource(
263 GnssSvIdSource& copyToSource,
264 const GnssConfiguration::BlacklistedSource& copyFromSource) {
265
266 bool retVal = true;
267 uint16_t svIdOffset = 0;
268 copyToSource.size = sizeof(GnssSvIdSource);
269 copyToSource.svId = copyFromSource.svid;
270
271 switch(copyFromSource.constellation) {
272 case GnssConstellationType::GPS:
273 copyToSource.constellation = GNSS_SV_TYPE_GPS;
274 LOC_LOGe("GPS SVs can't be blacklisted.");
275 retVal = false;
276 break;
277 case GnssConstellationType::SBAS:
278 copyToSource.constellation = GNSS_SV_TYPE_SBAS;
279 LOC_LOGe("SBAS SVs can't be blacklisted.");
280 retVal = false;
281 break;
282 case GnssConstellationType::GLONASS:
283 copyToSource.constellation = GNSS_SV_TYPE_GLONASS;
284 svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1;
285 break;
286 case GnssConstellationType::QZSS:
287 copyToSource.constellation = GNSS_SV_TYPE_QZSS;
288 svIdOffset = 0;
289 break;
290 case GnssConstellationType::BEIDOU:
291 copyToSource.constellation = GNSS_SV_TYPE_BEIDOU;
292 svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1;
293 break;
294 case GnssConstellationType::GALILEO:
295 copyToSource.constellation = GNSS_SV_TYPE_GALILEO;
296 svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1;
297 break;
298 default:
299 copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN;
300 LOC_LOGe("Invalid constellation %d", copyFromSource.constellation);
301 retVal = false;
302 break;
303 }
304
305 if (copyToSource.svId > 0 && svIdOffset > 0) {
306 copyToSource.svId += svIdOffset;
307 }
308
309 return retVal;
310 }
311
312 } // namespace implementation
313 } // namespace V1_1
314 } // namespace gnss
315 } // namespace hardware
316 } // namespace android
317