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