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