GnssConfiguration.cpp 10 KB

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