1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LOC_GPS_H
18 #define LOC_GPS_H
19 
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 #include <sys/types.h>
23 #include <pthread.h>
24 #include <sys/socket.h>
25 #include <stdbool.h>
26 
27 __BEGIN_DECLS
28 
29 #define LOC_FLP_STATUS_LOCATION_AVAILABLE         0
30 #define LOC_FLP_STATUS_LOCATION_UNAVAILABLE       1
31 #define LOC_CAPABILITY_GNSS         (1U<<0)
32 #define LOC_CAPABILITY_WIFI         (1U<<1)
33 #define LOC_CAPABILITY_CELL         (1U<<3)
34 
35 /** Milliseconds since January 1, 1970 */
36 typedef int64_t LocGpsUtcTime;
37 
38 /** Maximum number of SVs for loc_gps_sv_status_callback(). */
39 #define LOC_GPS_MAX_SVS 32
40 /** Maximum number of SVs for loc_gps_sv_status_callback(). */
41 #define LOC_GNSS_MAX_SVS 64
42 
43 /** Maximum number of Measurements in loc_gps_measurement_callback(). */
44 #define LOC_GPS_MAX_MEASUREMENT   32
45 
46 /** Maximum number of Measurements in loc_gnss_measurement_callback(). */
47 #define LOC_GNSS_MAX_MEASUREMENT   64
48 
49 /** Requested operational mode for GPS operation. */
50 typedef uint32_t LocGpsPositionMode;
51 /* IMPORTANT: Note that the following values must match
52  * constants in GpsLocationProvider.java. */
53 /** Mode for running GPS standalone (no assistance). */
54 #define LOC_GPS_POSITION_MODE_STANDALONE    0
55 /** AGPS MS-Based mode. */
56 #define LOC_GPS_POSITION_MODE_MS_BASED      1
57 /**
58  * AGPS MS-Assisted mode. This mode is not maintained by the platform anymore.
59  * It is strongly recommended to use LOC_GPS_POSITION_MODE_MS_BASED instead.
60  */
61 #define LOC_GPS_POSITION_MODE_MS_ASSISTED   2
62 
63 /** Requested recurrence mode for GPS operation. */
64 typedef uint32_t LocGpsPositionRecurrence;
65 /* IMPORTANT: Note that the following values must match
66  * constants in GpsLocationProvider.java. */
67 /** Receive GPS fixes on a recurring basis at a specified period. */
68 #define LOC_GPS_POSITION_RECURRENCE_PERIODIC    0
69 /** Request a single shot GPS fix. */
70 #define LOC_GPS_POSITION_RECURRENCE_SINGLE      1
71 
72 /** GPS status event values. */
73 typedef uint16_t LocGpsStatusValue;
74 /* IMPORTANT: Note that the following values must match
75  * constants in GpsLocationProvider.java. */
76 /** GPS status unknown. */
77 #define LOC_GPS_STATUS_NONE             0
78 /** GPS has begun navigating. */
79 #define LOC_GPS_STATUS_SESSION_BEGIN    1
80 /** GPS has stopped navigating. */
81 #define LOC_GPS_STATUS_SESSION_END      2
82 /** GPS has powered on but is not navigating. */
83 #define LOC_GPS_STATUS_ENGINE_ON        3
84 /** GPS is powered off. */
85 #define LOC_GPS_STATUS_ENGINE_OFF       4
86 
87 /** Flags to indicate which values are valid in a LocGpsLocation. */
88 typedef uint16_t LocGpsLocationFlags;
89 /* IMPORTANT: Note that the following values must match
90  * constants in GpsLocationProvider.java. */
91 /** LocGpsLocation has valid latitude and longitude. */
92 #define LOC_GPS_LOCATION_HAS_LAT_LONG   0x0001
93 /** LocGpsLocation has valid altitude. */
94 #define LOC_GPS_LOCATION_HAS_ALTITUDE   0x0002
95 /** LocGpsLocation has valid speed. */
96 #define LOC_GPS_LOCATION_HAS_SPEED      0x0004
97 /** LocGpsLocation has valid bearing. */
98 #define LOC_GPS_LOCATION_HAS_BEARING    0x0008
99 /** LocGpsLocation has valid accuracy. */
100 #define LOC_GPS_LOCATION_HAS_ACCURACY   0x0010
101 /** LocGpsLocation has valid vertical uncertainity */
102 #define LOC_GPS_LOCATION_HAS_VERT_UNCERTAINITY   0x0040
103 /** LocGpsLocation has valid spoof mask */
104 #define LOC_GPS_LOCATION_HAS_SPOOF_MASK   0x0080
105 /** LocGpsLocation has valid speed accuracy */
106 #define LOC_GPS_LOCATION_HAS_SPEED_ACCURACY   0x0100
107 /** LocGpsLocation has valid bearing accuracy */
108 #define LOC_GPS_LOCATION_HAS_BEARING_ACCURACY 0x0200
109 
110 /** Spoof mask in LocGpsLocation */
111 typedef uint32_t LocGpsSpoofMask;
112 #define LOC_GPS_LOCATION_NONE_SPOOFED            0x0000
113 #define LOC_GPS_LOCATION_POSITION_SPOOFED        0x0001
114 #define LOC_GPS_LOCATION_TIME_SPOOFED            0x0002
115 #define LOC_GPS_LOCATION_NAVIGATION_DATA_SPOOFED 0x0004
116 
117 /** Flags for the loc_gps_set_capabilities callback. */
118 
119 /**
120  * GPS HAL schedules fixes for LOC_GPS_POSITION_RECURRENCE_PERIODIC mode. If this is
121  * not set, then the framework will use 1000ms for min_interval and will start
122  * and call start() and stop() to schedule the GPS.
123  */
124 #define LOC_GPS_CAPABILITY_SCHEDULING       (1 << 0)
125 /** GPS supports MS-Based AGPS mode */
126 #define LOC_GPS_CAPABILITY_MSB              (1 << 1)
127 /** GPS supports MS-Assisted AGPS mode */
128 #define LOC_GPS_CAPABILITY_MSA              (1 << 2)
129 /** GPS supports single-shot fixes */
130 #define LOC_GPS_CAPABILITY_SINGLE_SHOT      (1 << 3)
131 /** GPS supports on demand time injection */
132 #define LOC_GPS_CAPABILITY_ON_DEMAND_TIME   (1 << 4)
133 /** GPS supports Geofencing  */
134 #define LOC_GPS_CAPABILITY_GEOFENCING       (1 << 5)
135 /** GPS supports Measurements. */
136 #define LOC_GPS_CAPABILITY_MEASUREMENTS     (1 << 6)
137 /** GPS supports Navigation Messages */
138 #define LOC_GPS_CAPABILITY_NAV_MESSAGES     (1 << 7)
139 
140 /**
141  * Flags used to specify which aiding data to delete when calling
142  * delete_aiding_data().
143  */
144 typedef uint16_t LocGpsAidingData;
145 /* IMPORTANT: Note that the following values must match
146  * constants in GpsLocationProvider.java. */
147 #define LOC_GPS_DELETE_EPHEMERIS        0x0001
148 #define LOC_GPS_DELETE_ALMANAC          0x0002
149 #define LOC_GPS_DELETE_POSITION         0x0004
150 #define LOC_GPS_DELETE_TIME             0x0008
151 #define LOC_GPS_DELETE_IONO             0x0010
152 #define LOC_GPS_DELETE_UTC              0x0020
153 #define LOC_GPS_DELETE_HEALTH           0x0040
154 #define LOC_GPS_DELETE_SVDIR            0x0080
155 #define LOC_GPS_DELETE_SVSTEER          0x0100
156 #define LOC_GPS_DELETE_SADATA           0x0200
157 #define LOC_GPS_DELETE_RTI              0x0400
158 #define LOC_GPS_DELETE_MB_DATA          0x0800
159 #define LOC_GPS_DELETE_CELLDB_INFO      0x8000
160 #define LOC_GPS_DELETE_ALL              0xFFFF
161 
162 /** AGPS type */
163 typedef uint16_t LocAGpsType;
164 #define LOC_AGPS_TYPE_ANY           0
165 #define LOC_AGPS_TYPE_SUPL          1
166 #define LOC_AGPS_TYPE_C2K           2
167 #define LOC_AGPS_TYPE_WWAN_ANY      3
168 #define LOC_AGPS_TYPE_WIFI          4
169 #define LOC_AGPS_TYPE_SUPL_ES       5
170 
171 typedef uint16_t LocAGpsSetIDType;
172 #define LOC_AGPS_SETID_TYPE_NONE    0
173 #define LOC_AGPS_SETID_TYPE_IMSI    1
174 #define LOC_AGPS_SETID_TYPE_MSISDN  2
175 
176 typedef uint16_t LocApnIpType;
177 #define LOC_APN_IP_INVALID          0
178 #define LOC_APN_IP_IPV4             1
179 #define LOC_APN_IP_IPV6             2
180 #define LOC_APN_IP_IPV4V6           3
181 
182 /**
183  * String length constants
184  */
185 #define LOC_GPS_NI_SHORT_STRING_MAXLEN      256
186 #define LOC_GPS_NI_LONG_STRING_MAXLEN       2048
187 
188 /**
189  * LocGpsNiType constants
190  */
191 typedef uint32_t LocGpsNiType;
192 #define LOC_GPS_NI_TYPE_VOICE              1
193 #define LOC_GPS_NI_TYPE_UMTS_SUPL          2
194 #define LOC_GPS_NI_TYPE_UMTS_CTRL_PLANE    3
195 /*Emergency SUPL*/
196 #define LOC_GPS_NI_TYPE_EMERGENCY_SUPL     4
197 
198 /**
199  * LocGpsNiNotifyFlags constants
200  */
201 typedef uint32_t LocGpsNiNotifyFlags;
202 /** NI requires notification */
203 #define LOC_GPS_NI_NEED_NOTIFY          0x0001
204 /** NI requires verification */
205 #define LOC_GPS_NI_NEED_VERIFY          0x0002
206 /** NI requires privacy override, no notification/minimal trace */
207 #define LOC_GPS_NI_PRIVACY_OVERRIDE     0x0004
208 
209 /**
210  * GPS NI responses, used to define the response in
211  * NI structures
212  */
213 typedef int LocGpsUserResponseType;
214 #define LOC_GPS_NI_RESPONSE_ACCEPT         1
215 #define LOC_GPS_NI_RESPONSE_DENY           2
216 #define LOC_GPS_NI_RESPONSE_NORESP         3
217 
218 /**
219  * NI data encoding scheme
220  */
221 typedef int LocGpsNiEncodingType;
222 #define LOC_GPS_ENC_NONE                   0
223 #define LOC_GPS_ENC_SUPL_GSM_DEFAULT       1
224 #define LOC_GPS_ENC_SUPL_UTF8              2
225 #define LOC_GPS_ENC_SUPL_UCS2              3
226 #define LOC_GPS_ENC_UNKNOWN                -1
227 
228 /** AGPS status event values. */
229 typedef uint8_t LocAGpsStatusValue;
230 /** GPS requests data connection for AGPS. */
231 #define LOC_GPS_REQUEST_AGPS_DATA_CONN  1
232 /** GPS releases the AGPS data connection. */
233 #define LOC_GPS_RELEASE_AGPS_DATA_CONN  2
234 /** AGPS data connection initiated */
235 #define LOC_GPS_AGPS_DATA_CONNECTED     3
236 /** AGPS data connection completed */
237 #define LOC_GPS_AGPS_DATA_CONN_DONE     4
238 /** AGPS data connection failed */
239 #define LOC_GPS_AGPS_DATA_CONN_FAILED   5
240 
241 typedef uint16_t LocAGpsRefLocationType;
242 #define LOC_AGPS_REF_LOCATION_TYPE_GSM_CELLID   1
243 #define LOC_AGPS_REF_LOCATION_TYPE_UMTS_CELLID  2
244 #define LOC_AGPS_REF_LOCATION_TYPE_MAC          3
245 #define LOC_AGPS_REF_LOCATION_TYPE_LTE_CELLID   4
246 
247 /* Deprecated, to be removed in the next Android release. */
248 #define LOC_AGPS_REG_LOCATION_TYPE_MAC          3
249 
250 /** Network types for update_network_state "type" parameter */
251 #define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE        0
252 #define LOC_AGPS_RIL_NETWORK_TYPE_WIFI          1
253 #define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE_MMS    2
254 #define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL   3
255 #define LOC_AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN   4
256 #define LOC_AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
257 #define LOC_AGPS_RIL_NETWORK_TTYPE_WIMAX        6
258 
259 /* The following typedef together with its constants below are deprecated, and
260  * will be removed in the next release. */
261 typedef uint16_t LocGpsClockFlags;
262 #define LOC_GPS_CLOCK_HAS_LEAP_SECOND               (1<<0)
263 #define LOC_GPS_CLOCK_HAS_TIME_UNCERTAINTY          (1<<1)
264 #define LOC_GPS_CLOCK_HAS_FULL_BIAS                 (1<<2)
265 #define LOC_GPS_CLOCK_HAS_BIAS                      (1<<3)
266 #define LOC_GPS_CLOCK_HAS_BIAS_UNCERTAINTY          (1<<4)
267 #define LOC_GPS_CLOCK_HAS_DRIFT                     (1<<5)
268 #define LOC_GPS_CLOCK_HAS_DRIFT_UNCERTAINTY         (1<<6)
269 
270 /**
271  * Flags to indicate what fields in LocGnssClock are valid.
272  */
273 typedef uint16_t LocGnssClockFlags;
274 /** A valid 'leap second' is stored in the data structure. */
275 #define LOC_GNSS_CLOCK_HAS_LEAP_SECOND               (1<<0)
276 /** A valid 'time uncertainty' is stored in the data structure. */
277 #define LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY          (1<<1)
278 /** A valid 'full bias' is stored in the data structure. */
279 #define LOC_GNSS_CLOCK_HAS_FULL_BIAS                 (1<<2)
280 /** A valid 'bias' is stored in the data structure. */
281 #define LOC_GNSS_CLOCK_HAS_BIAS                      (1<<3)
282 /** A valid 'bias uncertainty' is stored in the data structure. */
283 #define LOC_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY          (1<<4)
284 /** A valid 'drift' is stored in the data structure. */
285 #define LOC_GNSS_CLOCK_HAS_DRIFT                     (1<<5)
286 /** A valid 'drift uncertainty' is stored in the data structure. */
287 #define LOC_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY         (1<<6)
288 
289 /* The following typedef together with its constants below are deprecated, and
290  * will be removed in the next release. */
291 typedef uint8_t LocGpsClockType;
292 #define LOC_GPS_CLOCK_TYPE_UNKNOWN                  0
293 #define LOC_GPS_CLOCK_TYPE_LOCAL_HW_TIME            1
294 #define LOC_GPS_CLOCK_TYPE_GPS_TIME                 2
295 
296 /* The following typedef together with its constants below are deprecated, and
297  * will be removed in the next release. */
298 typedef uint32_t LocGpsMeasurementFlags;
299 #define LOC_GPS_MEASUREMENT_HAS_SNR                               (1<<0)
300 #define LOC_GPS_MEASUREMENT_HAS_ELEVATION                         (1<<1)
301 #define LOC_GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY             (1<<2)
302 #define LOC_GPS_MEASUREMENT_HAS_AZIMUTH                           (1<<3)
303 #define LOC_GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY               (1<<4)
304 #define LOC_GPS_MEASUREMENT_HAS_PSEUDORANGE                       (1<<5)
305 #define LOC_GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY           (1<<6)
306 #define LOC_GPS_MEASUREMENT_HAS_CODE_PHASE                        (1<<7)
307 #define LOC_GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY            (1<<8)
308 #define LOC_GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY                 (1<<9)
309 #define LOC_GPS_MEASUREMENT_HAS_CARRIER_CYCLES                    (1<<10)
310 #define LOC_GPS_MEASUREMENT_HAS_CARRIER_PHASE                     (1<<11)
311 #define LOC_GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY         (1<<12)
312 #define LOC_GPS_MEASUREMENT_HAS_BIT_NUMBER                        (1<<13)
313 #define LOC_GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT                (1<<14)
314 #define LOC_GPS_MEASUREMENT_HAS_DOPPLER_SHIFT                     (1<<15)
315 #define LOC_GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY         (1<<16)
316 #define LOC_GPS_MEASUREMENT_HAS_USED_IN_FIX                       (1<<17)
317 #define LOC_GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE      (1<<18)
318 
319 /**
320  * Flags to indicate what fields in LocGnssMeasurement are valid.
321  */
322 typedef uint32_t LocGnssMeasurementFlags;
323 /** A valid 'snr' is stored in the data structure. */
324 #define LOC_GNSS_MEASUREMENT_HAS_SNR                               (1<<0)
325 /** A valid 'carrier frequency' is stored in the data structure. */
326 #define LOC_GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY                 (1<<9)
327 /** A valid 'carrier cycles' is stored in the data structure. */
328 #define LOC_GNSS_MEASUREMENT_HAS_CARRIER_CYCLES                    (1<<10)
329 /** A valid 'carrier phase' is stored in the data structure. */
330 #define LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE                     (1<<11)
331 /** A valid 'carrier phase uncertainty' is stored in the data structure. */
332 #define LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY         (1<<12)
333 
334 /* The following typedef together with its constants below are deprecated, and
335  * will be removed in the next release. */
336 typedef uint8_t LocGpsLossOfLock;
337 #define LOC_GPS_LOSS_OF_LOCK_UNKNOWN                            0
338 #define LOC_GPS_LOSS_OF_LOCK_OK                                 1
339 #define LOC_GPS_LOSS_OF_LOCK_CYCLE_SLIP                         2
340 
341 /* The following typedef together with its constants below are deprecated, and
342  * will be removed in the next release. Use LocGnssMultipathIndicator instead.
343  */
344 typedef uint8_t LocGpsMultipathIndicator;
345 #define LOC_GPS_MULTIPATH_INDICATOR_UNKNOWN                 0
346 #define LOC_GPS_MULTIPATH_INDICATOR_DETECTED                1
347 #define LOC_GPS_MULTIPATH_INDICATOR_NOT_USED                2
348 
349 /**
350  * Enumeration of available values for the GNSS Measurement's multipath
351  * indicator.
352  */
353 typedef uint8_t LocGnssMultipathIndicator;
354 /** The indicator is not available or unknown. */
355 #define LOC_GNSS_MULTIPATH_INDICATOR_UNKNOWN                 0
356 /** The measurement is indicated to be affected by multipath. */
357 #define LOC_GNSS_MULTIPATH_INDICATOR_PRESENT                 1
358 /** The measurement is indicated to be not affected by multipath. */
359 #define LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT             2
360 
361 /* The following typedef together with its constants below are deprecated, and
362  * will be removed in the next release. */
363 typedef uint16_t LocGpsMeasurementState;
364 #define LOC_GPS_MEASUREMENT_STATE_UNKNOWN                   0
365 #define LOC_GPS_MEASUREMENT_STATE_CODE_LOCK             (1<<0)
366 #define LOC_GPS_MEASUREMENT_STATE_BIT_SYNC              (1<<1)
367 #define LOC_GPS_MEASUREMENT_STATE_SUBFRAME_SYNC         (1<<2)
368 #define LOC_GPS_MEASUREMENT_STATE_TOW_DECODED           (1<<3)
369 #define LOC_GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS        (1<<4)
370 
371 /**
372  * Flags indicating the GNSS measurement state.
373  *
374  * The expected behavior here is for GPS HAL to set all the flags that applies.
375  * For example, if the state for a satellite is only C/A code locked and bit
376  * synchronized, and there is still millisecond ambiguity, the state should be
377  * set as:
378  *
379  * LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK | LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC |
380  *         LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS
381  *
382  * If GNSS is still searching for a satellite, the corresponding state should be
383  * set to LOC_GNSS_MEASUREMENT_STATE_UNKNOWN(0).
384  */
385 typedef uint32_t LocGnssMeasurementState;
386 #define LOC_GNSS_MEASUREMENT_STATE_UNKNOWN                   0
387 #define LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK             (1<<0)
388 #define LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC              (1<<1)
389 #define LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC         (1<<2)
390 #define LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED           (1<<3)
391 #define LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS        (1<<4)
392 #define LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC           (1<<5)
393 #define LOC_GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC       (1<<6)
394 #define LOC_GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED       (1<<7)
395 #define LOC_GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC       (1<<8)
396 #define LOC_GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC  (1<<9)
397 #define LOC_GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK    (1<<10)
398 #define LOC_GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK (1<<11)
399 #define LOC_GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC     (1<<12)
400 #define LOC_GNSS_MEASUREMENT_STATE_SBAS_SYNC             (1<<13)
401 
402 /* The following typedef together with its constants below are deprecated, and
403  * will be removed in the next release. */
404 typedef uint16_t LocGpsAccumulatedDeltaRangeState;
405 #define LOC_GPS_ADR_STATE_UNKNOWN                       0
406 #define LOC_GPS_ADR_STATE_VALID                     (1<<0)
407 #define LOC_GPS_ADR_STATE_RESET                     (1<<1)
408 #define LOC_GPS_ADR_STATE_CYCLE_SLIP                (1<<2)
409 
410 /**
411  * Flags indicating the Accumulated Delta Range's states.
412  */
413 typedef uint16_t LocGnssAccumulatedDeltaRangeState;
414 #define LOC_GNSS_ADR_STATE_UNKNOWN                       0
415 #define LOC_GNSS_ADR_STATE_VALID                     (1<<0)
416 #define LOC_GNSS_ADR_STATE_RESET                     (1<<1)
417 #define LOC_GNSS_ADR_STATE_CYCLE_SLIP                (1<<2)
418 
419 #if 0
420 /* The following typedef together with its constants below are deprecated, and
421  * will be removed in the next release. */
422 typedef uint8_t GpsNavigationMessageType;
423 #define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN         0
424 #define GPS_NAVIGATION_MESSAGE_TYPE_L1CA            1
425 #define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV          2
426 #define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV          3
427 #define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2           4
428 
429 /**
430  * Enumeration of available values to indicate the GNSS Navigation message
431  * types.
432  *
433  * For convenience, first byte is the LocGnssConstellationType on which that signal
434  * is typically transmitted
435  */
436 typedef int16_t GnssNavigationMessageType;
437 
438 #define GNSS_NAVIGATION_MESSAGE_TYPE_UNKNOWN       0
439 /** GPS L1 C/A message contained in the structure.  */
440 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L1CA      0x0101
441 /** GPS L2-CNAV message contained in the structure. */
442 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L2CNAV    0x0102
443 /** GPS L5-CNAV message contained in the structure. */
444 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L5CNAV    0x0103
445 /** GPS CNAV-2 message contained in the structure. */
446 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_CNAV2     0x0104
447 /** Glonass L1 CA message contained in the structure. */
448 #define GNSS_NAVIGATION_MESSAGE_TYPE_GLO_L1CA      0x0301
449 /** Beidou D1 message contained in the structure. */
450 #define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D1        0x0501
451 /** Beidou D2 message contained in the structure. */
452 #define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D2        0x0502
453 /** Galileo I/NAV message contained in the structure. */
454 #define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_I         0x0601
455 /** Galileo F/NAV message contained in the structure. */
456 #define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_F         0x0602
457 
458 /**
459  * Status of Navigation Message
460  * When a message is received properly without any parity error in its navigation words, the
461  * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received
462  * with words that failed parity check, but GPS is able to correct those words, the status
463  * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT.
464  * No need to send any navigation message that contains words with parity error and cannot be
465  * corrected.
466  */
467 typedef uint16_t NavigationMessageStatus;
468 #define NAV_MESSAGE_STATUS_UNKNOWN              0
469 #define NAV_MESSAGE_STATUS_PARITY_PASSED   (1<<0)
470 #define NAV_MESSAGE_STATUS_PARITY_REBUILT  (1<<1)
471 
472 /* This constant is deprecated, and will be removed in the next release. */
473 #define NAV_MESSAGE_STATUS_UNKONW              0
474 #endif
475 
476 /**
477  * Flags that indicate information about the satellite
478  */
479 typedef uint8_t                                 LocGnssSvFlags;
480 #define LOC_GNSS_SV_FLAGS_NONE                      0
481 #define LOC_GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA        (1 << 0)
482 #define LOC_GNSS_SV_FLAGS_HAS_ALMANAC_DATA          (1 << 1)
483 #define LOC_GNSS_SV_FLAGS_USED_IN_FIX               (1 << 2)
484 
485 /**
486  * Constellation type of LocGnssSvInfo
487  */
488 typedef uint8_t                         LocGnssConstellationType;
489 #define LOC_GNSS_CONSTELLATION_UNKNOWN      0
490 #define LOC_GNSS_CONSTELLATION_GPS          1
491 #define LOC_GNSS_CONSTELLATION_SBAS         2
492 #define LOC_GNSS_CONSTELLATION_GLONASS      3
493 #define LOC_GNSS_CONSTELLATION_QZSS         4
494 #define LOC_GNSS_CONSTELLATION_BEIDOU       5
495 #define LOC_GNSS_CONSTELLATION_GALILEO      6
496 
497 /**
498  * Name for the GPS XTRA interface.
499  */
500 #define LOC_GPS_XTRA_INTERFACE      "gps-xtra"
501 
502 /**
503  * Name for the GPS DEBUG interface.
504  */
505 #define LOC_GPS_DEBUG_INTERFACE      "gps-debug"
506 
507 /**
508  * Name for the AGPS interface.
509  */
510 
511 #define LOC_AGPS_INTERFACE      "agps"
512 
513 /**
514  * Name of the Supl Certificate interface.
515  */
516 #define LOC_SUPL_CERTIFICATE_INTERFACE  "supl-certificate"
517 
518 /**
519  * Name for NI interface
520  */
521 #define LOC_GPS_NI_INTERFACE "gps-ni"
522 
523 /**
524  * Name for the AGPS-RIL interface.
525  */
526 #define LOC_AGPS_RIL_INTERFACE      "agps_ril"
527 
528 /**
529  * Name for the GPS_Geofencing interface.
530  */
531 #define LOC_GPS_GEOFENCING_INTERFACE   "gps_geofencing"
532 
533 /**
534  * Name of the GPS Measurements interface.
535  */
536 #define LOC_GPS_MEASUREMENT_INTERFACE   "gps_measurement"
537 
538 /**
539  * Name of the GPS navigation message interface.
540  */
541 #define LOC_GPS_NAVIGATION_MESSAGE_INTERFACE     "gps_navigation_message"
542 
543 /**
544  * Name of the GNSS/GPS configuration interface.
545  */
546 #define LOC_GNSS_CONFIGURATION_INTERFACE     "gnss_configuration"
547 
548 /** Represents a location. */
549 typedef struct {
550     /** set to sizeof(LocGpsLocation) */
551     uint32_t        size;
552     /** Contains LocGpsLocationFlags bits. */
553     uint16_t        flags;
554     /** The spoof mask */
555     LocGpsSpoofMask spoof_mask;
556     /** Represents latitude in degrees. */
557     double          latitude;
558     /** Represents longitude in degrees. */
559     double          longitude;
560     /**
561      * Represents altitude in meters above the WGS 84 reference ellipsoid.
562      */
563     double          altitude;
564     /** Represents horizontal speed in meters per second. */
565     float           speed;
566     /** Represents heading in degrees. */
567     float           bearing;
568     /** Represents expected accuracy in meters. */
569     float           accuracy;
570     /** Represents the expected vertical uncertainity in meters*/
571     float           vertUncertainity;
572     /** Timestamp for the location fix. */
573     LocGpsUtcTime      timestamp;
574 } LocGpsLocation;
575 
576 /** Represents the status. */
577 typedef struct {
578     /** set to sizeof(LocGpsStatus) */
579     size_t          size;
580     LocGpsStatusValue status;
581 } LocGpsStatus;
582 
583 /**
584  * Legacy struct to represents SV information.
585  * Deprecated, to be removed in the next Android release.
586  * Use LocGnssSvInfo instead.
587  */
588 typedef struct {
589     /** set to sizeof(LocGpsSvInfo) */
590     size_t          size;
591     /** Pseudo-random number for the SV. */
592     int     prn;
593     /** Signal to noise ratio. */
594     float   snr;
595     /** Elevation of SV in degrees. */
596     float   elevation;
597     /** Azimuth of SV in degrees. */
598     float   azimuth;
599 } LocGpsSvInfo;
600 
601 typedef struct {
602     /** set to sizeof(LocGnssSvInfo) */
603     size_t size;
604 
605     /**
606      * Pseudo-random number for the SV, or FCN/OSN number for Glonass. The
607      * distinction is made by looking at constellation field. Values should be
608      * in the range of:
609      *
610      * - GPS:     1-32
611      * - SBAS:    120-151, 183-192
612      * - GLONASS: 1-24, the orbital slot number (OSN), if known.  Or, if not:
613      *            93-106, the frequency channel number (FCN) (-7 to +6) offset by + 100
614      *            i.e. report an FCN of -7 as 93, FCN of 0 as 100, and FCN of +6 as 106.
615      * - QZSS:    193-200
616      * - Galileo: 1-36
617      * - Beidou:  1-37
618      */
619     int16_t svid;
620 
621     /**
622      * Defines the constellation of the given SV. Value should be one of those
623      * LOC_GNSS_CONSTELLATION_* constants
624      */
625     LocGnssConstellationType constellation;
626 
627     /**
628      * Carrier-to-noise density in dB-Hz, typically in the range [0, 63].
629      * It contains the measured C/N0 value for the signal at the antenna port.
630      *
631      * This is a mandatory value.
632      */
633     float c_n0_dbhz;
634 
635     /** Elevation of SV in degrees. */
636     float elevation;
637 
638     /** Azimuth of SV in degrees. */
639     float azimuth;
640 
641     /**
642      * Contains additional data about the given SV. Value should be one of those
643      * LOC_GNSS_SV_FLAGS_* constants
644      */
645     LocGnssSvFlags flags;
646 
647 } LocGnssSvInfo;
648 
649 /**
650  * Legacy struct to represents SV status.
651  * Deprecated, to be removed in the next Android release.
652  * Use LocGnssSvStatus instead.
653  */
654 typedef struct {
655     /** set to sizeof(LocGpsSvStatus) */
656     size_t size;
657     int num_svs;
658     LocGpsSvInfo sv_list[LOC_GPS_MAX_SVS];
659     uint32_t ephemeris_mask;
660     uint32_t almanac_mask;
661     uint32_t used_in_fix_mask;
662 } LocGpsSvStatus;
663 
664 /**
665  * Represents SV status.
666  */
667 typedef struct {
668     /** set to sizeof(LocGnssSvStatus) */
669     size_t size;
670 
671     /** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */
672     int num_svs;
673     /**
674      * Pointer to an array of SVs information for all GNSS constellations,
675      * except GPS, which is reported using sv_list
676      */
677     LocGnssSvInfo gnss_sv_list[LOC_GNSS_MAX_SVS];
678 
679 } LocGnssSvStatus;
680 
681 /* CellID for 2G, 3G and LTE, used in AGPS. */
682 typedef struct {
683     LocAGpsRefLocationType type;
684     /** Mobile Country Code. */
685     uint16_t mcc;
686     /** Mobile Network Code .*/
687     uint16_t mnc;
688     /** Location Area Code in 2G, 3G and LTE. In 3G lac is discarded. In LTE,
689      * lac is populated with tac, to ensure that we don't break old clients that
690      * might rely in the old (wrong) behavior.
691      */
692     uint16_t lac;
693     /** Cell id in 2G. Utran Cell id in 3G. Cell Global Id EUTRA in LTE. */
694     uint32_t cid;
695     /** Tracking Area Code in LTE. */
696     uint16_t tac;
697     /** Physical Cell id in LTE (not used in 2G and 3G) */
698     uint16_t pcid;
699 } LocAGpsRefLocationCellID;
700 
701 typedef struct {
702     uint8_t mac[6];
703 } LocAGpsRefLocationMac;
704 
705 /** Represents ref locations */
706 typedef struct {
707     LocAGpsRefLocationType type;
708     union {
709         LocAGpsRefLocationCellID   cellID;
710         LocAGpsRefLocationMac      mac;
711     } u;
712 } LocAGpsRefLocation;
713 
714 /**
715  * Callback with location information. Can only be called from a thread created
716  * by create_thread_cb.
717  */
718 typedef void (* loc_gps_location_callback)(LocGpsLocation* location);
719 
720 /**
721  * Callback with status information. Can only be called from a thread created by
722  * create_thread_cb.
723  */
724 typedef void (* loc_gps_status_callback)(LocGpsStatus* status);
725 /**
726  * Legacy callback with SV status information.
727  * Can only be called from a thread created by create_thread_cb.
728  *
729  * This callback is deprecated, and will be removed in the next release. Use
730  * loc_gnss_sv_status_callback() instead.
731  */
732 typedef void (* loc_gps_sv_status_callback)(LocGpsSvStatus* sv_info);
733 
734 /**
735  * Callback with SV status information.
736  * Can only be called from a thread created by create_thread_cb.
737  */
738 typedef void (* loc_gnss_sv_status_callback)(LocGnssSvStatus* sv_info);
739 
740 /**
741  * Callback for reporting NMEA sentences. Can only be called from a thread
742  * created by create_thread_cb.
743  */
744 typedef void (* loc_gps_nmea_callback)(LocGpsUtcTime timestamp, const char* nmea, int length);
745 
746 /**
747  * Callback to inform framework of the GPS engine's capabilities. Capability
748  * parameter is a bit field of LOC_GPS_CAPABILITY_* flags.
749  */
750 typedef void (* loc_gps_set_capabilities)(uint32_t capabilities);
751 
752 /**
753  * Callback utility for acquiring the GPS wakelock. This can be used to prevent
754  * the CPU from suspending while handling GPS events.
755  */
756 typedef void (* loc_gps_acquire_wakelock)();
757 
758 /** Callback utility for releasing the GPS wakelock. */
759 typedef void (* loc_gps_release_wakelock)();
760 
761 /** Callback for requesting NTP time */
762 typedef void (* loc_gps_request_utc_time)();
763 
764 /**
765  * Callback for creating a thread that can call into the Java framework code.
766  * This must be used to create any threads that report events up to the
767  * framework.
768  */
769 typedef pthread_t (* loc_gps_create_thread)(const char* name, void (*start)(void *), void* arg);
770 
771 /**
772  * Provides information about how new the underlying GPS/GNSS hardware and
773  * software is.
774  *
775  * This information will be available for Android Test Applications. If a GPS
776  * HAL does not provide this information, it will be considered "2015 or
777  * earlier".
778  *
779  * If a GPS HAL does provide this information, then newer years will need to
780  * meet newer CTS standards. E.g. if the date are 2016 or above, then N+ level
781  * LocGpsMeasurement support will be verified.
782  */
783 typedef struct {
784     /** Set to sizeof(LocGnssSystemInfo) */
785     size_t   size;
786     /* year in which the last update was made to the underlying hardware/firmware
787      * used to capture GNSS signals, e.g. 2016 */
788     uint16_t year_of_hw;
789 } LocGnssSystemInfo;
790 
791 /**
792  * Callback to inform framework of the engine's hardware version information.
793  */
794 typedef void (*loc_gnss_set_system_info)(const LocGnssSystemInfo* info);
795 
796 /** New GPS callback structure. */
797 typedef struct {
798     /** set to sizeof(LocGpsCallbacks) */
799     size_t      size;
800     loc_gps_location_callback location_cb;
801     loc_gps_status_callback status_cb;
802     loc_gps_sv_status_callback sv_status_cb;
803     loc_gps_nmea_callback nmea_cb;
804     loc_gps_set_capabilities set_capabilities_cb;
805     loc_gps_acquire_wakelock acquire_wakelock_cb;
806     loc_gps_release_wakelock release_wakelock_cb;
807     loc_gps_create_thread create_thread_cb;
808     loc_gps_request_utc_time request_utc_time_cb;
809 
810     loc_gnss_set_system_info set_system_info_cb;
811     loc_gnss_sv_status_callback gnss_sv_status_cb;
812 } LocGpsCallbacks;
813 
814 /** Represents the standard GPS interface. */
815 typedef struct {
816     /** set to sizeof(LocGpsInterface) */
817     size_t          size;
818     /**
819      * Opens the interface and provides the callback routines
820      * to the implementation of this interface.
821      */
822     int   (*init)( LocGpsCallbacks* callbacks );
823 
824     /** Starts navigating. */
825     int   (*start)( void );
826 
827     /** Stops navigating. */
828     int   (*stop)( void );
829 
830     /** Closes the interface. */
831     void  (*cleanup)( void );
832 
833     /** Injects the current time. */
834     int   (*inject_time)(LocGpsUtcTime time, int64_t timeReference,
835                          int uncertainty);
836 
837     /**
838      * Injects current location from another location provider (typically cell
839      * ID). Latitude and longitude are measured in degrees expected accuracy is
840      * measured in meters
841      */
842     int  (*inject_location)(double latitude, double longitude, float accuracy);
843 
844     /**
845      * Specifies that the next call to start will not use the
846      * information defined in the flags. LOC_GPS_DELETE_ALL is passed for
847      * a cold start.
848      */
849     void  (*delete_aiding_data)(LocGpsAidingData flags);
850 
851     /**
852      * min_interval represents the time between fixes in milliseconds.
853      * preferred_accuracy represents the requested fix accuracy in meters.
854      * preferred_time represents the requested time to first fix in milliseconds.
855      *
856      * 'mode' parameter should be one of LOC_GPS_POSITION_MODE_MS_BASED
857      * or LOC_GPS_POSITION_MODE_STANDALONE.
858      * It is allowed by the platform (and it is recommended) to fallback to
859      * LOC_GPS_POSITION_MODE_MS_BASED if LOC_GPS_POSITION_MODE_MS_ASSISTED is passed in, and
860      * LOC_GPS_POSITION_MODE_MS_BASED is supported.
861      */
862     int   (*set_position_mode)(LocGpsPositionMode mode, LocGpsPositionRecurrence recurrence,
863             uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
864 
865     /** Get a pointer to extension information. */
866     const void* (*get_extension)(const char* name);
867 } LocGpsInterface;
868 
869 /**
870  * Callback to request the client to download XTRA data. The client should
871  * download XTRA data and inject it by calling inject_xtra_data(). Can only be
872  * called from a thread created by create_thread_cb.
873  */
874 typedef void (* loc_gps_xtra_download_request)();
875 
876 /** Callback structure for the XTRA interface. */
877 typedef struct {
878     loc_gps_xtra_download_request download_request_cb;
879     loc_gps_create_thread create_thread_cb;
880 } LocGpsXtraCallbacks;
881 
882 /** Extended interface for XTRA support. */
883 typedef struct {
884     /** set to sizeof(LocGpsXtraInterface) */
885     size_t          size;
886     /**
887      * Opens the XTRA interface and provides the callback routines
888      * to the implementation of this interface.
889      */
890     int  (*init)( LocGpsXtraCallbacks* callbacks );
891     /** Injects XTRA data into the GPS. */
892     int  (*inject_xtra_data)( char* data, int length );
893 } LocGpsXtraInterface;
894 
895 #if 0
896 /** Extended interface for DEBUG support. */
897 typedef struct {
898     /** set to sizeof(LocGpsDebugInterface) */
899     size_t          size;
900 
901     /**
902      * This function should return any information that the native
903      * implementation wishes to include in a bugreport.
904      */
905     size_t (*get_internal_state)(char* buffer, size_t bufferSize);
906 } LocGpsDebugInterface;
907 #endif
908 
909 /*
910  * Represents the status of AGPS augmented to support IPv4 and IPv6.
911  */
912 typedef struct {
913     /** set to sizeof(LocAGpsStatus) */
914     size_t                  size;
915 
916     LocAGpsType                type;
917     LocAGpsStatusValue         status;
918 
919     /**
920      * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
921      * address, or set to INADDR_NONE otherwise.
922      */
923     uint32_t                ipaddr;
924 
925     /**
926      * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
927      * Any other value of addr.ss_family will be rejected.
928      */
929     struct sockaddr_storage addr;
930 } LocAGpsStatus;
931 
932 /**
933  * Callback with AGPS status information. Can only be called from a thread
934  * created by create_thread_cb.
935  */
936 typedef void (* loc_agps_status_callback)(LocAGpsStatus* status);
937 
938 /** Callback structure for the AGPS interface. */
939 typedef struct {
940     loc_agps_status_callback status_cb;
941     loc_gps_create_thread create_thread_cb;
942 } LocAGpsCallbacks;
943 
944 /**
945  * Extended interface for AGPS support, it is augmented to enable to pass
946  * extra APN data.
947  */
948 typedef struct {
949     /** set to sizeof(LocAGpsInterface) */
950     size_t size;
951 
952     /**
953      * Opens the AGPS interface and provides the callback routines to the
954      * implementation of this interface.
955      */
956     void (*init)(LocAGpsCallbacks* callbacks);
957     /**
958      * Deprecated.
959      * If the HAL supports LocAGpsInterface_v2 this API will not be used, see
960      * data_conn_open_with_apn_ip_type for more information.
961      */
962     int (*data_conn_open)(const char* apn);
963     /**
964      * Notifies that the AGPS data connection has been closed.
965      */
966     int (*data_conn_closed)();
967     /**
968      * Notifies that a data connection is not available for AGPS.
969      */
970     int (*data_conn_failed)();
971     /**
972      * Sets the hostname and port for the AGPS server.
973      */
974     int (*set_server)(LocAGpsType type, const char* hostname, int port);
975 
976     /**
977      * Notifies that a data connection is available and sets the name of the
978      * APN, and its IP type, to be used for SUPL connections.
979      */
980     int (*data_conn_open_with_apn_ip_type)(
981             const char* apn,
982             LocApnIpType apnIpType);
983 } LocAGpsInterface;
984 
985 /** Error codes associated with certificate operations */
986 #define LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS               0
987 #define LOC_AGPS_CERTIFICATE_ERROR_GENERIC                -100
988 #define LOC_AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES  -101
989 
990 /** A data structure that represents an X.509 certificate using DER encoding */
991 typedef struct {
992     size_t  length;
993     u_char* data;
994 } LocDerEncodedCertificate;
995 
996 /**
997  * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
998  * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
999  */
1000 typedef struct {
1001     u_char data[20];
1002 } LocSha1CertificateFingerprint;
1003 
1004 /** AGPS Interface to handle SUPL certificate operations */
1005 typedef struct {
1006     /** set to sizeof(LocSuplCertificateInterface) */
1007     size_t size;
1008 
1009     /**
1010      * Installs a set of Certificates used for SUPL connections to the AGPS server.
1011      * If needed the HAL should find out internally any certificates that need to be removed to
1012      * accommodate the certificates to install.
1013      * The certificates installed represent a full set of valid certificates needed to connect to
1014      * AGPS SUPL servers.
1015      * The list of certificates is required, and all must be available at the same time, when trying
1016      * to establish a connection with the AGPS Server.
1017      *
1018      * Parameters:
1019      *      certificates - A pointer to an array of DER encoded certificates that are need to be
1020      *                     installed in the HAL.
1021      *      length - The number of certificates to install.
1022      * Returns:
1023      *      LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
1024      *      LOC_AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
1025      *          certificates attempted to be installed, the state of the certificates stored should
1026      *          remain the same as before on this error case.
1027      *
1028      * IMPORTANT:
1029      *      If needed the HAL should find out internally the set of certificates that need to be
1030      *      removed to accommodate the certificates to install.
1031      */
1032     int  (*install_certificates) ( const LocDerEncodedCertificate* certificates, size_t length );
1033 
1034     /**
1035      * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
1036      * expected that the given set of certificates is removed from the internal store of the HAL.
1037      *
1038      * Parameters:
1039      *      fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
1040      *                     certificates to revoke.
1041      *      length - The number of fingerprints provided.
1042      * Returns:
1043      *      LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
1044      *
1045      * IMPORTANT:
1046      *      If any of the certificates provided (through its fingerprint) is not known by the HAL,
1047      *      it should be ignored and continue revoking/deleting the rest of them.
1048      */
1049     int  (*revoke_certificates) ( const LocSha1CertificateFingerprint* fingerprints, size_t length );
1050 } LocSuplCertificateInterface;
1051 
1052 /** Represents an NI request */
1053 typedef struct {
1054     /** set to sizeof(LocGpsNiNotification) */
1055     size_t          size;
1056 
1057     /**
1058      * An ID generated by HAL to associate NI notifications and UI
1059      * responses
1060      */
1061     int             notification_id;
1062 
1063     /**
1064      * An NI type used to distinguish different categories of NI
1065      * events, such as LOC_GPS_NI_TYPE_VOICE, LOC_GPS_NI_TYPE_UMTS_SUPL, ...
1066      */
1067     LocGpsNiType       ni_type;
1068 
1069     /**
1070      * Notification/verification options, combinations of LocGpsNiNotifyFlags constants
1071      */
1072     LocGpsNiNotifyFlags notify_flags;
1073 
1074     /**
1075      * Timeout period to wait for user response.
1076      * Set to 0 for no time out limit.
1077      */
1078     int             timeout;
1079 
1080     /**
1081      * Default response when time out.
1082      */
1083     LocGpsUserResponseType default_response;
1084 
1085     /**
1086      * Requestor ID
1087      */
1088     char            requestor_id[LOC_GPS_NI_SHORT_STRING_MAXLEN];
1089 
1090     /**
1091      * Notification message. It can also be used to store client_id in some cases
1092      */
1093     char            text[LOC_GPS_NI_LONG_STRING_MAXLEN];
1094 
1095     /**
1096      * Client name decoding scheme
1097      */
1098     LocGpsNiEncodingType requestor_id_encoding;
1099 
1100     /**
1101      * Client name decoding scheme
1102      */
1103     LocGpsNiEncodingType text_encoding;
1104 
1105     /**
1106      * A pointer to extra data. Format:
1107      * key_1 = value_1
1108      * key_2 = value_2
1109      */
1110     char           extras[LOC_GPS_NI_LONG_STRING_MAXLEN];
1111 
1112 } LocGpsNiNotification;
1113 
1114 /**
1115  * Callback with NI notification. Can only be called from a thread created by
1116  * create_thread_cb.
1117  */
1118 typedef void (*loc_gps_ni_notify_callback)(LocGpsNiNotification *notification);
1119 
1120 /** GPS NI callback structure. */
1121 typedef struct
1122 {
1123     /**
1124      * Sends the notification request from HAL to GPSLocationProvider.
1125      */
1126     loc_gps_ni_notify_callback notify_cb;
1127     loc_gps_create_thread create_thread_cb;
1128 } LocGpsNiCallbacks;
1129 
1130 /**
1131  * Extended interface for Network-initiated (NI) support.
1132  */
1133 typedef struct
1134 {
1135     /** set to sizeof(LocGpsNiInterface) */
1136     size_t          size;
1137 
1138    /** Registers the callbacks for HAL to use. */
1139    void (*init) (LocGpsNiCallbacks *callbacks);
1140 
1141    /** Sends a response to HAL. */
1142    void (*respond) (int notif_id, LocGpsUserResponseType user_response);
1143 } LocGpsNiInterface;
1144 
1145 #define LOC_AGPS_RIL_REQUEST_SETID_IMSI     (1<<0L)
1146 #define LOC_AGPS_RIL_REQUEST_SETID_MSISDN   (1<<1L)
1147 
1148 #define LOC_AGPS_RIL_REQUEST_REFLOC_CELLID  (1<<0L)
1149 #define LOC_AGPS_RIL_REQUEST_REFLOC_MAC     (1<<1L)
1150 
1151 typedef void (*loc_agps_ril_request_set_id)(uint32_t flags);
1152 typedef void (*loc_agps_ril_request_ref_loc)(uint32_t flags);
1153 
1154 typedef struct {
1155     loc_agps_ril_request_set_id request_setid;
1156     loc_agps_ril_request_ref_loc request_refloc;
1157     loc_gps_create_thread create_thread_cb;
1158 } LocAGpsRilCallbacks;
1159 
1160 /** Extended interface for AGPS_RIL support. */
1161 typedef struct {
1162     /** set to sizeof(LocAGpsRilInterface) */
1163     size_t          size;
1164     /**
1165      * Opens the AGPS interface and provides the callback routines
1166      * to the implementation of this interface.
1167      */
1168     void  (*init)( LocAGpsRilCallbacks* callbacks );
1169 
1170     /**
1171      * Sets the reference location.
1172      */
1173     void (*set_ref_location) (const LocAGpsRefLocation *agps_reflocation, size_t sz_struct);
1174     /**
1175      * Sets the set ID.
1176      */
1177     void (*set_set_id) (LocAGpsSetIDType type, const char* setid);
1178 
1179     /**
1180      * Send network initiated message.
1181      */
1182     void (*ni_message) (uint8_t *msg, size_t len);
1183 
1184     /**
1185      * Notify GPS of network status changes.
1186      * These parameters match values in the android.net.NetworkInfo class.
1187      */
1188     void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
1189 
1190     /**
1191      * Notify GPS of network status changes.
1192      * These parameters match values in the android.net.NetworkInfo class.
1193      */
1194     void (*update_network_availability) (int avaiable, const char* apn);
1195 } LocAGpsRilInterface;
1196 
1197 /**
1198  * GPS Geofence.
1199  *      There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1200  * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1201  *
1202  * An example state diagram with confidence level: 95% and Unknown time limit
1203  * set as 30 secs is shown below. (confidence level and Unknown time limit are
1204  * explained latter)
1205  *                         ____________________________
1206  *                        |       Unknown (30 secs)   |
1207  *                         """"""""""""""""""""""""""""
1208  *                            ^ |                  |  ^
1209  *                   UNCERTAIN| |ENTERED     EXITED|  |UNCERTAIN
1210  *                            | v                  v  |
1211  *                        ________    EXITED     _________
1212  *                       | Inside | -----------> | Outside |
1213  *                       |        | <----------- |         |
1214  *                        """"""""    ENTERED    """""""""
1215  *
1216  * Inside state: We are 95% confident that the user is inside the geofence.
1217  * Outside state: We are 95% confident that the user is outside the geofence
1218  * Unknown state: Rest of the time.
1219  *
1220  * The Unknown state is better explained with an example:
1221  *
1222  *                            __________
1223  *                           |         c|
1224  *                           |  ___     |    _______
1225  *                           |  |a|     |   |   b   |
1226  *                           |  """     |    """""""
1227  *                           |          |
1228  *                            """"""""""
1229  * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1230  * circle reported by the GPS subsystem. Now with regard to "b", the system is
1231  * confident that the user is outside. But with regard to "a" is not confident
1232  * whether it is inside or outside the geofence. If the accuracy remains the
1233  * same for a sufficient period of time, the UNCERTAIN transition would be
1234  * triggered with the state set to Unknown. If the accuracy improves later, an
1235  * appropriate transition should be triggered.  This "sufficient period of time"
1236  * is defined by the parameter in the add_geofence_area API.
1237  *     In other words, Unknown state can be interpreted as a state in which the
1238  * GPS subsystem isn't confident enough that the user is either inside or
1239  * outside the Geofence. It moves to Unknown state only after the expiry of the
1240  * timeout.
1241  *
1242  * The geofence callback needs to be triggered for the ENTERED and EXITED
1243  * transitions, when the GPS system is confident that the user has entered
1244  * (Inside state) or exited (Outside state) the Geofence. An implementation
1245  * which uses a value of 95% as the confidence is recommended. The callback
1246  * should be triggered only for the transitions requested by the
1247  * add_geofence_area call.
1248  *
1249  * Even though the diagram and explanation talks about states and transitions,
1250  * the callee is only interested in the transistions. The states are mentioned
1251  * here for illustrative purposes.
1252  *
1253  * Startup Scenario: When the device boots up, if an application adds geofences,
1254  * and then we get an accurate GPS location fix, it needs to trigger the
1255  * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1256  * By default, all the Geofences will be in the Unknown state.
1257  *
1258  * When the GPS system is unavailable, loc_gps_geofence_status_callback should be
1259  * called to inform the upper layers of the same. Similarly, when it becomes
1260  * available the callback should be called. This is a global state while the
1261  * UNKNOWN transition described above is per geofence.
1262  *
1263  * An important aspect to note is that users of this API (framework), will use
1264  * other subsystems like wifi, sensors, cell to handle Unknown case and
1265  * hopefully provide a definitive state transition to the third party
1266  * application. GPS Geofence will just be a signal indicating what the GPS
1267  * subsystem knows about the Geofence.
1268  *
1269  */
1270 #define LOC_GPS_GEOFENCE_ENTERED     (1<<0L)
1271 #define LOC_GPS_GEOFENCE_EXITED      (1<<1L)
1272 #define LOC_GPS_GEOFENCE_UNCERTAIN   (1<<2L)
1273 
1274 #define LOC_GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1275 #define LOC_GPS_GEOFENCE_AVAILABLE   (1<<1L)
1276 
1277 #define LOC_GPS_GEOFENCE_OPERATION_SUCCESS           0
1278 #define LOC_GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1279 #define LOC_GPS_GEOFENCE_ERROR_ID_EXISTS          -101
1280 #define LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN         -102
1281 #define LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1282 #define LOC_GPS_GEOFENCE_ERROR_GENERIC            -149
1283 
1284 /**
1285  * The callback associated with the geofence.
1286  * Parameters:
1287  *      geofence_id - The id associated with the add_geofence_area.
1288  *      location    - The current GPS location.
1289  *      transition  - Can be one of LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED,
1290  *                    LOC_GPS_GEOFENCE_UNCERTAIN.
1291  *      timestamp   - Timestamp when the transition was detected.
1292  *
1293  * The callback should only be called when the caller is interested in that
1294  * particular transition. For instance, if the caller is interested only in
1295  * ENTERED transition, then the callback should NOT be called with the EXITED
1296  * transition.
1297  *
1298  * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1299  * subsystem will wake up the application processor, if its in suspend state.
1300  */
1301 typedef void (*loc_gps_geofence_transition_callback) (int32_t geofence_id,  LocGpsLocation* location,
1302         int32_t transition, LocGpsUtcTime timestamp);
1303 
1304 /**
1305  * The callback associated with the availability of the GPS system for geofencing
1306  * monitoring. If the GPS system determines that it cannot monitor geofences
1307  * because of lack of reliability or unavailability of the GPS signals, it will
1308  * call this callback with LOC_GPS_GEOFENCE_UNAVAILABLE parameter.
1309  *
1310  * Parameters:
1311  *  status - LOC_GPS_GEOFENCE_UNAVAILABLE or LOC_GPS_GEOFENCE_AVAILABLE.
1312  *  last_location - Last known location.
1313  */
1314 typedef void (*loc_gps_geofence_status_callback) (int32_t status, LocGpsLocation* last_location);
1315 
1316 /**
1317  * The callback associated with the add_geofence call.
1318  *
1319  * Parameter:
1320  * geofence_id - Id of the geofence.
1321  * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS
1322  *          LOC_GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES  - geofence limit has been reached.
1323  *          LOC_GPS_GEOFENCE_ERROR_ID_EXISTS  - geofence with id already exists
1324  *          LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1325  *              invalid transition
1326  *          LOC_GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1327  */
1328 typedef void (*loc_gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1329 
1330 /**
1331  * The callback associated with the remove_geofence call.
1332  *
1333  * Parameter:
1334  * geofence_id - Id of the geofence.
1335  * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS
1336  *          LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1337  *          LOC_GPS_GEOFENCE_ERROR_GENERIC for others.
1338  */
1339 typedef void (*loc_gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1340 
1341 
1342 /**
1343  * The callback associated with the pause_geofence call.
1344  *
1345  * Parameter:
1346  * geofence_id - Id of the geofence.
1347  * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS
1348  *          LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1349  *          LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1350  *                    when monitor_transitions is invalid
1351  *          LOC_GPS_GEOFENCE_ERROR_GENERIC for others.
1352  */
1353 typedef void (*loc_gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1354 
1355 /**
1356  * The callback associated with the resume_geofence call.
1357  *
1358  * Parameter:
1359  * geofence_id - Id of the geofence.
1360  * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS
1361  *          LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1362  *          LOC_GPS_GEOFENCE_ERROR_GENERIC for others.
1363  */
1364 typedef void (*loc_gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1365 
1366 typedef struct {
1367     loc_gps_geofence_transition_callback geofence_transition_callback;
1368     loc_gps_geofence_status_callback geofence_status_callback;
1369     loc_gps_geofence_add_callback geofence_add_callback;
1370     loc_gps_geofence_remove_callback geofence_remove_callback;
1371     loc_gps_geofence_pause_callback geofence_pause_callback;
1372     loc_gps_geofence_resume_callback geofence_resume_callback;
1373     loc_gps_create_thread create_thread_cb;
1374 } LocGpsGeofenceCallbacks;
1375 
1376 /** Extended interface for GPS_Geofencing support */
1377 typedef struct {
1378    /** set to sizeof(LocGpsGeofencingInterface) */
1379    size_t          size;
1380 
1381    /**
1382     * Opens the geofence interface and provides the callback routines
1383     * to the implementation of this interface.
1384     */
1385    void  (*init)( LocGpsGeofenceCallbacks* callbacks );
1386 
1387    /**
1388     * Add a geofence area. This api currently supports circular geofences.
1389     * Parameters:
1390     *    geofence_id - The id for the geofence. If a geofence with this id
1391     *       already exists, an error value (LOC_GPS_GEOFENCE_ERROR_ID_EXISTS)
1392     *       should be returned.
1393     *    latitude, longtitude, radius_meters - The lat, long and radius
1394     *       (in meters) for the geofence
1395     *    last_transition - The current state of the geofence. For example, if
1396     *       the system already knows that the user is inside the geofence,
1397     *       this will be set to LOC_GPS_GEOFENCE_ENTERED. In most cases, it
1398     *       will be LOC_GPS_GEOFENCE_UNCERTAIN.
1399     *    monitor_transition - Which transitions to monitor. Bitwise OR of
1400     *       LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED and
1401     *       LOC_GPS_GEOFENCE_UNCERTAIN.
1402     *    notification_responsiveness_ms - Defines the best-effort description
1403     *       of how soon should the callback be called when the transition
1404     *       associated with the Geofence is triggered. For instance, if set
1405     *       to 1000 millseconds with LOC_GPS_GEOFENCE_ENTERED, the callback
1406     *       should be called 1000 milliseconds within entering the geofence.
1407     *       This parameter is defined in milliseconds.
1408     *       NOTE: This is not to be confused with the rate that the GPS is
1409     *       polled at. It is acceptable to dynamically vary the rate of
1410     *       sampling the GPS for power-saving reasons; thus the rate of
1411     *       sampling may be faster or slower than this.
1412     *    unknown_timer_ms - The time limit after which the UNCERTAIN transition
1413     *       should be triggered. This parameter is defined in milliseconds.
1414     *       See above for a detailed explanation.
1415     */
1416    void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1417        double radius_meters, int last_transition, int monitor_transitions,
1418        int notification_responsiveness_ms, int unknown_timer_ms);
1419 
1420    /**
1421     * Pause monitoring a particular geofence.
1422     * Parameters:
1423     *   geofence_id - The id for the geofence.
1424     */
1425    void (*pause_geofence) (int32_t geofence_id);
1426 
1427    /**
1428     * Resume monitoring a particular geofence.
1429     * Parameters:
1430     *   geofence_id - The id for the geofence.
1431     *   monitor_transitions - Which transitions to monitor. Bitwise OR of
1432     *       LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED and
1433     *       LOC_GPS_GEOFENCE_UNCERTAIN.
1434     *       This supersedes the value associated provided in the
1435     *       add_geofence_area call.
1436     */
1437    void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
1438 
1439    /**
1440     * Remove a geofence area. After the function returns, no notifications
1441     * should be sent.
1442     * Parameter:
1443     *   geofence_id - The id for the geofence.
1444     */
1445    void (*remove_geofence_area) (int32_t geofence_id);
1446 } LocGpsGeofencingInterface;
1447 
1448 /**
1449  * Legacy struct to represent an estimate of the GPS clock time.
1450  * Deprecated, to be removed in the next Android release.
1451  * Use LocGnssClock instead.
1452  */
1453 typedef struct {
1454     /** set to sizeof(LocGpsClock) */
1455     size_t size;
1456     LocGpsClockFlags flags;
1457     int16_t leap_second;
1458     LocGpsClockType type;
1459     int64_t time_ns;
1460     double time_uncertainty_ns;
1461     int64_t full_bias_ns;
1462     double bias_ns;
1463     double bias_uncertainty_ns;
1464     double drift_nsps;
1465     double drift_uncertainty_nsps;
1466 } LocGpsClock;
1467 
1468 /**
1469  * Represents an estimate of the GPS clock time.
1470  */
1471 typedef struct {
1472     /** set to sizeof(LocGnssClock) */
1473     size_t size;
1474 
1475     /**
1476      * A set of flags indicating the validity of the fields in this data
1477      * structure.
1478      */
1479     LocGnssClockFlags flags;
1480 
1481     /**
1482      * Leap second data.
1483      * The sign of the value is defined by the following equation:
1484      *      utc_time_ns = time_ns - (full_bias_ns + bias_ns) - leap_second *
1485      *      1,000,000,000
1486      *
1487      * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_LEAP_SECOND.
1488      */
1489     int16_t leap_second;
1490 
1491     /**
1492      * The GNSS receiver internal clock value. This is the local hardware clock
1493      * value.
1494      *
1495      * For local hardware clock, this value is expected to be monotonically
1496      * increasing while the hardware clock remains power on. (For the case of a
1497      * HW clock that is not continuously on, see the
1498      * hw_clock_discontinuity_count field). The receiver's estimate of GPS time
1499      * can be derived by substracting the sum of full_bias_ns and bias_ns (when
1500      * available) from this value.
1501      *
1502      * This GPS time is expected to be the best estimate of current GPS time
1503      * that GNSS receiver can achieve.
1504      *
1505      * Sub-nanosecond accuracy can be provided by means of the 'bias_ns' field.
1506      * The value contains the 'time uncertainty' in it.
1507      *
1508      * This field is mandatory.
1509      */
1510     int64_t time_ns;
1511 
1512     /**
1513      * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1514      * The uncertainty is represented as an absolute (single sided) value.
1515      *
1516      * If the data is available, 'flags' must contain
1517      * LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY. This value is effectively zero (it is
1518      * the reference local clock, by which all other times and time
1519      * uncertainties are measured.)  (And thus this field can be not provided,
1520      * per LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY flag, or provided & set to 0.)
1521      */
1522     double time_uncertainty_ns;
1523 
1524     /**
1525      * The difference between hardware clock ('time' field) inside GPS receiver
1526      * and the true GPS time since 0000Z, January 6, 1980, in nanoseconds.
1527      *
1528      * The sign of the value is defined by the following equation:
1529      *      local estimate of GPS time = time_ns - (full_bias_ns + bias_ns)
1530      *
1531      * This value is mandatory if the receiver has estimated GPS time. If the
1532      * computed time is for a non-GPS constellation, the time offset of that
1533      * constellation to GPS has to be applied to fill this value. The error
1534      * estimate for the sum of this and the bias_ns is the bias_uncertainty_ns,
1535      * and the caller is responsible for using this uncertainty (it can be very
1536      * large before the GPS time has been solved for.) If the data is available
1537      * 'flags' must contain LOC_GNSS_CLOCK_HAS_FULL_BIAS.
1538      */
1539     int64_t full_bias_ns;
1540 
1541     /**
1542      * Sub-nanosecond bias.
1543      * The error estimate for the sum of this and the full_bias_ns is the
1544      * bias_uncertainty_ns
1545      *
1546      * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_BIAS. If GPS
1547      * has computed a position fix. This value is mandatory if the receiver has
1548      * estimated GPS time.
1549      */
1550     double bias_ns;
1551 
1552     /**
1553      * 1-Sigma uncertainty associated with the local estimate of GPS time (clock
1554      * bias) in nanoseconds. The uncertainty is represented as an absolute
1555      * (single sided) value.
1556      *
1557      * If the data is available 'flags' must contain
1558      * LOC_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY. This value is mandatory if the receiver
1559      * has estimated GPS time.
1560      */
1561     double bias_uncertainty_ns;
1562 
1563     /**
1564      * The clock's drift in nanoseconds (per second).
1565      *
1566      * A positive value means that the frequency is higher than the nominal
1567      * frequency, and that the (full_bias_ns + bias_ns) is growing more positive
1568      * over time.
1569      *
1570      * The value contains the 'drift uncertainty' in it.
1571      * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_DRIFT.
1572      *
1573      * This value is mandatory if the receiver has estimated GNSS time
1574      */
1575     double drift_nsps;
1576 
1577     /**
1578      * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1579      * The uncertainty is represented as an absolute (single sided) value.
1580      *
1581      * If the data is available 'flags' must contain
1582      * LOC_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY. If GPS has computed a position fix this
1583      * field is mandatory and must be populated.
1584      */
1585     double drift_uncertainty_nsps;
1586 
1587     /**
1588      * When there are any discontinuities in the HW clock, this field is
1589      * mandatory.
1590      *
1591      * A "discontinuity" is meant to cover the case of a switch from one source
1592      * of clock to another.  A single free-running crystal oscillator (XO)
1593      * should generally not have any discontinuities, and this can be set and
1594      * left at 0.
1595      *
1596      * If, however, the time_ns value (HW clock) is derived from a composite of
1597      * sources, that is not as smooth as a typical XO, or is otherwise stopped &
1598      * restarted, then this value shall be incremented each time a discontinuity
1599      * occurs.  (E.g. this value may start at zero at device boot-up and
1600      * increment each time there is a change in clock continuity. In the
1601      * unlikely event that this value reaches full scale, rollover (not
1602      * clamping) is required, such that this value continues to change, during
1603      * subsequent discontinuity events.)
1604      *
1605      * While this number stays the same, between LocGnssClock reports, it can be
1606      * safely assumed that the time_ns value has been running continuously, e.g.
1607      * derived from a single, high quality clock (XO like, or better, that's
1608      * typically used during continuous GNSS signal sampling.)
1609      *
1610      * It is expected, esp. during periods where there are few GNSS signals
1611      * available, that the HW clock be discontinuity-free as long as possible,
1612      * as this avoids the need to use (waste) a GNSS measurement to fully
1613      * re-solve for the GPS clock bias and drift, when using the accompanying
1614      * measurements, from consecutive LocGnssData reports.
1615      */
1616     uint32_t hw_clock_discontinuity_count;
1617 
1618 } LocGnssClock;
1619 
1620 /**
1621  * Legacy struct to represent a GPS Measurement, it contains raw and computed
1622  * information.
1623  * Deprecated, to be removed in the next Android release.
1624  * Use LocGnssMeasurement instead.
1625  */
1626 typedef struct {
1627     /** set to sizeof(LocGpsMeasurement) */
1628     size_t size;
1629     LocGpsMeasurementFlags flags;
1630     int8_t prn;
1631     double time_offset_ns;
1632     LocGpsMeasurementState state;
1633     int64_t received_gps_tow_ns;
1634     int64_t received_gps_tow_uncertainty_ns;
1635     double c_n0_dbhz;
1636     double pseudorange_rate_mps;
1637     double pseudorange_rate_uncertainty_mps;
1638     LocGpsAccumulatedDeltaRangeState accumulated_delta_range_state;
1639     double accumulated_delta_range_m;
1640     double accumulated_delta_range_uncertainty_m;
1641     double pseudorange_m;
1642     double pseudorange_uncertainty_m;
1643     double code_phase_chips;
1644     double code_phase_uncertainty_chips;
1645     float carrier_frequency_hz;
1646     int64_t carrier_cycles;
1647     double carrier_phase;
1648     double carrier_phase_uncertainty;
1649     LocGpsLossOfLock loss_of_lock;
1650     int32_t bit_number;
1651     int16_t time_from_last_bit_ms;
1652     double doppler_shift_hz;
1653     double doppler_shift_uncertainty_hz;
1654     LocGpsMultipathIndicator multipath_indicator;
1655     double snr_db;
1656     double elevation_deg;
1657     double elevation_uncertainty_deg;
1658     double azimuth_deg;
1659     double azimuth_uncertainty_deg;
1660     bool used_in_fix;
1661 } LocGpsMeasurement;
1662 
1663 /**
1664  * Represents a GNSS Measurement, it contains raw and computed information.
1665  *
1666  * Independence - All signal measurement information (e.g. sv_time,
1667  * pseudorange_rate, multipath_indicator) reported in this struct should be
1668  * based on GNSS signal measurements only. You may not synthesize measurements
1669  * by calculating or reporting expected measurements based on known or estimated
1670  * position, velocity, or time.
1671  */
1672 typedef struct {
1673     /** set to sizeof(LocGnssMeasurement) */
1674     size_t size;
1675 
1676     /** A set of flags indicating the validity of the fields in this data structure. */
1677     LocGnssMeasurementFlags flags;
1678 
1679     /**
1680      * Satellite vehicle ID number, as defined in LocGnssSvInfo::svid
1681      * This is a mandatory value.
1682      */
1683     int16_t svid;
1684 
1685     /**
1686      * Defines the constellation of the given SV. Value should be one of those
1687      * LOC_GNSS_CONSTELLATION_* constants
1688      */
1689     LocGnssConstellationType constellation;
1690 
1691     /**
1692      * Time offset at which the measurement was taken in nanoseconds.
1693      * The reference receiver's time is specified by LocGpsData::clock::time_ns and should be
1694      * interpreted in the same way as indicated by LocGpsClock::type.
1695      *
1696      * The sign of time_offset_ns is given by the following equation:
1697      *      measurement time = LocGpsClock::time_ns + time_offset_ns
1698      *
1699      * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1700      * This is a mandatory value.
1701      */
1702     double time_offset_ns;
1703 
1704     /**
1705      * Per satellite sync state. It represents the current sync state for the associated satellite.
1706      * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
1707      *
1708      * This is a mandatory value.
1709      */
1710     LocGnssMeasurementState state;
1711 
1712     /**
1713      * The received GNSS Time-of-Week at the measurement time, in nanoseconds.
1714      * Ensure that this field is independent (see comment at top of
1715      * LocGnssMeasurement struct.)
1716      *
1717      * For GPS & QZSS, this is:
1718      *   Received GPS Time-of-Week at the measurement time, in nanoseconds.
1719      *   The value is relative to the beginning of the current GPS week.
1720      *
1721      *   Given the highest sync state that can be achieved, per each satellite, valid range
1722      *   for this field can be:
1723      *     Searching       : [ 0       ]   : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN
1724      *     C/A code lock   : [ 0   1ms ]   : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1725      *     Bit sync        : [ 0  20ms ]   : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1726      *     Subframe sync   : [ 0    6s ]   : LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1727      *     TOW decoded     : [ 0 1week ]   : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set
1728      *
1729      *   Note well: if there is any ambiguity in integer millisecond,
1730      *   LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field.
1731      *
1732      *   This value must be populated if 'state' != LOC_GNSS_MEASUREMENT_STATE_UNKNOWN.
1733      *
1734      * For Glonass, this is:
1735      *   Received Glonass time of day, at the measurement time in nanoseconds.
1736      *
1737      *   Given the highest sync state that can be achieved, per each satellite, valid range for
1738      *   this field can be:
1739      *     Searching       : [ 0       ]   : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN
1740      *     C/A code lock   : [ 0   1ms ]   : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1741      *     Symbol sync     : [ 0  10ms ]   : LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set
1742      *     Bit sync        : [ 0  20ms ]   : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1743      *     String sync     : [ 0    2s ]   : LOC_GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC is set
1744      *     Time of day     : [ 0  1day ]   : LOC_GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED is set
1745      *
1746      * For Beidou, this is:
1747      *   Received Beidou time of week, at the measurement time in nanoseconds.
1748      *
1749      *   Given the highest sync state that can be achieved, per each satellite, valid range for
1750      *   this field can be:
1751      *     Searching    : [ 0       ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN
1752      *     C/A code lock: [ 0   1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1753      *     Bit sync (D2): [ 0   2ms ] : LOC_GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC is set
1754      *     Bit sync (D1): [ 0  20ms ] : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1755      *     Subframe (D2): [ 0  0.6s ] : LOC_GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC is set
1756      *     Subframe (D1): [ 0    6s ] : LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1757      *     Time of week : [ 0 1week ] : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set
1758      *
1759      * For Galileo, this is:
1760      *   Received Galileo time of week, at the measurement time in nanoseconds.
1761      *
1762      *     E1BC code lock   : [ 0   4ms ]   : LOC_GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK is set
1763      *     E1C 2nd code lock: [ 0 100ms ]   :
1764      *     LOC_GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK is set
1765      *
1766      *     E1B page    : [ 0    2s ] : LOC_GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC is set
1767      *     Time of week: [ 0 1week ] : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set
1768      *
1769      * For SBAS, this is:
1770      *   Received SBAS time, at the measurement time in nanoseconds.
1771      *
1772      *   Given the highest sync state that can be achieved, per each satellite,
1773      *   valid range for this field can be:
1774      *     Searching    : [ 0     ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN
1775      *     C/A code lock: [ 0 1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1776      *     Symbol sync  : [ 0 2ms ] : LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set
1777      *     Message      : [ 0  1s ] : LOC_GNSS_MEASUREMENT_STATE_SBAS_SYNC is set
1778     */
1779     int64_t received_sv_time_in_ns;
1780 
1781     /**
1782      * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
1783      *
1784      * This value must be populated if 'state' != LOC_GPS_MEASUREMENT_STATE_UNKNOWN.
1785      */
1786     int64_t received_sv_time_uncertainty_in_ns;
1787 
1788     /**
1789      * Carrier-to-noise density in dB-Hz, typically in the range [0, 63].
1790      * It contains the measured C/N0 value for the signal at the antenna port.
1791      *
1792      * This is a mandatory value.
1793      */
1794     double c_n0_dbhz;
1795 
1796     /**
1797      * Pseudorange rate at the timestamp in m/s. The correction of a given
1798      * Pseudorange Rate value includes corrections for receiver and satellite
1799      * clock frequency errors. Ensure that this field is independent (see
1800      * comment at top of LocGnssMeasurement struct.)
1801      *
1802      * It is mandatory to provide the 'uncorrected' 'pseudorange rate', and provide LocGpsClock's
1803      * 'drift' field as well (When providing the uncorrected pseudorange rate, do not apply the
1804      * corrections described above.)
1805      *
1806      * The value includes the 'pseudorange rate uncertainty' in it.
1807      * A positive 'uncorrected' value indicates that the SV is moving away from the receiver.
1808      *
1809      * The sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler
1810      * shift' is given by the equation:
1811      *      pseudorange rate = -k * doppler shift   (where k is a constant)
1812      *
1813      * This should be the most accurate pseudorange rate available, based on
1814      * fresh signal measurements from this channel.
1815      *
1816      * It is mandatory that this value be provided at typical carrier phase PRR
1817      * quality (few cm/sec per second of uncertainty, or better) - when signals
1818      * are sufficiently strong & stable, e.g. signals from a GPS simulator at >=
1819      * 35 dB-Hz.
1820      */
1821     double pseudorange_rate_mps;
1822 
1823     /**
1824      * 1-Sigma uncertainty of the pseudorange_rate_mps.
1825      * The uncertainty is represented as an absolute (single sided) value.
1826      *
1827      * This is a mandatory value.
1828      */
1829     double pseudorange_rate_uncertainty_mps;
1830 
1831     /**
1832      * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1833      * (indicating loss of lock).
1834      *
1835      * This is a mandatory value.
1836      */
1837     LocGnssAccumulatedDeltaRangeState accumulated_delta_range_state;
1838 
1839     /**
1840      * Accumulated delta range since the last channel reset in meters.
1841      * A positive value indicates that the SV is moving away from the receiver.
1842      *
1843      * The sign of the 'accumulated delta range' and its relation to the sign of 'carrier phase'
1844      * is given by the equation:
1845      *          accumulated delta range = -k * carrier phase    (where k is a constant)
1846      *
1847      * This value must be populated if 'accumulated delta range state' != LOC_GPS_ADR_STATE_UNKNOWN.
1848      * However, it is expected that the data is only accurate when:
1849      *      'accumulated delta range state' == LOC_GPS_ADR_STATE_VALID.
1850      */
1851     double accumulated_delta_range_m;
1852 
1853     /**
1854      * 1-Sigma uncertainty of the accumulated delta range in meters.
1855      * This value must be populated if 'accumulated delta range state' != LOC_GPS_ADR_STATE_UNKNOWN.
1856      */
1857     double accumulated_delta_range_uncertainty_m;
1858 
1859     /**
1860      * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1861      * If the field is not set, the carrier frequency is assumed to be L1.
1862      *
1863      * If the data is available, 'flags' must contain
1864      * LOC_GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1865      */
1866     float carrier_frequency_hz;
1867 
1868     /**
1869      * The number of full carrier cycles between the satellite and the receiver.
1870      * The reference frequency is given by the field 'carrier_frequency_hz'.
1871      * Indications of possible cycle slips and resets in the accumulation of
1872      * this value can be inferred from the accumulated_delta_range_state flags.
1873      *
1874      * If the data is available, 'flags' must contain
1875      * LOC_GNSS_MEASUREMENT_HAS_CARRIER_CYCLES.
1876      */
1877     int64_t carrier_cycles;
1878 
1879     /**
1880      * The RF phase detected by the receiver, in the range [0.0, 1.0].
1881      * This is usually the fractional part of the complete carrier phase measurement.
1882      *
1883      * The reference frequency is given by the field 'carrier_frequency_hz'.
1884      * The value contains the 'carrier-phase uncertainty' in it.
1885      *
1886      * If the data is available, 'flags' must contain
1887      * LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE.
1888      */
1889     double carrier_phase;
1890 
1891     /**
1892      * 1-Sigma uncertainty of the carrier-phase.
1893      * If the data is available, 'flags' must contain
1894      * LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1895      */
1896     double carrier_phase_uncertainty;
1897 
1898     /**
1899      * An enumeration that indicates the 'multipath' state of the event.
1900      *
1901      * The multipath Indicator is intended to report the presence of overlapping
1902      * signals that manifest as distorted correlation peaks.
1903      *
1904      * - if there is a distorted correlation peak shape, report that multipath
1905      *   is LOC_GNSS_MULTIPATH_INDICATOR_PRESENT.
1906      * - if there is not a distorted correlation peak shape, report
1907      *   LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT
1908      * - if signals are too weak to discern this information, report
1909      *   LOC_GNSS_MULTIPATH_INDICATOR_UNKNOWN
1910      *
1911      * Example: when doing the standardized overlapping Multipath Performance
1912      * test (3GPP TS 34.171) the Multipath indicator should report
1913      * LOC_GNSS_MULTIPATH_INDICATOR_PRESENT for those signals that are tracked, and
1914      * contain multipath, and LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT for those
1915      * signals that are tracked and do not contain multipath.
1916      */
1917     LocGnssMultipathIndicator multipath_indicator;
1918 
1919     /**
1920      * Signal-to-noise ratio at correlator output in dB.
1921      * If the data is available, 'flags' must contain LOC_GNSS_MEASUREMENT_HAS_SNR.
1922      * This is the power ratio of the "correlation peak height above the
1923      * observed noise floor" to "the noise RMS".
1924      */
1925     double snr_db;
1926 } LocGnssMeasurement;
1927 
1928 /**
1929  * Legacy struct to represents a reading of GPS measurements.
1930  * Deprecated, to be removed in the next Android release.
1931  * Use LocGnssData instead.
1932  */
1933 typedef struct {
1934     /** set to sizeof(LocGpsData) */
1935     size_t size;
1936     size_t measurement_count;
1937     LocGpsMeasurement measurements[LOC_GPS_MAX_MEASUREMENT];
1938 
1939     /** The GPS clock time reading. */
1940     LocGpsClock clock;
1941 } LocGpsData;
1942 
1943 /**
1944  * Represents a reading of GNSS measurements. For devices where LocGnssSystemInfo's
1945  * year_of_hw is set to 2016+, it is mandatory that these be provided, on
1946  * request, when the GNSS receiver is searching/tracking signals.
1947  *
1948  * - Reporting of GPS constellation measurements is mandatory.
1949  * - Reporting of all tracked constellations are encouraged.
1950  */
1951 typedef struct {
1952     /** set to sizeof(LocGnssData) */
1953     size_t size;
1954 
1955     /** Number of measurements. */
1956     size_t measurement_count;
1957 
1958     /** The array of measurements. */
1959     LocGnssMeasurement measurements[LOC_GNSS_MAX_MEASUREMENT];
1960 
1961     /** The GPS clock time reading. */
1962     LocGnssClock clock;
1963 } LocGnssData;
1964 
1965 /**
1966  * The legacy callback for to report measurements from the HAL.
1967  *
1968  * This callback is deprecated, and will be removed in the next release. Use
1969  * loc_gnss_measurement_callback() instead.
1970  *
1971  * Parameters:
1972  *    data - A data structure containing the measurements.
1973  */
1974 typedef void (*loc_gps_measurement_callback) (LocGpsData* data);
1975 
1976 /**
1977  * The callback for to report measurements from the HAL.
1978  *
1979  * Parameters:
1980  *    data - A data structure containing the measurements.
1981  */
1982 typedef void (*loc_gnss_measurement_callback) (LocGnssData* data);
1983 
1984 typedef struct {
1985     /** set to sizeof(LocGpsMeasurementCallbacks) */
1986     size_t size;
1987     loc_gps_measurement_callback measurement_callback;
1988     loc_gnss_measurement_callback loc_gnss_measurement_callback;
1989 } LocGpsMeasurementCallbacks;
1990 
1991 #define LOC_GPS_MEASUREMENT_OPERATION_SUCCESS          0
1992 #define LOC_GPS_MEASUREMENT_ERROR_ALREADY_INIT      -100
1993 #define LOC_GPS_MEASUREMENT_ERROR_GENERIC           -101
1994 
1995 /**
1996  * Extended interface for GPS Measurements support.
1997  */
1998 typedef struct {
1999     /** Set to sizeof(LocGpsMeasurementInterface) */
2000     size_t size;
2001 
2002     /**
2003      * Initializes the interface and registers the callback routines with the HAL.
2004      * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
2005      *
2006      * Status:
2007      *    LOC_GPS_MEASUREMENT_OPERATION_SUCCESS
2008      *    LOC_GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
2009      *              corresponding call to 'close'
2010      *    LOC_GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
2011      *              will not generate any updates upon returning this error code.
2012      */
2013     int (*init) (LocGpsMeasurementCallbacks* callbacks);
2014 
2015     /**
2016      * Stops updates from the HAL, and unregisters the callback routines.
2017      * After a call to stop, the previously registered callbacks must be considered invalid by the
2018      * HAL.
2019      * If stop is invoked without a previous 'init', this function should perform no work.
2020      */
2021     void (*close) ();
2022 
2023 } LocGpsMeasurementInterface;
2024 
2025 #if 0
2026 /**
2027  * Legacy struct to represents a GPS navigation message (or a fragment of it).
2028  * Deprecated, to be removed in the next Android release.
2029  * Use GnssNavigationMessage instead.
2030  */
2031 typedef struct {
2032     /** set to sizeof(GpsNavigationMessage) */
2033     size_t size;
2034     int8_t prn;
2035     GpsNavigationMessageType type;
2036     NavigationMessageStatus status;
2037     int16_t message_id;
2038     int16_t submessage_id;
2039     size_t data_length;
2040     uint8_t* data;
2041 } GpsNavigationMessage;
2042 
2043 /** Represents a GPS navigation message (or a fragment of it). */
2044 typedef struct {
2045     /** set to sizeof(GnssNavigationMessage) */
2046     size_t size;
2047 
2048     /**
2049      * Satellite vehicle ID number, as defined in LocGnssSvInfo::svid
2050      * This is a mandatory value.
2051      */
2052     int16_t svid;
2053 
2054     /**
2055      * The type of message contained in the structure.
2056      * This is a mandatory value.
2057      */
2058     GnssNavigationMessageType type;
2059 
2060     /**
2061      * The status of the received navigation message.
2062      * No need to send any navigation message that contains words with parity error and cannot be
2063      * corrected.
2064      */
2065     NavigationMessageStatus status;
2066 
2067     /**
2068      * Message identifier. It provides an index so the complete Navigation
2069      * Message can be assembled.
2070      *
2071      * - For GPS L1 C/A subframe 4 and 5, this value corresponds to the 'frame
2072      *   id' of the navigation message, in the range of 1-25 (Subframe 1, 2, 3
2073      *   does not contain a 'frame id' and this value can be set to -1.)
2074      *
2075      * - For Glonass L1 C/A, this refers to the frame ID, in the range of 1-5.
2076      *
2077      * - For BeiDou D1, this refers to the frame number in the range of 1-24
2078      *
2079      * - For Beidou D2, this refers to the frame number, in the range of 1-120
2080      *
2081      * - For Galileo F/NAV nominal frame structure, this refers to the subframe
2082      *   number, in the range of 1-12
2083      *
2084      * - For Galileo I/NAV nominal frame structure, this refers to the subframe
2085      *   number in the range of 1-24
2086      */
2087     int16_t message_id;
2088 
2089     /**
2090      * Sub-message identifier. If required by the message 'type', this value
2091      * contains a sub-index within the current message (or frame) that is being
2092      * transmitted.
2093      *
2094      * - For GPS L1 C/A, BeiDou D1 & BeiDou D2, the submessage id corresponds to
2095      *   the subframe number of the navigation message, in the range of 1-5.
2096      *
2097      * - For Glonass L1 C/A, this refers to the String number, in the range from
2098      *   1-15
2099      *
2100      * - For Galileo F/NAV, this refers to the page type in the range 1-6
2101      *
2102      * - For Galileo I/NAV, this refers to the word type in the range 1-10+
2103      */
2104     int16_t submessage_id;
2105 
2106     /**
2107      * The length of the data (in bytes) contained in the current message.
2108      * If this value is different from zero, 'data' must point to an array of the same size.
2109      * e.g. for L1 C/A the size of the sub-frame will be 40 bytes (10 words, 30 bits/word).
2110      *
2111      * This is a mandatory value.
2112      */
2113     size_t data_length;
2114 
2115     /**
2116      * The data of the reported GPS message. The bytes (or words) specified
2117      * using big endian format (MSB first).
2118      *
2119      * - For GPS L1 C/A, Beidou D1 & Beidou D2, each subframe contains 10 30-bit
2120      *   words. Each word (30 bits) should be fit into the last 30 bits in a
2121      *   4-byte word (skip B31 and B32), with MSB first, for a total of 40
2122      *   bytes, covering a time period of 6, 6, and 0.6 seconds, respectively.
2123      *
2124      * - For Glonass L1 C/A, each string contains 85 data bits, including the
2125      *   checksum.  These bits should be fit into 11 bytes, with MSB first (skip
2126      *   B86-B88), covering a time period of 2 seconds.
2127      *
2128      * - For Galileo F/NAV, each word consists of 238-bit (sync & tail symbols
2129      *   excluded). Each word should be fit into 30-bytes, with MSB first (skip
2130      *   B239, B240), covering a time period of 10 seconds.
2131      *
2132      * - For Galileo I/NAV, each page contains 2 page parts, even and odd, with
2133      *   a total of 2x114 = 228 bits, (sync & tail excluded) that should be fit
2134      *   into 29 bytes, with MSB first (skip B229-B232).
2135      */
2136     uint8_t* data;
2137 
2138 } GnssNavigationMessage;
2139 
2140 /**
2141  * The legacy callback to report an available fragment of a GPS navigation
2142  * messages from the HAL.
2143  *
2144  * This callback is deprecated, and will be removed in the next release. Use
2145  * gnss_navigation_message_callback() instead.
2146  *
2147  * Parameters:
2148  *      message - The GPS navigation submessage/subframe representation.
2149  */
2150 typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
2151 
2152 /**
2153  * The callback to report an available fragment of a GPS navigation messages from the HAL.
2154  *
2155  * Parameters:
2156  *      message - The GPS navigation submessage/subframe representation.
2157  */
2158 typedef void (*gnss_navigation_message_callback) (GnssNavigationMessage* message);
2159 
2160 typedef struct {
2161     /** set to sizeof(GpsNavigationMessageCallbacks) */
2162     size_t size;
2163     gps_navigation_message_callback navigation_message_callback;
2164     gnss_navigation_message_callback gnss_navigation_message_callback;
2165 } GpsNavigationMessageCallbacks;
2166 
2167 #define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS             0
2168 #define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT         -100
2169 #define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC              -101
2170 
2171 /**
2172  * Extended interface for GPS navigation message reporting support.
2173  */
2174 typedef struct {
2175     /** Set to sizeof(GpsNavigationMessageInterface) */
2176     size_t size;
2177 
2178     /**
2179      * Initializes the interface and registers the callback routines with the HAL.
2180      * After a successful call to 'init' the HAL must begin to provide updates as they become
2181      * available.
2182      *
2183      * Status:
2184      *      GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
2185      *      GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
2186      *              without a corresponding call to 'close'.
2187      *      GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
2188      *              the HAL will not generate any updates upon returning this error code.
2189      */
2190     int (*init) (GpsNavigationMessageCallbacks* callbacks);
2191 
2192     /**
2193      * Stops updates from the HAL, and unregisters the callback routines.
2194      * After a call to stop, the previously registered callbacks must be considered invalid by the
2195      * HAL.
2196      * If stop is invoked without a previous 'init', this function should perform no work.
2197      */
2198     void (*close) ();
2199 
2200 } GpsNavigationMessageInterface;
2201 #endif
2202 
2203 /**
2204  * Interface for passing GNSS configuration contents from platform to HAL.
2205  */
2206 typedef struct {
2207     /** Set to sizeof(LocGnssConfigurationInterface) */
2208     size_t size;
2209 
2210     /**
2211      * Deliver GNSS configuration contents to HAL.
2212      * Parameters:
2213      *     config_data - a pointer to a char array which holds what usually is expected from
2214                          file(/vendor/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
2215      *     length - total number of UTF8 characters in configuraiton data.
2216      *
2217      * IMPORTANT:
2218      *      GPS HAL should expect this function can be called multiple times. And it may be
2219      *      called even when GpsLocationProvider is already constructed and enabled. GPS HAL
2220      *      should maintain the existing requests for various callback regardless the change
2221      *      in configuration data.
2222      */
2223     void (*configuration_update) (const char* config_data, int32_t length);
2224 } LocGnssConfigurationInterface;
2225 
2226 __END_DECLS
2227 
2228 #endif /* LOC_GPS_H */
2229 
2230