blob: 6fd47a99db42e9e1b5fe85b658a5d967c3c25b11 [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
42
destradaa9f7c3732014-04-29 10:50:22 -070043/** Maximum number of Measurements in gps_measurement_callback(). */
44#define GPS_MAX_MEASUREMENT 32
45
Mike Lockwoodb15879a2010-04-14 15:36:34 -040046/** Requested operational mode for GPS operation. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050047typedef uint32_t GpsPositionMode;
48// IMPORTANT: Note that the following values must match
49// constants in GpsLocationProvider.java.
50/** Mode for running GPS standalone (no assistance). */
51#define GPS_POSITION_MODE_STANDALONE 0
52/** AGPS MS-Based mode. */
53#define GPS_POSITION_MODE_MS_BASED 1
destradaa81534882015-04-28 13:10:56 -070054/**
55 * AGPS MS-Assisted mode. This mode is not maintained by the platform anymore.
Lifu Tangdf0fcf72015-10-27 14:58:25 -070056 * It is strongly recommended to use GPS_POSITION_MODE_MS_BASED instead.
destradaa81534882015-04-28 13:10:56 -070057 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050058#define GPS_POSITION_MODE_MS_ASSISTED 2
59
Mike Lockwoodb15879a2010-04-14 15:36:34 -040060/** Requested recurrence mode for GPS operation. */
61typedef uint32_t GpsPositionRecurrence;
62// IMPORTANT: Note that the following values must match
63// constants in GpsLocationProvider.java.
64/** Receive GPS fixes on a recurring basis at a specified period. */
65#define GPS_POSITION_RECURRENCE_PERIODIC 0
66/** Request a single shot GPS fix. */
67#define GPS_POSITION_RECURRENCE_SINGLE 1
68
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050069/** GPS status event values. */
70typedef uint16_t GpsStatusValue;
71// IMPORTANT: Note that the following values must match
72// constants in GpsLocationProvider.java.
73/** GPS status unknown. */
74#define GPS_STATUS_NONE 0
75/** GPS has begun navigating. */
76#define GPS_STATUS_SESSION_BEGIN 1
77/** GPS has stopped navigating. */
78#define GPS_STATUS_SESSION_END 2
79/** GPS has powered on but is not navigating. */
80#define GPS_STATUS_ENGINE_ON 3
81/** GPS is powered off. */
82#define GPS_STATUS_ENGINE_OFF 4
83
84/** Flags to indicate which values are valid in a GpsLocation. */
85typedef uint16_t GpsLocationFlags;
86// IMPORTANT: Note that the following values must match
87// constants in GpsLocationProvider.java.
88/** GpsLocation has valid latitude and longitude. */
89#define GPS_LOCATION_HAS_LAT_LONG 0x0001
90/** GpsLocation has valid altitude. */
91#define GPS_LOCATION_HAS_ALTITUDE 0x0002
92/** GpsLocation has valid speed. */
93#define GPS_LOCATION_HAS_SPEED 0x0004
94/** GpsLocation has valid bearing. */
95#define GPS_LOCATION_HAS_BEARING 0x0008
96/** GpsLocation has valid accuracy. */
97#define GPS_LOCATION_HAS_ACCURACY 0x0010
98
Mike Lockwoodb15879a2010-04-14 15:36:34 -040099/** Flags for the gps_set_capabilities callback. */
100
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700101/**
102 * GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode. If this is
103 * not set, then the framework will use 1000ms for min_interval and will start
104 * and call start() and stop() to schedule the GPS.
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400105 */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700106#define GPS_CAPABILITY_SCHEDULING (1 << 0)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400107/** GPS supports MS-Based AGPS mode */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700108#define GPS_CAPABILITY_MSB (1 << 1)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400109/** GPS supports MS-Assisted AGPS mode */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700110#define GPS_CAPABILITY_MSA (1 << 2)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400111/** GPS supports single-shot fixes */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700112#define GPS_CAPABILITY_SINGLE_SHOT (1 << 3)
Mike Lockwood8aac5912011-06-29 15:10:36 -0400113/** GPS supports on demand time injection */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700114#define GPS_CAPABILITY_ON_DEMAND_TIME (1 << 4)
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800115/** GPS supports Geofencing */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700116#define GPS_CAPABILITY_GEOFENCING (1 << 5)
destradaa69d5ea52014-07-31 16:34:09 -0700117/** GPS supports Measurements */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700118#define GPS_CAPABILITY_MEASUREMENTS (1 << 6)
destradaa69d5ea52014-07-31 16:34:09 -0700119/** GPS supports Navigation Messages */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700120#define GPS_CAPABILITY_NAV_MESSAGES (1 << 7)
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400121
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700122/**
123 * Flags used to specify which aiding data to delete when calling
124 * delete_aiding_data().
125 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500126typedef uint16_t GpsAidingData;
127// IMPORTANT: Note that the following values must match
128// constants in GpsLocationProvider.java.
129#define GPS_DELETE_EPHEMERIS 0x0001
130#define GPS_DELETE_ALMANAC 0x0002
131#define GPS_DELETE_POSITION 0x0004
132#define GPS_DELETE_TIME 0x0008
133#define GPS_DELETE_IONO 0x0010
134#define GPS_DELETE_UTC 0x0020
135#define GPS_DELETE_HEALTH 0x0040
136#define GPS_DELETE_SVDIR 0x0080
137#define GPS_DELETE_SVSTEER 0x0100
138#define GPS_DELETE_SADATA 0x0200
139#define GPS_DELETE_RTI 0x0400
140#define GPS_DELETE_CELLDB_INFO 0x8000
141#define GPS_DELETE_ALL 0xFFFF
142
143/** AGPS type */
144typedef uint16_t AGpsType;
145#define AGPS_TYPE_SUPL 1
146#define AGPS_TYPE_C2K 2
147
Miguel Torroja5f404f52010-07-27 06:34:15 +0200148typedef uint16_t AGpsSetIDType;
149#define AGPS_SETID_TYPE_NONE 0
150#define AGPS_SETID_TYPE_IMSI 1
151#define AGPS_SETID_TYPE_MSISDN 2
152
destradaaf48cc672014-06-05 11:07:09 -0700153typedef uint16_t ApnIpType;
154#define APN_IP_INVALID 0
155#define APN_IP_IPV4 1
156#define APN_IP_IPV6 2
157#define APN_IP_IPV4V6 3
158
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500159/**
160 * String length constants
161 */
162#define GPS_NI_SHORT_STRING_MAXLEN 256
163#define GPS_NI_LONG_STRING_MAXLEN 2048
164
165/**
166 * GpsNiType constants
167 */
168typedef uint32_t GpsNiType;
169#define GPS_NI_TYPE_VOICE 1
170#define GPS_NI_TYPE_UMTS_SUPL 2
171#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
172
173/**
174 * GpsNiNotifyFlags constants
175 */
176typedef uint32_t GpsNiNotifyFlags;
177/** NI requires notification */
178#define GPS_NI_NEED_NOTIFY 0x0001
179/** NI requires verification */
180#define GPS_NI_NEED_VERIFY 0x0002
181/** NI requires privacy override, no notification/minimal trace */
182#define GPS_NI_PRIVACY_OVERRIDE 0x0004
183
184/**
185 * GPS NI responses, used to define the response in
186 * NI structures
187 */
188typedef int GpsUserResponseType;
189#define GPS_NI_RESPONSE_ACCEPT 1
190#define GPS_NI_RESPONSE_DENY 2
191#define GPS_NI_RESPONSE_NORESP 3
192
193/**
194 * NI data encoding scheme
195 */
196typedef int GpsNiEncodingType;
197#define GPS_ENC_NONE 0
198#define GPS_ENC_SUPL_GSM_DEFAULT 1
199#define GPS_ENC_SUPL_UTF8 2
200#define GPS_ENC_SUPL_UCS2 3
201#define GPS_ENC_UNKNOWN -1
202
203/** AGPS status event values. */
204typedef uint16_t AGpsStatusValue;
205/** GPS requests data connection for AGPS. */
206#define GPS_REQUEST_AGPS_DATA_CONN 1
207/** GPS releases the AGPS data connection. */
208#define GPS_RELEASE_AGPS_DATA_CONN 2
209/** AGPS data connection initiated */
210#define GPS_AGPS_DATA_CONNECTED 3
211/** AGPS data connection completed */
212#define GPS_AGPS_DATA_CONN_DONE 4
213/** AGPS data connection failed */
214#define GPS_AGPS_DATA_CONN_FAILED 5
215
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700216typedef uint16_t AGpsRefLocationType;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200217#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
218#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
219#define AGPS_REG_LOCATION_TYPE_MAC 3
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700220#define AGPS_REF_LOCATION_TYPE_LTE_CELLID 4
Miguel Torroja5f404f52010-07-27 06:34:15 +0200221
Mike Lockwood455e83b2010-10-11 06:16:57 -0400222/** Network types for update_network_state "type" parameter */
223#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
224#define AGPS_RIL_NETWORK_TYPE_WIFI 1
225#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
226#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
227#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
228#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
229#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
230
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500231/**
destradaa9f7c3732014-04-29 10:50:22 -0700232 * Flags to indicate what fields in GpsClock are valid.
233 */
234typedef uint16_t GpsClockFlags;
235/** A valid 'leap second' is stored in the data structure. */
236#define GPS_CLOCK_HAS_LEAP_SECOND (1<<0)
237/** A valid 'time uncertainty' is stored in the data structure. */
238#define GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
destradaa75843eb2014-07-17 14:04:50 -0700239/** A valid 'full bias' is stored in the data structure. */
240#define GPS_CLOCK_HAS_FULL_BIAS (1<<2)
destradaa9f7c3732014-04-29 10:50:22 -0700241/** A valid 'bias' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700242#define GPS_CLOCK_HAS_BIAS (1<<3)
destradaa9f7c3732014-04-29 10:50:22 -0700243/** A valid 'bias uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700244#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
destradaa9f7c3732014-04-29 10:50:22 -0700245/** A valid 'drift' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700246#define GPS_CLOCK_HAS_DRIFT (1<<5)
destradaa9f7c3732014-04-29 10:50:22 -0700247/** A valid 'drift uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700248#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
249
250/**
251 * Enumeration of the available values for the GPS Clock type.
252 */
253typedef uint8_t GpsClockType;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700254/** The type is not available or it is unknown. */
destradaa75843eb2014-07-17 14:04:50 -0700255#define GPS_CLOCK_TYPE_UNKNOWN 0
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700256/**
257 * The source of the time value reported by GPS clock is the local hardware
258 * clock. This is a mandatory flag. When the GpsSystemInfo's year_of_hw is 2016
259 * or higher, it is mandatory that 'time' is populated with the local hardware
260 * clock value, and this flag must always be set.
261 */
destradaa75843eb2014-07-17 14:04:50 -0700262#define GPS_CLOCK_TYPE_LOCAL_HW_TIME 1
263/**
264 * The source of the time value reported by GPS clock is the GPS time derived from satellites
265 * (epoch = Jan 6, 1980)
266 */
267#define GPS_CLOCK_TYPE_GPS_TIME 2
destradaa9f7c3732014-04-29 10:50:22 -0700268
269/**
270 * Flags to indicate what fields in GpsMeasurement are valid.
271 */
272typedef uint32_t GpsMeasurementFlags;
273/** A valid 'snr' is stored in the data structure. */
274#define GPS_MEASUREMENT_HAS_SNR (1<<0)
275/** A valid 'elevation' is stored in the data structure. */
276#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
277/** A valid 'elevation uncertainty' is stored in the data structure. */
278#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
279/** A valid 'azimuth' is stored in the data structure. */
280#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
281/** A valid 'azimuth uncertainty' is stored in the data structure. */
282#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
283/** A valid 'pseudorange' is stored in the data structure. */
284#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
285/** A valid 'pseudorange uncertainty' is stored in the data structure. */
286#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
287/** A valid 'code phase' is stored in the data structure. */
288#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
289/** A valid 'code phase uncertainty' is stored in the data structure. */
290#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
291/** A valid 'carrier frequency' is stored in the data structure. */
292#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
293/** A valid 'carrier cycles' is stored in the data structure. */
294#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
295/** A valid 'carrier phase' is stored in the data structure. */
296#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
297/** A valid 'carrier phase uncertainty' is stored in the data structure. */
298#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
299/** A valid 'bit number' is stored in the data structure. */
300#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
301/** A valid 'time from last bit' is stored in the data structure. */
302#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
303/** A valid 'doppler shift' is stored in the data structure. */
304#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
305/** A valid 'doppler shift uncertainty' is stored in the data structure. */
306#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
307/** A valid 'used in fix' flag is stored in the data structure. */
308#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700309/**
310 * The value of 'pseudorange rate' is uncorrected.
311 * This is a mandatory flag. It is mandatory that 'pseudorange rate' is
312 * populated with the uncorrected value, and this flag must always be set.
313 * See comments of GpsMeasurement::pseudorange_rate_mps for more details.
314 */
destradaa00caa892015-04-09 18:41:46 -0700315#define GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE (1<<18)
destradaa9f7c3732014-04-29 10:50:22 -0700316
317/**
destradaa75843eb2014-07-17 14:04:50 -0700318 * Enumeration of the available values for the GPS Measurement's loss of lock.
destradaa9f7c3732014-04-29 10:50:22 -0700319 */
320typedef uint8_t GpsLossOfLock;
321/** The indicator is not available or it is unknown. */
322#define GPS_LOSS_OF_LOCK_UNKNOWN 0
323/** The measurement does not present any indication of loss of lock. */
324#define GPS_LOSS_OF_LOCK_OK 1
325/** Loss of lock between previous and current observation: cycle slip possible. */
326#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
327
328/**
destradaa75843eb2014-07-17 14:04:50 -0700329 * Enumeration of available values for the GPS Measurement's multipath indicator.
destradaa9f7c3732014-04-29 10:50:22 -0700330 */
331typedef uint8_t GpsMultipathIndicator;
332/** The indicator is not available or unknown. */
333#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700334/** The measurement is indicated to be affected by multipath. */
destradaa9f7c3732014-04-29 10:50:22 -0700335#define GPS_MULTIPATH_INDICATOR_DETECTED 1
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700336/** The measurement is indicated to be not affected by multipath. */
destradaa9f7c3732014-04-29 10:50:22 -0700337#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
338
339/**
destradaa75843eb2014-07-17 14:04:50 -0700340 * Flags indicating the GPS measurement state.
Tsuwei Chena90cf192014-10-23 12:49:12 -0700341 * The expected behavior here is for GPS HAL to set all the flags that applies. For
342 * example, if the state for a satellite is only C/A code locked and bit synchronized,
343 * and there is still millisecond ambiguity, the state should be set as:
344 * GPS_MEASUREMENT_STATE_CODE_LOCK|GPS_MEASUREMENT_STATE_BIT_SYNC|GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS
345 * If GPS is still searching for a satellite, the corresponding state should be set to
346 * GPS_MEASUREMENT_STATE_UNKNOWN(0).
destradaa75843eb2014-07-17 14:04:50 -0700347 */
348typedef uint16_t GpsMeasurementState;
349#define GPS_MEASUREMENT_STATE_UNKNOWN 0
350#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
351#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
352#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
353#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
Tsuwei Chena90cf192014-10-23 12:49:12 -0700354#define GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4)
destradaa75843eb2014-07-17 14:04:50 -0700355
356/**
357 * Flags indicating the Accumulated Delta Range's states.
358 */
359typedef uint16_t GpsAccumulatedDeltaRangeState;
360#define GPS_ADR_STATE_UNKNOWN 0
361#define GPS_ADR_STATE_VALID (1<<0)
362#define GPS_ADR_STATE_RESET (1<<1)
363#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
364
365/**
Tsuwei Chena90cf192014-10-23 12:49:12 -0700366 * Enumeration of available values to indicate the available GPS Navigation message types.
destradaa9f7c3732014-04-29 10:50:22 -0700367 */
368typedef uint8_t GpsNavigationMessageType;
369/** The message type is unknown. */
370#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
371/** L1 C/A message contained in the structure. */
372#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
373/** L2-CNAV message contained in the structure. */
374#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
375/** L5-CNAV message contained in the structure. */
376#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
377/** CNAV-2 message contained in the structure. */
378#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
379
Tsuwei Chena90cf192014-10-23 12:49:12 -0700380/**
381 * Status of Navigation Message
382 * When a message is received properly without any parity error in its navigation words, the
383 * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received
384 * with words that failed parity check, but GPS is able to correct those words, the status
385 * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT.
386 * No need to send any navigation message that contains words with parity error and cannot be
387 * corrected.
388 */
389typedef uint16_t NavigationMessageStatus;
390#define NAV_MESSAGE_STATUS_UNKONW 0
391#define NAV_MESSAGE_STATUS_PARITY_PASSED (1<<0)
392#define NAV_MESSAGE_STATUS_PARITY_REBUILT (1<<1)
destradaa9f7c3732014-04-29 10:50:22 -0700393
394/**
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700395 * Flag that indicates which extra data GnssSvInfo includes.
396 */
397typedef uint8_t GnssSvFlags;
398#define GNSS_SV_FLAGS_NONE 0
399#define GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA (1 << 0)
400#define GNSS_SV_FLAGS_HAS_ALMANAC_DATA (1 << 1)
401#define GNSS_SV_FLAGS_USED_IN_FIX (1 << 2)
402
403/**
404 * Constellation type of GnssSvInfo
405 */
406typedef uint8_t GnssConstellationType;
407#define GNSS_CONSTELLATION_UNKNOWN 0
408#define GNSS_CONSTELLATION_GPS 1
409#define GNSS_CONSTELLATION_SBAS 2
410#define GNSS_CONSTELLATION_GLONASS 3
411#define GNSS_CONSTELLATION_QZSS 4
412#define GNSS_CONSTELLATION_BEIDOU 5
413#define GNSS_CONSTELLATION_GALILEO 6
414
415/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500416 * Name for the GPS XTRA interface.
417 */
418#define GPS_XTRA_INTERFACE "gps-xtra"
419
420/**
421 * Name for the GPS DEBUG interface.
422 */
423#define GPS_DEBUG_INTERFACE "gps-debug"
424
425/**
426 * Name for the AGPS interface.
427 */
428#define AGPS_INTERFACE "agps"
429
430/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700431 * Name of the Supl Certificate interface.
432 */
433#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
434
435/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500436 * Name for NI interface
437 */
438#define GPS_NI_INTERFACE "gps-ni"
439
Miguel Torroja5f404f52010-07-27 06:34:15 +0200440/**
441 * Name for the AGPS-RIL interface.
442 */
443#define AGPS_RIL_INTERFACE "agps_ril"
444
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800445/**
446 * Name for the GPS_Geofencing interface.
447 */
448#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
449
destradaa9f7c3732014-04-29 10:50:22 -0700450/**
451 * Name of the GPS Measurements interface.
452 */
453#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
454
455/**
456 * Name of the GPS navigation message interface.
457 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -0700458#define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
459
460/**
461 * Name of the GNSS/GPS configuration interface.
462 */
463#define GNSS_CONFIGURATION_INTERFACE "gnss_configuration"
destradaa9f7c3732014-04-29 10:50:22 -0700464
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800465
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500466/** Represents a location. */
467typedef struct {
468 /** set to sizeof(GpsLocation) */
469 size_t size;
470 /** Contains GpsLocationFlags bits. */
471 uint16_t flags;
472 /** Represents latitude in degrees. */
473 double latitude;
474 /** Represents longitude in degrees. */
475 double longitude;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700476 /**
477 * Represents altitude in meters above the WGS 84 reference ellipsoid.
478 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500479 double altitude;
480 /** Represents speed in meters per second. */
481 float speed;
482 /** Represents heading in degrees. */
483 float bearing;
484 /** Represents expected accuracy in meters. */
485 float accuracy;
486 /** Timestamp for the location fix. */
487 GpsUtcTime timestamp;
488} GpsLocation;
489
490/** Represents the status. */
491typedef struct {
492 /** set to sizeof(GpsStatus) */
493 size_t size;
494 GpsStatusValue status;
495} GpsStatus;
496
497/** Represents SV information. */
498typedef struct {
499 /** set to sizeof(GpsSvInfo) */
500 size_t size;
501 /** Pseudo-random number for the SV. */
502 int prn;
503 /** Signal to noise ratio. */
504 float snr;
505 /** Elevation of SV in degrees. */
506 float elevation;
507 /** Azimuth of SV in degrees. */
508 float azimuth;
509} GpsSvInfo;
510
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500511typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700512 /** set to sizeof(GnssSvInfo) */
513 size_t size;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500514
515 /**
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700516 * Pseudo-random number for the SV, or Amanac/slot number for Glonass. The
517 * distinction is made by looking at constellation field. Values should be
518 * in the range of:
519 *
520 * - GPS: 1-32
521 * - SBAS: 120-151, 183-192
522 * - GLONASS: 1-24 (slot number)
523 * - QZSS: 193-200
524 * - Galileo: 1-25
525 * - Beidou: 1-35
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500526 */
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700527 int prn;
528
529 /** Signal to noise ratio. */
530 float snr;
531
532 /** Elevation of SV in degrees. */
533 float elevation;
534
535 /** Azimuth of SV in degrees. */
536 float azimuth;
537
538 /**
539 * Contains additional data about the given SV. Value should be one of those
540 * GNSS_SV_FLAGS_* constants
541 */
542 GnssSvFlags flags;
543
544 /**
545 * Defines the constellation of the given SV. Value should be one of those
546 * GNSS_CONSTELLATION_* constants
547 */
548 GnssConstellationType constellation;
549
550} GnssSvInfo;
551
552/**
553 * Represents SV status.
554 *
555 * When switching from pre-N to N version of GpsSvStatus:
556 *
557 * 1) Fill in the fields from num_svs through used_in_fix_mask the same way as
558 * was done before, e.g. using the range of 65-88 to report Glonass info,
559 * 201-235 for Beidou, etc. (but with no used_in_fix_mask info - those are
560 * index by prn, and thus for GPS only). This will help ensure compatibility
561 * when a newer GPS HAL is used with an older version of Android.
562 *
563 * 2) Fill in the gnss_sv_list with information about SVs from all
564 * constellations (GPS & other GNSS's) - when this is filled in, this will be
565 * the only source of information about satellite status (e.g. for working with
566 * GpsStatus facing applications), the earlier fields will be ignored.
567 */
568typedef struct {
569 /** set to sizeof(GpsSvStatus) */
570 size_t size;
571
572 /** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */
573 int num_svs;
574
575 /** Contains an array of GPS SV information in legacy GPS format. */
576 GpsSvInfo sv_list[GPS_MAX_SVS];
577
578 /**
579 * Represents a bit mask indicating which GPS SVs have ephemeris data,
580 * refers to sv_list.
581 */
582 uint32_t ephemeris_mask;
583
584 /**
585 * Represents a bit mask indicating which GPS SVs have almanac data, refers
586 * to sv_list.
587 */
588 uint32_t almanac_mask;
589
590 /**
591 * Represents a bit mask indicating which GPS SVs
592 * were used for computing the most recent position fix,
593 * refers to sv_list.
594 */
595 uint32_t used_in_fix_mask;
596
597 /**
598 * Size of the array which contains SV info for all GNSS constellation
599 * except for GPS.
600 */
601 size_t gnss_sv_list_size;
602
603 /**
604 * Pointer to an array of SVs information for all GNSS constellations,
605 * except GPS, which is reported using sv_list
606 */
607 GnssSvInfo* gnss_sv_list;
608
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500609} GpsSvStatus;
610
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700611/* CellID for 2G, 3G and LTE, used in AGPS. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200612typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700613 AGpsRefLocationType type;
614 /** Mobile Country Code. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200615 uint16_t mcc;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700616 /** Mobile Network Code .*/
Miguel Torroja5f404f52010-07-27 06:34:15 +0200617 uint16_t mnc;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700618 /** Location Area Code in 2G, 3G and LTE. In 3G lac is discarded. In LTE,
619 * lac is populated with tac, to ensure that we don't break old clients that
620 * might rely in the old (wrong) behavior.
621 */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200622 uint16_t lac;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700623 /** Cell id in 2G. Utran Cell id in 3G. Cell Global Id EUTRA in LTE. */
Miguel Torroja5f404f52010-07-27 06:34:15 +0200624 uint32_t cid;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700625 /** Tracking Area Code in LTE. */
626 uint16_t tac;
627 /** Physical Cell id in LTE (not used in 2G and 3G) */
628 uint16_t pcid;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200629} AGpsRefLocationCellID;
630
631typedef struct {
632 uint8_t mac[6];
633} AGpsRefLocationMac;
634
635/** Represents ref locations */
636typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700637 AGpsRefLocationType type;
Miguel Torroja5f404f52010-07-27 06:34:15 +0200638 union {
639 AGpsRefLocationCellID cellID;
640 AGpsRefLocationMac mac;
641 } u;
642} AGpsRefLocation;
643
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700644/**
645 * Callback with location information. Can only be called from a thread created
646 * by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700647 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500648typedef void (* gps_location_callback)(GpsLocation* location);
649
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700650/**
651 * Callback with status information. Can only be called from a thread created by
652 * create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700653 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500654typedef void (* gps_status_callback)(GpsStatus* status);
655
destradaa9f7c3732014-04-29 10:50:22 -0700656/**
657 * Callback with SV status information.
658 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700659 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500660typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
661
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700662/**
663 * Callback for reporting NMEA sentences. Can only be called from a thread
664 * created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700665 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500666typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
667
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700668/**
669 * Callback to inform framework of the GPS engine's capabilities. Capability
670 * parameter is a bit field of GPS_CAPABILITY_* flags.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700671 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400672typedef void (* gps_set_capabilities)(uint32_t capabilities);
673
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700674/**
675 * Callback utility for acquiring the GPS wakelock. This can be used to prevent
676 * the CPU from suspending while handling GPS events.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700677 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400678typedef void (* gps_acquire_wakelock)();
679
680/** Callback utility for releasing the GPS wakelock. */
681typedef void (* gps_release_wakelock)();
682
Mike Lockwood8aac5912011-06-29 15:10:36 -0400683/** Callback for requesting NTP time */
684typedef void (* gps_request_utc_time)();
685
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700686/**
687 * Callback for creating a thread that can call into the Java framework code.
688 * This must be used to create any threads that report events up to the
689 * framework.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700690 */
691typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
692
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700693/**
694 * Provides information about how new the underlying GPS/GNSS hardware and
695 * software is.
696 *
697 * This information will be available for Android Test Applications. If a GPS
698 * HAL does not provide this information, it will be considered "2015 or
699 * earlier".
700 *
701 * If a GPS HAL does provide this information, then newer years will need to
702 * meet newer CTS standards. E.g. if the date are 2016 or above, then N+ level
703 * GpsMeasurement support will be verified.
704 */
705typedef struct {
706 /** Set to sizeof(GpsSystemInfo) */
707 size_t size;
708 /* year in which the last update was made to the underlying hardware/firmware
709 * used to capture GNSS signals, e.g. 2016 */
710 uint16_t year_of_hw;
711} GpsSystemInfo;
712
713/**
714 * Callback to inform framework of the engine's hardware version information.
715 */
716typedef void (*gps_set_system_info)(const GpsSystemInfo* info);
717
718/**
719 * Legacy GPS callback structure.
720 * See GpsCallbacks for more information.
721 */
722typedef struct {
723 /** set to sizeof(GpsCallbacks_v1) */
724 size_t size;
725 gps_location_callback location_cb;
726 gps_status_callback status_cb;
727 gps_sv_status_callback sv_status_cb;
728 gps_nmea_callback nmea_cb;
729 gps_set_capabilities set_capabilities_cb;
730 gps_acquire_wakelock acquire_wakelock_cb;
731 gps_release_wakelock release_wakelock_cb;
732 gps_create_thread create_thread_cb;
733 gps_request_utc_time request_utc_time_cb;
734} GpsCallbacks_v1;
735
736/** New GPS callback structure. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500737typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400738 /** set to sizeof(GpsCallbacks) */
739 size_t size;
740 gps_location_callback location_cb;
741 gps_status_callback status_cb;
742 gps_sv_status_callback sv_status_cb;
743 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400744 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400745 gps_acquire_wakelock acquire_wakelock_cb;
746 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700747 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400748 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500749
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700750 /**
751 * Callback for the chipset to report system information.
752 *
753 * This field is newly introduced since N. The driver implementation must
754 * check 'size' field against 'sizeof(GpsCallbacks)' and
755 * 'sizeof(GpsCallbacks_v1)' to decide whether the new field is valid before
756 * calling it.
757 */
758 gps_set_system_info set_system_info_cb;
759} GpsCallbacks;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500760
761/** Represents the standard GPS interface. */
762typedef struct {
763 /** set to sizeof(GpsInterface) */
764 size_t size;
765 /**
766 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700767 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500768 */
769 int (*init)( GpsCallbacks* callbacks );
770
771 /** Starts navigating. */
772 int (*start)( void );
773
774 /** Stops navigating. */
775 int (*stop)( void );
776
777 /** Closes the interface. */
778 void (*cleanup)( void );
779
780 /** Injects the current time. */
781 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
782 int uncertainty);
783
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700784 /**
785 * Injects current location from another location provider (typically cell
786 * ID). Latitude and longitude are measured in degrees expected accuracy is
787 * measured in meters
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500788 */
789 int (*inject_location)(double latitude, double longitude, float accuracy);
790
791 /**
792 * Specifies that the next call to start will not use the
793 * information defined in the flags. GPS_DELETE_ALL is passed for
794 * a cold start.
795 */
796 void (*delete_aiding_data)(GpsAidingData flags);
797
798 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400799 * min_interval represents the time between fixes in milliseconds.
800 * preferred_accuracy represents the requested fix accuracy in meters.
801 * preferred_time represents the requested time to first fix in milliseconds.
destradaa81534882015-04-28 13:10:56 -0700802 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700803 * 'mode' parameter should be one of GPS_POSITION_MODE_MS_BASED
destradaa81534882015-04-28 13:10:56 -0700804 * or GPS_POSITION_MODE_STANDALONE.
805 * It is allowed by the platform (and it is recommended) to fallback to
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700806 * GPS_POSITION_MODE_MS_BASED if GPS_POSITION_MODE_MS_ASSISTED is passed in, and
destradaa81534882015-04-28 13:10:56 -0700807 * GPS_POSITION_MODE_MS_BASED is supported.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500808 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400809 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
810 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500811
812 /** Get a pointer to extension information. */
813 const void* (*get_extension)(const char* name);
814} GpsInterface;
815
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700816/**
817 * Callback to request the client to download XTRA data. The client should
818 * download XTRA data and inject it by calling inject_xtra_data(). Can only be
819 * called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700820 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500821typedef void (* gps_xtra_download_request)();
822
823/** Callback structure for the XTRA interface. */
824typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700825 gps_xtra_download_request download_request_cb;
826 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500827} GpsXtraCallbacks;
828
829/** Extended interface for XTRA support. */
830typedef struct {
831 /** set to sizeof(GpsXtraInterface) */
832 size_t size;
833 /**
834 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700835 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500836 */
837 int (*init)( GpsXtraCallbacks* callbacks );
838 /** Injects XTRA data into the GPS. */
839 int (*inject_xtra_data)( char* data, int length );
840} GpsXtraInterface;
841
842/** Extended interface for DEBUG support. */
843typedef struct {
844 /** set to sizeof(GpsDebugInterface) */
845 size_t size;
846
847 /**
848 * This function should return any information that the native
849 * implementation wishes to include in a bugreport.
850 */
851 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
852} GpsDebugInterface;
853
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700854/*
855 * Represents the status of AGPS augmented to support IPv4 and IPv6.
856 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500857typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700858 /** set to sizeof(AGpsStatus) */
destradaaf48cc672014-06-05 11:07:09 -0700859 size_t size;
860
861 AGpsType type;
862 AGpsStatusValue status;
863
864 /**
865 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
866 * address, or set to INADDR_NONE otherwise.
867 */
868 uint32_t ipaddr;
869
870 /**
871 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
872 * Any other value of addr.ss_family will be rejected.
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700873 */
destradaaf48cc672014-06-05 11:07:09 -0700874 struct sockaddr_storage addr;
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700875} AGpsStatus;
destradaaf48cc672014-06-05 11:07:09 -0700876
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700877/**
878 * Callback with AGPS status information. Can only be called from a thread
879 * created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700880 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500881typedef void (* agps_status_callback)(AGpsStatus* status);
882
883/** Callback structure for the AGPS interface. */
884typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700885 agps_status_callback status_cb;
886 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500887} AGpsCallbacks;
888
destradaaf48cc672014-06-05 11:07:09 -0700889/**
890 * Extended interface for AGPS support, it is augmented to enable to pass
891 * extra APN data.
892 */
893typedef struct {
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700894 /** set to sizeof(AGpsInterface) */
destradaaf48cc672014-06-05 11:07:09 -0700895 size_t size;
896
897 /**
898 * Opens the AGPS interface and provides the callback routines to the
899 * implementation of this interface.
900 */
901 void (*init)(AGpsCallbacks* callbacks);
902 /**
903 * Deprecated.
904 * If the HAL supports AGpsInterface_v2 this API will not be used, see
905 * data_conn_open_with_apn_ip_type for more information.
906 */
907 int (*data_conn_open)(const char* apn);
908 /**
909 * Notifies that the AGPS data connection has been closed.
910 */
911 int (*data_conn_closed)();
912 /**
913 * Notifies that a data connection is not available for AGPS.
914 */
915 int (*data_conn_failed)();
916 /**
917 * Sets the hostname and port for the AGPS server.
918 */
919 int (*set_server)(AGpsType type, const char* hostname, int port);
920
921 /**
922 * Notifies that a data connection is available and sets the name of the
923 * APN, and its IP type, to be used for SUPL connections.
924 */
925 int (*data_conn_open_with_apn_ip_type)(
926 const char* apn,
927 ApnIpType apnIpType);
Lifu Tangdf0fcf72015-10-27 14:58:25 -0700928} AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500929
destradaaa1f4c0a2013-09-13 15:45:03 -0700930/** Error codes associated with certificate operations */
931#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
932#define AGPS_CERTIFICATE_ERROR_GENERIC -100
933#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
934
935/** A data structure that represents an X.509 certificate using DER encoding */
936typedef struct {
937 size_t length;
938 u_char* data;
939} DerEncodedCertificate;
940
941/**
942 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
943 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
944 */
945typedef struct {
946 u_char data[20];
947} Sha1CertificateFingerprint;
948
destradaa9f7c3732014-04-29 10:50:22 -0700949/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700950typedef struct {
951 /** set to sizeof(SuplCertificateInterface) */
952 size_t size;
953
954 /**
955 * Installs a set of Certificates used for SUPL connections to the AGPS server.
956 * If needed the HAL should find out internally any certificates that need to be removed to
957 * accommodate the certificates to install.
958 * The certificates installed represent a full set of valid certificates needed to connect to
959 * AGPS SUPL servers.
960 * The list of certificates is required, and all must be available at the same time, when trying
961 * to establish a connection with the AGPS Server.
962 *
963 * Parameters:
964 * certificates - A pointer to an array of DER encoded certificates that are need to be
965 * installed in the HAL.
966 * length - The number of certificates to install.
967 * Returns:
968 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
969 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
970 * certificates attempted to be installed, the state of the certificates stored should
971 * remain the same as before on this error case.
972 *
973 * IMPORTANT:
974 * If needed the HAL should find out internally the set of certificates that need to be
975 * removed to accommodate the certificates to install.
976 */
977 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
978
979 /**
980 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
981 * expected that the given set of certificates is removed from the internal store of the HAL.
982 *
983 * Parameters:
984 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
985 * certificates to revoke.
986 * length - The number of fingerprints provided.
987 * Returns:
988 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
989 *
990 * IMPORTANT:
991 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
992 * it should be ignored and continue revoking/deleting the rest of them.
993 */
994 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800995} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500996
997/** Represents an NI request */
998typedef struct {
999 /** set to sizeof(GpsNiNotification) */
1000 size_t size;
1001
1002 /**
1003 * An ID generated by HAL to associate NI notifications and UI
1004 * responses
1005 */
1006 int notification_id;
1007
1008 /**
1009 * An NI type used to distinguish different categories of NI
1010 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
1011 */
1012 GpsNiType ni_type;
1013
1014 /**
1015 * Notification/verification options, combinations of GpsNiNotifyFlags constants
1016 */
1017 GpsNiNotifyFlags notify_flags;
1018
1019 /**
1020 * Timeout period to wait for user response.
1021 * Set to 0 for no time out limit.
1022 */
1023 int timeout;
1024
1025 /**
1026 * Default response when time out.
1027 */
1028 GpsUserResponseType default_response;
1029
1030 /**
1031 * Requestor ID
1032 */
1033 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
1034
1035 /**
1036 * Notification message. It can also be used to store client_id in some cases
1037 */
1038 char text[GPS_NI_LONG_STRING_MAXLEN];
1039
1040 /**
1041 * Client name decoding scheme
1042 */
1043 GpsNiEncodingType requestor_id_encoding;
1044
1045 /**
1046 * Client name decoding scheme
1047 */
1048 GpsNiEncodingType text_encoding;
1049
1050 /**
1051 * A pointer to extra data. Format:
1052 * key_1 = value_1
1053 * key_2 = value_2
1054 */
1055 char extras[GPS_NI_LONG_STRING_MAXLEN];
1056
1057} GpsNiNotification;
1058
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001059/**
1060 * Callback with NI notification. Can only be called from a thread created by
1061 * create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -07001062 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001063typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
1064
1065/** GPS NI callback structure. */
1066typedef struct
1067{
Mike Lockwood4453b5b2010-06-20 14:23:10 -07001068 /**
1069 * Sends the notification request from HAL to GPSLocationProvider.
1070 */
1071 gps_ni_notify_callback notify_cb;
1072 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001073} GpsNiCallbacks;
1074
1075/**
1076 * Extended interface for Network-initiated (NI) support.
1077 */
1078typedef struct
1079{
1080 /** set to sizeof(GpsNiInterface) */
1081 size_t size;
1082
1083 /** Registers the callbacks for HAL to use. */
1084 void (*init) (GpsNiCallbacks *callbacks);
1085
1086 /** Sends a response to HAL. */
1087 void (*respond) (int notif_id, GpsUserResponseType user_response);
1088} GpsNiInterface;
1089
1090struct gps_device_t {
1091 struct hw_device_t common;
1092
1093 /**
1094 * Set the provided lights to the provided values.
1095 *
1096 * Returns: 0 on succes, error code on failure.
1097 */
1098 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
1099};
1100
Miguel Torroja5f404f52010-07-27 06:34:15 +02001101#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
1102#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
1103
1104#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
1105#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
1106
1107typedef void (*agps_ril_request_set_id)(uint32_t flags);
1108typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
1109
1110typedef struct {
1111 agps_ril_request_set_id request_setid;
1112 agps_ril_request_ref_loc request_refloc;
1113 gps_create_thread create_thread_cb;
1114} AGpsRilCallbacks;
1115
1116/** Extended interface for AGPS_RIL support. */
1117typedef struct {
1118 /** set to sizeof(AGpsRilInterface) */
1119 size_t size;
1120 /**
1121 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001122 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +02001123 */
1124 void (*init)( AGpsRilCallbacks* callbacks );
1125
1126 /**
1127 * Sets the reference location.
1128 */
1129 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
1130 /**
1131 * Sets the set ID.
1132 */
1133 void (*set_set_id) (AGpsSetIDType type, const char* setid);
1134
1135 /**
1136 * Send network initiated message.
1137 */
1138 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -04001139
1140 /**
1141 * Notify GPS of network status changes.
1142 * These parameters match values in the android.net.NetworkInfo class.
1143 */
1144 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -07001145
1146 /**
1147 * Notify GPS of network status changes.
1148 * These parameters match values in the android.net.NetworkInfo class.
1149 */
1150 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +02001151} AGpsRilInterface;
1152
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001153/**
1154 * GPS Geofence.
1155 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1156 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1157 *
1158 * An example state diagram with confidence level: 95% and Unknown time limit
1159 * set as 30 secs is shown below. (confidence level and Unknown time limit are
1160 * explained latter)
1161 * ____________________________
1162 * | Unknown (30 secs) |
1163 * """"""""""""""""""""""""""""
1164 * ^ | | ^
1165 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
1166 * | v v |
1167 * ________ EXITED _________
1168 * | Inside | -----------> | Outside |
1169 * | | <----------- | |
1170 * """""""" ENTERED """""""""
1171 *
1172 * Inside state: We are 95% confident that the user is inside the geofence.
1173 * Outside state: We are 95% confident that the user is outside the geofence
1174 * Unknown state: Rest of the time.
1175 *
1176 * The Unknown state is better explained with an example:
1177 *
1178 * __________
1179 * | c|
1180 * | ___ | _______
1181 * | |a| | | b |
1182 * | """ | """""""
1183 * | |
1184 * """"""""""
1185 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1186 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1187 * confident that the user is outside. But with regard to "a" is not confident
1188 * whether it is inside or outside the geofence. If the accuracy remains the
1189 * same for a sufficient period of time, the UNCERTAIN transition would be
1190 * triggered with the state set to Unknown. If the accuracy improves later, an
1191 * appropriate transition should be triggered. This "sufficient period of time"
1192 * is defined by the parameter in the add_geofence_area API.
1193 * In other words, Unknown state can be interpreted as a state in which the
1194 * GPS subsystem isn't confident enough that the user is either inside or
1195 * outside the Geofence. It moves to Unknown state only after the expiry of the
1196 * timeout.
1197 *
1198 * The geofence callback needs to be triggered for the ENTERED and EXITED
1199 * transitions, when the GPS system is confident that the user has entered
1200 * (Inside state) or exited (Outside state) the Geofence. An implementation
1201 * which uses a value of 95% as the confidence is recommended. The callback
1202 * should be triggered only for the transitions requested by the
1203 * add_geofence_area call.
1204 *
1205 * Even though the diagram and explanation talks about states and transitions,
1206 * the callee is only interested in the transistions. The states are mentioned
1207 * here for illustrative purposes.
1208 *
1209 * Startup Scenario: When the device boots up, if an application adds geofences,
1210 * and then we get an accurate GPS location fix, it needs to trigger the
1211 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1212 * By default, all the Geofences will be in the Unknown state.
1213 *
1214 * When the GPS system is unavailable, gps_geofence_status_callback should be
1215 * called to inform the upper layers of the same. Similarly, when it becomes
1216 * available the callback should be called. This is a global state while the
1217 * UNKNOWN transition described above is per geofence.
1218 *
1219 * An important aspect to note is that users of this API (framework), will use
1220 * other subsystems like wifi, sensors, cell to handle Unknown case and
1221 * hopefully provide a definitive state transition to the third party
1222 * application. GPS Geofence will just be a signal indicating what the GPS
1223 * subsystem knows about the Geofence.
1224 *
1225 */
1226#define GPS_GEOFENCE_ENTERED (1<<0L)
1227#define GPS_GEOFENCE_EXITED (1<<1L)
1228#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1229
1230#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1231#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1232
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001233#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1234#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1235#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1236#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1237#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1238#define GPS_GEOFENCE_ERROR_GENERIC -149
1239
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001240/**
1241 * The callback associated with the geofence.
1242 * Parameters:
1243 * geofence_id - The id associated with the add_geofence_area.
1244 * location - The current GPS location.
1245 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1246 * GPS_GEOFENCE_UNCERTAIN.
1247 * timestamp - Timestamp when the transition was detected.
1248 *
1249 * The callback should only be called when the caller is interested in that
1250 * particular transition. For instance, if the caller is interested only in
1251 * ENTERED transition, then the callback should NOT be called with the EXITED
1252 * transition.
1253 *
1254 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1255 * subsystem will wake up the application processor, if its in suspend state.
1256 */
1257typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1258 int32_t transition, GpsUtcTime timestamp);
1259
1260/**
destradaa9f7c3732014-04-29 10:50:22 -07001261 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001262 * monitoring. If the GPS system determines that it cannot monitor geofences
1263 * because of lack of reliability or unavailability of the GPS signals, it will
1264 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1265 *
1266 * Parameters:
1267 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1268 * last_location - Last known location.
1269 */
1270typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1271
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001272/**
1273 * The callback associated with the add_geofence call.
1274 *
1275 * Parameter:
1276 * geofence_id - Id of the geofence.
1277 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1278 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1279 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1280 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1281 * invalid transition
1282 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1283 */
1284typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1285
1286/**
1287 * The callback associated with the remove_geofence call.
1288 *
1289 * Parameter:
1290 * geofence_id - Id of the geofence.
1291 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1292 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1293 * GPS_GEOFENCE_ERROR_GENERIC for others.
1294 */
1295typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1296
1297
1298/**
1299 * The callback associated with the pause_geofence call.
1300 *
1301 * Parameter:
1302 * geofence_id - Id of the geofence.
1303 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1304 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1305 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1306 * when monitor_transitions is invalid
1307 * GPS_GEOFENCE_ERROR_GENERIC for others.
1308 */
1309typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1310
1311/**
1312 * The callback associated with the resume_geofence call.
1313 *
1314 * Parameter:
1315 * geofence_id - Id of the geofence.
1316 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1317 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1318 * GPS_GEOFENCE_ERROR_GENERIC for others.
1319 */
1320typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1321
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001322typedef struct {
1323 gps_geofence_transition_callback geofence_transition_callback;
1324 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001325 gps_geofence_add_callback geofence_add_callback;
1326 gps_geofence_remove_callback geofence_remove_callback;
1327 gps_geofence_pause_callback geofence_pause_callback;
1328 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001329 gps_create_thread create_thread_cb;
1330} GpsGeofenceCallbacks;
1331
1332/** Extended interface for GPS_Geofencing support */
1333typedef struct {
1334 /** set to sizeof(GpsGeofencingInterface) */
1335 size_t size;
1336
1337 /**
1338 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001339 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001340 */
1341 void (*init)( GpsGeofenceCallbacks* callbacks );
1342
1343 /**
1344 * Add a geofence area. This api currently supports circular geofences.
1345 * Parameters:
1346 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001347 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1348 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001349 * latitude, longtitude, radius_meters - The lat, long and radius
1350 * (in meters) for the geofence
1351 * last_transition - The current state of the geofence. For example, if
1352 * the system already knows that the user is inside the geofence,
1353 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1354 * will be GPS_GEOFENCE_UNCERTAIN.
1355 * monitor_transition - Which transitions to monitor. Bitwise OR of
1356 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1357 * GPS_GEOFENCE_UNCERTAIN.
1358 * notification_responsiveness_ms - Defines the best-effort description
1359 * of how soon should the callback be called when the transition
1360 * associated with the Geofence is triggered. For instance, if set
1361 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1362 * should be called 1000 milliseconds within entering the geofence.
1363 * This parameter is defined in milliseconds.
1364 * NOTE: This is not to be confused with the rate that the GPS is
1365 * polled at. It is acceptable to dynamically vary the rate of
1366 * sampling the GPS for power-saving reasons; thus the rate of
1367 * sampling may be faster or slower than this.
1368 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001369 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001370 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001371 */
destradaa9f7c3732014-04-29 10:50:22 -07001372 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1373 double radius_meters, int last_transition, int monitor_transitions,
1374 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001375
1376 /**
1377 * Pause monitoring a particular geofence.
1378 * Parameters:
1379 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001380 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001381 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001382
1383 /**
1384 * Resume monitoring a particular geofence.
1385 * Parameters:
1386 * geofence_id - The id for the geofence.
1387 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1388 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1389 * GPS_GEOFENCE_UNCERTAIN.
1390 * This supersedes the value associated provided in the
1391 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001392 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001393 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001394
1395 /**
1396 * Remove a geofence area. After the function returns, no notifications
1397 * should be sent.
1398 * Parameter:
1399 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001400 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001401 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001402} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001403
destradaa9f7c3732014-04-29 10:50:22 -07001404/**
1405 * Represents an estimate of the GPS clock time.
1406 */
1407typedef struct {
1408 /** set to sizeof(GpsClock) */
1409 size_t size;
1410
1411 /** A set of flags indicating the validity of the fields in this data structure. */
1412 GpsClockFlags flags;
1413
1414 /**
1415 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001416 * The sign of the value is defined by the following equation:
1417 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second * 1,000,000,000
1418 *
destradaa9f7c3732014-04-29 10:50:22 -07001419 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1420 */
1421 int16_t leap_second;
1422
1423 /**
destradaa75843eb2014-07-17 14:04:50 -07001424 * Indicates the type of time reported by the 'time_ns' field.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001425 * This is a mandatory field.
destradaa75843eb2014-07-17 14:04:50 -07001426 */
1427 GpsClockType type;
1428
1429 /**
1430 * The GPS receiver internal clock value. This can be either the local hardware clock value
1431 * (GPS_CLOCK_TYPE_LOCAL_HW_TIME), or the current GPS time derived inside GPS receiver
1432 * (GPS_CLOCK_TYPE_GPS_TIME). The field 'type' defines the time reported.
destradaa9f7c3732014-04-29 10:50:22 -07001433 *
destradaa75843eb2014-07-17 14:04:50 -07001434 * For local hardware clock, this value is expected to be monotonically increasing during
1435 * the reporting session. The real GPS time can be derived by compensating the 'full bias'
1436 * (when it is available) from this value.
destradaa9f7c3732014-04-29 10:50:22 -07001437 *
destradaa75843eb2014-07-17 14:04:50 -07001438 * For GPS time, this value is expected to be the best estimation of current GPS time that GPS
1439 * receiver can achieve. Set the 'time uncertainty' appropriately when GPS time is specified.
1440 *
1441 * Sub-nanosecond accuracy can be provided by means of the 'bias' field.
destradaa9f7c3732014-04-29 10:50:22 -07001442 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001443 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001444 * This field is mandatory.
1445 *
1446 * For devices where GpsSystemInfo's year_of_hw is set to 2016+, it is
1447 * mandatory that it contains the value from the 'local hardware clock, and
1448 * thus GPS_CLOCK_TYPE_LOCAL_HW_TIME must be set in 'type' field.
destradaa9f7c3732014-04-29 10:50:22 -07001449 */
1450 int64_t time_ns;
1451
1452 /**
1453 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1454 * The uncertainty is represented as an absolute (single sided) value.
1455 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001456 * If the data is available, 'flags' must contain
1457 * GPS_CLOCK_HAS_TIME_UNCERTAINTY. If GPS has computed a position fix, this
1458 * field is mandatory and must be populated.
destradaa9f7c3732014-04-29 10:50:22 -07001459 */
1460 double time_uncertainty_ns;
1461
1462 /**
destradaa75843eb2014-07-17 14:04:50 -07001463 * The difference between hardware clock ('time' field) inside GPS receiver and the true GPS
1464 * time since 0000Z, January 6, 1980, in nanoseconds.
1465 * This value is used if and only if GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, and GPS receiver
1466 * has solved the clock for GPS time.
1467 * The caller is responsible for using the 'bias uncertainty' field for quality check.
destradaa9f7c3732014-04-29 10:50:22 -07001468 *
destradaa75843eb2014-07-17 14:04:50 -07001469 * The sign of the value is defined by the following equation:
1470 * true time (GPS time) = time_ns + (full_bias_ns + bias_ns)
1471 *
1472 * This value contains the 'bias uncertainty' in it.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001473 * If GPS has computed a position fix this field is mandatory and must be
1474 * populated. If the data is available 'flags' must contain
1475 * GPS_CLOCK_HAS_FULL_BIAS.
destradaa75843eb2014-07-17 14:04:50 -07001476 */
1477 int64_t full_bias_ns;
1478
1479 /**
1480 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001481 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001482 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001483 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS. If GPS
1484 * has computed a position fix, this field is mandatory and must be
1485 * populated.
destradaa9f7c3732014-04-29 10:50:22 -07001486 */
1487 double bias_ns;
1488
1489 /**
1490 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1491 * The uncertainty is represented as an absolute (single sided) value.
1492 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001493 * If the data is available 'flags' must contain
1494 * GPS_CLOCK_HAS_BIAS_UNCERTAINTY. If GPS has computed a position fix this
1495 * field is mandatory and must be populated.
destradaa9f7c3732014-04-29 10:50:22 -07001496 */
1497 double bias_uncertainty_ns;
1498
1499 /**
1500 * The clock's drift in nanoseconds (per second).
1501 * A positive value means that the frequency is higher than the nominal frequency.
1502 *
1503 * The value contains the 'drift uncertainty' in it.
1504 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
destradaa00caa892015-04-09 18:41:46 -07001505 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001506 * If GpsMeasurement's 'flags' field contains
1507 * GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE, it is encouraged that
1508 * this field is also provided. If GPS has computed a position fix this
1509 * field is mandatory and must be populated.
destradaa9f7c3732014-04-29 10:50:22 -07001510 */
1511 double drift_nsps;
1512
1513 /**
1514 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1515 * The uncertainty is represented as an absolute (single sided) value.
1516 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001517 * If the data is available 'flags' must contain
1518 * GPS_CLOCK_HAS_DRIFT_UNCERTAINTY. If GPS has computed a position fix this
1519 * field is mandatory and must be populated.
destradaa9f7c3732014-04-29 10:50:22 -07001520 */
1521 double drift_uncertainty_nsps;
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001522
1523 /**
1524 * When the GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, this field is mandatory.
1525 *
1526 * A "discontinuity" is meant to cover the case of a switch from one source
1527 * of clock to another. A single free-running crystal oscillator (XO)
1528 * should generally not have any discontinuities, and this can be set to 0.
1529 * If, however, the time_ns value (HW clock) is derived from a composite of
1530 * sources, that is not as smooth as a typical XO, then this value shall be
1531 * set to the time_ns value since which the time_ns has been derived from a
1532 * single, high quality clock (XO like, or better, that's typically used
1533 * during continuous GPS signal sampling.)
1534 *
1535 * It is expected, esp. during periods where there are few GNSS signals
1536 * available, that the HW clock be discontinuity-free as long as possible,
1537 * as this avoids the need to use (waste) a GPS measurement to fully
1538 * re-solve for the clock bias and drift.
1539 */
1540 int64_t time_of_last_hw_clock_discontinuity_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001541} GpsClock;
1542
1543/**
1544 * Represents a GPS Measurement, it contains raw and computed information.
1545 */
1546typedef struct {
1547 /** set to sizeof(GpsMeasurement) */
1548 size_t size;
1549
1550 /** A set of flags indicating the validity of the fields in this data structure. */
1551 GpsMeasurementFlags flags;
1552
1553 /**
1554 * Pseudo-random number in the range of [1, 32]
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001555 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001556 */
1557 int8_t prn;
1558
1559 /**
destradaa75843eb2014-07-17 14:04:50 -07001560 * Time offset at which the measurement was taken in nanoseconds.
1561 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1562 * interpreted in the same way as indicated by GpsClock::type.
1563 *
destradaa9f7c3732014-04-29 10:50:22 -07001564 * The sign of time_offset_ns is given by the following equation:
1565 * measurement time = GpsClock::time_ns + time_offset_ns
1566 *
1567 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001568 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001569 */
destradaa75843eb2014-07-17 14:04:50 -07001570 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001571
1572 /**
destradaa75843eb2014-07-17 14:04:50 -07001573 * Per satellite sync state. It represents the current sync state for the associated satellite.
1574 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001575 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001576 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001577 */
destradaa75843eb2014-07-17 14:04:50 -07001578 GpsMeasurementState state;
1579
1580 /**
1581 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1582 * The value is relative to the beginning of the current GPS week.
1583 *
Tsuwei Chena90cf192014-10-23 12:49:12 -07001584 * Given the highest sync state that can be achieved, per each satellite, valid range for
1585 * this field can be:
1586 * Searching : [ 0 ] : GPS_MEASUREMENT_STATE_UNKNOWN
1587 * C/A code lock : [ 0 1ms ] : GPS_MEASUREMENT_STATE_CODE_LOCK is set
1588 * Bit sync : [ 0 20ms ] : GPS_MEASUREMENT_STATE_BIT_SYNC is set
1589 * Subframe sync : [ 0 6s ] : GPS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1590 * TOW decoded : [ 0 1week ] : GPS_MEASUREMENT_STATE_TOW_DECODED is set
1591 *
1592 * However, if there is any ambiguity in integer millisecond,
1593 * GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field.
destradaa00caa892015-04-09 18:41:46 -07001594 *
1595 * This value must be populated if 'state' != GPS_MEASUREMENT_STATE_UNKNOWN.
destradaa75843eb2014-07-17 14:04:50 -07001596 */
destradaa9f7c3732014-04-29 10:50:22 -07001597 int64_t received_gps_tow_ns;
1598
1599 /**
destradaa941c9282014-07-21 18:13:42 -07001600 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
destradaa00caa892015-04-09 18:41:46 -07001601 *
1602 * This value must be populated if 'state' != GPS_MEASUREMENT_STATE_UNKNOWN.
destradaa941c9282014-07-21 18:13:42 -07001603 */
1604 int64_t received_gps_tow_uncertainty_ns;
1605
1606 /**
destradaa9f7c3732014-04-29 10:50:22 -07001607 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1608 * It contains the measured C/N0 value for the signal at the antenna input.
1609 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001610 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001611 */
1612 double c_n0_dbhz;
1613
1614 /**
1615 * Pseudorange rate at the timestamp in m/s.
destradaa357e6222015-04-14 16:30:21 -07001616 * The correction of a given Pseudorange Rate value includes corrections for receiver and
1617 * satellite clock frequency errors.
destradaa00caa892015-04-09 18:41:46 -07001618 *
destradaa00caa892015-04-09 18:41:46 -07001619 * It is encouraged to provide the 'uncorrected' 'pseudorange rate', and provide GpsClock's
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001620 * 'drift' field as well. When providing the uncorrected pseudorange rate,
1621 * do not apply the corrections described above.
destradaa9f7c3732014-04-29 10:50:22 -07001622 *
1623 * The value includes the 'pseudorange rate uncertainty' in it.
destradaa00caa892015-04-09 18:41:46 -07001624 * A positive 'uncorrected' value indicates that the SV is moving away from the receiver.
1625 *
destradaa357e6222015-04-14 16:30:21 -07001626 * The sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler
destradaa00caa892015-04-09 18:41:46 -07001627 * shift' is given by the equation:
destradaa357e6222015-04-14 16:30:21 -07001628 * pseudorange rate = -k * doppler shift (where k is a constant)
destradaa9f7c3732014-04-29 10:50:22 -07001629 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001630 * This field should be based on the signal energy doppler measurement. (See
1631 * also pseudorate_rate_carrier_mps for a similar field, based on carrier
1632 * phase changes.)
1633 *
1634 * This is a mandatory value. It is mandatory (and expected) that it
1635 * contains the 'uncorrected' reading, and
1636 * GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE must be set in 'flags'
1637 * field.
destradaa9f7c3732014-04-29 10:50:22 -07001638 */
destradaa75843eb2014-07-17 14:04:50 -07001639 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001640
1641 /**
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001642 * 1-Sigma uncertainty of the pseudorange_rate_mps.
destradaa9f7c3732014-04-29 10:50:22 -07001643 * The uncertainty is represented as an absolute (single sided) value.
1644 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001645 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001646 */
destradaa75843eb2014-07-17 14:04:50 -07001647 double pseudorange_rate_uncertainty_mps;
1648
1649 /**
1650 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1651 * (indicating loss of lock).
1652 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001653 * This is a mandatory value.
destradaa75843eb2014-07-17 14:04:50 -07001654 */
1655 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001656
1657 /**
1658 * Accumulated delta range since the last channel reset in meters.
destradaa357e6222015-04-14 16:30:21 -07001659 * A positive value indicates that the SV is moving away from the receiver.
destradaa00caa892015-04-09 18:41:46 -07001660 *
destradaa357e6222015-04-14 16:30:21 -07001661 * The sign of the 'accumulated delta range' and its relation to the sign of 'carrier phase'
destradaa00caa892015-04-09 18:41:46 -07001662 * is given by the equation:
destradaa357e6222015-04-14 16:30:21 -07001663 * accumulated delta range = -k * carrier phase (where k is a constant)
destradaa00caa892015-04-09 18:41:46 -07001664 *
1665 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
1666 * However, it is expected that the data is only accurate when:
1667 * 'accumulated delta range state' == GPS_ADR_STATE_VALID.
destradaa9f7c3732014-04-29 10:50:22 -07001668 */
1669 double accumulated_delta_range_m;
1670
1671 /**
1672 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa00caa892015-04-09 18:41:46 -07001673 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001674 */
1675 double accumulated_delta_range_uncertainty_m;
1676
1677 /**
1678 * Best derived Pseudorange by the chip-set, in meters.
1679 * The value contains the 'pseudorange uncertainty' in it.
1680 *
1681 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1682 */
1683 double pseudorange_m;
1684
1685 /**
1686 * 1-Sigma uncertainty of the pseudorange in meters.
1687 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1688 * The uncertainty is represented as an absolute (single sided) value.
1689 *
1690 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1691 */
1692 double pseudorange_uncertainty_m;
1693
1694 /**
1695 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1696 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1697 *
1698 * The reference frequency is given by the field 'carrier_frequency_hz'.
1699 * The value contains the 'code-phase uncertainty' in it.
1700 *
1701 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1702 */
1703 double code_phase_chips;
1704
1705 /**
1706 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1707 * The uncertainty is represented as an absolute (single sided) value.
1708 *
1709 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1710 */
1711 double code_phase_uncertainty_chips;
1712
1713 /**
1714 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1715 * If the field is not set, the carrier frequency is assumed to be L1.
1716 *
1717 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1718 */
1719 float carrier_frequency_hz;
1720
1721 /**
1722 * The number of full carrier cycles between the satellite and the receiver.
1723 * The reference frequency is given by the field 'carrier_frequency_hz'.
1724 *
1725 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1726 */
1727 int64_t carrier_cycles;
1728
1729 /**
1730 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1731 * This is usually the fractional part of the complete carrier phase measurement.
1732 *
1733 * The reference frequency is given by the field 'carrier_frequency_hz'.
1734 * The value contains the 'carrier-phase uncertainty' in it.
1735 *
1736 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1737 */
1738 double carrier_phase;
1739
1740 /**
1741 * 1-Sigma uncertainty of the carrier-phase.
1742 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1743 */
1744 double carrier_phase_uncertainty;
1745
1746 /**
1747 * An enumeration that indicates the 'loss of lock' state of the event.
1748 */
1749 GpsLossOfLock loss_of_lock;
1750
1751 /**
1752 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1753 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1754 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001755 int32_t bit_number;
destradaa9f7c3732014-04-29 10:50:22 -07001756
1757 /**
destradaa75843eb2014-07-17 14:04:50 -07001758 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
destradaa9f7c3732014-04-29 10:50:22 -07001759 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1760 */
destradaa75843eb2014-07-17 14:04:50 -07001761 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001762
1763 /**
1764 * Doppler shift in Hz.
1765 * A positive value indicates that the SV is moving toward the receiver.
1766 *
1767 * The reference frequency is given by the field 'carrier_frequency_hz'.
1768 * The value contains the 'doppler shift uncertainty' in it.
1769 *
1770 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1771 */
1772 double doppler_shift_hz;
1773
1774 /**
1775 * 1-Sigma uncertainty of the doppler shift in Hz.
1776 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1777 */
1778 double doppler_shift_uncertainty_hz;
1779
1780 /**
1781 * An enumeration that indicates the 'multipath' state of the event.
1782 */
1783 GpsMultipathIndicator multipath_indicator;
1784
1785 /**
1786 * Signal-to-noise ratio in dB.
1787 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1788 */
1789 double snr_db;
1790
1791 /**
1792 * Elevation in degrees, the valid range is [-90, 90].
1793 * The value contains the 'elevation uncertainty' in it.
1794 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1795 */
1796 double elevation_deg;
1797
1798 /**
1799 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1800 * The uncertainty is represented as the absolute (single sided) value.
1801 *
1802 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1803 */
1804 double elevation_uncertainty_deg;
1805
1806 /**
1807 * Azimuth in degrees, in the range [0, 360).
1808 * The value contains the 'azimuth uncertainty' in it.
1809 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001810 */
destradaa9f7c3732014-04-29 10:50:22 -07001811 double azimuth_deg;
1812
1813 /**
1814 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1815 * The uncertainty is represented as an absolute (single sided) value.
1816 *
1817 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1818 */
1819 double azimuth_uncertainty_deg;
1820
1821 /**
1822 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1823 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1824 */
1825 bool used_in_fix;
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001826
1827 /**
1828 * Pseudorange rate (based on carrier phase changes) at the timestamp in m/s.
1829 *
1830 * The correction of a given Pseudorange Rate value includes corrections for
1831 * receiver and satellite clock frequency errors.
1832 *
1833 * It is mandatory to provide the 'uncorrected' 'pseudorange rate' in this
1834 * field. (Do not apply the corrections described above.)
1835 *
1836 * The value includes the 'pseudorange rate (carrier) uncertainty' in it. A
1837 * positive 'uncorrected' value indicates that the SV is moving away from
1838 * the receiver.
1839 *
1840 * The sign of the 'uncorrected' 'pseudorange rate' and its relation to the
1841 * sign of 'doppler shift' is given by the equation:
1842 *
1843 * pseudorange rate = -k * doppler shift (where k is a constant)
1844 *
1845 * This field must be based on changes in the carrier phase measurement.
1846 * (See pseudorange_rate_mps for a similar field, based on signal energy
1847 * doppler.)
1848 *
1849 * It is mandatory that this value be provided, when signals are
1850 * sufficiently strong, e.g. signals from a GPS simulator at >= 30 dB-Hz.
1851 */
1852 double pseudorange_rate_carrier_mps;
1853 /**
1854 * 1-Sigma uncertainty of the pseudorange_rate_carrier_mps.
1855 * The uncertainty is represented as an absolute (single sided) value.
1856 *
1857 * This is a mandatory value when pseudorange_rate_carrier_mps is provided.
1858 */
1859 double pseudorange_rate_carrier_uncertainty_mps;
1860
destradaa9f7c3732014-04-29 10:50:22 -07001861} GpsMeasurement;
1862
1863/** Represents a reading of GPS measurements. */
1864typedef struct {
1865 /** set to sizeof(GpsData) */
1866 size_t size;
1867
1868 /** Number of measurements. */
1869 size_t measurement_count;
1870
1871 /** The array of measurements. */
1872 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1873
1874 /** The GPS clock time reading. */
1875 GpsClock clock;
1876} GpsData;
1877
1878/**
1879 * The callback for to report measurements from the HAL.
1880 *
1881 * Parameters:
1882 * data - A data structure containing the measurements.
1883 */
1884typedef void (*gps_measurement_callback) (GpsData* data);
1885
1886typedef struct {
1887 /** set to sizeof(GpsMeasurementCallbacks) */
1888 size_t size;
1889 gps_measurement_callback measurement_callback;
1890} GpsMeasurementCallbacks;
1891
1892#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1893#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1894#define GPS_MEASUREMENT_ERROR_GENERIC -101
1895
1896/**
1897 * Extended interface for GPS Measurements support.
1898 */
1899typedef struct {
1900 /** Set to sizeof(GpsMeasurementInterface) */
1901 size_t size;
1902
1903 /**
1904 * Initializes the interface and registers the callback routines with the HAL.
1905 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1906 *
1907 * Status:
1908 * GPS_MEASUREMENT_OPERATION_SUCCESS
1909 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1910 * corresponding call to 'close'
1911 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1912 * will not generate any updates upon returning this error code.
1913 */
1914 int (*init) (GpsMeasurementCallbacks* callbacks);
1915
1916 /**
1917 * Stops updates from the HAL, and unregisters the callback routines.
1918 * After a call to stop, the previously registered callbacks must be considered invalid by the
1919 * HAL.
1920 * If stop is invoked without a previous 'init', this function should perform no work.
1921 */
1922 void (*close) ();
1923
1924} GpsMeasurementInterface;
1925
1926
1927/** Represents a GPS navigation message (or a fragment of it). */
1928typedef struct {
1929 /** set to sizeof(GpsNavigationMessage) */
1930 size_t size;
1931
1932 /**
1933 * Pseudo-random number in the range of [1, 32]
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001934 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001935 */
1936 int8_t prn;
1937
1938 /**
1939 * The type of message contained in the structure.
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001940 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001941 */
1942 GpsNavigationMessageType type;
1943
1944 /**
Tsuwei Chena90cf192014-10-23 12:49:12 -07001945 * The status of the received navigation message.
1946 * No need to send any navigation message that contains words with parity error and cannot be
1947 * corrected.
1948 */
1949 NavigationMessageStatus status;
1950
1951 /**
destradaa9f7c3732014-04-29 10:50:22 -07001952 * Message identifier.
destradaa75843eb2014-07-17 14:04:50 -07001953 * It provides an index so the complete Navigation Message can be assembled. i.e. fo L1 C/A
1954 * subframe 4 and 5, this value corresponds to the 'frame id' of the navigation message.
1955 * Subframe 1, 2, 3 does not contain a 'frame id' and this value can be set to -1.
destradaa9f7c3732014-04-29 10:50:22 -07001956 */
1957 int16_t message_id;
1958
1959 /**
1960 * Sub-message identifier.
1961 * If required by the message 'type', this value contains a sub-index within the current
1962 * message (or frame) that is being transmitted.
1963 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1964 */
1965 int16_t submessage_id;
1966
1967 /**
1968 * The length of the data (in bytes) contained in the current message.
1969 * If this value is different from zero, 'data' must point to an array of the same size.
destradaa69d5ea52014-07-31 16:34:09 -07001970 * 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 -07001971 *
Lifu Tangdf0fcf72015-10-27 14:58:25 -07001972 * This is a mandatory value.
destradaa9f7c3732014-04-29 10:50:22 -07001973 */
1974 size_t data_length;
1975
1976 /**
1977 * The data of the reported GPS message.
1978 * The bytes (or words) specified using big endian format (MSB first).
destradaa69d5ea52014-07-31 16:34:09 -07001979 *
1980 * For L1 C/A, each subframe contains 10 30-bit GPS words. Each GPS word (30 bits) should be
1981 * fitted into the last 30 bits in a 4-byte word (skip B31 and B32), with MSB first.
destradaa9f7c3732014-04-29 10:50:22 -07001982 */
1983 uint8_t* data;
1984
1985} GpsNavigationMessage;
1986
1987/**
1988 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1989 *
1990 * Parameters:
1991 * message - The GPS navigation submessage/subframe representation.
1992 */
1993typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1994
1995typedef struct {
1996 /** set to sizeof(GpsNavigationMessageCallbacks) */
1997 size_t size;
1998 gps_navigation_message_callback navigation_message_callback;
1999} GpsNavigationMessageCallbacks;
2000
2001#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
2002#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
2003#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
2004
2005/**
2006 * Extended interface for GPS navigation message reporting support.
2007 */
2008typedef struct {
2009 /** Set to sizeof(GpsNavigationMessageInterface) */
2010 size_t size;
2011
2012 /**
2013 * Initializes the interface and registers the callback routines with the HAL.
2014 * After a successful call to 'init' the HAL must begin to provide updates as they become
2015 * available.
2016 *
2017 * Status:
2018 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
2019 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
2020 * without a corresponding call to 'close'.
2021 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
2022 * the HAL will not generate any updates upon returning this error code.
2023 */
2024 int (*init) (GpsNavigationMessageCallbacks* callbacks);
2025
2026 /**
2027 * Stops updates from the HAL, and unregisters the callback routines.
2028 * After a call to stop, the previously registered callbacks must be considered invalid by the
2029 * HAL.
2030 * If stop is invoked without a previous 'init', this function should perform no work.
2031 */
2032 void (*close) ();
2033
2034} GpsNavigationMessageInterface;
2035
Tsuwei Chen167d31f2014-08-26 16:34:19 -07002036/**
2037 * Interface for passing GNSS configuration contents from platform to HAL.
2038 */
2039typedef struct {
2040 /** Set to sizeof(GnssConfigurationInterface) */
2041 size_t size;
2042
2043 /**
2044 * Deliver GNSS configuration contents to HAL.
2045 * Parameters:
2046 * config_data - a pointer to a char array which holds what usually is expected from
2047 file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
2048 * length - total number of UTF8 characters in configuraiton data.
2049 *
2050 * IMPORTANT:
2051 * GPS HAL should expect this function can be called multiple times. And it may be
2052 * called even when GpsLocationProvider is already constructed and enabled. GPS HAL
2053 * should maintain the existing requests for various callback regardless the change
2054 * in configuration data.
2055 */
2056 void (*configuration_update) (const char* config_data, int32_t length);
2057} GnssConfigurationInterface;
2058
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05002059__END_DECLS
2060
2061#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
2062