1 /* Copyright (c) 2013-2017 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 #ifndef GPS_EXTENDED_C_H
30 #define GPS_EXTENDED_C_H
31 
32 #include <ctype.h>
33 #include <stdbool.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <loc_gps.h>
37 #include <LocationAPI.h>
38 #include <time.h>
39 
40 /**
41  * @file
42  * @brief C++ declarations for GPS types
43  */
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif /* __cplusplus */
48 
49 /** Location has valid source information. */
50 #define LOCATION_HAS_SOURCE_INFO   0x0020
51 /** LocGpsLocation has valid "is indoor?" flag */
52 #define LOC_GPS_LOCATION_HAS_IS_INDOOR   0x0040
53 /** LocGpsLocation has valid floor number */
54 #define LOC_GPS_LOCATION_HAS_FLOOR_NUMBER   0x0080
55 /** LocGpsLocation has valid map URL*/
56 #define LOC_GPS_LOCATION_HAS_MAP_URL   0x0100
57 /** LocGpsLocation has valid map index */
58 #define LOC_GPS_LOCATION_HAS_MAP_INDEX   0x0200
59 
60 /** Sizes for indoor fields */
61 #define GPS_LOCATION_MAP_URL_SIZE 400
62 #define GPS_LOCATION_MAP_INDEX_SIZE 16
63 
64 /** Position source is ULP */
65 #define ULP_LOCATION_IS_FROM_HYBRID   0x0001
66 /** Position source is GNSS only */
67 #define ULP_LOCATION_IS_FROM_GNSS     0x0002
68 /** Position source is ZPP only */
69 #define ULP_LOCATION_IS_FROM_ZPP      0x0004
70 /** Position is from a Geofence Breach Event */
71 #define ULP_LOCATION_IS_FROM_GEOFENCE 0X0008
72 /** Position is from Hardware FLP */
73 #define ULP_LOCATION_IS_FROM_HW_FLP   0x0010
74 /** Position is from NLP */
75 #define ULP_LOCATION_IS_FROM_NLP      0x0020
76 /** Position is from PIP */
77 #define ULP_LOCATION_IS_FROM_PIP      0x0040
78 /** Position is from external DR solution*/
79 #define ULP_LOCATION_IS_FROM_EXT_DR   0X0080
80 /** Raw GNSS position fixes */
81 #define ULP_LOCATION_IS_FROM_GNSS_RAW   0X0100
82 
83 typedef uint32_t LocSvInfoSource;
84 /** SVinfo source is GNSS/DR */
85 #define ULP_SVINFO_IS_FROM_GNSS       ((LocSvInfoSource)0x0001)
86 /** Raw SVinfo from GNSS */
87 #define ULP_SVINFO_IS_FROM_DR         ((LocSvInfoSource)0x0002)
88 
89 #define ULP_MIN_INTERVAL_INVALID 0xffffffff
90 #define ULP_MAX_NMEA_STRING_SIZE 201
91 
92 /*Emergency SUPL*/
93 #define LOC_GPS_NI_TYPE_EMERGENCY_SUPL    4
94 
95 #define LOC_AGPS_CERTIFICATE_MAX_LENGTH 2000
96 #define LOC_AGPS_CERTIFICATE_MAX_SLOTS 10
97 
98 typedef uint32_t LocPosTechMask;
99 #define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000)
100 #define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001)
101 #define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002)
102 #define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004)
103 #define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008)
104 #define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010)
105 #define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020)
106 #define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040)
107 #define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080)
108 
109 enum loc_registration_mask_status {
110     LOC_REGISTRATION_MASK_ENABLED,
111     LOC_REGISTRATION_MASK_DISABLED,
112     LOC_REGISTRATION_MASK_SET
113 };
114 
115 typedef enum {
116     LOC_SUPPORTED_FEATURE_ODCPI_2_V02 = 0, /**<  Support ODCPI version 2 feature  */
117     LOC_SUPPORTED_FEATURE_WIFI_AP_DATA_INJECT_2_V02, /**<  Support Wifi AP data inject version 2 feature  */
118     LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02 /**< Support debug NMEA feature */
119 } loc_supported_feature_enum;
120 
121 typedef struct {
122     /** set to sizeof(UlpLocation) */
123     size_t          size;
124     LocGpsLocation     gpsLocation;
125     /* Provider indicator for HYBRID or GPS */
126     uint16_t        position_source;
127     LocPosTechMask  tech_mask;
128     /*allows HAL to pass additional information related to the location */
129     int             rawDataSize;         /* in # of bytes */
130     void            * rawData;
131     bool            is_indoor;
132     float           floor_number;
133     char            map_url[GPS_LOCATION_MAP_URL_SIZE];
134     unsigned char   map_index[GPS_LOCATION_MAP_INDEX_SIZE];
135 } UlpLocation;
136 
137 typedef struct {
138     /** set to sizeof(UlpNmea) */
139     size_t          size;
140     char            nmea_str[ULP_MAX_NMEA_STRING_SIZE];
141     unsigned int    len;
142 } UlpNmea;
143 
144 
145 /** AGPS type */
146 typedef int16_t AGpsExtType;
147 #define LOC_AGPS_TYPE_INVALID       -1
148 #define LOC_AGPS_TYPE_ANY           0
149 #define LOC_AGPS_TYPE_SUPL          1
150 #define LOC_AGPS_TYPE_C2K           2
151 #define LOC_AGPS_TYPE_WWAN_ANY      3
152 #define LOC_AGPS_TYPE_WIFI          4
153 #define LOC_AGPS_TYPE_SUPL_ES       5
154 
155 /** SSID length */
156 #define SSID_BUF_SIZE (32+1)
157 
158 typedef int16_t AGpsBearerType;
159 #define AGPS_APN_BEARER_INVALID    -1
160 #define AGPS_APN_BEARER_IPV4        0
161 #define AGPS_APN_BEARER_IPV6        1
162 #define AGPS_APN_BEARER_IPV4V6      2
163 
164 typedef enum {
165     AGPS_CB_PRIORITY_LOW  = 1,
166     AGPS_CB_PRIORITY_MED  = 2,
167     AGPS_CB_PRIORITY_HIGH = 3
168 } AgpsCbPriority;
169 
170 typedef struct {
171     void* statusV4Cb;
172     AgpsCbPriority cbPriority;
173 } AgpsCbInfo;
174 
175 /** GPS extended callback structure. */
176 typedef struct {
177     /** set to sizeof(LocGpsCallbacks) */
178     size_t      size;
179     loc_gps_set_capabilities set_capabilities_cb;
180     loc_gps_acquire_wakelock acquire_wakelock_cb;
181     loc_gps_release_wakelock release_wakelock_cb;
182     loc_gps_create_thread create_thread_cb;
183     loc_gps_request_utc_time request_utc_time_cb;
184 } GpsExtCallbacks;
185 
186 /** Callback to report the xtra server url to the client.
187  *  The client should use this url when downloading xtra unless overwritten
188  *  in the gps.conf file
189  */
190 typedef void (* report_xtra_server)(const char*, const char*, const char*);
191 
192 /** Callback structure for the XTRA interface. */
193 typedef struct {
194     loc_gps_xtra_download_request download_request_cb;
195     loc_gps_create_thread create_thread_cb;
196     report_xtra_server report_xtra_server_cb;
197 } GpsXtraExtCallbacks;
198 
199 /** Represents the status of AGPS. */
200 typedef struct {
201     /** set to sizeof(AGpsExtStatus) */
202     size_t          size;
203 
204     AGpsExtType type;
205     LocAGpsStatusValue status;
206     uint32_t        ipv4_addr;
207     struct sockaddr_storage addr;
208     char            ssid[SSID_BUF_SIZE];
209     char            password[SSID_BUF_SIZE];
210 } AGpsExtStatus;
211 
212 /** Callback with AGPS status information.
213  *  Can only be called from a thread created by create_thread_cb.
214  */
215 typedef void (* agps_status_extended)(AGpsExtStatus* status);
216 
217 /** Callback structure for the AGPS interface. */
218 typedef struct {
219     agps_status_extended status_cb;
220     loc_gps_create_thread create_thread_cb;
221 } AGpsExtCallbacks;
222 
223 
224 typedef void (*loc_ni_notify_callback)(LocGpsNiNotification *notification, bool esEnalbed);
225 /** GPS NI callback structure. */
226 typedef struct
227 {
228     /**
229      * Sends the notification request from HAL to GPSLocationProvider.
230      */
231     loc_ni_notify_callback notify_cb;
232 } GpsNiExtCallbacks;
233 
234 typedef enum loc_server_type {
235     LOC_AGPS_CDMA_PDE_SERVER,
236     LOC_AGPS_CUSTOM_PDE_SERVER,
237     LOC_AGPS_MPC_SERVER,
238     LOC_AGPS_SUPL_SERVER
239 } LocServerType;
240 
241 typedef enum loc_position_mode_type {
242     LOC_POSITION_MODE_INVALID = -1,
243     LOC_POSITION_MODE_STANDALONE = 0,
244     LOC_POSITION_MODE_MS_BASED,
245     LOC_POSITION_MODE_MS_ASSISTED,
246     LOC_POSITION_MODE_RESERVED_1,
247     LOC_POSITION_MODE_RESERVED_2,
248     LOC_POSITION_MODE_RESERVED_3,
249     LOC_POSITION_MODE_RESERVED_4,
250     LOC_POSITION_MODE_RESERVED_5
251 
252 } LocPositionMode;
253 
254 /**
255  * @brief Minimum allowed value for fix interval.
256  *
257  * This value is a sanity limit in GPS framework. The hardware has own internal
258  * limits that may not match this value
259  *
260  * @sa GPS_DEFAULT_FIX_INTERVAL_MS
261  */
262 
263 #define GPS_MIN_POSSIBLE_FIX_INTERVAL_MS 100
264 /**
265  * @brief Default value for fix interval.
266  *
267  * This value is used by default whenever appropriate.
268  *
269  * @sa GPS_MIN_POSSIBLE_FIX_INTERVAL_MS
270  */
271 #define GPS_DEFAULT_FIX_INTERVAL_MS      1000
272 
273 /** Flags to indicate which values are valid in a GpsLocationExtended. */
274 typedef uint32_t GpsLocationExtendedFlags;
275 /** GpsLocationExtended has valid pdop, hdop, vdop. */
276 #define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001
277 /** GpsLocationExtended has valid altitude mean sea level. */
278 #define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002
279 /** UlpLocation has valid magnetic deviation. */
280 #define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004
281 /** UlpLocation has valid mode indicator. */
282 #define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008
283 /** GpsLocationExtended has valid vertical uncertainty */
284 #define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010
285 /** GpsLocationExtended has valid speed uncertainty */
286 #define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020
287 /** GpsLocationExtended has valid heading uncertainty */
288 #define GPS_LOCATION_EXTENDED_HAS_BEARING_UNC 0x0040
289 /** GpsLocationExtended has valid horizontal reliability */
290 #define GPS_LOCATION_EXTENDED_HAS_HOR_RELIABILITY 0x0080
291 /** GpsLocationExtended has valid vertical reliability */
292 #define GPS_LOCATION_EXTENDED_HAS_VERT_RELIABILITY 0x0100
293 /** GpsLocationExtended has valid Horizontal Elliptical Uncertainty (Semi-Major Axis) */
294 #define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MAJOR 0x0200
295 /** GpsLocationExtended has valid Horizontal Elliptical Uncertainty (Semi-Minor Axis) */
296 #define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MINOR 0x0400
297 /** GpsLocationExtended has valid Elliptical Horizontal Uncertainty Azimuth */
298 #define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_AZIMUTH 0x0800
299 /** GpsLocationExtended has valid gnss sv used in position data */
300 #define GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA 0x1000
301 /** GpsLocationExtended has valid navSolutionMask */
302 #define GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK 0x2000
303 /** GpsLocationExtended has valid LocPosTechMask */
304 #define GPS_LOCATION_EXTENDED_HAS_POS_TECH_MASK   0x4000
305 /** GpsLocationExtended has valid LocSvInfoSource */
306 #define GPS_LOCATION_EXTENDED_HAS_SV_SOURCE_INFO   0x8000
307 /** GpsLocationExtended has valid position dynamics data */
308 #define GPS_LOCATION_EXTENDED_HAS_POS_DYNAMICS_DATA   0x10000
309 /** GpsLocationExtended has GPS Time */
310 #define GPS_LOCATION_EXTENDED_HAS_GPS_TIME   0x20000
311 
312 typedef uint32_t LocNavSolutionMask;
313 /* Bitmask to specify whether SBAS ionospheric correction is used  */
314 #define LOC_NAV_MASK_SBAS_CORRECTION_IONO ((LocNavSolutionMask)0x0001)
315 /* Bitmask to specify whether SBAS fast correction is used  */
316 #define LOC_NAV_MASK_SBAS_CORRECTION_FAST ((LocNavSolutionMask)0x0002)
317 /**<  Bitmask to specify whether SBAS long-tem correction is used  */
318 #define LOC_NAV_MASK_SBAS_CORRECTION_LONG ((LocNavSolutionMask)0x0004)
319 /**<  Bitmask to specify whether SBAS integrity information is used  */
320 #define LOC_NAV_MASK_SBAS_INTEGRITY ((LocNavSolutionMask)0x0008)
321 
322 typedef uint32_t LocPosDataMask;
323 /* Bitmask to specify whether Navigation data has Forward Acceleration  */
324 #define LOC_NAV_DATA_HAS_LONG_ACCEL ((LocPosDataMask)0x0001)
325 /* Bitmask to specify whether Navigation data has Sideward Acceleration */
326 #define LOC_NAV_DATA_HAS_LAT_ACCEL ((LocPosDataMask)0x0002)
327 /* Bitmask to specify whether Navigation data has Vertical Acceleration */
328 #define LOC_NAV_DATA_HAS_VERT_ACCEL ((LocPosDataMask)0x0004)
329 /* Bitmask to specify whether Navigation data has Heading Rate */
330 #define LOC_NAV_DATA_HAS_YAW_RATE ((LocPosDataMask)0x0008)
331 /* Bitmask to specify whether Navigation data has Body pitch */
332 #define LOC_NAV_DATA_HAS_PITCH ((LocPosDataMask)0x0010)
333 
334 /** GPS PRN Range */
335 #define GPS_SV_PRN_MIN      1
336 #define GPS_SV_PRN_MAX      32
337 #define GLO_SV_PRN_MIN      65
338 #define GLO_SV_PRN_MAX      96
339 #define QZSS_SV_PRN_MIN     193
340 #define QZSS_SV_PRN_MAX     197
341 #define BDS_SV_PRN_MIN      201
342 #define BDS_SV_PRN_MAX      235
343 #define GAL_SV_PRN_MIN      301
344 #define GAL_SV_PRN_MAX      336
345 
346 typedef uint32_t LocPosTechMask;
347 #define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000)
348 #define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001)
349 #define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002)
350 #define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004)
351 #define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008)
352 #define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010)
353 #define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020)
354 #define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040)
355 #define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080)
356 
357 typedef enum {
358     LOC_RELIABILITY_NOT_SET = 0,
359     LOC_RELIABILITY_VERY_LOW = 1,
360     LOC_RELIABILITY_LOW = 2,
361     LOC_RELIABILITY_MEDIUM = 3,
362     LOC_RELIABILITY_HIGH = 4
363 }LocReliability;
364 
365 typedef struct {
366     struct timespec apTimeStamp;
367     /*boottime received from pps-ktimer*/
368     float apTimeStampUncertaintyMs;
369     /* timestamp uncertainty in milli seconds */
370 }Gnss_ApTimeStampStructType;
371 
372 typedef struct {
373     uint64_t gps_sv_used_ids_mask;
374     uint64_t glo_sv_used_ids_mask;
375     uint64_t gal_sv_used_ids_mask;
376     uint64_t bds_sv_used_ids_mask;
377     uint64_t qzss_sv_used_ids_mask;
378 } GnssSvUsedInPosition;
379 
380 /* Body Frame parameters */
381 typedef struct {
382     /** Contains Body frame LocPosDataMask bits. */
383    uint32_t        bodyFrameDatamask;
384    /* Forward Acceleration in body frame (m/s2)*/
385    float           longAccel;
386    /* Sideward Acceleration in body frame (m/s2)*/
387    float           latAccel;
388    /* Vertical Acceleration in body frame (m/s2)*/
389    float           vertAccel;
390    /* Heading Rate (Radians/second) */
391    float           yawRate;
392    /* Body pitch (Radians) */
393    float           pitch;
394 }LocPositionDynamics;
395 
396 /* GPS Time structure */
397 typedef struct {
398 
399   /**<   Current GPS week as calculated from midnight, Jan. 6, 1980. \n
400        - Units: Weeks */
401   uint16_t gpsWeek;
402 
403   /**<   Amount of time into the current GPS week. \n
404        - Units: Milliseconds */
405   uint32_t gpsTimeOfWeekMs;
406 }GPSTimeStruct;
407 
408 /** Represents gps location extended. */
409 typedef struct {
410     /** set to sizeof(GpsLocationExtended) */
411     size_t          size;
412     /** Contains GpsLocationExtendedFlags bits. */
413     uint32_t        flags;
414     /** Contains the Altitude wrt mean sea level */
415     float           altitudeMeanSeaLevel;
416     /** Contains Position Dilusion of Precision. */
417     float           pdop;
418     /** Contains Horizontal Dilusion of Precision. */
419     float           hdop;
420     /** Contains Vertical Dilusion of Precision. */
421     float           vdop;
422     /** Contains Magnetic Deviation. */
423     float           magneticDeviation;
424     /** vertical uncertainty in meters */
425     float           vert_unc;
426     /** speed uncertainty in m/s */
427     float           speed_unc;
428     /** heading uncertainty in degrees (0 to 359.999) */
429     float           bearing_unc;
430     /** horizontal reliability. */
431     LocReliability  horizontal_reliability;
432     /** vertical reliability. */
433     LocReliability  vertical_reliability;
434     /*  Horizontal Elliptical Uncertainty (Semi-Major Axis) */
435     float           horUncEllipseSemiMajor;
436     /*  Horizontal Elliptical Uncertainty (Semi-Minor Axis) */
437     float           horUncEllipseSemiMinor;
438     /*    Elliptical Horizontal Uncertainty Azimuth */
439     float           horUncEllipseOrientAzimuth;
440 
441     Gnss_ApTimeStampStructType               timeStamp;
442     /** Gnss sv used in position data */
443     GnssSvUsedInPosition gnss_sv_used_ids;
444     /** Nav solution mask to indicate sbas corrections */
445     LocNavSolutionMask  navSolutionMask;
446     /** Position technology used in computing this fix */
447     LocPosTechMask tech_mask;
448     /** SV Info source used in computing this fix */
449     LocSvInfoSource sv_source;
450     /** Body Frame Dynamics: 4wayAcceleration and pitch set with validity */
451     LocPositionDynamics bodyFrameData;
452     /** GPS Time */
453     GPSTimeStruct gpsTime;
454 } GpsLocationExtended;
455 
456 enum loc_sess_status {
457     LOC_SESS_SUCCESS,
458     LOC_SESS_INTERMEDIATE,
459     LOC_SESS_FAILURE
460 };
461 
462 // Nmea sentence types mask
463 typedef uint32_t NmeaSentenceTypesMask;
464 #define LOC_NMEA_MASK_GGA_V02   ((NmeaSentenceTypesMask)0x00000001) /**<  Enable GGA type  */
465 #define LOC_NMEA_MASK_RMC_V02   ((NmeaSentenceTypesMask)0x00000002) /**<  Enable RMC type  */
466 #define LOC_NMEA_MASK_GSV_V02   ((NmeaSentenceTypesMask)0x00000004) /**<  Enable GSV type  */
467 #define LOC_NMEA_MASK_GSA_V02   ((NmeaSentenceTypesMask)0x00000008) /**<  Enable GSA type  */
468 #define LOC_NMEA_MASK_VTG_V02   ((NmeaSentenceTypesMask)0x00000010) /**<  Enable VTG type  */
469 #define LOC_NMEA_MASK_PQXFI_V02 ((NmeaSentenceTypesMask)0x00000020) /**<  Enable PQXFI type  */
470 #define LOC_NMEA_MASK_PSTIS_V02 ((NmeaSentenceTypesMask)0x00000040) /**<  Enable PSTIS type  */
471 #define LOC_NMEA_MASK_GLGSV_V02 ((NmeaSentenceTypesMask)0x00000080) /**<  Enable GLGSV type  */
472 #define LOC_NMEA_MASK_GNGSA_V02 ((NmeaSentenceTypesMask)0x00000100) /**<  Enable GNGSA type  */
473 #define LOC_NMEA_MASK_GNGNS_V02 ((NmeaSentenceTypesMask)0x00000200) /**<  Enable GNGNS type  */
474 #define LOC_NMEA_MASK_GARMC_V02 ((NmeaSentenceTypesMask)0x00000400) /**<  Enable GARMC type  */
475 #define LOC_NMEA_MASK_GAGSV_V02 ((NmeaSentenceTypesMask)0x00000800) /**<  Enable GAGSV type  */
476 #define LOC_NMEA_MASK_GAGSA_V02 ((NmeaSentenceTypesMask)0x00001000) /**<  Enable GAGSA type  */
477 #define LOC_NMEA_MASK_GAVTG_V02 ((NmeaSentenceTypesMask)0x00002000) /**<  Enable GAVTG type  */
478 #define LOC_NMEA_MASK_GAGGA_V02 ((NmeaSentenceTypesMask)0x00004000) /**<  Enable GAGGA type  */
479 #define LOC_NMEA_MASK_PQGSA_V02 ((NmeaSentenceTypesMask)0x00008000) /**<  Enable PQGSA type  */
480 #define LOC_NMEA_MASK_PQGSV_V02 ((NmeaSentenceTypesMask)0x00010000) /**<  Enable PQGSV type  */
481 #define LOC_NMEA_MASK_DEBUG_V02 ((NmeaSentenceTypesMask)0x00020000) /**<  Enable DEBUG type  */
482 
483 // all bitmasks of general supported NMEA sentenses - debug is not part of this
484 #define LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK  (LOC_NMEA_MASK_GGA_V02 | LOC_NMEA_MASK_RMC_V02 | \
485               LOC_NMEA_MASK_GSV_V02 | LOC_NMEA_MASK_GSA_V02 | LOC_NMEA_MASK_VTG_V02 | \
486         LOC_NMEA_MASK_PQXFI_V02 | LOC_NMEA_MASK_PSTIS_V02 | LOC_NMEA_MASK_GLGSV_V02 | \
487         LOC_NMEA_MASK_GNGSA_V02 | LOC_NMEA_MASK_GNGNS_V02 | LOC_NMEA_MASK_GARMC_V02 | \
488         LOC_NMEA_MASK_GAGSV_V02 | LOC_NMEA_MASK_GAGSA_V02 | LOC_NMEA_MASK_GAVTG_V02 | \
489         LOC_NMEA_MASK_GAGGA_V02 | LOC_NMEA_MASK_PQGSA_V02 | LOC_NMEA_MASK_PQGSV_V02)
490 
491 typedef enum {
492   LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0,
493   LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM,
494   LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU,
495   LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
496   LOC_ENG_IF_REQUEST_SENDER_ID_MODEM,
497   LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN
498 } loc_if_req_sender_id_e_type;
499 
500 
501 #define smaller_of(a, b) (((a) > (b)) ? (b) : (a))
502 #define MAX_APN_LEN 100
503 
504 // This will be overridden by the individual adapters
505 // if necessary.
506 #define DEFAULT_IMPL(rtv)                                     \
507 {                                                             \
508     LOC_LOGD("%s: default implementation invoked", __func__); \
509     return rtv;                                               \
510 }
511 
512 enum loc_api_adapter_err {
513     LOC_API_ADAPTER_ERR_SUCCESS             = 0,
514     LOC_API_ADAPTER_ERR_GENERAL_FAILURE     = 1,
515     LOC_API_ADAPTER_ERR_UNSUPPORTED         = 2,
516     LOC_API_ADAPTER_ERR_INVALID_HANDLE      = 4,
517     LOC_API_ADAPTER_ERR_INVALID_PARAMETER   = 5,
518     LOC_API_ADAPTER_ERR_ENGINE_BUSY         = 6,
519     LOC_API_ADAPTER_ERR_PHONE_OFFLINE       = 7,
520     LOC_API_ADAPTER_ERR_TIMEOUT             = 8,
521     LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9,
522     LOC_API_ADAPTER_ERR_INTERNAL            = 10,
523 
524     /* equating engine down to phone offline, as they are the same errror */
525     LOC_API_ADAPTER_ERR_ENGINE_DOWN         = LOC_API_ADAPTER_ERR_PHONE_OFFLINE,
526     LOC_API_ADAPTER_ERR_FAILURE             = 101,
527     LOC_API_ADAPTER_ERR_UNKNOWN
528 };
529 
530 enum loc_api_adapter_event_index {
531     LOC_API_ADAPTER_REPORT_POSITION = 0,               // Position report comes in loc_parsed_position_s_type
532     LOC_API_ADAPTER_REPORT_SATELLITE,                  // Satellite in view report
533     LOC_API_ADAPTER_REPORT_NMEA_1HZ,                   // NMEA report at 1HZ rate
534     LOC_API_ADAPTER_REPORT_NMEA_POSITION,              // NMEA report at position report rate
535     LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY,          // NI notification/verification request
536     LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA,           // Assistance data, eg: time, predicted orbits request
537     LOC_API_ADAPTER_REQUEST_LOCATION_SERVER,           // Request for location server
538     LOC_API_ADAPTER_REPORT_IOCTL,                      // Callback report for loc_ioctl
539     LOC_API_ADAPTER_REPORT_STATUS,                     // Misc status report: eg, engine state
540     LOC_API_ADAPTER_REQUEST_WIFI,                      //
541     LOC_API_ADAPTER_SENSOR_STATUS,                     //
542     LOC_API_ADAPTER_REQUEST_TIME_SYNC,                 //
543     LOC_API_ADAPTER_REPORT_SPI,                        //
544     LOC_API_ADAPTER_REPORT_NI_GEOFENCE,                //
545     LOC_API_ADAPTER_GEOFENCE_GEN_ALERT,                //
546     LOC_API_ADAPTER_REPORT_GENFENCE_BREACH,            //
547     LOC_API_ADAPTER_PEDOMETER_CTRL,                    //
548     LOC_API_ADAPTER_MOTION_CTRL,                       //
549     LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA,              // Wifi ap data
550     LOC_API_ADAPTER_BATCH_FULL,                        // Batching on full
551     LOC_API_ADAPTER_BATCHED_POSITION_REPORT,           // Batching on fix
552     LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT,    //
553     LOC_API_ADAPTER_GNSS_MEASUREMENT_REPORT,          //GNSS Measurement Report
554     LOC_API_ADAPTER_GNSS_SV_POLYNOMIAL_REPORT,        //GNSS SV Polynomial Report
555     LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ,              // GDT upload start request
556     LOC_API_ADAPTER_GDT_UPLOAD_END_REQ,                // GDT upload end request
557     LOC_API_ADAPTER_GNSS_MEASUREMENT,                  // GNSS Measurement report
558     LOC_API_ADAPTER_REQUEST_TIMEZONE,                  // Timezone injection request
559     LOC_API_ADAPTER_REPORT_GENFENCE_DWELL_REPORT,      // Geofence dwell report
560     LOC_API_ADAPTER_REQUEST_SRN_DATA,                  // request srn data from AP
561     LOC_API_ADAPTER_REQUEST_POSITION_INJECTION,        // Position injection request
562     LOC_API_ADAPTER_BATCH_STATUS,                       // batch status
563     LOC_API_ADAPTER_EVENT_MAX
564 };
565 
566 #define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT           (1<<LOC_API_ADAPTER_REPORT_POSITION)
567 #define LOC_API_ADAPTER_BIT_SATELLITE_REPORT                 (1<<LOC_API_ADAPTER_REPORT_SATELLITE)
568 #define LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT                  (1<<LOC_API_ADAPTER_REPORT_NMEA_1HZ)
569 #define LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT             (1<<LOC_API_ADAPTER_REPORT_NMEA_POSITION)
570 #define LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST         (1<<LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY)
571 #define LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST          (1<<LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA)
572 #define LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST          (1<<LOC_API_ADAPTER_REQUEST_LOCATION_SERVER)
573 #define LOC_API_ADAPTER_BIT_IOCTL_REPORT                     (1<<LOC_API_ADAPTER_REPORT_IOCTL)
574 #define LOC_API_ADAPTER_BIT_STATUS_REPORT                    (1<<LOC_API_ADAPTER_REPORT_STATUS)
575 #define LOC_API_ADAPTER_BIT_REQUEST_WIFI                     (1<<LOC_API_ADAPTER_REQUEST_WIFI)
576 #define LOC_API_ADAPTER_BIT_SENSOR_STATUS                    (1<<LOC_API_ADAPTER_SENSOR_STATUS)
577 #define LOC_API_ADAPTER_BIT_REQUEST_TIME_SYNC                (1<<LOC_API_ADAPTER_REQUEST_TIME_SYNC)
578 #define LOC_API_ADAPTER_BIT_REPORT_SPI                       (1<<LOC_API_ADAPTER_REPORT_SPI)
579 #define LOC_API_ADAPTER_BIT_REPORT_NI_GEOFENCE               (1<<LOC_API_ADAPTER_REPORT_NI_GEOFENCE)
580 #define LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT               (1<<LOC_API_ADAPTER_GEOFENCE_GEN_ALERT)
581 #define LOC_API_ADAPTER_BIT_REPORT_GENFENCE_BREACH           (1<<LOC_API_ADAPTER_REPORT_GENFENCE_BREACH)
582 #define LOC_API_ADAPTER_BIT_BATCHED_GENFENCE_BREACH_REPORT   (1<<LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT)
583 #define LOC_API_ADAPTER_BIT_PEDOMETER_CTRL                   (1<<LOC_API_ADAPTER_PEDOMETER_CTRL)
584 #define LOC_API_ADAPTER_BIT_MOTION_CTRL                      (1<<LOC_API_ADAPTER_MOTION_CTRL)
585 #define LOC_API_ADAPTER_BIT_REQUEST_WIFI_AP_DATA             (1<<LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA)
586 #define LOC_API_ADAPTER_BIT_BATCH_FULL                       (1<<LOC_API_ADAPTER_BATCH_FULL)
587 #define LOC_API_ADAPTER_BIT_BATCHED_POSITION_REPORT          (1<<LOC_API_ADAPTER_BATCHED_POSITION_REPORT)
588 #define LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT_REPORT          (1<<LOC_API_ADAPTER_GNSS_MEASUREMENT_REPORT)
589 #define LOC_API_ADAPTER_BIT_GNSS_SV_POLYNOMIAL_REPORT        (1<<LOC_API_ADAPTER_GNSS_SV_POLYNOMIAL_REPORT)
590 #define LOC_API_ADAPTER_BIT_GDT_UPLOAD_BEGIN_REQ             (1<<LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ)
591 #define LOC_API_ADAPTER_BIT_GDT_UPLOAD_END_REQ               (1<<LOC_API_ADAPTER_GDT_UPLOAD_END_REQ)
592 #define LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT                 (1<<LOC_API_ADAPTER_GNSS_MEASUREMENT)
593 #define LOC_API_ADAPTER_BIT_REQUEST_TIMEZONE                 (1<<LOC_API_ADAPTER_REQUEST_TIMEZONE)
594 #define LOC_API_ADAPTER_BIT_REPORT_GENFENCE_DWELL            (1<<LOC_API_ADAPTER_REPORT_GENFENCE_DWELL_REPORT)
595 #define LOC_API_ADAPTER_BIT_REQUEST_SRN_DATA                 (1<<LOC_API_ADAPTER_REQUEST_SRN_DATA)
596 #define LOC_API_ADAPTER_BIT_POSITION_INJECTION_REQUEST       (1<<LOC_API_ADAPTER_REQUEST_POSITION_INJECTION)
597 #define LOC_API_ADAPTER_BIT_BATCH_STATUS                     (1<<LOC_API_ADAPTER_BATCH_STATUS)
598 
599 
600 typedef unsigned int LOC_API_ADAPTER_EVENT_MASK_T;
601 
602 typedef enum loc_api_adapter_msg_to_check_supported {
603     LOC_API_ADAPTER_MESSAGE_LOCATION_BATCHING,               // Batching 1.0
604     LOC_API_ADAPTER_MESSAGE_BATCHED_GENFENCE_BREACH,         // Geofence Batched Breach
605     LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING,          // DBT 2.0
606     LOC_API_ADAPTER_MESSAGE_ADAPTIVE_LOCATION_BATCHING,      // Batching 1.5
607     LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING, // Batching 2.0
608     LOC_API_ADAPTER_MESSAGE_UPDATE_TBF_ON_THE_FLY,           // Updating Tracking TBF On The Fly
609     LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING,           // Outdoor Trip Batching
610 
611     LOC_API_ADAPTER_MESSAGE_MAX
612 } LocCheckingMessagesID;
613 
614 typedef int IzatDevId_t;
615 
616 typedef uint32_t LOC_GPS_LOCK_MASK;
617 #define isGpsLockNone(lock) ((lock) == 0)
618 #define isGpsLockMO(lock) ((lock) & ((LOC_GPS_LOCK_MASK)1))
619 #define isGpsLockMT(lock) ((lock) & ((LOC_GPS_LOCK_MASK)2))
620 #define isGpsLockAll(lock) (((lock) & ((LOC_GPS_LOCK_MASK)3)) == 3)
621 
622 /*++ ***********************************************
623 **  Satellite Measurement and Satellite Polynomial
624 **  Structure definitions
625 **  ***********************************************
626 --*/
627 #define GNSS_SV_POLY_VELOCITY_COEF_MAX_SIZE         12
628 #define GNSS_SV_POLY_XYZ_0_TH_ORDER_COEFF_MAX_SIZE  3
629 #define GNSS_SV_POLY_XYZ_N_TH_ORDER_COEFF_MAX_SIZE  9
630 #define GNSS_SV_POLY_SV_CLKBIAS_COEFF_MAX_SIZE      4
631 #define GNSS_LOC_SV_MEAS_LIST_MAX_SIZE              16
632 
633 enum ulp_gnss_sv_measurement_valid_flags{
634 
635     ULP_GNSS_SV_MEAS_GPS_TIME = 0,
636     ULP_GNSS_SV_MEAS_PSUEDO_RANGE,
637     ULP_GNSS_SV_MEAS_MS_IN_WEEK,
638     ULP_GNSS_SV_MEAS_SUB_MSEC,
639     ULP_GNSS_SV_MEAS_CARRIER_PHASE,
640     ULP_GNSS_SV_MEAS_DOPPLER_SHIFT,
641     ULP_GNSS_SV_MEAS_CNO,
642     ULP_GNSS_SV_MEAS_LOSS_OF_LOCK,
643 
644     ULP_GNSS_SV_MEAS_MAX_VALID_FLAGS
645 };
646 
647 #define ULP_GNSS_SV_MEAS_BIT_GPS_TIME        (1<<ULP_GNSS_SV_MEAS_GPS_TIME)
648 #define ULP_GNSS_SV_MEAS_BIT_PSUEDO_RANGE    (1<<ULP_GNSS_SV_MEAS_PSUEDO_RANGE)
649 #define ULP_GNSS_SV_MEAS_BIT_MS_IN_WEEK      (1<<ULP_GNSS_SV_MEAS_MS_IN_WEEK)
650 #define ULP_GNSS_SV_MEAS_BIT_SUB_MSEC        (1<<ULP_GNSS_SV_MEAS_SUB_MSEC)
651 #define ULP_GNSS_SV_MEAS_BIT_CARRIER_PHASE   (1<<ULP_GNSS_SV_MEAS_CARRIER_PHASE)
652 #define ULP_GNSS_SV_MEAS_BIT_DOPPLER_SHIFT   (1<<ULP_GNSS_SV_MEAS_DOPPLER_SHIFT)
653 #define ULP_GNSS_SV_MEAS_BIT_CNO             (1<<ULP_GNSS_SV_MEAS_CNO)
654 #define ULP_GNSS_SV_MEAS_BIT_LOSS_OF_LOCK    (1<<ULP_GNSS_SV_MEAS_LOSS_OF_LOCK)
655 
656 enum ulp_gnss_sv_poly_valid_flags{
657 
658     ULP_GNSS_SV_POLY_GLO_FREQ = 0,
659     ULP_GNSS_SV_POLY_T0,
660     ULP_GNSS_SV_POLY_IODE,
661     ULP_GNSS_SV_POLY_FLAG,
662     ULP_GNSS_SV_POLY_POLYCOEFF_XYZ0,
663     ULP_GNSS_SV_POLY_POLYCOEFF_XYZN,
664     ULP_GNSS_SV_POLY_POLYCOEFF_OTHER,
665     ULP_GNSS_SV_POLY_SV_POSUNC,
666     ULP_GNSS_SV_POLY_IONODELAY,
667     ULP_GNSS_SV_POLY_IONODOT,
668     ULP_GNSS_SV_POLY_SBAS_IONODELAY,
669     ULP_GNSS_SV_POLY_SBAS_IONODOT,
670     ULP_GNSS_SV_POLY_TROPODELAY,
671     ULP_GNSS_SV_POLY_ELEVATION,
672     ULP_GNSS_SV_POLY_ELEVATIONDOT,
673     ULP_GNSS_SV_POLY_ELEVATIONUNC,
674     ULP_GNSS_SV_POLY_VELO_COEFF,
675     ULP_GNSS_SV_POLY_ENHANCED_IOD,
676 
677     ULP_GNSS_SV_POLY_VALID_FLAGS
678 
679 };
680 
681 #define ULP_GNSS_SV_POLY_BIT_GLO_FREQ               (1<<ULP_GNSS_SV_POLY_GLO_FREQ)
682 #define ULP_GNSS_SV_POLY_BIT_T0                     (1<<ULP_GNSS_SV_POLY_T0)
683 #define ULP_GNSS_SV_POLY_BIT_IODE                   (1<<ULP_GNSS_SV_POLY_IODE)
684 #define ULP_GNSS_SV_POLY_BIT_FLAG                   (1<<ULP_GNSS_SV_POLY_FLAG)
685 #define ULP_GNSS_SV_POLY_BIT_POLYCOEFF_XYZ0         (1<<ULP_GNSS_SV_POLY_POLYCOEFF_XYZ0)
686 #define ULP_GNSS_SV_POLY_BIT_POLYCOEFF_XYZN         (1<<ULP_GNSS_SV_POLY_POLYCOEFF_XYZN)
687 #define ULP_GNSS_SV_POLY_BIT_POLYCOEFF_OTHER        (1<<ULP_GNSS_SV_POLY_POLYCOEFF_OTHER)
688 #define ULP_GNSS_SV_POLY_BIT_SV_POSUNC              (1<<ULP_GNSS_SV_POLY_SV_POSUNC)
689 #define ULP_GNSS_SV_POLY_BIT_IONODELAY              (1<<ULP_GNSS_SV_POLY_IONODELAY)
690 #define ULP_GNSS_SV_POLY_BIT_IONODOT                (1<<ULP_GNSS_SV_POLY_IONODOT)
691 #define ULP_GNSS_SV_POLY_BIT_SBAS_IONODELAY         (1<<ULP_GNSS_SV_POLY_SBAS_IONODELAY)
692 #define ULP_GNSS_SV_POLY_BIT_SBAS_IONODOT           (1<<ULP_GNSS_SV_POLY_SBAS_IONODOT)
693 #define ULP_GNSS_SV_POLY_BIT_TROPODELAY             (1<<ULP_GNSS_SV_POLY_TROPODELAY)
694 #define ULP_GNSS_SV_POLY_BIT_ELEVATION              (1<<ULP_GNSS_SV_POLY_ELEVATION)
695 #define ULP_GNSS_SV_POLY_BIT_ELEVATIONDOT           (1<<ULP_GNSS_SV_POLY_ELEVATIONDOT)
696 #define ULP_GNSS_SV_POLY_BIT_ELEVATIONUNC           (1<<ULP_GNSS_SV_POLY_ELEVATIONUNC)
697 #define ULP_GNSS_SV_POLY_BIT_VELO_COEFF             (1<<ULP_GNSS_SV_POLY_VELO_COEFF)
698 #define ULP_GNSS_SV_POLY_BIT_ENHANCED_IOD           (1<<ULP_GNSS_SV_POLY_ENHANCED_IOD)
699 
700 
701 typedef enum
702 {
703     GNSS_LOC_SV_SYSTEM_GPS                    = 1,
704     /**< GPS satellite. */
705     GNSS_LOC_SV_SYSTEM_GALILEO                = 2,
706     /**< GALILEO satellite. */
707     GNSS_LOC_SV_SYSTEM_SBAS                   = 3,
708     /**< SBAS satellite. */
709     GNSS_LOC_SV_SYSTEM_COMPASS                = 4,
710     /**< COMPASS satellite. */
711     GNSS_LOC_SV_SYSTEM_GLONASS                = 5,
712     /**< GLONASS satellite. */
713     GNSS_LOC_SV_SYSTEM_BDS                    = 6,
714     /**< BDS satellite. */
715     GNSS_LOC_SV_SYSTEM_QZSS                   = 7
716     /**< QZSS satellite. */
717 } Gnss_LocSvSystemEnumType;
718 
719 typedef enum
720 {
721     GNSS_LOC_FREQ_SOURCE_INVALID = 0,
722     /**< Source of the frequency is invalid */
723     GNSS_LOC_FREQ_SOURCE_EXTERNAL = 1,
724     /**< Source of the frequency is from external injection */
725     GNSS_LOC_FREQ_SOURCE_PE_CLK_REPORT = 2,
726     /**< Source of the frequency is from Navigation engine */
727     GNSS_LOC_FREQ_SOURCE_UNKNOWN = 3
728     /**< Source of the frequency is unknown */
729 } Gnss_LocSourceofFreqEnumType;
730 
731 typedef struct
732 {
733     size_t                          size;
734     float                           clockDrift;
735     /**< Receiver clock Drift \n
736          - Units: meter per sec \n
737     */
738     float                           clockDriftUnc;
739     /**< Receiver clock Drift uncertainty \n
740          - Units: meter per sec \n
741     */
742     Gnss_LocSourceofFreqEnumType    sourceOfFreq;
743 }Gnss_LocRcvrClockFrequencyInfoStructType;
744 
745 typedef struct
746 {
747     size_t      size;
748     uint8_t     leapSec;
749     /**< GPS time leap second delta to UTC time  \n
750          - Units: sec \n
751        */
752     uint8_t     leapSecUnc;
753     /**< Uncertainty for GPS leap second \n
754          - Units: sec \n
755        */
756 }Gnss_LeapSecondInfoStructType;
757 
758 typedef enum
759 {
760    GNSS_LOC_SYS_TIME_BIAS_VALID                = 0x01,
761    /**< System time bias valid */
762    GNSS_LOC_SYS_TIME_BIAS_UNC_VALID            = 0x02,
763    /**< System time bias uncertainty valid */
764 }Gnss_LocInterSystemBiasValidMaskType;
765 
766 typedef struct
767 {
768     size_t          size;
769     uint32_t        validMask;
770     /* Validity mask as per Gnss_LocInterSystemBiasValidMaskType */
771 
772     float           timeBias;
773     /**< System-1 to System-2 Time Bias  \n
774         - Units: msec \n
775     */
776     float           timeBiasUnc;
777     /**< System-1 to System-2 Time Bias uncertainty  \n
778         - Units: msec \n
779     */
780 }Gnss_InterSystemBiasStructType;
781 
782 
783 typedef struct
784 {
785     size_t          size;
786     uint16_t        systemWeek;
787     /**< System week number for GPS, BDS and GAL satellite systems. \n
788          Set to 65535 when invalid or not available. \n
789          Not valid for GLONASS system. \n
790        */
791 
792     uint32_t        systemMsec;
793     /**< System time msec. Time of Week for GPS, BDS, GAL and
794          Time of Day for GLONASS.
795          - Units: msec \n
796       */
797     float           systemClkTimeBias;
798     /**< System clock time bias \n
799          - Units: msec \n
800          System time = systemMsec - systemClkTimeBias \n
801       */
802     float           systemClkTimeUncMs;
803     /**< Single sided maximum time bias uncertainty \n
804                                                     - Units: msec \n
805       */
806 }Gnss_LocSystemTimeStructType;
807 
808 typedef struct {
809 
810   size_t        size;
811   uint8_t       gloFourYear;
812   /**<   GLONASS four year number from 1996. Refer to GLONASS ICD.\n
813         Applicable only for GLONASS and shall be ignored for other constellations. \n
814         If unknown shall be set to 255
815         */
816 
817   uint16_t      gloDays;
818   /**<   GLONASS day number in four years. Refer to GLONASS ICD.
819         Applicable only for GLONASS and shall be ignored for other constellations. \n
820         If unknown shall be set to 65535
821         */
822 
823   uint32_t      gloMsec;
824   /**<   GLONASS time of day in msec. Refer to GLONASS ICD.
825             - Units: msec \n
826         */
827 
828   float         gloClkTimeBias;
829   /**<   System clock time bias (sub-millisecond) \n
830             - Units: msec \n
831         System time = systemMsec - systemClkTimeBias \n
832     */
833 
834   float         gloClkTimeUncMs;
835   /**<   Single sided maximum time bias uncertainty \n
836                 - Units: msec \n
837         */
838 }Gnss_LocGloTimeStructType;  /* Type */
839 
840 typedef struct {
841 
842   size_t    size;
843   uint32_t  refFCount;
844   /**<   Receiver frame counter value at reference tick */
845 
846   uint8_t   systemRtc_valid;
847   /**<   Validity indicator for System RTC */
848 
849   uint64_t  systemRtcMs;
850   /**<   Platform system RTC value \n
851         - Units: msec \n
852         */
853 
854   uint32_t  sourceOfTime;
855   /**<   Source of time information */
856 
857 }Gnss_LocGnssTimeExtStructType;
858 
859 
860 
861 typedef enum
862 {
863     GNSS_LOC_MEAS_STATUS_NULL                    = 0x00000000,
864     /**< No information state */
865     GNSS_LOC_MEAS_STATUS_SM_VALID                = 0x00000001,
866     /**< Code phase is known */
867     GNSS_LOC_MEAS_STATUS_SB_VALID                = 0x00000002,
868     /**< Sub-bit time is known */
869     GNSS_LOC_MEAS_STATUS_MS_VALID                = 0x00000004,
870     /**< Satellite time is known */
871     GNSS_LOC_MEAS_STATUS_BE_CONFIRM              = 0x00000008,
872     /**< Bit edge is confirmed from signal   */
873     GNSS_LOC_MEAS_STATUS_VELOCITY_VALID          = 0x00000010,
874     /**< Satellite Doppler measured */
875     GNSS_LOC_MEAS_STATUS_VELOCITY_FINE           = 0x00000020,
876     /**< TRUE: Fine Doppler measured, FALSE: Coarse Doppler measured */
877     GNSS_LOC_MEAS_STATUS_FROM_RNG_DIFF           = 0x00000200,
878     /**< Range update from Satellite differences */
879     GNSS_LOC_MEAS_STATUS_FROM_VE_DIFF            = 0x00000400,
880     /**< Doppler update from Satellite differences */
881     GNSS_LOC_MEAS_STATUS_DONT_USE_X              = 0x00000800,
882     /**< Don't use measurement if bit is set */
883     GNSS_LOC_MEAS_STATUS_DONT_USE_M              = 0x000001000,
884     /**< Don't use measurement if bit is set */
885     GNSS_LOC_MEAS_STATUS_DONT_USE_D              = 0x000002000,
886     /**< Don't use measurement if bit is set */
887     GNSS_LOC_MEAS_STATUS_DONT_USE_S              = 0x000004000,
888     /**< Don't use measurement if bit is set */
889     GNSS_LOC_MEAS_STATUS_DONT_USE_P              = 0x000008000
890     /**< Don't use measurement if bit is set */
891 }Gnss_LocSvMeasStatusMaskType;
892 
893 typedef struct
894 {
895     size_t              size;
896     uint32_t            svMs;
897     /**<  Satellite time milisecond.\n
898           For GPS, BDS, GAL range of 0 thru (604800000-1) \n
899           For GLONASS range of 0 thru (86400000-1) \n
900           Valid when PD_LOC_MEAS_STATUS_MS_VALID bit is set in measurement status \n
901           Note: All SV times in the current measurement block are alredy propagated to common reference time epoch. \n
902             - Units: msec \n
903        */
904     float               svSubMs;
905     /**<Satellite time sub-millisecond. \n
906         Total SV Time = svMs + svSubMs \n
907         - Units: msec \n
908        */
909     float               svTimeUncMs;
910     /**<  Satellite Time uncertainty \n
911           - Units: msec \n
912        */
913     float               dopplerShift;
914     /**< Satellite Doppler \n
915             - Units: meter per sec \n
916        */
917     float               dopplerShiftUnc;
918     /**< Satellite Doppler uncertainty\n
919             - Units: meter per sec \n
920        */
921 }Gnss_LocSVTimeSpeedStructType;
922 
923 typedef enum
924 {
925   GNSS_SV_STATE_IDLE = 0,
926   GNSS_SV_STATE_SEARCH = 1,
927   GNSS_SV_STATE_SEARCH_VERIFY = 2,
928   GNSS_SV_STATE_BIT_EDGE = 3,
929   GNSS_SV_STATE_VERIFY_TRACK = 4,
930   GNSS_SV_STATE_TRACK = 5,
931   GNSS_SV_STATE_RESTART = 6,
932   GNSS_SV_STATE_DPO_TRACK = 7
933 } Gnss_LocSVStateEnumType;
934 
935 typedef enum
936 {
937   GNSS_LOC_SVINFO_MASK_HAS_EPHEMERIS   = 0x01,
938   /**< Ephemeris is available for this SV */
939   GNSS_LOC_SVINFO_MASK_HAS_ALMANAC     = 0x02
940   /**< Almanac is available for this SV */
941 }Gnss_LocSvInfoMaskT;
942 
943 typedef enum
944 {
945   GNSS_LOC_SV_SRCH_STATUS_IDLE      = 1,
946     /**< SV is not being actively processed */
947   GNSS_LOC_SV_SRCH_STATUS_SEARCH    = 2,
948     /**< The system is searching for this SV */
949   GNSS_LOC_SV_SRCH_STATUS_TRACK     = 3
950     /**< SV is being tracked */
951 }Gnss_LocSvSearchStatusEnumT;
952 
953 
954 typedef struct
955 {
956     size_t                          size;
957     uint16_t                        gnssSvId;
958     /**< GNSS SV ID.
959          \begin{itemize1}
960          \item Range:  \begin{itemize1}
961            \item For GPS:      1 to 32
962            \item For GLONASS:  1 to 32
963            \item For SBAS:     120 to 151
964            \item For BDS:      201 to 237
965          \end{itemize1} \end{itemize1}
966         The GPS and GLONASS SVs can be disambiguated using the system field.
967     */
968     uint8_t                         gloFrequency;
969     /**< GLONASS frequency number + 7 \n
970          Valid only for GLONASS System \n
971          Shall be ignored for all other systems \n
972           - Range: 1 to 14 \n
973     */
974     Gnss_LocSvSearchStatusEnumT     svStatus;
975     /**< Satellite search state \n
976         @ENUM()
977     */
978     bool                         healthStatus_valid;
979     /**< SV Health Status validity flag\n
980         - 0: Not valid \n
981         - 1: Valid \n
982     */
983     uint8_t                         healthStatus;
984     /**< Health status.
985          \begin{itemize1}
986          \item    Range: 0 to 1; 0 = unhealthy, \n 1 = healthy, 2 = unknown
987          \vspace{-0.18in} \end{itemize1}
988     */
989     Gnss_LocSvInfoMaskT             svInfoMask;
990     /**< Indicates whether almanac and ephemeris information is available. \n
991         @MASK()
992     */
993     uint64_t                        measurementStatus;
994     /**< Bitmask indicating SV measurement status.
995         Valid bitmasks: \n
996         If any MSB bit in 0xFFC0000000000000 DONT_USE is set, the measurement
997         must not be used by the client.
998         @MASK()
999     */
1000     uint16_t                        CNo;
1001     /**< Carrier to Noise ratio  \n
1002         - Units: 0.1 dBHz \n
1003     */
1004     uint16_t                          gloRfLoss;
1005     /**< GLONASS Rf loss reference to Antenna. \n
1006          - Units: dB, Scale: 0.1 \n
1007     */
1008     bool                         lossOfLock;
1009     /**< Loss of signal lock indicator  \n
1010          - 0: Signal in continuous track \n
1011          - 1: Signal not in track \n
1012     */
1013     int16_t                         measLatency;
1014     /**< Age of the measurement. Positive value means measurement precedes ref time. \n
1015          - Units: msec \n
1016     */
1017     Gnss_LocSVTimeSpeedStructType   svTimeSpeed;
1018     /**< Unfiltered SV Time and Speed information
1019     */
1020     float                           dopplerAccel;
1021     /**< Satellite Doppler Accelertion\n
1022          - Units: Hz/s \n
1023     */
1024     bool                         multipathEstValid;
1025     /**< Multipath estimate validity flag\n
1026         - 0: Multipath estimate not valid \n
1027         - 1: Multipath estimate valid \n
1028     */
1029     float                           multipathEstimate;
1030     /**< Estimate of multipath in measurement\n
1031          - Units: Meters \n
1032     */
1033     bool                         fineSpeedValid;
1034     /**< Fine speed validity flag\n
1035          - 0: Fine speed not valid \n
1036          - 1: Fine speed valid \n
1037     */
1038     float                           fineSpeed;
1039     /**< Carrier phase derived speed \n
1040          - Units: m/s \n
1041     */
1042     bool                         fineSpeedUncValid;
1043     /**< Fine speed uncertainty validity flag\n
1044          - 0: Fine speed uncertainty not valid \n
1045          - 1: Fine speed uncertainty valid \n
1046     */
1047     float                           fineSpeedUnc;
1048     /**< Carrier phase derived speed \n
1049         - Units: m/s \n
1050     */
1051     bool                         carrierPhaseValid;
1052     /**< Carrier Phase measurement validity flag\n
1053          - 0: Carrier Phase not valid \n
1054          - 1: Carrier Phase valid \n
1055     */
1056     double                          carrierPhase;
1057     /**< Carrier phase measurement [L1 cycles] \n
1058     */
1059     bool                         cycleSlipCountValid;
1060      /**< Cycle slup count validity flag\n
1061          - 0: Not valid \n
1062          - 1: Valid \n
1063     */
1064     uint8_t                         cycleSlipCount;
1065     /**< Increments when a CSlip is detected */
1066 
1067     bool                         svDirectionValid;
1068     /**< Validity flag for SV direction */
1069 
1070     float                           svAzimuth;
1071     /**< Satellite Azimuth
1072         - Units: radians \n
1073     */
1074     float                           svElevation;
1075     /**< Satellite Elevation
1076         - Units: radians \n
1077     */
1078 } Gnss_SVMeasurementStructType;
1079 
1080 /**< Maximum number of satellites in measurement block for given system. */
1081 
1082 typedef struct
1083 {
1084     size_t                          size;
1085     Gnss_LocSvSystemEnumType        system;
1086     /**< Specifies the Satellite System Type
1087     */
1088     bool                            isSystemTimeValid;
1089     /**< Indicates whether System Time is Valid:\n
1090          - 0x01 (TRUE) --  System Time is valid \n
1091          - 0x00 (FALSE) -- System Time is not valid
1092     */
1093     Gnss_LocSystemTimeStructType    systemTime;
1094     /**< System Time Information \n
1095     */
1096     bool                            isGloTime_valid;
1097     Gnss_LocGloTimeStructType       gloTime;
1098 
1099     bool                            isSystemTimeExt_valid;
1100     Gnss_LocGnssTimeExtStructType   systemTimeExt;
1101 
1102     uint8_t                         numSvs;
1103     /* Number of SVs in this report block */
1104 
1105     Gnss_SVMeasurementStructType    svMeasurement[GNSS_LOC_SV_MEAS_LIST_MAX_SIZE];
1106     /**< Satellite measurement Information \n
1107     */
1108 } Gnss_ClockMeasurementStructType;
1109 
1110 
1111 typedef struct
1112 {
1113     size_t                                      size;
1114     uint8_t                                     seqNum;
1115     /**< Current message Number */
1116     uint8_t                                     maxMessageNum;
1117     /**< Maximum number of message that will be sent for present time epoch. */
1118 
1119     bool                                     leapSecValid;
1120     Gnss_LeapSecondInfoStructType               leapSec;
1121 
1122     Gnss_InterSystemBiasStructType              gpsGloInterSystemBias;
1123 
1124     Gnss_InterSystemBiasStructType              gpsBdsInterSystemBias;
1125 
1126     Gnss_InterSystemBiasStructType              gpsGalInterSystemBias;
1127 
1128     Gnss_InterSystemBiasStructType              bdsGloInterSystemBias;
1129 
1130     Gnss_InterSystemBiasStructType              galGloInterSystemBias;
1131 
1132     Gnss_InterSystemBiasStructType              galBdsInterSystemBias;
1133 
1134     bool                                     clockFreqValid;
1135     Gnss_LocRcvrClockFrequencyInfoStructType    clockFreq;   /* Freq */
1136     bool                                     gnssMeasValid;
1137     Gnss_ClockMeasurementStructType             gnssMeas;
1138     Gnss_ApTimeStampStructType               timeStamp;
1139 
1140 } GnssSvMeasurementSet;
1141 
1142 typedef enum
1143 {
1144    GNSS_SV_POLY_COEFF_VALID             = 0x01,
1145    /**< SV position in orbit coefficients are valid */
1146    GNSS_SV_POLY_IONO_VALID              = 0x02,
1147    /**< Iono estimates are valid */
1148 
1149    GNSS_SV_POLY_TROPO_VALID             = 0x04,
1150    /**< Tropo estimates are valid */
1151 
1152    GNSS_SV_POLY_ELEV_VALID              = 0x08,
1153    /**< Elevation, rate, uncertainty are valid */
1154 
1155    GNSS_SV_POLY_SRC_ALM_CORR            = 0x10,
1156    /**< Polynomials based on XTRA */
1157 
1158    GNSS_SV_POLY_SBAS_IONO_VALID         = 0x20,
1159    /**< SBAS IONO and rate are valid */
1160 
1161    GNSS_SV_POLY_GLO_STR4                = 0x40
1162    /**< GLONASS String 4 has been received */
1163 }Gnss_SvPolyStatusMaskType;
1164 
1165 
1166 typedef struct
1167 {
1168     size_t      size;
1169     uint16_t     gnssSvId;
1170     /* GPS: 1-32, GLO: 65-96, 0: Invalid,
1171        SBAS: 120-151, BDS:201-237,GAL:301 to 336
1172        All others are reserved
1173     */
1174     int8_t      freqNum;
1175     /* Freq index, only valid if u_SysInd is GLO */
1176 
1177     uint8_t     svPolyFlags;
1178     /* Indicate the validity of the elements
1179     as per Gnss_SvPolyStatusMaskType
1180     */
1181 
1182     uint32_t    is_valid;
1183 
1184     uint16_t     iode;
1185     /* Ephemeris reference time
1186        GPS:Issue of Data Ephemeris used [unitless].
1187        GLO: Tb 7-bit, refer to ICD02
1188     */
1189     double      T0;
1190     /* Reference time for polynominal calculations
1191        GPS: Secs in week.
1192        GLO: Full secs since Jan/01/96
1193     */
1194     double      polyCoeffXYZ0[GNSS_SV_POLY_XYZ_0_TH_ORDER_COEFF_MAX_SIZE];
1195     /* C0X, C0Y, C0Z */
1196     double      polyCoefXYZN[GNSS_SV_POLY_XYZ_N_TH_ORDER_COEFF_MAX_SIZE];
1197     /* C1X, C2X ... C2Z, C3Z */
1198     float       polyCoefOther[GNSS_SV_POLY_SV_CLKBIAS_COEFF_MAX_SIZE];
1199     /* C0T, C1T, C2T, C3T */
1200     float       svPosUnc;       /* SV position uncertainty [m]. */
1201     float       ionoDelay;    /* Ionospheric delay at d_T0 [m]. */
1202     float       ionoDot;      /* Iono delay rate [m/s].  */
1203     float       sbasIonoDelay;/* SBAS Ionospheric delay at d_T0 [m]. */
1204     float       sbasIonoDot;  /* SBAS Iono delay rate [m/s].  */
1205     float       tropoDelay;   /* Tropospheric delay [m]. */
1206     float       elevation;    /* Elevation [rad] at d_T0 */
1207     float       elevationDot;      /* Elevation rate [rad/s] */
1208     float       elevationUnc;      /* SV elevation [rad] uncertainty */
1209     double      velCoef[GNSS_SV_POLY_VELOCITY_COEF_MAX_SIZE];
1210     /* Coefficients of velocity poly */
1211     uint32_t    enhancedIOD;    /*  Enhanced Reference Time */
1212 } GnssSvPolynomial;
1213 
1214 /* Various Short Range Node Technology type*/
1215 typedef enum {
1216     SRN_AP_DATA_TECH_TYPE_NONE,
1217     SRN_AP_DATA_TECH_TYPE_BT,
1218     SRN_AP_DATA_TECH_TYPE_BTLE,
1219     SRN_AP_DATA_TECH_TYPE_NFC,
1220     SRN_AP_DATA_TECH_TYPE_MOBILE_CODE,
1221     SRN_AP_DATA_TECH_TYPE_OTHER
1222 } Gnss_SrnTech;
1223 
1224 /* Mac Address type requested by modem */
1225 typedef enum {
1226     SRN_AP_DATA_PUBLIC_MAC_ADDR_TYPE_INVALID, /* No valid mac address type send */
1227     SRN_AP_DATA_PUBLIC_MAC_ADDR_TYPE_PUBLIC, /* SRN AP MAC Address type PUBLIC  */
1228     SRN_AP_DATA_PUBLIC_MAC_ADDR_TYPE_PRIVATE, /* SRN AP MAC Address type PRIVATE  */
1229     SRN_AP_DATA_PUBLIC_MAC_ADDR_TYPE_OTHER, /* SRN AP MAC Address type OTHER  */
1230 }Gnss_Srn_MacAddr_Type;
1231 
1232 typedef struct
1233 {
1234     size_t                 size;
1235     Gnss_SrnTech           srnTechType; /* SRN Technology type in request */
1236     bool                   srnRequest; /* scan - start(true) or stop(false) */
1237     bool                   e911Mode; /* If in E911 emergency */
1238     Gnss_Srn_MacAddr_Type  macAddrType; /* SRN AP MAC Address type */
1239 } GnssSrnDataReq;
1240 
1241 
1242 #ifdef __cplusplus
1243 }
1244 #endif /* __cplusplus */
1245 
1246 #endif /* GPS_EXTENDED_C_H */
1247