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_0 {
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 } // namespace implementation
230 } // namespace V1_0
231 } // namespace gnss
232 } // namespace hardware
233 } // namespace android
234