1 /* Copyright (c) 2011-2014, 2016-2019 The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation, nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 #define LOG_NDEBUG 0 //Define to enable LOGV
30 #define LOG_TAG "LocSvc_LocApiBase"
31 
32 #include <dlfcn.h>
33 #include <inttypes.h>
34 #include <gps_extended_c.h>
35 #include <LocApiBase.h>
36 #include <LocAdapterBase.h>
37 #include <log_util.h>
38 #include <LocContext.h>
39 
40 namespace loc_core {
41 
42 #define TO_ALL_LOCADAPTERS(call) TO_ALL_ADAPTERS(mLocAdapters, (call))
43 #define TO_1ST_HANDLING_LOCADAPTERS(call) TO_1ST_HANDLING_ADAPTER(mLocAdapters, (call))
44 
hexcode(char * hexstring,int string_size,const char * data,int data_size)45 int hexcode(char *hexstring, int string_size,
46             const char *data, int data_size)
47 {
48    int i;
49    for (i = 0; i < data_size; i++)
50    {
51       char ch = data[i];
52       if (i*2 + 3 <= string_size)
53       {
54          snprintf(&hexstring[i*2], 3, "%02X", ch);
55       }
56       else {
57          break;
58       }
59    }
60    return i;
61 }
62 
decodeAddress(char * addr_string,int string_size,const char * data,int data_size)63 int decodeAddress(char *addr_string, int string_size,
64                    const char *data, int data_size)
65 {
66     const char addr_prefix = 0x91;
67     int i, idxOutput = 0;
68 
69     if (!data || !addr_string) { return 0; }
70 
71     if (data[0] != addr_prefix)
72     {
73         LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]);
74         addr_string[0] = '\0';
75         return 0; // prefix not correct
76     }
77 
78     for (i = 1; i < data_size; i++)
79     {
80         unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4;
81         if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; }
82         if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; }
83     }
84 
85     addr_string[idxOutput] = '\0'; // Terminates the string
86 
87     return idxOutput;
88 }
89 
90 struct LocSsrMsg : public LocMsg {
91     LocApiBase* mLocApi;
LocSsrMsgloc_core::LocSsrMsg92     inline LocSsrMsg(LocApiBase* locApi) :
93         LocMsg(), mLocApi(locApi)
94     {
95         locallog();
96     }
procloc_core::LocSsrMsg97     inline virtual void proc() const {
98         mLocApi->close();
99         if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask())) {
100             // Notify adapters that engine up after SSR
101             mLocApi->handleEngineUpEvent();
102         }
103     }
locallogloc_core::LocSsrMsg104     inline void locallog() const {
105         LOC_LOGV("LocSsrMsg");
106     }
logloc_core::LocSsrMsg107     inline virtual void log() const {
108         locallog();
109     }
110 };
111 
112 struct LocOpenMsg : public LocMsg {
113     LocApiBase* mLocApi;
114     LocAdapterBase* mAdapter;
LocOpenMsgloc_core::LocOpenMsg115     inline LocOpenMsg(LocApiBase* locApi, LocAdapterBase* adapter = nullptr) :
116             LocMsg(), mLocApi(locApi), mAdapter(adapter)
117     {
118         locallog();
119     }
procloc_core::LocOpenMsg120     inline virtual void proc() const {
121         if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask()) &&
122             nullptr != mAdapter) {
123             mAdapter->handleEngineUpEvent();
124         }
125     }
locallogloc_core::LocOpenMsg126     inline void locallog() const {
127         LOC_LOGv("LocOpen Mask: %" PRIx64 "\n", mLocApi->getEvtMask());
128     }
logloc_core::LocOpenMsg129     inline virtual void log() const {
130         locallog();
131     }
132 };
133 
134 struct LocCloseMsg : public LocMsg {
135     LocApiBase* mLocApi;
LocCloseMsgloc_core::LocCloseMsg136     inline LocCloseMsg(LocApiBase* locApi) :
137         LocMsg(), mLocApi(locApi)
138     {
139         locallog();
140     }
procloc_core::LocCloseMsg141     inline virtual void proc() const {
142         mLocApi->close();
143     }
locallogloc_core::LocCloseMsg144     inline void locallog() const {
145     }
logloc_core::LocCloseMsg146     inline virtual void log() const {
147         locallog();
148     }
149 };
150 
151 MsgTask* LocApiBase::mMsgTask;
152 
LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,ContextBase * context)153 LocApiBase::LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
154                        ContextBase* context) :
155     mContext(context),
156     mMask(0), mExcludedMask(excludedMask)
157 {
158     memset(mLocAdapters, 0, sizeof(mLocAdapters));
159 
160     if (nullptr == mMsgTask) {
161         mMsgTask = new MsgTask("LocApiMsgTask", false);
162     }
163 }
164 
getEvtMask()165 LOC_API_ADAPTER_EVENT_MASK_T LocApiBase::getEvtMask()
166 {
167     LOC_API_ADAPTER_EVENT_MASK_T mask = 0;
168 
169     TO_ALL_LOCADAPTERS(mask |= mLocAdapters[i]->getEvtMask());
170 
171     return mask & ~mExcludedMask;
172 }
173 
isMaster()174 bool LocApiBase::isMaster()
175 {
176     bool isMaster = false;
177 
178     for (int i = 0;
179             !isMaster && i < MAX_ADAPTERS && NULL != mLocAdapters[i];
180             i++) {
181         isMaster |= mLocAdapters[i]->isAdapterMaster();
182     }
183     return isMaster;
184 }
185 
isInSession()186 bool LocApiBase::isInSession()
187 {
188     bool inSession = false;
189 
190     for (int i = 0;
191          !inSession && i < MAX_ADAPTERS && NULL != mLocAdapters[i];
192          i++) {
193         inSession = mLocAdapters[i]->isInSession();
194     }
195 
196     return inSession;
197 }
198 
needReport(const UlpLocation & ulpLocation,enum loc_sess_status status,LocPosTechMask techMask)199 bool LocApiBase::needReport(const UlpLocation& ulpLocation,
200                             enum loc_sess_status status,
201                             LocPosTechMask techMask)
202 {
203     bool reported = false;
204 
205     if (LOC_SESS_SUCCESS == status) {
206         // this is a final fix
207         LocPosTechMask mask =
208             LOC_POS_TECH_MASK_SATELLITE | LOC_POS_TECH_MASK_SENSORS | LOC_POS_TECH_MASK_HYBRID;
209         // it is a Satellite fix or a sensor fix
210         reported = (mask & techMask);
211     }
212     else if (LOC_SESS_INTERMEDIATE == status &&
213         LOC_SESS_INTERMEDIATE == ContextBase::mGps_conf.INTERMEDIATE_POS) {
214         // this is a intermediate fix and we accept intermediate
215 
216         // it is NOT the case that
217         // there is inaccuracy; and
218         // we care about inaccuracy; and
219         // the inaccuracy exceeds our tolerance
220         reported = !((ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ACCURACY) &&
221             (ContextBase::mGps_conf.ACCURACY_THRES != 0) &&
222             (ulpLocation.gpsLocation.accuracy > ContextBase::mGps_conf.ACCURACY_THRES));
223     }
224 
225     return reported;
226 }
227 
addAdapter(LocAdapterBase * adapter)228 void LocApiBase::addAdapter(LocAdapterBase* adapter)
229 {
230     for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) {
231         if (mLocAdapters[i] == NULL) {
232             mLocAdapters[i] = adapter;
233             mMsgTask->sendMsg(new LocOpenMsg(this,  adapter));
234             break;
235         }
236     }
237 }
238 
removeAdapter(LocAdapterBase * adapter)239 void LocApiBase::removeAdapter(LocAdapterBase* adapter)
240 {
241     for (int i = 0;
242          i < MAX_ADAPTERS && NULL != mLocAdapters[i];
243          i++) {
244         if (mLocAdapters[i] == adapter) {
245             mLocAdapters[i] = NULL;
246 
247             // shift the rest of the adapters up so that the pointers
248             // in the array do not have holes.  This should be more
249             // performant, because the array maintenance is much much
250             // less frequent than event handlings, which need to linear
251             // search all the adapters
252             int j = i;
253             while (++i < MAX_ADAPTERS && mLocAdapters[i] != NULL);
254 
255             // i would be MAX_ADAPTERS or point to a NULL
256             i--;
257             // i now should point to a none NULL adapter within valid
258             // range although i could be equal to j, but it won't hurt.
259             // No need to check it, as it gains nothing.
260             mLocAdapters[j] = mLocAdapters[i];
261             // this makes sure that we exit the for loop
262             mLocAdapters[i] = NULL;
263 
264             // if we have an empty list of adapters
265             if (0 == i) {
266                 mMsgTask->sendMsg(new LocCloseMsg(this));
267             } else {
268                 // else we need to remove the bit
269                 mMsgTask->sendMsg(new LocOpenMsg(this));
270             }
271         }
272     }
273 }
274 
updateEvtMask()275 void LocApiBase::updateEvtMask()
276 {
277     mMsgTask->sendMsg(new LocOpenMsg(this));
278 }
279 
updateNmeaMask(uint32_t mask)280 void LocApiBase::updateNmeaMask(uint32_t mask)
281 {
282     struct LocSetNmeaMsg : public LocMsg {
283         LocApiBase* mLocApi;
284         uint32_t mMask;
285         inline LocSetNmeaMsg(LocApiBase* locApi, uint32_t mask) :
286             LocMsg(), mLocApi(locApi), mMask(mask)
287         {
288             locallog();
289         }
290         inline virtual void proc() const {
291             mLocApi->setNMEATypesSync(mMask);
292         }
293         inline void locallog() const {
294             LOC_LOGv("LocSyncNmea NmeaMask: %" PRIx32 "\n", mMask);
295         }
296         inline virtual void log() const {
297             locallog();
298         }
299     };
300 
301     mMsgTask->sendMsg(new LocSetNmeaMsg(this, mask));
302 }
303 
handleEngineUpEvent()304 void LocApiBase::handleEngineUpEvent()
305 {
306     // loop through adapters, and deliver to all adapters.
307     TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent());
308 }
309 
handleEngineDownEvent()310 void LocApiBase::handleEngineDownEvent()
311 {    // This will take care of renegotiating the loc handle
312     sendMsg(new LocSsrMsg(this));
313 
314     // loop through adapters, and deliver to all adapters.
315     TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent());
316 }
317 
reportPosition(UlpLocation & location,GpsLocationExtended & locationExtended,enum loc_sess_status status,LocPosTechMask loc_technology_mask,GnssDataNotification * pDataNotify,int msInWeek)318 void LocApiBase::reportPosition(UlpLocation& location,
319                                 GpsLocationExtended& locationExtended,
320                                 enum loc_sess_status status,
321                                 LocPosTechMask loc_technology_mask,
322                                 GnssDataNotification* pDataNotify,
323                                 int msInWeek)
324 {
325     // print the location info before delivering
326     LOC_LOGD("flags: %d\n  source: %d\n  latitude: %f\n  longitude: %f\n  "
327              "altitude: %f\n  speed: %f\n  bearing: %f\n  accuracy: %f\n  "
328              "timestamp: %" PRId64 "\n"
329              "Session status: %d\n Technology mask: %u\n "
330              "SV used in fix (gps/glo/bds/gal/qzss) : \
331              (0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 ")",
332              location.gpsLocation.flags, location.position_source,
333              location.gpsLocation.latitude, location.gpsLocation.longitude,
334              location.gpsLocation.altitude, location.gpsLocation.speed,
335              location.gpsLocation.bearing, location.gpsLocation.accuracy,
336              location.gpsLocation.timestamp, status, loc_technology_mask,
337              locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask,
338              locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask,
339              locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask,
340              locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask,
341              locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask);
342     // loop through adapters, and deliver to all adapters.
343     TO_ALL_LOCADAPTERS(
344         mLocAdapters[i]->reportPositionEvent(location, locationExtended,
345                                              status, loc_technology_mask,
346                                              false,
347                                              pDataNotify, msInWeek)
348     );
349 }
350 
reportWwanZppFix(LocGpsLocation & zppLoc)351 void LocApiBase::reportWwanZppFix(LocGpsLocation &zppLoc)
352 {
353     // loop through adapters, and deliver to the first handling adapter.
354     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportWwanZppFix(zppLoc));
355 }
356 
reportZppBestAvailableFix(LocGpsLocation & zppLoc,GpsLocationExtended & location_extended,LocPosTechMask tech_mask)357 void LocApiBase::reportZppBestAvailableFix(LocGpsLocation &zppLoc,
358         GpsLocationExtended &location_extended, LocPosTechMask tech_mask)
359 {
360     // loop through adapters, and deliver to the first handling adapter.
361     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportZppBestAvailableFix(zppLoc,
362             location_extended, tech_mask));
363 }
364 
requestOdcpi(OdcpiRequestInfo & request)365 void LocApiBase::requestOdcpi(OdcpiRequestInfo& request)
366 {
367     // loop through adapters, and deliver to the first handling adapter.
368     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestOdcpiEvent(request));
369 }
370 
reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot)371 void LocApiBase::reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot)
372 {
373     // loop through adapters, and deliver to the first handling adapter.
374     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssEngEnergyConsumedEvent(
375             energyConsumedSinceFirstBoot));
376 }
377 
reportDeleteAidingDataEvent(GnssAidingData & aidingData)378 void LocApiBase::reportDeleteAidingDataEvent(GnssAidingData& aidingData) {
379     // loop through adapters, and deliver to the first handling adapter.
380     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDeleteAidingDataEvent(aidingData));
381 }
382 
reportKlobucharIonoModel(GnssKlobucharIonoModel & ionoModel)383 void LocApiBase::reportKlobucharIonoModel(GnssKlobucharIonoModel & ionoModel) {
384     // loop through adapters, and deliver to the first handling adapter.
385     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportKlobucharIonoModelEvent(ionoModel));
386 }
387 
reportGnssAdditionalSystemInfo(GnssAdditionalSystemInfo & additionalSystemInfo)388 void LocApiBase::reportGnssAdditionalSystemInfo(GnssAdditionalSystemInfo& additionalSystemInfo) {
389     // loop through adapters, and deliver to the first handling adapter.
390     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportGnssAdditionalSystemInfoEvent(
391             additionalSystemInfo));
392 }
393 
sendNfwNotification(GnssNfwNotification & notification)394 void LocApiBase::sendNfwNotification(GnssNfwNotification& notification)
395 {
396     // loop through adapters, and deliver to the first handling adapter.
397     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNfwNotificationEvent(notification));
398 
399 }
400 
reportSv(GnssSvNotification & svNotify)401 void LocApiBase::reportSv(GnssSvNotification& svNotify)
402 {
403     const char* constellationString[] = { "Unknown", "GPS", "SBAS", "GLONASS",
404         "QZSS", "BEIDOU", "GALILEO" };
405 
406     // print the SV info before delivering
407     LOC_LOGV("num sv: %zu\n"
408         "      sv: constellation svid         cN0"
409         "    elevation    azimuth    flags",
410         svNotify.count);
411     for (size_t i = 0; i < svNotify.count && i < LOC_GNSS_MAX_SVS; i++) {
412         if (svNotify.gnssSvs[i].type >
413             sizeof(constellationString) / sizeof(constellationString[0]) - 1) {
414             svNotify.gnssSvs[i].type = GNSS_SV_TYPE_UNKNOWN;
415         }
416         // Display what we report to clients
417         uint16_t displaySvId = GNSS_SV_TYPE_QZSS == svNotify.gnssSvs[i].type ?
418                                svNotify.gnssSvs[i].svId + QZSS_SV_PRN_MIN - 1 :
419                                svNotify.gnssSvs[i].svId;
420         LOC_LOGV("   %03zu: %*s  %02d    %f    %f    %f    %f    0x%02X",
421             i,
422             13,
423             constellationString[svNotify.gnssSvs[i].type],
424             displaySvId,
425             svNotify.gnssSvs[i].cN0Dbhz,
426             svNotify.gnssSvs[i].elevation,
427             svNotify.gnssSvs[i].azimuth,
428             svNotify.gnssSvs[i].carrierFrequencyHz,
429             svNotify.gnssSvs[i].gnssSvOptionsMask);
430     }
431     // loop through adapters, and deliver to all adapters.
432     TO_ALL_LOCADAPTERS(
433         mLocAdapters[i]->reportSvEvent(svNotify)
434         );
435 }
436 
reportSvPolynomial(GnssSvPolynomial & svPolynomial)437 void LocApiBase::reportSvPolynomial(GnssSvPolynomial &svPolynomial)
438 {
439     // loop through adapters, and deliver to all adapters.
440     TO_ALL_LOCADAPTERS(
441         mLocAdapters[i]->reportSvPolynomialEvent(svPolynomial)
442     );
443 }
444 
reportSvEphemeris(GnssSvEphemerisReport & svEphemeris)445 void LocApiBase::reportSvEphemeris(GnssSvEphemerisReport & svEphemeris)
446 {
447     // loop through adapters, and deliver to all adapters.
448     TO_ALL_LOCADAPTERS(
449         mLocAdapters[i]->reportSvEphemerisEvent(svEphemeris)
450     );
451 }
452 
reportStatus(LocGpsStatusValue status)453 void LocApiBase::reportStatus(LocGpsStatusValue status)
454 {
455     // loop through adapters, and deliver to all adapters.
456     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status));
457 }
458 
reportData(GnssDataNotification & dataNotify,int msInWeek)459 void LocApiBase::reportData(GnssDataNotification& dataNotify, int msInWeek)
460 {
461     // loop through adapters, and deliver to all adapters.
462     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportDataEvent(dataNotify, msInWeek));
463 }
464 
reportNmea(const char * nmea,int length)465 void LocApiBase::reportNmea(const char* nmea, int length)
466 {
467     // loop through adapters, and deliver to all adapters.
468     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmeaEvent(nmea, length));
469 }
470 
reportXtraServer(const char * url1,const char * url2,const char * url3,const int maxlength)471 void LocApiBase::reportXtraServer(const char* url1, const char* url2,
472                                   const char* url3, const int maxlength)
473 {
474     // loop through adapters, and deliver to the first handling adapter.
475     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportXtraServer(url1, url2, url3, maxlength));
476 
477 }
478 
reportLocationSystemInfo(const LocationSystemInfo & locationSystemInfo)479 void LocApiBase::reportLocationSystemInfo(const LocationSystemInfo& locationSystemInfo)
480 {
481     // loop through adapters, and deliver to all adapters.
482     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportLocationSystemInfoEvent(locationSystemInfo));
483 }
484 
requestXtraData()485 void LocApiBase::requestXtraData()
486 {
487     // loop through adapters, and deliver to the first handling adapter.
488     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestXtraData());
489 }
490 
requestTime()491 void LocApiBase::requestTime()
492 {
493     // loop through adapters, and deliver to the first handling adapter.
494     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestTime());
495 }
496 
requestLocation()497 void LocApiBase::requestLocation()
498 {
499     // loop through adapters, and deliver to the first handling adapter.
500     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation());
501 }
502 
requestATL(int connHandle,LocAGpsType agps_type,LocApnTypeMask apn_type_mask)503 void LocApiBase::requestATL(int connHandle, LocAGpsType agps_type,
504                             LocApnTypeMask apn_type_mask)
505 {
506     // loop through adapters, and deliver to the first handling adapter.
507     TO_1ST_HANDLING_LOCADAPTERS(
508             mLocAdapters[i]->requestATL(connHandle, agps_type, apn_type_mask));
509 }
510 
releaseATL(int connHandle)511 void LocApiBase::releaseATL(int connHandle)
512 {
513     // loop through adapters, and deliver to the first handling adapter.
514     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->releaseATL(connHandle));
515 }
516 
requestNiNotify(GnssNiNotification & notify,const void * data)517 void LocApiBase::requestNiNotify(GnssNiNotification &notify, const void* data)
518 {
519     // loop through adapters, and deliver to the first handling adapter.
520     TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotifyEvent(notify, data));
521 }
522 
getSibling()523 void* LocApiBase :: getSibling()
524     DEFAULT_IMPL(NULL)
525 
526 LocApiProxyBase* LocApiBase :: getLocApiProxy()
527     DEFAULT_IMPL(NULL)
528 
529 void LocApiBase::reportGnssMeasurements(GnssMeasurements& gnssMeasurements, int msInWeek)
530 {
531     // loop through adapters, and deliver to all adapters.
532     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementsEvent(gnssMeasurements, msInWeek));
533 }
534 
reportGnssSvIdConfig(const GnssSvIdConfig & config)535 void LocApiBase::reportGnssSvIdConfig(const GnssSvIdConfig& config)
536 {
537     // Print the config
538     LOC_LOGv("gloBlacklistSvMask: %" PRIu64 ", bdsBlacklistSvMask: %" PRIu64 ",\n"
539              "qzssBlacklistSvMask: %" PRIu64 ", galBlacklistSvMask: %" PRIu64,
540              config.gloBlacklistSvMask, config.bdsBlacklistSvMask,
541              config.qzssBlacklistSvMask, config.galBlacklistSvMask);
542 
543     // Loop through adapters, and deliver to all adapters.
544     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssSvIdConfigEvent(config));
545 }
546 
reportGnssSvTypeConfig(const GnssSvTypeConfig & config)547 void LocApiBase::reportGnssSvTypeConfig(const GnssSvTypeConfig& config)
548 {
549     // Print the config
550     LOC_LOGv("blacklistedMask: %" PRIu64 ", enabledMask: %" PRIu64,
551              config.blacklistedSvTypesMask, config.enabledSvTypesMask);
552 
553     // Loop through adapters, and deliver to all adapters.
554     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssSvTypeConfigEvent(config));
555 }
556 
geofenceBreach(size_t count,uint32_t * hwIds,Location & location,GeofenceBreachType breachType,uint64_t timestamp)557 void LocApiBase::geofenceBreach(size_t count, uint32_t* hwIds, Location& location,
558                                 GeofenceBreachType breachType, uint64_t timestamp)
559 {
560     TO_ALL_LOCADAPTERS(mLocAdapters[i]->geofenceBreachEvent(count, hwIds, location, breachType,
561                                                             timestamp));
562 }
563 
geofenceStatus(GeofenceStatusAvailable available)564 void LocApiBase::geofenceStatus(GeofenceStatusAvailable available)
565 {
566     TO_ALL_LOCADAPTERS(mLocAdapters[i]->geofenceStatusEvent(available));
567 }
568 
reportDBTPosition(UlpLocation & location,GpsLocationExtended & locationExtended,enum loc_sess_status status,LocPosTechMask loc_technology_mask)569 void LocApiBase::reportDBTPosition(UlpLocation &location, GpsLocationExtended &locationExtended,
570                                    enum loc_sess_status status, LocPosTechMask loc_technology_mask)
571 {
572     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportPositionEvent(location, locationExtended, status,
573                                                             loc_technology_mask));
574 }
575 
reportLocations(Location * locations,size_t count,BatchingMode batchingMode)576 void LocApiBase::reportLocations(Location* locations, size_t count, BatchingMode batchingMode)
577 {
578     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportLocationsEvent(locations, count, batchingMode));
579 }
580 
reportCompletedTrips(uint32_t accumulated_distance)581 void LocApiBase::reportCompletedTrips(uint32_t accumulated_distance)
582 {
583     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportCompletedTripsEvent(accumulated_distance));
584 }
585 
handleBatchStatusEvent(BatchingStatus batchStatus)586 void LocApiBase::handleBatchStatusEvent(BatchingStatus batchStatus)
587 {
588     TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportBatchStatusChangeEvent(batchStatus));
589 }
590 
591 
592 enum loc_api_adapter_err LocApiBase::
593    open(LOC_API_ADAPTER_EVENT_MASK_T /*mask*/)
594 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
595 
596 enum loc_api_adapter_err LocApiBase::
597     close()
598 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
599 
600 void LocApiBase::startFix(const LocPosMode& /*posMode*/, LocApiResponse* /*adapterResponse*/)
601 DEFAULT_IMPL()
602 
603 void LocApiBase::stopFix(LocApiResponse* /*adapterResponse*/)
604 DEFAULT_IMPL()
605 
606 void LocApiBase::
607     deleteAidingData(const GnssAidingData& /*data*/, LocApiResponse* /*adapterResponse*/)
608 DEFAULT_IMPL()
609 
610 void LocApiBase::
611     injectPosition(double /*latitude*/, double /*longitude*/, float /*accuracy*/)
612 DEFAULT_IMPL()
613 
614 void LocApiBase::
615     injectPosition(const Location& /*location*/, bool /*onDemandCpi*/)
616 DEFAULT_IMPL()
617 
618 void LocApiBase::
619     injectPosition(const GnssLocationInfoNotification & /*locationInfo*/, bool /*onDemandCpi*/)
620 DEFAULT_IMPL()
621 
622 void LocApiBase::
623     setTime(LocGpsUtcTime /*time*/, int64_t /*timeReference*/, int /*uncertainty*/)
624 DEFAULT_IMPL()
625 
626 enum loc_api_adapter_err LocApiBase::
627     setXtraData(char* /*data*/, int /*length*/)
628 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
629 
630 void LocApiBase::
631    atlOpenStatus(int /*handle*/, int /*is_succ*/, char* /*apn*/, uint32_t /*apnLen*/,
632                  AGpsBearerType /*bear*/, LocAGpsType /*agpsType*/,
633                  LocApnTypeMask /*mask*/)
634 DEFAULT_IMPL()
635 
636 void LocApiBase::
637     atlCloseStatus(int /*handle*/, int /*is_succ*/)
638 DEFAULT_IMPL()
639 
640 LocationError LocApiBase::
641     setServerSync(const char* /*url*/, int /*len*/, LocServerType /*type*/)
642 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
643 
644 LocationError LocApiBase::
645     setServerSync(unsigned int /*ip*/, int /*port*/, LocServerType /*type*/)
646 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
647 
648 void LocApiBase::
649     informNiResponse(GnssNiResponse /*userResponse*/, const void* /*passThroughData*/)
650 DEFAULT_IMPL()
651 
652 LocationError LocApiBase::
653     setSUPLVersionSync(GnssConfigSuplVersion /*version*/)
654 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
655 
656 enum loc_api_adapter_err LocApiBase::
657     setNMEATypesSync (uint32_t /*typesMask*/)
658 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
659 
660 LocationError LocApiBase::
661     setLPPConfigSync(GnssConfigLppProfile /*profile*/)
662 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
663 
664 
665 enum loc_api_adapter_err LocApiBase::
666     setSensorPropertiesSync(bool /*gyroBiasVarianceRandomWalk_valid*/,
667                         float /*gyroBiasVarianceRandomWalk*/,
668                         bool /*accelBiasVarianceRandomWalk_valid*/,
669                         float /*accelBiasVarianceRandomWalk*/,
670                         bool /*angleBiasVarianceRandomWalk_valid*/,
671                         float /*angleBiasVarianceRandomWalk*/,
672                         bool /*rateBiasVarianceRandomWalk_valid*/,
673                         float /*rateBiasVarianceRandomWalk*/,
674                         bool /*velocityBiasVarianceRandomWalk_valid*/,
675                         float /*velocityBiasVarianceRandomWalk*/)
676 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
677 
678 enum loc_api_adapter_err LocApiBase::
679     setSensorPerfControlConfigSync(int /*controlMode*/,
680                                int /*accelSamplesPerBatch*/,
681                                int /*accelBatchesPerSec*/,
682                                int /*gyroSamplesPerBatch*/,
683                                int /*gyroBatchesPerSec*/,
684                                int /*accelSamplesPerBatchHigh*/,
685                                int /*accelBatchesPerSecHigh*/,
686                                int /*gyroSamplesPerBatchHigh*/,
687                                int /*gyroBatchesPerSecHigh*/,
688                                int /*algorithmConfig*/)
689 DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
690 
691 LocationError LocApiBase::
692     setAGLONASSProtocolSync(GnssConfigAGlonassPositionProtocolMask /*aGlonassProtocol*/)
693 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
694 
695 LocationError LocApiBase::
696     setLPPeProtocolCpSync(GnssConfigLppeControlPlaneMask /*lppeCP*/)
697 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
698 
699 LocationError LocApiBase::
700     setLPPeProtocolUpSync(GnssConfigLppeUserPlaneMask /*lppeUP*/)
701 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
702 
703 GnssConfigSuplVersion LocApiBase::convertSuplVersion(const uint32_t /*suplVersion*/)
704 DEFAULT_IMPL(GNSS_CONFIG_SUPL_VERSION_1_0_0)
705 
706 GnssConfigLppProfile LocApiBase::convertLppProfile(const uint32_t /*lppProfile*/)
707 DEFAULT_IMPL(GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE)
708 
709 GnssConfigLppeControlPlaneMask LocApiBase::convertLppeCp(const uint32_t /*lppeControlPlaneMask*/)
710 DEFAULT_IMPL(0)
711 
712 GnssConfigLppeUserPlaneMask LocApiBase::convertLppeUp(const uint32_t /*lppeUserPlaneMask*/)
713 DEFAULT_IMPL(0)
714 
715 LocationError LocApiBase::setEmergencyExtensionWindowSync(
716         const uint32_t /*emergencyExtensionSeconds*/)
717 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
718 
719 void LocApiBase::
720    getWwanZppFix()
721 DEFAULT_IMPL()
722 
723 void LocApiBase::
724    getBestAvailableZppFix()
725 DEFAULT_IMPL()
726 
727 LocationError LocApiBase::
728     setGpsLockSync(GnssConfigGpsLock /*lock*/)
729 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
730 
731 void LocApiBase::
732     requestForAidingData(GnssAidingDataSvMask /*svDataMask*/)
733 DEFAULT_IMPL()
734 
735 void LocApiBase::
736     installAGpsCert(const LocDerEncodedCertificate* /*pData*/,
737                     size_t /*length*/,
738                     uint32_t /*slotBitMask*/)
739 DEFAULT_IMPL()
740 
741 LocationError LocApiBase::
742     setXtraVersionCheckSync(uint32_t /*check*/)
743 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
744 
745 LocationError LocApiBase::setBlacklistSvSync(const GnssSvIdConfig& /*config*/)
746 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
747 
748 void LocApiBase::setBlacklistSv(const GnssSvIdConfig& /*config*/)
749 DEFAULT_IMPL()
750 
751 void LocApiBase::getBlacklistSv()
752 DEFAULT_IMPL()
753 
754 void LocApiBase::setConstellationControl(const GnssSvTypeConfig& /*config*/)
755 DEFAULT_IMPL()
756 
757 void LocApiBase::getConstellationControl()
758 DEFAULT_IMPL()
759 
760 void LocApiBase::resetConstellationControl()
761 DEFAULT_IMPL()
762 
763 LocationError LocApiBase::
764     setConstrainedTuncMode(bool /*enabled*/,
765                            float /*tuncConstraint*/,
766                            uint32_t /*energyBudget*/)
767 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
768 
769 LocationError LocApiBase::
770     setPositionAssistedClockEstimatorMode(bool /*enabled*/)
771 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
772 
773 LocationError LocApiBase::getGnssEnergyConsumed()
774 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
775 
776 
777 void LocApiBase::addGeofence(uint32_t /*clientId*/, const GeofenceOption& /*options*/,
778         const GeofenceInfo& /*info*/,
779         LocApiResponseData<LocApiGeofenceData>* /*adapterResponseData*/)
780 DEFAULT_IMPL()
781 
782 void LocApiBase::removeGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/,
783         LocApiResponse* /*adapterResponse*/)
784 DEFAULT_IMPL()
785 
786 void LocApiBase::pauseGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/,
787         LocApiResponse* /*adapterResponse*/)
788 DEFAULT_IMPL()
789 
790 void LocApiBase::resumeGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/,
791         LocApiResponse* /*adapterResponse*/)
792 DEFAULT_IMPL()
793 
794 void LocApiBase::modifyGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/,
795          const GeofenceOption& /*options*/, LocApiResponse* /*adapterResponse*/)
796 DEFAULT_IMPL()
797 
798 void LocApiBase::startTimeBasedTracking(const TrackingOptions& /*options*/,
799         LocApiResponse* /*adapterResponse*/)
800 DEFAULT_IMPL()
801 
802 void LocApiBase::stopTimeBasedTracking(LocApiResponse* /*adapterResponse*/)
803 DEFAULT_IMPL()
804 
805 void LocApiBase::startDistanceBasedTracking(uint32_t /*sessionId*/,
806         const LocationOptions& /*options*/, LocApiResponse* /*adapterResponse*/)
807 DEFAULT_IMPL()
808 
809 void LocApiBase::stopDistanceBasedTracking(uint32_t /*sessionId*/,
810         LocApiResponse* /*adapterResponse*/)
811 DEFAULT_IMPL()
812 
813 void LocApiBase::startBatching(uint32_t /*sessionId*/, const LocationOptions& /*options*/,
814         uint32_t /*accuracy*/, uint32_t /*timeout*/, LocApiResponse* /*adapterResponse*/)
815 DEFAULT_IMPL()
816 
817 void LocApiBase::stopBatching(uint32_t /*sessionId*/, LocApiResponse* /*adapterResponse*/)
818 DEFAULT_IMPL()
819 
820 LocationError LocApiBase::startOutdoorTripBatchingSync(uint32_t /*tripDistance*/,
821         uint32_t /*tripTbf*/, uint32_t /*timeout*/)
822 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
823 
824 void LocApiBase::startOutdoorTripBatching(uint32_t /*tripDistance*/, uint32_t /*tripTbf*/,
825         uint32_t /*timeout*/, LocApiResponse* /*adapterResponse*/)
826 DEFAULT_IMPL()
827 
828 void LocApiBase::reStartOutdoorTripBatching(uint32_t /*ongoingTripDistance*/,
829         uint32_t /*ongoingTripInterval*/, uint32_t /*batchingTimeout,*/,
830         LocApiResponse* /*adapterResponse*/)
831 DEFAULT_IMPL()
832 
833 LocationError LocApiBase::stopOutdoorTripBatchingSync(bool /*deallocBatchBuffer*/)
834 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
835 
836 void LocApiBase::stopOutdoorTripBatching(bool /*deallocBatchBuffer*/,
837         LocApiResponse* /*adapterResponse*/)
838 DEFAULT_IMPL()
839 
840 LocationError LocApiBase::getBatchedLocationsSync(size_t /*count*/)
841 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
842 
843 void LocApiBase::getBatchedLocations(size_t /*count*/, LocApiResponse* /*adapterResponse*/)
844 DEFAULT_IMPL()
845 
846 LocationError LocApiBase::getBatchedTripLocationsSync(size_t /*count*/,
847         uint32_t /*accumulatedDistance*/)
848 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
849 
850 void LocApiBase::getBatchedTripLocations(size_t /*count*/, uint32_t /*accumulatedDistance*/,
851         LocApiResponse* /*adapterResponse*/)
852 DEFAULT_IMPL()
853 
854 LocationError LocApiBase::queryAccumulatedTripDistanceSync(uint32_t& /*accumulated_trip_distance*/,
855         uint32_t& /*numOfBatchedPositions*/)
856 DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
857 
858 void LocApiBase::queryAccumulatedTripDistance(
859         LocApiResponseData<LocApiBatchData>* /*adapterResponseData*/)
860 DEFAULT_IMPL()
861 
862 void LocApiBase::setBatchSize(size_t /*size*/)
863 DEFAULT_IMPL()
864 
865 void LocApiBase::setTripBatchSize(size_t /*size*/)
866 DEFAULT_IMPL()
867 
868 void LocApiBase::addToCallQueue(LocApiResponse* /*adapterResponse*/)
869 DEFAULT_IMPL()
870 
871 
872 } // namespace loc_core
873