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     }
84 
85     return mGnss->updateConfiguration(config);
86 }
87 
setSuplMode(uint8_t mode)88 Return<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 
setLppProfile(uint8_t lppProfileMask)119 Return<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 
setGlonassPositioningProtocol(uint8_t protocol)146 Return<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 
setGpsLock(uint8_t lock)173 Return<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 
setEmergencySuplPdn(bool enabled)204 Return<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 }  // namespace implementation
222 }  // namespace V1_0
223 }  // namespace gnss
224 }  // namespace hardware
225 }  // namespace android
226