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