1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
/*
* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2_0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2_0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "LocSvc_GnssConfigurationInterface"
#include <log_util.h>
#include "Gnss.h"
#include "GnssConfiguration.h"
#include "ContextBase.h"
#include <android/hardware/gnss/1.0/types.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V2_1 {
namespace implementation {
using ::android::hardware::gnss::V2_0::GnssConstellationType;
using namespace loc_core;
GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
}
// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
// deprecated function. Must return false to pass VTS
return false;
}
Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
switch (version) {
case 0x00020004:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4;
break;
case 0x00020002:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
break;
case 0x00020000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
break;
case 0x00010000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
break;
default:
LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
return false;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
switch (mode) {
case 0:
config.suplModeMask = 0; // STANDALONE ONLY
break;
case 1:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
break;
case 2:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
case 3:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
default:
LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
return false;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfileMask) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config = {};
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default
if (lppProfileMask & (1<<0)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT;
}
if (lppProfileMask & (1<<1)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT;
}
if (lppProfileMask & (1<<2)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT;
}
if (lppProfileMask & (1<<3)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
if (protocol & (1<<0)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
}
if (protocol & (1<<1)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
}
if (protocol & (1<<2)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
}
if (protocol & (1<<3)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config = {};
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
switch (lock) {
case 0:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE;
break;
case 1:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO;
break;
case 2:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI;
break;
case 3:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
break;
default:
LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock);
return false;
}
mGnss->updateConfiguration(config);
// Must return false to pass VTS
return false;
}
Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
config.emergencyPdnForEmergencySupl = (enabled ?
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
return mGnss->updateConfiguration(config);
}
// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setBlacklist(
const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource>& blacklist) {
ENTRY_LOG_CALLFLOW();
if (nullptr == mGnss) {
LOC_LOGe("mGnss is null");
return false;
}
// blValid is true if blacklist is empty, i.e. clearing the BL;
// if blacklist is not empty, blValid is initialied to false, and later
// updated in the for loop to become true only if there is at least
// one {constellation, svid} in the list that is valid.
bool blValid = (0 == blacklist.size());
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
config.blacklistedSvIds.clear();
GnssSvIdSource source = {};
for (int idx = 0; idx < (int)blacklist.size(); idx++) {
// Set blValid true if any one source is valid
blValid = setBlacklistedSource(source, (GnssConstellationType)blacklist[idx].constellation,
blacklist[idx].svid) || blValid;
config.blacklistedSvIds.push_back(source);
}
// Update configuration only if blValid is true
// i.e. only if atleast one source is valid for blacklisting
return (blValid && mGnss->updateConfiguration(config));
}
bool GnssConfiguration::setBlacklistedSource(
GnssSvIdSource& copyToSource, const GnssConstellationType& constellation,
const int16_t svid) {
bool retVal = true;
uint16_t svIdOffset = 0;
copyToSource.size = sizeof(GnssSvIdSource);
copyToSource.svId = svid;
switch(constellation) {
case GnssConstellationType::GPS:
copyToSource.constellation = GNSS_SV_TYPE_GPS;
LOC_LOGe("GPS SVs can't be blacklisted.");
retVal = false;
break;
case GnssConstellationType::SBAS:
copyToSource.constellation = GNSS_SV_TYPE_SBAS;
LOC_LOGe("SBAS SVs can't be blacklisted.");
retVal = false;
break;
case GnssConstellationType::GLONASS:
copyToSource.constellation = GNSS_SV_TYPE_GLONASS;
svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::QZSS:
copyToSource.constellation = GNSS_SV_TYPE_QZSS;
svIdOffset = 0;
break;
case GnssConstellationType::BEIDOU:
copyToSource.constellation = GNSS_SV_TYPE_BEIDOU;
svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::GALILEO:
copyToSource.constellation = GNSS_SV_TYPE_GALILEO;
svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::IRNSS:
copyToSource.constellation = GNSS_SV_TYPE_NAVIC;
svIdOffset = 0;
break;
default:
copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN;
LOC_LOGe("Invalid constellation %hhu", constellation);
retVal = false;
break;
}
if (copyToSource.svId > 0 && svIdOffset > 0) {
copyToSource.svId += svIdOffset;
}
return retVal;
}
bool GnssConfiguration::setBlacklistedSource(
GnssSvIdSource& copyToSource,
const GnssConfiguration::BlacklistedSource& copyFromSource) {
bool retVal = true;
uint16_t svIdOffset = 0;
copyToSource.size = sizeof(GnssSvIdSource);
copyToSource.svId = copyFromSource.svid;
switch(copyFromSource.constellation) {
case GnssConstellationType::GPS:
copyToSource.constellation = GNSS_SV_TYPE_GPS;
LOC_LOGe("GPS SVs can't be blacklisted.");
retVal = false;
break;
case GnssConstellationType::SBAS:
copyToSource.constellation = GNSS_SV_TYPE_SBAS;
LOC_LOGe("SBAS SVs can't be blacklisted.");
retVal = false;
break;
case GnssConstellationType::GLONASS:
copyToSource.constellation = GNSS_SV_TYPE_GLONASS;
svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::QZSS:
copyToSource.constellation = GNSS_SV_TYPE_QZSS;
svIdOffset = GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::BEIDOU:
copyToSource.constellation = GNSS_SV_TYPE_BEIDOU;
svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::GALILEO:
copyToSource.constellation = GNSS_SV_TYPE_GALILEO;
svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::IRNSS:
copyToSource.constellation = GNSS_SV_TYPE_NAVIC;
svIdOffset = GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID - 1;
break;
default:
copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN;
LOC_LOGe("Invalid constellation %hhu", copyFromSource.constellation);
retVal = false;
break;
}
if (copyToSource.svId > 0 && svIdOffset > 0) {
copyToSource.svId += svIdOffset;
}
return retVal;
}
// Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) {
ENTRY_LOG_CALLFLOW();
if (mGnss == nullptr) {
LOC_LOGe("mGnss is nullptr");
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT;
config.emergencyExtensionSeconds = emergencyExtensionSeconds;
return mGnss->updateConfiguration(config);
}
// Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setBlacklist_2_1(
const hidl_vec<V2_1::IGnssConfiguration::BlacklistedSource>& blacklist) {
ENTRY_LOG_CALLFLOW();
if (nullptr == mGnss) {
LOC_LOGe("mGnss is null");
return false;
}
// blValid is true if blacklist is empty, i.e. clearing the BL;
// if blacklist is not empty, blValid is initialied to false, and later
// updated in the for loop to become true only if there is at least
// one {constellation, svid} in the list that is valid.
bool blValid = (0 == blacklist.size());
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
config.blacklistedSvIds.clear();
GnssSvIdSource source = {};
for (int idx = 0; idx < (int)blacklist.size(); idx++) {
// Set blValid true if any one source is valid
blValid = setBlacklistedSource(source, blacklist[idx]) || blValid;
config.blacklistedSvIds.push_back(source);
}
// Update configuration only if blValid is true
// i.e. only if atleast one source is valid for blacklisting
return (blValid && mGnss->updateConfiguration(config));
}
} // namespace implementation
} // namespace V2_1
} // namespace gnss
} // namespace hardware
} // namespace android
|