blob: 5e8f66d267540d8bb9152c46852580ebf216f5e1 [file] [log] [blame]
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001/*
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#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
Mike Lockwood4453b5b2010-06-20 14:23:10 -070023#include <pthread.h>
destradaaf48cc672014-06-05 11:07:09 -070024#include <sys/socket.h>
destradaa9f7c3732014-04-29 10:50:22 -070025#include <stdbool.h>
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050026
27#include <hardware/hardware.h>
28
29__BEGIN_DECLS
30
31/**
32 * The id of this module
33 */
34#define GPS_HARDWARE_MODULE_ID "gps"
35
36
37/** Milliseconds since January 1, 1970 */
38typedef int64_t GpsUtcTime;
39
40/** Maximum number of SVs for gps_sv_status_callback(). */
41#define GPS_MAX_SVS 32
Lifu Tang7e33bb22016-02-07 18:09:30 -080042/** Maximum number of SVs for gps_sv_status_callback(). */
43#define GNSS_MAX_SVS 64
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050044
destradaa9f7c3732014-04-29 10:50:22 -070045/** Maximum number of Measurements in gps_measurement_callback(). */
46#define GPS_MAX_MEASUREMENT 32
47
Lifu Tang7e33bb22016-02-07 18:09:30 -080048/** Maximum number of Measurements in gnss_measurement_callback(). */
49#define GNSS_MAX_MEASUREMENT 64
50
Mike Lockwoodb15879a2010-04-14 15:36:34 -040051/** Requested operational mode for GPS operation. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050052typedef uint32_t GpsPositionMode;
Lifu Tanga1ca5742016-02-16 17:42:13 -080053/* IMPORTANT: Note that the following values must match
54 * constants in GpsLocationProvider.java. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050055/** Mode for running GPS standalone (no assistance). */
56#define GPS_POSITION_MODE_STANDALONE 0
57/** AGPS MS-Based mode. */
58#define GPS_POSITION_MODE_MS_BASED 1
destradaa81534882015-04-28 13:10:56 -070059/**
60 * AGPS MS-Assisted mode. This mode is not maintained by the platform anymore.
Lifu Tangdf0fcf72015-10-27 14:58:25 -070061 * It is strongly recommended to use GPS_POSITION_MODE_MS_BASED instead.
destradaa81534882015-04-28 13:10:56 -070062 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050063#define GPS_POSITION_MODE_MS_ASSISTED 2
64
Mike Lockwoodb15879a2010-04-14 15:36:34 -040065/** Requested recurrence mode for GPS operation. */
66typedef uint32_t GpsPositionRecurrence;
Lifu Tanga1ca5742016-02-16 17:42:13 -080067/* IMPORTANT: Note that the following values must match
68 * constants in GpsLocationProvider.java. */
Mike Lockwoodb15879a2010-04-14 15:36:34 -040069/** Receive GPS fixes on a recurring basis at a specified period. */
70#define GPS_POSITION_RECURRENCE_PERIODIC 0
71/** Request a single shot GPS fix. */
72#define GPS_POSITION_RECURRENCE_SINGLE 1
73
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050074/** GPS status event values. */
75typedef uint16_t GpsStatusValue;
Lifu Tanga1ca5742016-02-16 17:42:13 -080076/* IMPORTANT: Note that the following values must match
77 * constants in GpsLocationProvider.java. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050078/** GPS status unknown. */
79#define GPS_STATUS_NONE 0
80/** GPS has begun navigating. */
81#define GPS_STATUS_SESSION_BEGIN 1
82/** GPS has stopped navigating. */
83#define GPS_STATUS_SESSION_END 2
84/** GPS has powered on but is not navigating. */
85#define GPS_STATUS_ENGINE_ON 3
86/** GPS is powered off. */
87#define GPS_STATUS_ENGINE_OFF 4
88
89/** Flags to indicate which values are valid in a GpsLocation. */
90typedef uint16_t GpsLocationFlags;
Lifu Tanga1ca5742016-02-16 17:42:13 -080091/* IMPORTANT: Note that the following values must match
92 * constants in GpsLocationProvider.java. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050093/** GpsLocation has valid latitude and longitude. */
94#define GPS_LOCATION_HAS_LAT_LONG 0x0001
95/** GpsLocation has valid altitude. */
96#define GPS_LOCATION_HAS_ALTITUDE 0x0002
97/** GpsLocation has valid speed. */
98#define GPS_LOCATION_HAS_SPEED 0x0004
99/** GpsLocation has valid bearing. */
100#define GPS_LOCATION_HAS_BEARING 0x0008
101/** GpsLocation has valid accuracy. */
102#define GPS_LOCATION_HAS_ACCURACY 0x0010
103
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400104/** Flags for the gps_set_capabilities callback. */
105
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700106/**
107 * GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode. If this is
108 * not set, then the framework will use 1000ms for min_interval and will start
109 * and call start() and stop() to schedule the GPS.
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400110 */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700111#define GPS_CAPABILITY_SCHEDULING (1 << 0)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400112/** GPS supports MS-Based AGPS mode */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700113#define GPS_CAPABILITY_MSB (1 << 1)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400114/** GPS supports MS-Assisted AGPS mode */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700115#define GPS_CAPABILITY_MSA (1 << 2)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400116/** GPS supports single-shot fixes */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700117#define GPS_CAPABILITY_SINGLE_SHOT (1 << 3)
Mike Lockwood8aac5912011-06-29 15:10:36 -0400118/** GPS supports on demand time injection */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700119#define GPS_CAPABILITY_ON_DEMAND_TIME (1 << 4)
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800120/** GPS supports Geofencing */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700121#define GPS_CAPABILITY_GEOFENCING (1 << 5)
Lifu Tanga1ca5742016-02-16 17:42:13 -0800122/**
123 * GPS supports Measurements.
124 * All hardware with GnssSystemInfo::year_of_hw greater or equal to 2016 must
125 * support raw-measurement. Thus this flag is deprecated, and will be removed in
126 * the next release.
127 */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700128#define GPS_CAPABILITY_MEASUREMENTS (1 << 6)
destradaa69d5ea52014-07-31 16:34:09 -0700129/** GPS supports Navigation Messages */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700130#define GPS_CAPABILITY_NAV_MESSAGES (1 << 7)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400131
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700132/**
133 * Flags used to specify which aiding data to delete when calling
134 * delete_aiding_data().
135 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500136typedef uint16_t GpsAidingData;
Lifu Tanga1ca5742016-02-16 17:42:13 -0800137/* IMPORTANT: Note that the following values must match
138 * constants in GpsLocationProvider.java. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500139#define GPS_DELETE_EPHEMERIS 0x0001
140#define GPS_DELETE_ALMANAC 0x0002
141#define GPS_DELETE_POSITION 0x0004
142#define GPS_DELETE_TIME 0x0008
143#define GPS_DELETE_IONO 0x0010
144#define GPS_DELETE_UTC 0x0020
145#define GPS_DELETE_HEALTH 0x0040
146#define GPS_DELETE_SVDIR 0x0080
147#define GPS_DELETE_SVSTEER 0x0100
148#define GPS_DELETE_SADATA 0x0200
149#define GPS_DELETE_RTI 0x0400
150#define GPS_DELETE_CELLDB_INFO 0x8000
151#define GPS_DELETE_ALL 0xFFFF
152
153/** AGPS type */
154typedef uint16_t AGpsType;
155#define AGPS_TYPE_SUPL 1
156#define AGPS_TYPE_C2K 2
157
Miguel Torroja5f404f52010-07-27 06:34:15 +0200158typedef uint16_t AGpsSetIDType;
159#define AGPS_SETID_TYPE_NONE 0
160#define AGPS_SETID_TYPE_IMSI 1
161#define AGPS_SETID_TYPE_MSISDN 2
162
destradaaf48cc672014-06-05 11:07:09 -0700163typedef uint16_t ApnIpType;
164#define APN_IP_INVALID 0
165#define APN_IP_IPV4 1
166#define APN_IP_IPV6 2
167#define APN_IP_IPV4V6 3
168
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500169/**
170 * String length constants
171 */
172#define GPS_NI_SHORT_STRING_MAXLEN 256
173#define GPS_NI_LONG_STRING_MAXLEN 2048
174
175/**
176 * GpsNiType constants
177 */
178typedef uint32_t GpsNiType;
179#define GPS_NI_TYPE_VOICE 1
180#define GPS_NI_TYPE_UMTS_SUPL 2
181#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
182
183/**
184 * GpsNiNotifyFlags constants
185 */
186typedef uint32_t GpsNiNotifyFlags;
187/** NI requires notification */
188#define GPS_NI_NEED_NOTIFY 0x0001
189/** NI requires verification */
190#define GPS_NI_NEED_VERIFY 0x0002
191/** NI requires privacy override, no notification/minimal trace */
192#define GPS_NI_PRIVACY_OVERRIDE 0x0004
193
194/**
195 * GPS NI responses, used to define the response in
196 * NI structures
197 */
198typedef int GpsUserResponseType;
199#define GPS_NI_RESPONSE_ACCEPT 1
200#define GPS_NI_RESPONSE_DENY 2
201#define GPS_NI_RESPONSE_NORESP 3
202
203/**
204 * NI data encoding scheme
205 */
206typedef int GpsNiEncodingType;
207#define GPS_ENC_NONE 0
208#define GPS_ENC_SUPL_GSM_DEFAULT 1
209#define GPS_ENC_SUPL_UTF8 2
210#define GPS_ENC_SUPL_UCS2 3
211#define GPS_ENC_UNKNOWN -1
212
213/** AGPS status event values. */
214typedef uint16_t AGpsStatusValue;
215/** GPS requests data connection for AGPS. */
216#define GPS_REQUEST_AGPS_DATA_CONN 1
217/** GPS releases the AGPS data connection. */
218#define GPS_RELEASE_AGPS_DATA_CONN 2
219/** AGPS data connection initiated */
220#define GPS_AGPS_DATA_CONNECTED 3
221/** AGPS data connection completed */
222#define GPS_AGPS_DATA_CONN_DONE 4
223/** AGPS data connection failed */
224#define GPS_AGPS_DATA_CONN_FAILED 5
225
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700226typedef uint16_t AGpsRefLocationType;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200227#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
228#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
229#define AGPS_REG_LOCATION_TYPE_MAC 3
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700230#define AGPS_REF_LOCATION_TYPE_LTE_CELLID 4
Miguel Torroja5f404f52010-07-27 06:34:15 +0200231
Mike Lockwood455e83b2010-10-11 06:16:57 -0400232/** Network types for update_network_state "type" parameter */
233#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
234#define AGPS_RIL_NETWORK_TYPE_WIFI 1
235#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
236#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
237#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
238#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
239#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
240
Lifu Tanga1ca5742016-02-16 17:42:13 -0800241/* The following typedef together with its constants below are deprecated, and
242 * will be removed in the next release. */
destradaa9f7c3732014-04-29 10:50:22 -0700243typedef uint16_t GpsClockFlags;
destradaa9f7c3732014-04-29 10:50:22 -0700244#define GPS_CLOCK_HAS_LEAP_SECOND (1<<0)
destradaa9f7c3732014-04-29 10:50:22 -0700245#define GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
destradaa75843eb2014-07-17 14:04:50 -0700246#define GPS_CLOCK_HAS_FULL_BIAS (1<<2)
destradaa75843eb2014-07-17 14:04:50 -0700247#define GPS_CLOCK_HAS_BIAS (1<<3)
destradaa75843eb2014-07-17 14:04:50 -0700248#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
destradaa75843eb2014-07-17 14:04:50 -0700249#define GPS_CLOCK_HAS_DRIFT (1<<5)
destradaa75843eb2014-07-17 14:04:50 -0700250#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
251
252/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800253 * Flags to indicate what fields in GnssClock are valid.
destradaa75843eb2014-07-17 14:04:50 -0700254 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800255typedef uint16_t GnssClockFlags;
256/** A valid 'leap second' is stored in the data structure. */
257#define GNSS_CLOCK_HAS_LEAP_SECOND (1<<0)
258/** A valid 'time uncertainty' is stored in the data structure. */
259#define GNSS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
260/** A valid 'full bias' is stored in the data structure. */
261#define GNSS_CLOCK_HAS_FULL_BIAS (1<<2)
262/** A valid 'bias' is stored in the data structure. */
263#define GNSS_CLOCK_HAS_BIAS (1<<3)
264/** A valid 'bias uncertainty' is stored in the data structure. */
265#define GNSS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
266/** A valid 'drift' is stored in the data structure. */
267#define GNSS_CLOCK_HAS_DRIFT (1<<5)
268/** A valid 'drift uncertainty' is stored in the data structure. */
269#define GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
270
271/* The following typedef together with its constants below are deprecated, and
272 * will be removed in the next release. */
destradaa75843eb2014-07-17 14:04:50 -0700273typedef uint8_t GpsClockType;
destradaa75843eb2014-07-17 14:04:50 -0700274#define GPS_CLOCK_TYPE_UNKNOWN 0
destradaa75843eb2014-07-17 14:04:50 -0700275#define GPS_CLOCK_TYPE_LOCAL_HW_TIME 1
destradaa75843eb2014-07-17 14:04:50 -0700276#define GPS_CLOCK_TYPE_GPS_TIME 2
destradaa9f7c3732014-04-29 10:50:22 -0700277
Lifu Tanga1ca5742016-02-16 17:42:13 -0800278/* The following typedef together with its constants below are deprecated, and
279 * will be removed in the next release. */
destradaa9f7c3732014-04-29 10:50:22 -0700280typedef uint32_t GpsMeasurementFlags;
destradaa9f7c3732014-04-29 10:50:22 -0700281#define GPS_MEASUREMENT_HAS_SNR (1<<0)
destradaa9f7c3732014-04-29 10:50:22 -0700282#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
destradaa9f7c3732014-04-29 10:50:22 -0700283#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
destradaa9f7c3732014-04-29 10:50:22 -0700284#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
destradaa9f7c3732014-04-29 10:50:22 -0700285#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
destradaa9f7c3732014-04-29 10:50:22 -0700286#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
destradaa9f7c3732014-04-29 10:50:22 -0700287#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
destradaa9f7c3732014-04-29 10:50:22 -0700288#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
destradaa9f7c3732014-04-29 10:50:22 -0700289#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
destradaa9f7c3732014-04-29 10:50:22 -0700290#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
destradaa9f7c3732014-04-29 10:50:22 -0700291#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
destradaa9f7c3732014-04-29 10:50:22 -0700292#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
destradaa9f7c3732014-04-29 10:50:22 -0700293#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
destradaa9f7c3732014-04-29 10:50:22 -0700294#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
destradaa9f7c3732014-04-29 10:50:22 -0700295#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
destradaa9f7c3732014-04-29 10:50:22 -0700296#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
destradaa9f7c3732014-04-29 10:50:22 -0700297#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
destradaa9f7c3732014-04-29 10:50:22 -0700298#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
destradaa00caa892015-04-09 18:41:46 -0700299#define GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE (1<<18)
destradaa9f7c3732014-04-29 10:50:22 -0700300
301/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800302 * Flags to indicate what fields in GnssMeasurement are valid.
destradaa9f7c3732014-04-29 10:50:22 -0700303 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800304typedef uint32_t GnssMeasurementFlags;
305/** A valid 'snr' is stored in the data structure. */
306#define GNSS_MEASUREMENT_HAS_SNR (1<<0)
307/** A valid 'elevation' is stored in the data structure. */
308#define GNSS_MEASUREMENT_HAS_ELEVATION (1<<1)
309/** A valid 'elevation uncertainty' is stored in the data structure. */
310#define GNSS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
311/** A valid 'azimuth' is stored in the data structure. */
312#define GNSS_MEASUREMENT_HAS_AZIMUTH (1<<3)
313/** A valid 'azimuth uncertainty' is stored in the data structure. */
314#define GNSS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
315/** A valid 'pseudorange' is stored in the data structure. */
316#define GNSS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
317/** A valid 'pseudorange uncertainty' is stored in the data structure. */
318#define GNSS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
319/** A valid 'code phase' is stored in the data structure. */
320#define GNSS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
321/** A valid 'code phase uncertainty' is stored in the data structure. */
322#define GNSS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
323/** A valid 'carrier frequency' is stored in the data structure. */
324#define GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
325/** A valid 'carrier cycles' is stored in the data structure. */
326#define GNSS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
327/** A valid 'carrier phase' is stored in the data structure. */
328#define GNSS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
329/** A valid 'carrier phase uncertainty' is stored in the data structure. */
330#define GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
331/** A valid 'bit number' is stored in the data structure. */
332#define GNSS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
333/** A valid 'time from last bit' is stored in the data structure. */
334#define GNSS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
335/** A valid 'doppler shift' is stored in the data structure. */
336#define GNSS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
337/** A valid 'doppler shift uncertainty' is stored in the data structure. */
338#define GNSS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
339/** A valid 'used in fix' flag is stored in the data structure. */
340#define GNSS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
341/**
342 * The value of 'pseudorange rate' is uncorrected.
343 * This is a mandatory flag. See comments of
344 * GpsMeasurement::pseudorange_rate_mps for more details.
345 */
346#define GNSS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE (1<<18)
347
348/* The following typedef together with its constants below are deprecated, and
349 * will be removed in the next release. */
destradaa9f7c3732014-04-29 10:50:22 -0700350typedef uint8_t GpsLossOfLock;
destradaa9f7c3732014-04-29 10:50:22 -0700351#define GPS_LOSS_OF_LOCK_UNKNOWN 0
destradaa9f7c3732014-04-29 10:50:22 -0700352#define GPS_LOSS_OF_LOCK_OK 1
destradaa9f7c3732014-04-29 10:50:22 -0700353#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
354
Lifu Tanga1ca5742016-02-16 17:42:13 -0800355/* The following typedef together with its constants below are deprecated, and
356 * will be removed in the next release. */
destradaa9f7c3732014-04-29 10:50:22 -0700357typedef uint8_t GpsMultipathIndicator;
destradaa9f7c3732014-04-29 10:50:22 -0700358#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
destradaa9f7c3732014-04-29 10:50:22 -0700359#define GPS_MULTIPATH_INDICATOR_DETECTED 1
destradaa9f7c3732014-04-29 10:50:22 -0700360#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
361
362/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800363 * Enumeration of available values for the GNSS Measurement's multipath
364 * indicator.
destradaa75843eb2014-07-17 14:04:50 -0700365 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800366typedef uint8_t GnssMultipathIndicator;
367/** The indicator is not available or unknown. */
368#define GNSS_MULTIPATH_INDICATOR_UNKNOWN 0
369/** The measurement is indicated to be affected by multipath. */
370#define GNSS_MULTIPATH_INDICATOR_DETECTED 1
371/** The measurement is indicated to be not affected by multipath. */
372#define GNSS_MULTIPATH_INDICATOR_NOT_USED 2
373
374/* The following typedef together with its constants below are deprecated, and
375 * will be removed in the next release. */
destradaa75843eb2014-07-17 14:04:50 -0700376typedef uint16_t GpsMeasurementState;
377#define GPS_MEASUREMENT_STATE_UNKNOWN 0
378#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
379#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
380#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
381#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
Tsuwei Chena90cf192014-10-23 12:49:12 -0700382#define GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4)
destradaa75843eb2014-07-17 14:04:50 -0700383
384/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800385 * Flags indicating the GNSS measurement state.
386 *
387 * The expected behavior here is for GPS HAL to set all the flags that applies.
388 * For example, if the state for a satellite is only C/A code locked and bit
389 * synchronized, and there is still millisecond ambiguity, the state should be
390 * set as:
391 *
392 * GNSS_MEASUREMENT_STATE_CODE_LOCK | GNSS_MEASUREMENT_STATE_BIT_SYNC |
393 * GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS
394 *
395 * If GNSS is still searching for a satellite, the corresponding state should be
396 * set to GNSS_MEASUREMENT_STATE_UNKNOWN(0).
destradaa75843eb2014-07-17 14:04:50 -0700397 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800398typedef uint16_t GnssMeasurementState;
399#define GNSS_MEASUREMENT_STATE_UNKNOWN 0
400#define GNSS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
401#define GNSS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
402#define GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
403#define GNSS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
404#define GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4)
405
406/* The following typedef together with its constants below are deprecated, and
407 * will be removed in the next release. */
destradaa75843eb2014-07-17 14:04:50 -0700408typedef uint16_t GpsAccumulatedDeltaRangeState;
409#define GPS_ADR_STATE_UNKNOWN 0
410#define GPS_ADR_STATE_VALID (1<<0)
411#define GPS_ADR_STATE_RESET (1<<1)
412#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
413
414/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800415 * Flags indicating the Accumulated Delta Range's states.
destradaa9f7c3732014-04-29 10:50:22 -0700416 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800417typedef uint16_t GnssAccumulatedDeltaRangeState;
418#define GNSS_ADR_STATE_UNKNOWN 0
419#define GNSS_ADR_STATE_VALID (1<<0)
420#define GNSS_ADR_STATE_RESET (1<<1)
421#define GNSS_ADR_STATE_CYCLE_SLIP (1<<2)
422
423/* The following typedef together with its constants below are deprecated, and
424 * will be removed in the next release. */
destradaa9f7c3732014-04-29 10:50:22 -0700425typedef uint8_t GpsNavigationMessageType;
destradaa9f7c3732014-04-29 10:50:22 -0700426#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
destradaa9f7c3732014-04-29 10:50:22 -0700427#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
destradaa9f7c3732014-04-29 10:50:22 -0700428#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
destradaa9f7c3732014-04-29 10:50:22 -0700429#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
destradaa9f7c3732014-04-29 10:50:22 -0700430#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
431
Tsuwei Chena90cf192014-10-23 12:49:12 -0700432/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800433 * Enumeration of available values to indicate the GNSS Navigation message
434 * types.
435 *
436 * For convenience, first byte is the GnssConstellationType on which that signal
437 * is typically transmitted
438 */
439typedef int16_t GnssNavigationMessageType;
440
441#define GNSS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
442/** GPS L1 C/A message contained in the structure. */
443#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L1CA 0x0101
444/** GPS L2-CNAV message contained in the structure. */
445#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L2CNAV 0x0102
446/** GPS L5-CNAV message contained in the structure. */
447#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L5CNAV 0x0103
448/** GPS CNAV-2 message contained in the structure. */
449#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_CNAV2 0x0104
450/** Glonass L1 CA message contained in the structure. */
451#define GNSS_NAVIGATION_MESSAGE_TYPE_GLO_L1CA 0x0301
452/** Beidou D1 message contained in the structure. */
453#define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D1 0x0501
454/** Beidou D2 message contained in the structure. */
455#define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D2 0x0502
456/** Galileo I/NAV message contained in the structure. */
457#define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_I 0x0601
458/** Galileo F/NAV message contained in the structure. */
459#define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_F 0x0602
460
461/**
Tsuwei Chena90cf192014-10-23 12:49:12 -0700462 * Status of Navigation Message
463 * When a message is received properly without any parity error in its navigation words, the
464 * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received
465 * with words that failed parity check, but GPS is able to correct those words, the status
466 * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT.
467 * No need to send any navigation message that contains words with parity error and cannot be
468 * corrected.
469 */
470typedef uint16_t NavigationMessageStatus;
471#define NAV_MESSAGE_STATUS_UNKONW 0
472#define NAV_MESSAGE_STATUS_PARITY_PASSED (1<<0)
473#define NAV_MESSAGE_STATUS_PARITY_REBUILT (1<<1)
destradaa9f7c3732014-04-29 10:50:22 -0700474
475/**
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700476 * Flag that indicates which extra data GnssSvInfo includes.
477 */
478typedef uint8_t GnssSvFlags;
479#define GNSS_SV_FLAGS_NONE 0
480#define GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA (1 << 0)
481#define GNSS_SV_FLAGS_HAS_ALMANAC_DATA (1 << 1)
482#define GNSS_SV_FLAGS_USED_IN_FIX (1 << 2)
483
484/**
485 * Constellation type of GnssSvInfo
486 */
487typedef uint8_t GnssConstellationType;
488#define GNSS_CONSTELLATION_UNKNOWN 0
489#define GNSS_CONSTELLATION_GPS 1
490#define GNSS_CONSTELLATION_SBAS 2
491#define GNSS_CONSTELLATION_GLONASS 3
492#define GNSS_CONSTELLATION_QZSS 4
493#define GNSS_CONSTELLATION_BEIDOU 5
494#define GNSS_CONSTELLATION_GALILEO 6
495
496/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500497 * Name for the GPS XTRA interface.
498 */
499#define GPS_XTRA_INTERFACE "gps-xtra"
500
501/**
502 * Name for the GPS DEBUG interface.
503 */
504#define GPS_DEBUG_INTERFACE "gps-debug"
505
506/**
507 * Name for the AGPS interface.
508 */
509#define AGPS_INTERFACE "agps"
510
511/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700512 * Name of the Supl Certificate interface.
513 */
514#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
515
516/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500517 * Name for NI interface
518 */
519#define GPS_NI_INTERFACE "gps-ni"
520
Miguel Torroja5f404f52010-07-27 06:34:15 +0200521/**
522 * Name for the AGPS-RIL interface.
523 */
524#define AGPS_RIL_INTERFACE "agps_ril"
525
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800526/**
527 * Name for the GPS_Geofencing interface.
528 */
529#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
530
destradaa9f7c3732014-04-29 10:50:22 -0700531/**
532 * Name of the GPS Measurements interface.
533 */
534#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
535
536/**
537 * Name of the GPS navigation message interface.
538 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -0700539#define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
540
541/**
542 * Name of the GNSS/GPS configuration interface.
543 */
544#define GNSS_CONFIGURATION_INTERFACE "gnss_configuration"
destradaa9f7c3732014-04-29 10:50:22 -0700545
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800546
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500547/** Represents a location. */
548typedef struct {
549 /** set to sizeof(GpsLocation) */
550 size_t size;
551 /** Contains GpsLocationFlags bits. */
552 uint16_t flags;
553 /** Represents latitude in degrees. */
554 double latitude;
555 /** Represents longitude in degrees. */
556 double longitude;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700557 /**
558 * Represents altitude in meters above the WGS 84 reference ellipsoid.
559 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500560 double altitude;
561 /** Represents speed in meters per second. */
562 float speed;
563 /** Represents heading in degrees. */
564 float bearing;
565 /** Represents expected accuracy in meters. */
566 float accuracy;
567 /** Timestamp for the location fix. */
568 GpsUtcTime timestamp;
569} GpsLocation;
570
571/** Represents the status. */
572typedef struct {
573 /** set to sizeof(GpsStatus) */
574 size_t size;
575 GpsStatusValue status;
576} GpsStatus;
577
Lifu Tanga1ca5742016-02-16 17:42:13 -0800578/**
579 * Legacy struct to represents SV information.
580 * Deprecated, to be removed in the next Android release.
581 * Use GnssSvInfo instead.
582 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500583typedef struct {
584 /** set to sizeof(GpsSvInfo) */
585 size_t size;
586 /** Pseudo-random number for the SV. */
587 int prn;
588 /** Signal to noise ratio. */
589 float snr;
590 /** Elevation of SV in degrees. */
591 float elevation;
592 /** Azimuth of SV in degrees. */
593 float azimuth;
594} GpsSvInfo;
595
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500596typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700597 /** set to sizeof(GnssSvInfo) */
598 size_t size;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500599
600 /**
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700601 * Pseudo-random number for the SV, or Amanac/slot number for Glonass. The
602 * distinction is made by looking at constellation field. Values should be
603 * in the range of:
604 *
605 * - GPS: 1-32
606 * - SBAS: 120-151, 183-192
607 * - GLONASS: 1-24 (slot number)
608 * - QZSS: 193-200
609 * - Galileo: 1-25
610 * - Beidou: 1-35
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500611 */
Lifu Tang7e33bb22016-02-07 18:09:30 -0800612 int16_t svid;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700613
Lifu Tanga1ca5742016-02-16 17:42:13 -0800614 /**
615 * Defines the constellation of the given SV. Value should be one of those
616 * GNSS_CONSTELLATION_* constants
617 */
618 GnssConstellationType constellation;
619
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700620 /** Signal to noise ratio. */
621 float snr;
622
623 /** Elevation of SV in degrees. */
624 float elevation;
625
626 /** Azimuth of SV in degrees. */
627 float azimuth;
628
629 /**
630 * Contains additional data about the given SV. Value should be one of those
631 * GNSS_SV_FLAGS_* constants
632 */
633 GnssSvFlags flags;
634
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700635} GnssSvInfo;
636
637/**
Lifu Tang7e33bb22016-02-07 18:09:30 -0800638 * Legacy struct to represents SV status.
639 * Deprecated, to be removed in the next Android release.
640 * Use GnssSvStatus instead.
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700641 */
642typedef struct {
643 /** set to sizeof(GpsSvStatus) */
644 size_t size;
Lifu Tang7e33bb22016-02-07 18:09:30 -0800645 int num_svs;
646 GpsSvInfo sv_list[GPS_MAX_SVS];
647 uint32_t ephemeris_mask;
648 uint32_t almanac_mask;
649 uint32_t used_in_fix_mask;
650} GpsSvStatus;
651
652/**
653 * Represents SV status.
654 */
655typedef struct {
656 /** set to sizeof(GnssSvStatus) */
657 size_t size;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700658
659 /** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */
660 int num_svs;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700661 /**
662 * Pointer to an array of SVs information for all GNSS constellations,
663 * except GPS, which is reported using sv_list
664 */
Lifu Tang7e33bb22016-02-07 18:09:30 -0800665 GnssSvInfo gnss_sv_list[GNSS_MAX_SVS];
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700666
Lifu Tang7e33bb22016-02-07 18:09:30 -0800667} GnssSvStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500668
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700669/* CellID for 2G, 3G and LTE, used in AGPS. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200670typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700671 AGpsRefLocationType type;
672 /** Mobile Country Code. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200673 uint16_t mcc;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700674 /** Mobile Network Code .*/
Miguel Torroja5f404f52010-07-27 06:34:15 +0200675 uint16_t mnc;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700676 /** Location Area Code in 2G, 3G and LTE. In 3G lac is discarded. In LTE,
677 * lac is populated with tac, to ensure that we don't break old clients that
678 * might rely in the old (wrong) behavior.
679 */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200680 uint16_t lac;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700681 /** Cell id in 2G. Utran Cell id in 3G. Cell Global Id EUTRA in LTE. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200682 uint32_t cid;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700683 /** Tracking Area Code in LTE. */
684 uint16_t tac;
685 /** Physical Cell id in LTE (not used in 2G and 3G) */
686 uint16_t pcid;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200687} AGpsRefLocationCellID;
688
689typedef struct {
690 uint8_t mac[6];
691} AGpsRefLocationMac;
692
693/** Represents ref locations */
694typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700695 AGpsRefLocationType type;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200696 union {
697 AGpsRefLocationCellID cellID;
698 AGpsRefLocationMac mac;
699 } u;
700} AGpsRefLocation;
701
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700702/**
703 * Callback with location information. Can only be called from a thread created
704 * by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700705 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500706typedef void (* gps_location_callback)(GpsLocation* location);
707
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700708/**
709 * Callback with status information. Can only be called from a thread created by
710 * create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700711 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500712typedef void (* gps_status_callback)(GpsStatus* status);
713
destradaa9f7c3732014-04-29 10:50:22 -0700714/**
Lifu Tanga1ca5742016-02-16 17:42:13 -0800715 * Legacy callback with SV status information.
destradaa9f7c3732014-04-29 10:50:22 -0700716 * Can only be called from a thread created by create_thread_cb.
Lifu Tanga1ca5742016-02-16 17:42:13 -0800717 *
718 * This callback is deprecated, and will be removed in the next release. Use
719 * gnss_sv_status_callback() instead.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700720 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500721typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
722
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700723/**
Lifu Tang7e33bb22016-02-07 18:09:30 -0800724 * Callback with SV status information.
725 * Can only be called from a thread created by create_thread_cb.
726 */
727typedef void (* gnss_sv_status_callback)(GnssSvStatus* sv_info);
728
729/**
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700730 * Callback for reporting NMEA sentences. Can only be called from a thread
731 * created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700732 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500733typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
734
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700735/**
736 * Callback to inform framework of the GPS engine's capabilities. Capability
737 * parameter is a bit field of GPS_CAPABILITY_* flags.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700738 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400739typedef void (* gps_set_capabilities)(uint32_t capabilities);
740
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700741/**
742 * Callback utility for acquiring the GPS wakelock. This can be used to prevent
743 * the CPU from suspending while handling GPS events.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700744 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400745typedef void (* gps_acquire_wakelock)();
746
747/** Callback utility for releasing the GPS wakelock. */
748typedef void (* gps_release_wakelock)();
749
Mike Lockwood8aac5912011-06-29 15:10:36 -0400750/** Callback for requesting NTP time */
751typedef void (* gps_request_utc_time)();
752
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700753/**
754 * Callback for creating a thread that can call into the Java framework code.
755 * This must be used to create any threads that report events up to the
756 * framework.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700757 */
758typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
759
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700760/**
761 * Provides information about how new the underlying GPS/GNSS hardware and
762 * software is.
763 *
764 * This information will be available for Android Test Applications. If a GPS
765 * HAL does not provide this information, it will be considered "2015 or
766 * earlier".
767 *
768 * If a GPS HAL does provide this information, then newer years will need to
769 * meet newer CTS standards. E.g. if the date are 2016 or above, then N+ level
770 * GpsMeasurement support will be verified.
771 */
772typedef struct {
Lifu Tanga1ca5742016-02-16 17:42:13 -0800773 /** Set to sizeof(GnssSystemInfo) */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700774 size_t size;
775 /* year in which the last update was made to the underlying hardware/firmware
776 * used to capture GNSS signals, e.g. 2016 */
777 uint16_t year_of_hw;
Lifu Tanga1ca5742016-02-16 17:42:13 -0800778} GnssSystemInfo;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700779
780/**
781 * Callback to inform framework of the engine's hardware version information.
782 */
Lifu Tanga1ca5742016-02-16 17:42:13 -0800783typedef void (*gnss_set_system_info)(const GnssSystemInfo* info);
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700784
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700785/** New GPS callback structure. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500786typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400787 /** set to sizeof(GpsCallbacks) */
788 size_t size;
789 gps_location_callback location_cb;
790 gps_status_callback status_cb;
791 gps_sv_status_callback sv_status_cb;
792 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400793 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400794 gps_acquire_wakelock acquire_wakelock_cb;
795 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700796 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400797 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500798
Lifu Tanga1ca5742016-02-16 17:42:13 -0800799 gnss_set_system_info set_system_info_cb;
Lifu Tang7e33bb22016-02-07 18:09:30 -0800800 gnss_sv_status_callback gnss_sv_status_cb;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700801} GpsCallbacks;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500802
803/** Represents the standard GPS interface. */
804typedef struct {
805 /** set to sizeof(GpsInterface) */
806 size_t size;
807 /**
808 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700809 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500810 */
811 int (*init)( GpsCallbacks* callbacks );
812
813 /** Starts navigating. */
814 int (*start)( void );
815
816 /** Stops navigating. */
817 int (*stop)( void );
818
819 /** Closes the interface. */
820 void (*cleanup)( void );
821
822 /** Injects the current time. */
823 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
824 int uncertainty);
825
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700826 /**
827 * Injects current location from another location provider (typically cell
828 * ID). Latitude and longitude are measured in degrees expected accuracy is
829 * measured in meters
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500830 */
831 int (*inject_location)(double latitude, double longitude, float accuracy);
832
833 /**
834 * Specifies that the next call to start will not use the
835 * information defined in the flags. GPS_DELETE_ALL is passed for
836 * a cold start.
837 */
838 void (*delete_aiding_data)(GpsAidingData flags);
839
840 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400841 * min_interval represents the time between fixes in milliseconds.
842 * preferred_accuracy represents the requested fix accuracy in meters.
843 * preferred_time represents the requested time to first fix in milliseconds.
destradaa81534882015-04-28 13:10:56 -0700844 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700845 * 'mode' parameter should be one of GPS_POSITION_MODE_MS_BASED
destradaa81534882015-04-28 13:10:56 -0700846 * or GPS_POSITION_MODE_STANDALONE.
847 * It is allowed by the platform (and it is recommended) to fallback to
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700848 * GPS_POSITION_MODE_MS_BASED if GPS_POSITION_MODE_MS_ASSISTED is passed in, and
destradaa81534882015-04-28 13:10:56 -0700849 * GPS_POSITION_MODE_MS_BASED is supported.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500850 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400851 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
852 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500853
854 /** Get a pointer to extension information. */
855 const void* (*get_extension)(const char* name);
856} GpsInterface;
857
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700858/**
859 * Callback to request the client to download XTRA data. The client should
860 * download XTRA data and inject it by calling inject_xtra_data(). Can only be
861 * called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700862 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500863typedef void (* gps_xtra_download_request)();
864
865/** Callback structure for the XTRA interface. */
866typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700867 gps_xtra_download_request download_request_cb;
868 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500869} GpsXtraCallbacks;
870
871/** Extended interface for XTRA support. */
872typedef struct {
873 /** set to sizeof(GpsXtraInterface) */
874 size_t size;
875 /**
876 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700877 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500878 */
879 int (*init)( GpsXtraCallbacks* callbacks );
880 /** Injects XTRA data into the GPS. */
881 int (*inject_xtra_data)( char* data, int length );
882} GpsXtraInterface;
883
884/** Extended interface for DEBUG support. */
885typedef struct {
886 /** set to sizeof(GpsDebugInterface) */
887 size_t size;
888
889 /**
890 * This function should return any information that the native
891 * implementation wishes to include in a bugreport.
892 */
893 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
894} GpsDebugInterface;
895
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700896/*
897 * Represents the status of AGPS augmented to support IPv4 and IPv6.
898 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500899typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700900 /** set to sizeof(AGpsStatus) */
destradaaf48cc672014-06-05 11:07:09 -0700901 size_t size;
902
903 AGpsType type;
904 AGpsStatusValue status;
905
906 /**
907 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
908 * address, or set to INADDR_NONE otherwise.
909 */
910 uint32_t ipaddr;
911
912 /**
913 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
914 * Any other value of addr.ss_family will be rejected.
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700915 */
destradaaf48cc672014-06-05 11:07:09 -0700916 struct sockaddr_storage addr;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700917} AGpsStatus;
destradaaf48cc672014-06-05 11:07:09 -0700918
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700919/**
920 * Callback with AGPS status information. Can only be called from a thread
921 * created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700922 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500923typedef void (* agps_status_callback)(AGpsStatus* status);
924
925/** Callback structure for the AGPS interface. */
926typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700927 agps_status_callback status_cb;
928 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500929} AGpsCallbacks;
930
destradaaf48cc672014-06-05 11:07:09 -0700931/**
932 * Extended interface for AGPS support, it is augmented to enable to pass
933 * extra APN data.
934 */
935typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700936 /** set to sizeof(AGpsInterface) */
destradaaf48cc672014-06-05 11:07:09 -0700937 size_t size;
938
939 /**
940 * Opens the AGPS interface and provides the callback routines to the
941 * implementation of this interface.
942 */
943 void (*init)(AGpsCallbacks* callbacks);
944 /**
945 * Deprecated.
946 * If the HAL supports AGpsInterface_v2 this API will not be used, see
947 * data_conn_open_with_apn_ip_type for more information.
948 */
949 int (*data_conn_open)(const char* apn);
950 /**
951 * Notifies that the AGPS data connection has been closed.
952 */
953 int (*data_conn_closed)();
954 /**
955 * Notifies that a data connection is not available for AGPS.
956 */
957 int (*data_conn_failed)();
958 /**
959 * Sets the hostname and port for the AGPS server.
960 */
961 int (*set_server)(AGpsType type, const char* hostname, int port);
962
963 /**
964 * Notifies that a data connection is available and sets the name of the
965 * APN, and its IP type, to be used for SUPL connections.
966 */
967 int (*data_conn_open_with_apn_ip_type)(
968 const char* apn,
969 ApnIpType apnIpType);
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700970} AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500971
destradaaa1f4c0a2013-09-13 15:45:03 -0700972/** Error codes associated with certificate operations */
973#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
974#define AGPS_CERTIFICATE_ERROR_GENERIC -100
975#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
976
977/** A data structure that represents an X.509 certificate using DER encoding */
978typedef struct {
979 size_t length;
980 u_char* data;
981} DerEncodedCertificate;
982
983/**
984 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
985 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
986 */
987typedef struct {
988 u_char data[20];
989} Sha1CertificateFingerprint;
990
destradaa9f7c3732014-04-29 10:50:22 -0700991/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700992typedef struct {
993 /** set to sizeof(SuplCertificateInterface) */
994 size_t size;
995
996 /**
997 * Installs a set of Certificates used for SUPL connections to the AGPS server.
998 * If needed the HAL should find out internally any certificates that need to be removed to
999 * accommodate the certificates to install.
1000 * The certificates installed represent a full set of valid certificates needed to connect to
1001 * AGPS SUPL servers.
1002 * The list of certificates is required, and all must be available at the same time, when trying
1003 * to establish a connection with the AGPS Server.
1004 *
1005 * Parameters:
1006 * certificates - A pointer to an array of DER encoded certificates that are need to be
1007 * installed in the HAL.
1008 * length - The number of certificates to install.
1009 * Returns:
1010 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
1011 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
1012 * certificates attempted to be installed, the state of the certificates stored should
1013 * remain the same as before on this error case.
1014 *
1015 * IMPORTANT:
1016 * If needed the HAL should find out internally the set of certificates that need to be
1017 * removed to accommodate the certificates to install.
1018 */
1019 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
1020
1021 /**
1022 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
1023 * expected that the given set of certificates is removed from the internal store of the HAL.
1024 *
1025 * Parameters:
1026 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
1027 * certificates to revoke.
1028 * length - The number of fingerprints provided.
1029 * Returns:
1030 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
1031 *
1032 * IMPORTANT:
1033 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
1034 * it should be ignored and continue revoking/deleting the rest of them.
1035 */
1036 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -08001037} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001038
1039/** Represents an NI request */
1040typedef struct {
1041 /** set to sizeof(GpsNiNotification) */
1042 size_t size;
1043
1044 /**
1045 * An ID generated by HAL to associate NI notifications and UI
1046 * responses
1047 */
1048 int notification_id;
1049
1050 /**
1051 * An NI type used to distinguish different categories of NI
1052 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
1053 */
1054 GpsNiType ni_type;
1055
1056 /**
1057 * Notification/verification options, combinations of GpsNiNotifyFlags constants
1058 */
1059 GpsNiNotifyFlags notify_flags;
1060
1061 /**
1062 * Timeout period to wait for user response.
1063 * Set to 0 for no time out limit.
1064 */
1065 int timeout;
1066
1067 /**
1068 * Default response when time out.
1069 */
1070 GpsUserResponseType default_response;
1071
1072 /**
1073 * Requestor ID
1074 */
1075 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
1076
1077 /**
1078 * Notification message. It can also be used to store client_id in some cases
1079 */
1080 char text[GPS_NI_LONG_STRING_MAXLEN];
1081
1082 /**
1083 * Client name decoding scheme
1084 */
1085 GpsNiEncodingType requestor_id_encoding;
1086
1087 /**
1088 * Client name decoding scheme
1089 */
1090 GpsNiEncodingType text_encoding;
1091
1092 /**
1093 * A pointer to extra data. Format:
1094 * key_1 = value_1
1095 * key_2 = value_2
1096 */
1097 char extras[GPS_NI_LONG_STRING_MAXLEN];
1098
1099} GpsNiNotification;
1100
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001101/**
1102 * Callback with NI notification. Can only be called from a thread created by
1103 * create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -07001104 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001105typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
1106
1107/** GPS NI callback structure. */
1108typedef struct
1109{
Mike Lockwood4453b5b2010-06-20 14:23:10 -07001110 /**
1111 * Sends the notification request from HAL to GPSLocationProvider.
1112 */
1113 gps_ni_notify_callback notify_cb;
1114 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001115} GpsNiCallbacks;
1116
1117/**
1118 * Extended interface for Network-initiated (NI) support.
1119 */
1120typedef struct
1121{
1122 /** set to sizeof(GpsNiInterface) */
1123 size_t size;
1124
1125 /** Registers the callbacks for HAL to use. */
1126 void (*init) (GpsNiCallbacks *callbacks);
1127
1128 /** Sends a response to HAL. */
1129 void (*respond) (int notif_id, GpsUserResponseType user_response);
1130} GpsNiInterface;
1131
1132struct gps_device_t {
1133 struct hw_device_t common;
1134
1135 /**
1136 * Set the provided lights to the provided values.
1137 *
1138 * Returns: 0 on succes, error code on failure.
1139 */
1140 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
1141};
1142
Miguel Torroja5f404f52010-07-27 06:34:15 +02001143#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
1144#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
1145
1146#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
1147#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
1148
1149typedef void (*agps_ril_request_set_id)(uint32_t flags);
1150typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
1151
1152typedef struct {
1153 agps_ril_request_set_id request_setid;
1154 agps_ril_request_ref_loc request_refloc;
1155 gps_create_thread create_thread_cb;
1156} AGpsRilCallbacks;
1157
1158/** Extended interface for AGPS_RIL support. */
1159typedef struct {
1160 /** set to sizeof(AGpsRilInterface) */
1161 size_t size;
1162 /**
1163 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001164 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +02001165 */
1166 void (*init)( AGpsRilCallbacks* callbacks );
1167
1168 /**
1169 * Sets the reference location.
1170 */
1171 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
1172 /**
1173 * Sets the set ID.
1174 */
1175 void (*set_set_id) (AGpsSetIDType type, const char* setid);
1176
1177 /**
1178 * Send network initiated message.
1179 */
1180 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -04001181
1182 /**
1183 * Notify GPS of network status changes.
1184 * These parameters match values in the android.net.NetworkInfo class.
1185 */
1186 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -07001187
1188 /**
1189 * Notify GPS of network status changes.
1190 * These parameters match values in the android.net.NetworkInfo class.
1191 */
1192 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +02001193} AGpsRilInterface;
1194
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001195/**
1196 * GPS Geofence.
1197 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1198 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1199 *
1200 * An example state diagram with confidence level: 95% and Unknown time limit
1201 * set as 30 secs is shown below. (confidence level and Unknown time limit are
1202 * explained latter)
1203 * ____________________________
1204 * | Unknown (30 secs) |
1205 * """"""""""""""""""""""""""""
1206 * ^ | | ^
1207 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
1208 * | v v |
1209 * ________ EXITED _________
1210 * | Inside | -----------> | Outside |
1211 * | | <----------- | |
1212 * """""""" ENTERED """""""""
1213 *
1214 * Inside state: We are 95% confident that the user is inside the geofence.
1215 * Outside state: We are 95% confident that the user is outside the geofence
1216 * Unknown state: Rest of the time.
1217 *
1218 * The Unknown state is better explained with an example:
1219 *
1220 * __________
1221 * | c|
1222 * | ___ | _______
1223 * | |a| | | b |
1224 * | """ | """""""
1225 * | |
1226 * """"""""""
1227 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1228 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1229 * confident that the user is outside. But with regard to "a" is not confident
1230 * whether it is inside or outside the geofence. If the accuracy remains the
1231 * same for a sufficient period of time, the UNCERTAIN transition would be
1232 * triggered with the state set to Unknown. If the accuracy improves later, an
1233 * appropriate transition should be triggered. This "sufficient period of time"
1234 * is defined by the parameter in the add_geofence_area API.
1235 * In other words, Unknown state can be interpreted as a state in which the
1236 * GPS subsystem isn't confident enough that the user is either inside or
1237 * outside the Geofence. It moves to Unknown state only after the expiry of the
1238 * timeout.
1239 *
1240 * The geofence callback needs to be triggered for the ENTERED and EXITED
1241 * transitions, when the GPS system is confident that the user has entered
1242 * (Inside state) or exited (Outside state) the Geofence. An implementation
1243 * which uses a value of 95% as the confidence is recommended. The callback
1244 * should be triggered only for the transitions requested by the
1245 * add_geofence_area call.
1246 *
1247 * Even though the diagram and explanation talks about states and transitions,
1248 * the callee is only interested in the transistions. The states are mentioned
1249 * here for illustrative purposes.
1250 *
1251 * Startup Scenario: When the device boots up, if an application adds geofences,
1252 * and then we get an accurate GPS location fix, it needs to trigger the
1253 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1254 * By default, all the Geofences will be in the Unknown state.
1255 *
1256 * When the GPS system is unavailable, gps_geofence_status_callback should be
1257 * called to inform the upper layers of the same. Similarly, when it becomes
1258 * available the callback should be called. This is a global state while the
1259 * UNKNOWN transition described above is per geofence.
1260 *
1261 * An important aspect to note is that users of this API (framework), will use
1262 * other subsystems like wifi, sensors, cell to handle Unknown case and
1263 * hopefully provide a definitive state transition to the third party
1264 * application. GPS Geofence will just be a signal indicating what the GPS
1265 * subsystem knows about the Geofence.
1266 *
1267 */
1268#define GPS_GEOFENCE_ENTERED (1<<0L)
1269#define GPS_GEOFENCE_EXITED (1<<1L)
1270#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1271
1272#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1273#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1274
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001275#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1276#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1277#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1278#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1279#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1280#define GPS_GEOFENCE_ERROR_GENERIC -149
1281
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001282/**
1283 * The callback associated with the geofence.
1284 * Parameters:
1285 * geofence_id - The id associated with the add_geofence_area.
1286 * location - The current GPS location.
1287 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1288 * GPS_GEOFENCE_UNCERTAIN.
1289 * timestamp - Timestamp when the transition was detected.
1290 *
1291 * The callback should only be called when the caller is interested in that
1292 * particular transition. For instance, if the caller is interested only in
1293 * ENTERED transition, then the callback should NOT be called with the EXITED
1294 * transition.
1295 *
1296 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1297 * subsystem will wake up the application processor, if its in suspend state.
1298 */
1299typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1300 int32_t transition, GpsUtcTime timestamp);
1301
1302/**
destradaa9f7c3732014-04-29 10:50:22 -07001303 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001304 * monitoring. If the GPS system determines that it cannot monitor geofences
1305 * because of lack of reliability or unavailability of the GPS signals, it will
1306 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1307 *
1308 * Parameters:
1309 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1310 * last_location - Last known location.
1311 */
1312typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1313
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001314/**
1315 * The callback associated with the add_geofence call.
1316 *
1317 * Parameter:
1318 * geofence_id - Id of the geofence.
1319 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1320 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1321 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1322 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1323 * invalid transition
1324 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1325 */
1326typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1327
1328/**
1329 * The callback associated with the remove_geofence call.
1330 *
1331 * Parameter:
1332 * geofence_id - Id of the geofence.
1333 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1334 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1335 * GPS_GEOFENCE_ERROR_GENERIC for others.
1336 */
1337typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1338
1339
1340/**
1341 * The callback associated with the pause_geofence call.
1342 *
1343 * Parameter:
1344 * geofence_id - Id of the geofence.
1345 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1346 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1347 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1348 * when monitor_transitions is invalid
1349 * GPS_GEOFENCE_ERROR_GENERIC for others.
1350 */
1351typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1352
1353/**
1354 * The callback associated with the resume_geofence call.
1355 *
1356 * Parameter:
1357 * geofence_id - Id of the geofence.
1358 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1359 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1360 * GPS_GEOFENCE_ERROR_GENERIC for others.
1361 */
1362typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1363
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001364typedef struct {
1365 gps_geofence_transition_callback geofence_transition_callback;
1366 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001367 gps_geofence_add_callback geofence_add_callback;
1368 gps_geofence_remove_callback geofence_remove_callback;
1369 gps_geofence_pause_callback geofence_pause_callback;
1370 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001371 gps_create_thread create_thread_cb;
1372} GpsGeofenceCallbacks;
1373
1374/** Extended interface for GPS_Geofencing support */
1375typedef struct {
1376 /** set to sizeof(GpsGeofencingInterface) */
1377 size_t size;
1378
1379 /**
1380 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001381 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001382 */
1383 void (*init)( GpsGeofenceCallbacks* callbacks );
1384
1385 /**
1386 * Add a geofence area. This api currently supports circular geofences.
1387 * Parameters:
1388 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001389 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1390 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001391 * latitude, longtitude, radius_meters - The lat, long and radius
1392 * (in meters) for the geofence
1393 * last_transition - The current state of the geofence. For example, if
1394 * the system already knows that the user is inside the geofence,
1395 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1396 * will be GPS_GEOFENCE_UNCERTAIN.
1397 * monitor_transition - Which transitions to monitor. Bitwise OR of
1398 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1399 * GPS_GEOFENCE_UNCERTAIN.
1400 * notification_responsiveness_ms - Defines the best-effort description
1401 * of how soon should the callback be called when the transition
1402 * associated with the Geofence is triggered. For instance, if set
1403 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1404 * should be called 1000 milliseconds within entering the geofence.
1405 * This parameter is defined in milliseconds.
1406 * NOTE: This is not to be confused with the rate that the GPS is
1407 * polled at. It is acceptable to dynamically vary the rate of
1408 * sampling the GPS for power-saving reasons; thus the rate of
1409 * sampling may be faster or slower than this.
1410 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001411 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001412 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001413 */
destradaa9f7c3732014-04-29 10:50:22 -07001414 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1415 double radius_meters, int last_transition, int monitor_transitions,
1416 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001417
1418 /**
1419 * Pause monitoring a particular geofence.
1420 * Parameters:
1421 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001422 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001423 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001424
1425 /**
1426 * Resume monitoring a particular geofence.
1427 * Parameters:
1428 * geofence_id - The id for the geofence.
1429 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1430 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1431 * GPS_GEOFENCE_UNCERTAIN.
1432 * This supersedes the value associated provided in the
1433 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001434 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001435 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001436
1437 /**
1438 * Remove a geofence area. After the function returns, no notifications
1439 * should be sent.
1440 * Parameter:
1441 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001442 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001443 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001444} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001445
destradaa9f7c3732014-04-29 10:50:22 -07001446/**
Lifu Tang7e33bb22016-02-07 18:09:30 -08001447 * Legacy struct to represent an estimate of the GPS clock time.
1448 * Deprecated, to be removed in the next Android release.
1449 * Use GnssClock instead.
destradaa9f7c3732014-04-29 10:50:22 -07001450 */
1451typedef struct {
1452 /** set to sizeof(GpsClock) */
1453 size_t size;
Lifu Tang7e33bb22016-02-07 18:09:30 -08001454 GpsClockFlags flags;
1455 int16_t leap_second;
1456 GpsClockType type;
1457 int64_t time_ns;
1458 double time_uncertainty_ns;
1459 int64_t full_bias_ns;
1460 double bias_ns;
1461 double bias_uncertainty_ns;
1462 double drift_nsps;
1463 double drift_uncertainty_nsps;
1464} GpsClock;
1465
1466/**
1467 * Represents an estimate of the GPS clock time.
1468 */
1469typedef struct {
1470 /** set to sizeof(GnssClock) */
1471 size_t size;
destradaa9f7c3732014-04-29 10:50:22 -07001472
Lifu Tanga1ca5742016-02-16 17:42:13 -08001473 /**
1474 * A set of flags indicating the validity of the fields in this data
1475 * structure.
1476 */
1477 GnssClockFlags flags;
destradaa9f7c3732014-04-29 10:50:22 -07001478
1479 /**
1480 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001481 * The sign of the value is defined by the following equation:
Lifu Tanga1ca5742016-02-16 17:42:13 -08001482 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second *
1483 * 1,000,000,000
destradaa75843eb2014-07-17 14:04:50 -07001484 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001485 * If the data is available 'flags' must contain GNSS_CLOCK_HAS_LEAP_SECOND.
destradaa9f7c3732014-04-29 10:50:22 -07001486 */
1487 int16_t leap_second;
1488
1489 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001490 * The GNSS receiver internal clock value. This is the local hardware clock
1491 * value.
destradaa9f7c3732014-04-29 10:50:22 -07001492 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001493 * For local hardware clock, this value is expected to be monotonically
1494 * increasing while the hardware clock remains power on. (For the case of a
1495 * HW clock that is not continuously on, see the
1496 * hw_clock_discontinuity_count field). The real GPS time can be derived by
1497 * adding the 'full_bias_ns + bias_ns' (when it is available) to this value.
destradaa9f7c3732014-04-29 10:50:22 -07001498 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001499 * This GPS time is expected to be the best estimate of current GPS time
1500 * that GNSS receiver can achieve.
destradaa75843eb2014-07-17 14:04:50 -07001501 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001502 * Sub-nanosecond accuracy can be provided by means of the 'bias_ns' field.
destradaa9f7c3732014-04-29 10:50:22 -07001503 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001504 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001505 * This field is mandatory.
destradaa9f7c3732014-04-29 10:50:22 -07001506 */
1507 int64_t time_ns;
1508
1509 /**
1510 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1511 * The uncertainty is represented as an absolute (single sided) value.
1512 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001513 * If the data is available, 'flags' must contain
Lifu Tanga1ca5742016-02-16 17:42:13 -08001514 * GNSS_CLOCK_HAS_TIME_UNCERTAINTY. This value is effectively zero (it is
1515 * the reference local clock, by which all other times and time
1516 * uncertainties are measured.) (And thus this field can be not provided,
1517 * per GNSS_CLOCK_HAS_TIME_UNCERTAINTY flag, or provided & set to 0.)
destradaa9f7c3732014-04-29 10:50:22 -07001518 */
1519 double time_uncertainty_ns;
1520
1521 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001522 * The difference between hardware clock ('time' field) inside GPS receiver
1523 * and the true GPS time since 0000Z, January 6, 1980, in nanoseconds.
destradaa9f7c3732014-04-29 10:50:22 -07001524 *
destradaa75843eb2014-07-17 14:04:50 -07001525 * The sign of the value is defined by the following equation:
Lifu Tanga1ca5742016-02-16 17:42:13 -08001526 * local estimate of GPS time = time_ns + (full_bias_ns + bias_ns)
destradaa75843eb2014-07-17 14:04:50 -07001527 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001528 * This value is mandatory if the receiver has estimated GPS time. If the
1529 * computed time is for a non-GPS constellation, the time offset of that
1530 * constellation to GPS has to be applied to fill this value. The value
1531 * contains the 'bias uncertainty' in it, and the caller is responsible of
1532 * using the uncertainty. If the data is available 'flags' must contain
1533 * GNSS_CLOCK_HAS_FULL_BIAS.
destradaa75843eb2014-07-17 14:04:50 -07001534 */
1535 int64_t full_bias_ns;
1536
1537 /**
1538 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001539 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001540 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001541 * If the data is available 'flags' must contain GNSS_CLOCK_HAS_BIAS. If GPS
1542 * has computed a position fix. This value is mandatory if the receiver has
1543 * estimated GPS time.
destradaa9f7c3732014-04-29 10:50:22 -07001544 */
1545 double bias_ns;
1546
1547 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001548 * 1-Sigma uncertainty associated with the local estimate of GPS time (clock
1549 * bias) in nanoseconds. The uncertainty is represented as an absolute
1550 * (single sided) value.
destradaa9f7c3732014-04-29 10:50:22 -07001551 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001552 * If the data is available 'flags' must contain
Lifu Tanga1ca5742016-02-16 17:42:13 -08001553 * GNSS_CLOCK_HAS_BIAS_UNCERTAINTY. This value is mandatory if the receiver
1554 * has estimated GPS time.
destradaa9f7c3732014-04-29 10:50:22 -07001555 */
1556 double bias_uncertainty_ns;
1557
1558 /**
1559 * The clock's drift in nanoseconds (per second).
Lifu Tanga1ca5742016-02-16 17:42:13 -08001560 *
1561 * A positive value means that the frequency is higher than the nominal
1562 * frequency.
destradaa9f7c3732014-04-29 10:50:22 -07001563 *
1564 * The value contains the 'drift uncertainty' in it.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001565 * If the data is available 'flags' must contain GNSS_CLOCK_HAS_DRIFT.
destradaa00caa892015-04-09 18:41:46 -07001566 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001567 * This value is mandatory if the receiver has estimated GNSS time
destradaa9f7c3732014-04-29 10:50:22 -07001568 */
1569 double drift_nsps;
1570
1571 /**
1572 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1573 * The uncertainty is represented as an absolute (single sided) value.
1574 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001575 * If the data is available 'flags' must contain
Lifu Tanga1ca5742016-02-16 17:42:13 -08001576 * GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY. If GPS has computed a position fix this
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001577 * field is mandatory and must be populated.
destradaa9f7c3732014-04-29 10:50:22 -07001578 */
1579 double drift_uncertainty_nsps;
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001580
1581 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001582 * When there are any discontinuities in the HW clock, this field is
1583 * mandatory.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001584 *
1585 * A "discontinuity" is meant to cover the case of a switch from one source
1586 * of clock to another. A single free-running crystal oscillator (XO)
Lifu Tanga1ca5742016-02-16 17:42:13 -08001587 * should generally not have any discontinuities, and this can be set and
1588 * left at 0.
1589 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001590 * If, however, the time_ns value (HW clock) is derived from a composite of
Lifu Tanga1ca5742016-02-16 17:42:13 -08001591 * sources, that is not as smooth as a typical XO, or is otherwise stopped &
1592 * restarted, then this value shall be incremented each time a discontinuity
1593 * occurs. (E.g. this value may start at zero at device boot-up and
1594 * increment each time there is a change in clock continuity. In the
1595 * unlikely event that this value reaches full scale, rollover (not
1596 * clamping) is required, such that this value continues to change, during
1597 * subsequent discontinuity events.)
1598 *
1599 * While this number stays the same, between GnssClock reports, it can be
1600 * safely assumed that the time_ns value has been running continuously, e.g.
1601 * derived from a single, high quality clock (XO like, or better, that's
1602 * typically used during continuous GNSS signal sampling.)
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001603 *
1604 * It is expected, esp. during periods where there are few GNSS signals
1605 * available, that the HW clock be discontinuity-free as long as possible,
Lifu Tanga1ca5742016-02-16 17:42:13 -08001606 * as this avoids the need to use (waste) a GNSS measurement to fully
1607 * re-solve for the GPS clock bias and drift, when using the accompanying
1608 * measurements, from consecutive GnssData reports.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001609 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001610 uint32_t hw_clock_discontinuity_count;
1611
Lifu Tang7e33bb22016-02-07 18:09:30 -08001612} GnssClock;
destradaa9f7c3732014-04-29 10:50:22 -07001613
1614/**
Lifu Tang7e33bb22016-02-07 18:09:30 -08001615 * Legacy struct to represent a GPS Measurement, it contains raw and computed
1616 * information.
1617 * Deprecated, to be removed in the next Android release.
1618 * Use GnssMeasurement instead.
1619 */
1620typedef struct {
1621 /** set to sizeof(GpsMeasurement) */
1622 size_t size;
1623 GpsMeasurementFlags flags;
1624 int8_t prn;
1625 double time_offset_ns;
1626 GpsMeasurementState state;
1627 int64_t received_gps_tow_ns;
1628 int64_t received_gps_tow_uncertainty_ns;
1629 double c_n0_dbhz;
1630 double pseudorange_rate_mps;
1631 double pseudorange_rate_uncertainty_mps;
1632 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
1633 double accumulated_delta_range_m;
1634 double accumulated_delta_range_uncertainty_m;
1635 double pseudorange_m;
1636 double pseudorange_uncertainty_m;
1637 double code_phase_chips;
1638 double code_phase_uncertainty_chips;
1639 float carrier_frequency_hz;
1640 int64_t carrier_cycles;
1641 double carrier_phase;
1642 double carrier_phase_uncertainty;
1643 GpsLossOfLock loss_of_lock;
1644 int32_t bit_number;
1645 int16_t time_from_last_bit_ms;
1646 double doppler_shift_hz;
1647 double doppler_shift_uncertainty_hz;
1648 GpsMultipathIndicator multipath_indicator;
1649 double snr_db;
1650 double elevation_deg;
1651 double elevation_uncertainty_deg;
1652 double azimuth_deg;
1653 double azimuth_uncertainty_deg;
1654 bool used_in_fix;
1655} GpsMeasurement;
1656
1657/**
1658 * Represents a GNSS Measurement, it contains raw and computed information.
destradaa9f7c3732014-04-29 10:50:22 -07001659 */
1660typedef struct {
1661 /** set to sizeof(GpsMeasurement) */
1662 size_t size;
1663
1664 /** A set of flags indicating the validity of the fields in this data structure. */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001665 GnssMeasurementFlags flags;
destradaa9f7c3732014-04-29 10:50:22 -07001666
1667 /**
Lifu Tang7e33bb22016-02-07 18:09:30 -08001668 * Satellite vehicle ID number, as defined in GnssSvInfo::svid
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001669 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001670 */
Lifu Tang7e33bb22016-02-07 18:09:30 -08001671 int16_t svid;
destradaa9f7c3732014-04-29 10:50:22 -07001672
1673 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001674 * Defines the constellation of the given SV. Value should be one of those
1675 * GNSS_CONSTELLATION_* constants
1676 */
1677 GnssConstellationType constellation;
1678
1679 /**
destradaa75843eb2014-07-17 14:04:50 -07001680 * Time offset at which the measurement was taken in nanoseconds.
1681 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1682 * interpreted in the same way as indicated by GpsClock::type.
1683 *
destradaa9f7c3732014-04-29 10:50:22 -07001684 * The sign of time_offset_ns is given by the following equation:
1685 * measurement time = GpsClock::time_ns + time_offset_ns
1686 *
1687 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001688 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001689 */
destradaa75843eb2014-07-17 14:04:50 -07001690 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001691
1692 /**
destradaa75843eb2014-07-17 14:04:50 -07001693 * Per satellite sync state. It represents the current sync state for the associated satellite.
1694 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001695 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001696 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001697 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001698 GnssMeasurementState state;
destradaa75843eb2014-07-17 14:04:50 -07001699
1700 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08001701 * The received GNSS Time-of-Week at the measurement time, in nanoseconds.
destradaa75843eb2014-07-17 14:04:50 -07001702 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001703 * For GPS & QZSS, this is:
1704 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1705 * The value is relative to the beginning of the current GPS week.
Tsuwei Chena90cf192014-10-23 12:49:12 -07001706 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001707 * Given the highest sync state that can be achieved, per each satellite, valid range
1708 * for this field can be:
1709 * Searching : [ 0 ] : GNSS_MEASUREMENT_STATE_UNKNOWN
1710 * C/A code lock : [ 0 1ms ] : GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1711 * Bit sync : [ 0 20ms ] : GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1712 * Subframe sync : [ 0 6s ] : GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1713 * TOW decoded : [ 0 1week ] : GNSS_MEASUREMENT_STATE_TOW_DECODED is set
destradaa00caa892015-04-09 18:41:46 -07001714 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001715 * Note well: if there is any ambiguity in integer millisecond,
1716 * GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field.
1717 *
1718 * This value must be populated if 'state' != GNSS_MEASUREMENT_STATE_UNKNOWN.
1719 *
1720 * For Glonass, this is:
1721 * Received Glonass time of day, at the measurement time in nanoseconds.
1722 *
1723 * Given the highest sync state that can be achieved, per each satellite, valid range for
1724 * this field can be:
1725 * Searching : [ 0 ] : GNSS_MEASUREMENT_STATE_UNKNOWN
1726 * C/A code lock : [ 0 1ms ] : GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1727 * Symbol sync : [ 0 10ms ] : GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set
1728 * Bit sync : [ 0 20ms ] : GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1729 * String sync : [ 0 2s ] : GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC is set
1730 * Time of day : [ 0 1day ] : GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED is set
1731 *
1732 * For Beidou, this is:
1733 * Received Beidou time of week, at the measurement time in nanoseconds.
1734 *
1735 * Given the highest sync state that can be achieved, per each satellite, valid range for
1736 * this field can be:
1737 * Searching : [ 0 ] : GNSS_MEASUREMENT_STATE_UNKNOWN
1738 * C/A code lock: [ 0 1ms ] : GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1739 * Bit sync (D2): [ 0 2ms ] : GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC is set
1740 * Bit sync (D1): [ 0 20ms ] : GNSS_MEASUREMENT_STATE_BIT_SYNC is set
1741 * Subframe (D2): [ 0 0.6s ] : GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC is set
1742 * Subframe (D1): [ 0 6s ] : GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1743 * Time of week : [ 0 1week ] : GNSS_MEASUREMENT_STATE_TOW_DECODED is set
1744 *
1745 * For Galileo, this is:
1746 * Received Galileo time of week, at the measurement time in nanoseconds.
1747 *
1748 * E1BC code lock : [ 0 4ms ] : GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK is set
1749 * E1C 2nd code lock: [ 0 100ms ] :
1750 * GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK is set
1751 *
1752 * E1B page : [ 0 2s ] : GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC is set
1753 * Time of week: [ 0 1week ] : GNSS_MEASUREMENT_STATE_GAL_TOW_DECODED is set
1754 *
1755 * For SBAS, this is:
1756 * Received SBAS time, at the measurement time in nanoseconds.
1757 *
1758 * Given the highest sync state that can be achieved, per each satellite,
1759 * valid range for this field can be:
1760 * Searching : [ 0 ] : GNSS_MEASUREMENT_STATE_UNKNOWN
1761 * C/A code lock: [ 0 1ms ] : GNSS_MEASUREMENT_STATE_CODE_LOCK is set
1762 * Symbol sync : [ 0 2ms ] : GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set
1763 * Message : [ 0 1s ] : GNSS_MEASUREMENT_STATE_SBAS_SYNC is set
1764 */
1765 int64_t received_sv_time_in_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001766
1767 /**
destradaa941c9282014-07-21 18:13:42 -07001768 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
destradaa00caa892015-04-09 18:41:46 -07001769 *
1770 * This value must be populated if 'state' != GPS_MEASUREMENT_STATE_UNKNOWN.
destradaa941c9282014-07-21 18:13:42 -07001771 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001772 int64_t received_sv_time_uncertainty_in_ns;
destradaa941c9282014-07-21 18:13:42 -07001773
1774 /**
destradaa9f7c3732014-04-29 10:50:22 -07001775 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1776 * It contains the measured C/N0 value for the signal at the antenna input.
1777 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001778 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001779 */
1780 double c_n0_dbhz;
1781
1782 /**
1783 * Pseudorange rate at the timestamp in m/s.
destradaa357e6222015-04-14 16:30:21 -07001784 * The correction of a given Pseudorange Rate value includes corrections for receiver and
1785 * satellite clock frequency errors.
destradaa00caa892015-04-09 18:41:46 -07001786 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001787 * It is mandatory to provide the 'uncorrected' 'pseudorange rate', and provide GpsClock's
1788 * 'drift' field as well, and
1789 * GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE must be set in 'flags'
1790 * field. (When providing the uncorrected pseudorange rate, do not apply the
1791 * corrections described above.)
destradaa9f7c3732014-04-29 10:50:22 -07001792 *
1793 * The value includes the 'pseudorange rate uncertainty' in it.
destradaa00caa892015-04-09 18:41:46 -07001794 * A positive 'uncorrected' value indicates that the SV is moving away from the receiver.
1795 *
destradaa357e6222015-04-14 16:30:21 -07001796 * The sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler
destradaa00caa892015-04-09 18:41:46 -07001797 * shift' is given by the equation:
destradaa357e6222015-04-14 16:30:21 -07001798 * pseudorange rate = -k * doppler shift (where k is a constant)
destradaa9f7c3732014-04-29 10:50:22 -07001799 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001800 * This field should be based on the signal energy doppler measurement. (See
1801 * also pseudorate_rate_carrier_mps for a similar field, based on carrier
1802 * phase changes.)
1803 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001804 * This should be the most accurate pseudorange rate available, based on
1805 * fresh signal measurements from this channel.
1806 *
1807 * It is mandatory that this value be provided at typical carrier phase PRR
1808 * quality (few cm/sec per second of uncertainty, or better) - when signals
1809 * are sufficiently strong & stable, e.g. signals from a GPS simulator at >=
1810 * 35 dB-Hz.
destradaa9f7c3732014-04-29 10:50:22 -07001811 */
destradaa75843eb2014-07-17 14:04:50 -07001812 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001813
1814 /**
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001815 * 1-Sigma uncertainty of the pseudorange_rate_mps.
destradaa9f7c3732014-04-29 10:50:22 -07001816 * The uncertainty is represented as an absolute (single sided) value.
1817 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001818 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001819 */
destradaa75843eb2014-07-17 14:04:50 -07001820 double pseudorange_rate_uncertainty_mps;
1821
1822 /**
1823 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1824 * (indicating loss of lock).
1825 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001826 * This is a mandatory value.
destradaa75843eb2014-07-17 14:04:50 -07001827 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001828 GnssAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001829
1830 /**
1831 * Accumulated delta range since the last channel reset in meters.
destradaa357e6222015-04-14 16:30:21 -07001832 * A positive value indicates that the SV is moving away from the receiver.
destradaa00caa892015-04-09 18:41:46 -07001833 *
destradaa357e6222015-04-14 16:30:21 -07001834 * The sign of the 'accumulated delta range' and its relation to the sign of 'carrier phase'
destradaa00caa892015-04-09 18:41:46 -07001835 * is given by the equation:
destradaa357e6222015-04-14 16:30:21 -07001836 * accumulated delta range = -k * carrier phase (where k is a constant)
destradaa00caa892015-04-09 18:41:46 -07001837 *
1838 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
1839 * However, it is expected that the data is only accurate when:
1840 * 'accumulated delta range state' == GPS_ADR_STATE_VALID.
destradaa9f7c3732014-04-29 10:50:22 -07001841 */
1842 double accumulated_delta_range_m;
1843
1844 /**
1845 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa00caa892015-04-09 18:41:46 -07001846 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001847 */
1848 double accumulated_delta_range_uncertainty_m;
1849
1850 /**
1851 * Best derived Pseudorange by the chip-set, in meters.
1852 * The value contains the 'pseudorange uncertainty' in it.
1853 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001854 * If the data is available, 'flags' must contain
1855 * GNSS_MEASUREMENT_HAS_PSEUDORANGE.
destradaa9f7c3732014-04-29 10:50:22 -07001856 */
1857 double pseudorange_m;
1858
1859 /**
1860 * 1-Sigma uncertainty of the pseudorange in meters.
1861 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1862 * The uncertainty is represented as an absolute (single sided) value.
1863 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001864 * If the data is available, 'flags' must contain
1865 * GNSS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07001866 */
1867 double pseudorange_uncertainty_m;
1868
1869 /**
1870 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1871 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1872 *
1873 * The reference frequency is given by the field 'carrier_frequency_hz'.
1874 * The value contains the 'code-phase uncertainty' in it.
1875 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001876 * If the data is available, 'flags' must contain
1877 * GNSS_MEASUREMENT_HAS_CODE_PHASE.
destradaa9f7c3732014-04-29 10:50:22 -07001878 */
1879 double code_phase_chips;
1880
1881 /**
1882 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1883 * The uncertainty is represented as an absolute (single sided) value.
1884 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001885 * If the data is available, 'flags' must contain
1886 * GNSS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07001887 */
1888 double code_phase_uncertainty_chips;
1889
1890 /**
1891 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1892 * If the field is not set, the carrier frequency is assumed to be L1.
1893 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001894 * If the data is available, 'flags' must contain
1895 * GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
destradaa9f7c3732014-04-29 10:50:22 -07001896 */
1897 float carrier_frequency_hz;
1898
1899 /**
1900 * The number of full carrier cycles between the satellite and the receiver.
1901 * The reference frequency is given by the field 'carrier_frequency_hz'.
1902 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001903 * If the data is available, 'flags' must contain
1904 * GNSS_MEASUREMENT_HAS_CARRIER_CYCLES.
destradaa9f7c3732014-04-29 10:50:22 -07001905 */
1906 int64_t carrier_cycles;
1907
1908 /**
1909 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1910 * This is usually the fractional part of the complete carrier phase measurement.
1911 *
1912 * The reference frequency is given by the field 'carrier_frequency_hz'.
1913 * The value contains the 'carrier-phase uncertainty' in it.
1914 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001915 * If the data is available, 'flags' must contain
1916 * GNSS_MEASUREMENT_HAS_CARRIER_PHASE.
destradaa9f7c3732014-04-29 10:50:22 -07001917 */
1918 double carrier_phase;
1919
1920 /**
1921 * 1-Sigma uncertainty of the carrier-phase.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001922 * If the data is available, 'flags' must contain
1923 * GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07001924 */
1925 double carrier_phase_uncertainty;
1926
1927 /**
destradaa9f7c3732014-04-29 10:50:22 -07001928 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
Lifu Tanga1ca5742016-02-16 17:42:13 -08001929 * If the data is available, 'flags' must contain
1930 * GNSS_MEASUREMENT_HAS_BIT_NUMBER.
destradaa9f7c3732014-04-29 10:50:22 -07001931 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001932 int32_t bit_number;
destradaa9f7c3732014-04-29 10:50:22 -07001933
1934 /**
destradaa75843eb2014-07-17 14:04:50 -07001935 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
Lifu Tanga1ca5742016-02-16 17:42:13 -08001936 * If the data is available, 'flags' must contain
1937 * GNSS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
destradaa9f7c3732014-04-29 10:50:22 -07001938 */
destradaa75843eb2014-07-17 14:04:50 -07001939 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001940
1941 /**
1942 * Doppler shift in Hz.
1943 * A positive value indicates that the SV is moving toward the receiver.
1944 *
1945 * The reference frequency is given by the field 'carrier_frequency_hz'.
1946 * The value contains the 'doppler shift uncertainty' in it.
1947 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001948 * If the data is available, 'flags' must contain
1949 * GNSS_MEASUREMENT_HAS_DOPPLER_SHIFT.
destradaa9f7c3732014-04-29 10:50:22 -07001950 */
1951 double doppler_shift_hz;
1952
1953 /**
1954 * 1-Sigma uncertainty of the doppler shift in Hz.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001955 * If the data is available, 'flags' must contain
1956 * GNSS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07001957 */
1958 double doppler_shift_uncertainty_hz;
1959
1960 /**
1961 * An enumeration that indicates the 'multipath' state of the event.
1962 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08001963 GnssMultipathIndicator multipath_indicator;
destradaa9f7c3732014-04-29 10:50:22 -07001964
1965 /**
1966 * Signal-to-noise ratio in dB.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001967 * If the data is available, 'flags' must contain GNSS_MEASUREMENT_HAS_SNR.
destradaa9f7c3732014-04-29 10:50:22 -07001968 */
1969 double snr_db;
1970
1971 /**
1972 * Elevation in degrees, the valid range is [-90, 90].
1973 * The value contains the 'elevation uncertainty' in it.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001974 * If the data is available, 'flags' must contain
1975 * GNSS_MEASUREMENT_HAS_ELEVATION.
destradaa9f7c3732014-04-29 10:50:22 -07001976 */
1977 double elevation_deg;
1978
1979 /**
1980 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1981 * The uncertainty is represented as the absolute (single sided) value.
1982 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08001983 * If the data is available, 'flags' must contain
1984 * GNSS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07001985 */
1986 double elevation_uncertainty_deg;
1987
1988 /**
1989 * Azimuth in degrees, in the range [0, 360).
1990 * The value contains the 'azimuth uncertainty' in it.
Lifu Tanga1ca5742016-02-16 17:42:13 -08001991 * If the data is available, 'flags' must contain
1992 * GNSS_MEASUREMENT_HAS_AZIMUTH.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001993 */
destradaa9f7c3732014-04-29 10:50:22 -07001994 double azimuth_deg;
1995
1996 /**
1997 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1998 * The uncertainty is represented as an absolute (single sided) value.
1999 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08002000 * If the data is available, 'flags' must contain
2001 * GNSS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
destradaa9f7c3732014-04-29 10:50:22 -07002002 */
2003 double azimuth_uncertainty_deg;
2004
2005 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002006 * Whether the GPS represented by the measurement was used for computing the
2007 * most recent fix. If the data is available, 'flags' must contain
2008 * GNSS_MEASUREMENT_HAS_USED_IN_FIX.
destradaa9f7c3732014-04-29 10:50:22 -07002009 */
2010 bool used_in_fix;
Lifu Tang7e33bb22016-02-07 18:09:30 -08002011} GnssMeasurement;
2012
2013/**
2014 * Legacy struct to represents a reading of GPS measurements.
2015 * Deprecated, to be removed in the next Android release.
2016 * Use GnssData instead.
2017 */
2018typedef struct {
2019 /** set to sizeof(GpsData) */
2020 size_t size;
2021 size_t measurement_count;
2022 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
2023
2024 /** The GPS clock time reading. */
2025 GpsClock clock;
2026} GpsData;
destradaa9f7c3732014-04-29 10:50:22 -07002027
Lifu Tanga1ca5742016-02-16 17:42:13 -08002028/**
2029 * Represents a reading of GNSS measurements. For devices where GnssSystemInfo's
2030 * year_of_hw is set to 2016+, it is mandatory that these be provided, on
2031 * request, when the GNSS receiver is searching/tracking signals.
2032 *
2033 * - Reporting of GPS constellation measurements is mandatory.
2034 * - Reporting of all tracked constellations are encouraged.
2035 */
destradaa9f7c3732014-04-29 10:50:22 -07002036typedef struct {
Lifu Tang7e33bb22016-02-07 18:09:30 -08002037 /** set to sizeof(GnssData) */
destradaa9f7c3732014-04-29 10:50:22 -07002038 size_t size;
2039
2040 /** Number of measurements. */
2041 size_t measurement_count;
2042
2043 /** The array of measurements. */
Lifu Tang7e33bb22016-02-07 18:09:30 -08002044 GnssMeasurement measurements[GNSS_MAX_MEASUREMENT];
destradaa9f7c3732014-04-29 10:50:22 -07002045
2046 /** The GPS clock time reading. */
Lifu Tang7e33bb22016-02-07 18:09:30 -08002047 GnssClock clock;
2048} GnssData;
destradaa9f7c3732014-04-29 10:50:22 -07002049
2050/**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002051 * The legacy callback for to report measurements from the HAL.
2052 *
2053 * This callback is deprecated, and will be removed in the next release. Use
2054 * gnss_measurement_callback() instead.
destradaa9f7c3732014-04-29 10:50:22 -07002055 *
2056 * Parameters:
2057 * data - A data structure containing the measurements.
2058 */
2059typedef void (*gps_measurement_callback) (GpsData* data);
2060
Lifu Tang7e33bb22016-02-07 18:09:30 -08002061/**
2062 * The callback for to report measurements from the HAL.
2063 *
2064 * Parameters:
2065 * data - A data structure containing the measurements.
2066 */
2067typedef void (*gnss_measurement_callback) (GnssData* data);
2068
destradaa9f7c3732014-04-29 10:50:22 -07002069typedef struct {
2070 /** set to sizeof(GpsMeasurementCallbacks) */
2071 size_t size;
2072 gps_measurement_callback measurement_callback;
Lifu Tang7e33bb22016-02-07 18:09:30 -08002073 gnss_measurement_callback gnss_measurement_callback;
destradaa9f7c3732014-04-29 10:50:22 -07002074} GpsMeasurementCallbacks;
2075
2076#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
2077#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
2078#define GPS_MEASUREMENT_ERROR_GENERIC -101
2079
2080/**
2081 * Extended interface for GPS Measurements support.
2082 */
2083typedef struct {
2084 /** Set to sizeof(GpsMeasurementInterface) */
2085 size_t size;
2086
2087 /**
2088 * Initializes the interface and registers the callback routines with the HAL.
2089 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
2090 *
2091 * Status:
2092 * GPS_MEASUREMENT_OPERATION_SUCCESS
2093 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
2094 * corresponding call to 'close'
2095 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
2096 * will not generate any updates upon returning this error code.
2097 */
2098 int (*init) (GpsMeasurementCallbacks* callbacks);
2099
2100 /**
2101 * Stops updates from the HAL, and unregisters the callback routines.
2102 * After a call to stop, the previously registered callbacks must be considered invalid by the
2103 * HAL.
2104 * If stop is invoked without a previous 'init', this function should perform no work.
2105 */
2106 void (*close) ();
2107
2108} GpsMeasurementInterface;
2109
Lifu Tang7e33bb22016-02-07 18:09:30 -08002110/**
2111 * Legacy struct to represents a GPS navigation message (or a fragment of it).
2112 * Deprecated, to be removed in the next Android release.
2113 * Use GnssNavigationMessage instead.
2114 */
destradaa9f7c3732014-04-29 10:50:22 -07002115typedef struct {
2116 /** set to sizeof(GpsNavigationMessage) */
2117 size_t size;
Lifu Tang7e33bb22016-02-07 18:09:30 -08002118 int8_t prn;
2119 GpsNavigationMessageType type;
2120 NavigationMessageStatus status;
2121 int16_t message_id;
2122 int16_t submessage_id;
2123 size_t data_length;
2124 uint8_t* data;
2125} GpsNavigationMessage;
2126
2127/** Represents a GPS navigation message (or a fragment of it). */
2128typedef struct {
2129 /** set to sizeof(GnssNavigationMessage) */
2130 size_t size;
destradaa9f7c3732014-04-29 10:50:22 -07002131
2132 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002133 * Satellite vehicle ID number, as defined in GnssSvInfo::svid
Lifu Tangdf0fcf72015-10-27 14:58:25 -07002134 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07002135 */
Lifu Tang7e33bb22016-02-07 18:09:30 -08002136 int16_t svid;
destradaa9f7c3732014-04-29 10:50:22 -07002137
2138 /**
2139 * The type of message contained in the structure.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07002140 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07002141 */
Lifu Tanga1ca5742016-02-16 17:42:13 -08002142 GnssNavigationMessageType type;
destradaa9f7c3732014-04-29 10:50:22 -07002143
2144 /**
Tsuwei Chena90cf192014-10-23 12:49:12 -07002145 * The status of the received navigation message.
2146 * No need to send any navigation message that contains words with parity error and cannot be
2147 * corrected.
2148 */
2149 NavigationMessageStatus status;
2150
2151 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002152 * Message identifier. It provides an index so the complete Navigation
2153 * Message can be assembled.
2154 *
2155 * - For GPS L1 C/A subframe 4 and 5, this value corresponds to the 'frame
2156 * id' of the navigation message, in the range of 1-25 (Subframe 1, 2, 3
2157 * does not contain a 'frame id' and this value can be set to -1.)
2158 *
2159 * - For Glonass L1 C/A, this refers to the frame ID, in the range of 1-5.
2160 *
2161 * - For BeiDou D1, this refers to the frame number in the range of 1-24
2162 *
2163 * - For Beidou D2, this refers to the frame number, in the range of 1-120
2164 *
2165 * - For Galileo F/NAV, this refers to the frame number, in the range of 1-N
2166 *
2167 * - For Galileo I/NAV, this refers to the frame number in the range of 1-N
destradaa9f7c3732014-04-29 10:50:22 -07002168 */
2169 int16_t message_id;
2170
2171 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002172 * Sub-message identifier. If required by the message 'type', this value
2173 * contains a sub-index within the current message (or frame) that is being
2174 * transmitted.
2175 *
2176 * - For GPS L1 C/A, BeiDou D1 & BeiDou D2, the submessage id corresponds to
2177 * the subframe number of the navigation message, in the range of 1-5.
2178 *
2179 * - For Glonass L1 C/A, this refers to the String number, in the range from
2180 * 1-15
2181 *
2182 * - For Galileo F/NAV, this refers to the subframe number in the range 1-12
2183 *
2184 * - For Galileo I/NAV, this refers to the subframe number in the range 1-24
destradaa9f7c3732014-04-29 10:50:22 -07002185 */
2186 int16_t submessage_id;
2187
2188 /**
2189 * The length of the data (in bytes) contained in the current message.
2190 * If this value is different from zero, 'data' must point to an array of the same size.
destradaa69d5ea52014-07-31 16:34:09 -07002191 * e.g. for L1 C/A the size of the sub-frame will be 40 bytes (10 words, 30 bits/word).
destradaa9f7c3732014-04-29 10:50:22 -07002192 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07002193 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07002194 */
2195 size_t data_length;
2196
2197 /**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002198 * The data of the reported GPS message. The bytes (or words) specified
2199 * using big endian format (MSB first).
destradaa69d5ea52014-07-31 16:34:09 -07002200 *
Lifu Tanga1ca5742016-02-16 17:42:13 -08002201 * - For GPS L1 C/A, Beidou D1 & Beidou D2, each subframe contains 10 30-bit
2202 * words. Each word (30 bits) should be fit into the last 30 bits in a
2203 * 4-byte word (skip B31 and B32), with MSB first, for a total of 40
2204 * bytes, covering a time period of 6, 6, and 0.6 seconds, respectively.
2205 *
2206 * - For Glonass L1 C/A, each string contains 85 data bits, including the
2207 * checksum. These bits should be fit into 11 bytes, with MSB first (skip
2208 * B86-B88), covering a time period of 2 seconds.
2209 *
2210 * - For Galileo F/NAV, each subframe contains 5 238-bit word (sync & tail
2211 * symbols excluded). Each word should be fit into 30-bytes, with MSB
2212 * first (skip B239, B240), covering a time period of 10 seconds.
2213 *
2214 * - For Galileo I/NAV, each subframe contains 15 114-bit word (sync & tail
2215 * symbols excluded). Each word should be fit into 15-bytes, with MSB
2216 * first (skip B115-B120), covering a time period of 2 seconds.
destradaa9f7c3732014-04-29 10:50:22 -07002217 */
2218 uint8_t* data;
2219
Lifu Tang7e33bb22016-02-07 18:09:30 -08002220} GnssNavigationMessage;
destradaa9f7c3732014-04-29 10:50:22 -07002221
2222/**
Lifu Tanga1ca5742016-02-16 17:42:13 -08002223 * The legacy callback to report an available fragment of a GPS navigation
2224 * messages from the HAL.
2225 *
2226 * This callback is deprecated, and will be removed in the next release. Use
2227 * gnss_navigation_message_callback() instead.
destradaa9f7c3732014-04-29 10:50:22 -07002228 *
2229 * Parameters:
2230 * message - The GPS navigation submessage/subframe representation.
2231 */
2232typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
2233
Lifu Tang7e33bb22016-02-07 18:09:30 -08002234/**
2235 * The callback to report an available fragment of a GPS navigation messages from the HAL.
2236 *
2237 * Parameters:
2238 * message - The GPS navigation submessage/subframe representation.
2239 */
2240typedef void (*gnss_navigation_message_callback) (GnssNavigationMessage* message);
2241
destradaa9f7c3732014-04-29 10:50:22 -07002242typedef struct {
2243 /** set to sizeof(GpsNavigationMessageCallbacks) */
2244 size_t size;
2245 gps_navigation_message_callback navigation_message_callback;
Lifu Tang7e33bb22016-02-07 18:09:30 -08002246 gnss_navigation_message_callback gnss_navigation_message_callback;
destradaa9f7c3732014-04-29 10:50:22 -07002247} GpsNavigationMessageCallbacks;
2248
2249#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
2250#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
2251#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
2252
2253/**
2254 * Extended interface for GPS navigation message reporting support.
2255 */
2256typedef struct {
2257 /** Set to sizeof(GpsNavigationMessageInterface) */
2258 size_t size;
2259
2260 /**
2261 * Initializes the interface and registers the callback routines with the HAL.
2262 * After a successful call to 'init' the HAL must begin to provide updates as they become
2263 * available.
2264 *
2265 * Status:
2266 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
2267 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
2268 * without a corresponding call to 'close'.
2269 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
2270 * the HAL will not generate any updates upon returning this error code.
2271 */
2272 int (*init) (GpsNavigationMessageCallbacks* callbacks);
2273
2274 /**
2275 * Stops updates from the HAL, and unregisters the callback routines.
2276 * After a call to stop, the previously registered callbacks must be considered invalid by the
2277 * HAL.
2278 * If stop is invoked without a previous 'init', this function should perform no work.
2279 */
2280 void (*close) ();
2281
2282} GpsNavigationMessageInterface;
2283
Tsuwei Chen167d31f2014-08-26 16:34:19 -07002284/**
2285 * Interface for passing GNSS configuration contents from platform to HAL.
2286 */
2287typedef struct {
2288 /** Set to sizeof(GnssConfigurationInterface) */
2289 size_t size;
2290
2291 /**
2292 * Deliver GNSS configuration contents to HAL.
2293 * Parameters:
2294 * config_data - a pointer to a char array which holds what usually is expected from
2295 file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
2296 * length - total number of UTF8 characters in configuraiton data.
2297 *
2298 * IMPORTANT:
2299 * GPS HAL should expect this function can be called multiple times. And it may be
2300 * called even when GpsLocationProvider is already constructed and enabled. GPS HAL
2301 * should maintain the existing requests for various callback regardless the change
2302 * in configuration data.
2303 */
2304 void (*configuration_update) (const char* config_data, int32_t length);
2305} GnssConfigurationInterface;
2306
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05002307__END_DECLS
2308
2309#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
2310