GnssConfiguration.cpp 9.8 KB

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