blob: 937436b3e4be737f9651836c2235c208b45c1ff6 [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
54/** AGPS MS-Assisted mode. */
55#define GPS_POSITION_MODE_MS_ASSISTED 2
56
Mike Lockwoodb15879a2010-04-14 15:36:34 -040057/** Requested recurrence mode for GPS operation. */
58typedef uint32_t GpsPositionRecurrence;
59// IMPORTANT: Note that the following values must match
60// constants in GpsLocationProvider.java.
61/** Receive GPS fixes on a recurring basis at a specified period. */
62#define GPS_POSITION_RECURRENCE_PERIODIC 0
63/** Request a single shot GPS fix. */
64#define GPS_POSITION_RECURRENCE_SINGLE 1
65
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050066/** GPS status event values. */
67typedef uint16_t GpsStatusValue;
68// IMPORTANT: Note that the following values must match
69// constants in GpsLocationProvider.java.
70/** GPS status unknown. */
71#define GPS_STATUS_NONE 0
72/** GPS has begun navigating. */
73#define GPS_STATUS_SESSION_BEGIN 1
74/** GPS has stopped navigating. */
75#define GPS_STATUS_SESSION_END 2
76/** GPS has powered on but is not navigating. */
77#define GPS_STATUS_ENGINE_ON 3
78/** GPS is powered off. */
79#define GPS_STATUS_ENGINE_OFF 4
80
81/** Flags to indicate which values are valid in a GpsLocation. */
82typedef uint16_t GpsLocationFlags;
83// IMPORTANT: Note that the following values must match
84// constants in GpsLocationProvider.java.
85/** GpsLocation has valid latitude and longitude. */
86#define GPS_LOCATION_HAS_LAT_LONG 0x0001
87/** GpsLocation has valid altitude. */
88#define GPS_LOCATION_HAS_ALTITUDE 0x0002
89/** GpsLocation has valid speed. */
90#define GPS_LOCATION_HAS_SPEED 0x0004
91/** GpsLocation has valid bearing. */
92#define GPS_LOCATION_HAS_BEARING 0x0008
93/** GpsLocation has valid accuracy. */
94#define GPS_LOCATION_HAS_ACCURACY 0x0010
95
Mike Lockwoodb15879a2010-04-14 15:36:34 -040096/** Flags for the gps_set_capabilities callback. */
97
98/** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
99 If this is not set, then the framework will use 1000ms for min_interval
100 and will start and call start() and stop() to schedule the GPS.
101 */
102#define GPS_CAPABILITY_SCHEDULING 0x0000001
103/** GPS supports MS-Based AGPS mode */
104#define GPS_CAPABILITY_MSB 0x0000002
105/** GPS supports MS-Assisted AGPS mode */
106#define GPS_CAPABILITY_MSA 0x0000004
107/** GPS supports single-shot fixes */
108#define GPS_CAPABILITY_SINGLE_SHOT 0x0000008
Mike Lockwood8aac5912011-06-29 15:10:36 -0400109/** GPS supports on demand time injection */
110#define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800111/** GPS supports Geofencing */
112#define GPS_CAPABILITY_GEOFENCING 0x0000020
destradaa69d5ea52014-07-31 16:34:09 -0700113/** GPS supports Measurements */
114#define GPS_CAPABILITY_MEASUREMENTS 0x0000040
115/** GPS supports Navigation Messages */
116#define GPS_CAPABILITY_NAV_MESSAGES 0x0000080
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400117
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500118/** Flags used to specify which aiding data to delete
119 when calling delete_aiding_data(). */
120typedef uint16_t GpsAidingData;
121// IMPORTANT: Note that the following values must match
122// constants in GpsLocationProvider.java.
123#define GPS_DELETE_EPHEMERIS 0x0001
124#define GPS_DELETE_ALMANAC 0x0002
125#define GPS_DELETE_POSITION 0x0004
126#define GPS_DELETE_TIME 0x0008
127#define GPS_DELETE_IONO 0x0010
128#define GPS_DELETE_UTC 0x0020
129#define GPS_DELETE_HEALTH 0x0040
130#define GPS_DELETE_SVDIR 0x0080
131#define GPS_DELETE_SVSTEER 0x0100
132#define GPS_DELETE_SADATA 0x0200
133#define GPS_DELETE_RTI 0x0400
134#define GPS_DELETE_CELLDB_INFO 0x8000
135#define GPS_DELETE_ALL 0xFFFF
136
137/** AGPS type */
138typedef uint16_t AGpsType;
139#define AGPS_TYPE_SUPL 1
140#define AGPS_TYPE_C2K 2
141
Miguel Torroja5f404f52010-07-27 06:34:15 +0200142typedef uint16_t AGpsSetIDType;
143#define AGPS_SETID_TYPE_NONE 0
144#define AGPS_SETID_TYPE_IMSI 1
145#define AGPS_SETID_TYPE_MSISDN 2
146
destradaaf48cc672014-06-05 11:07:09 -0700147typedef uint16_t ApnIpType;
148#define APN_IP_INVALID 0
149#define APN_IP_IPV4 1
150#define APN_IP_IPV6 2
151#define APN_IP_IPV4V6 3
152
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500153/**
154 * String length constants
155 */
156#define GPS_NI_SHORT_STRING_MAXLEN 256
157#define GPS_NI_LONG_STRING_MAXLEN 2048
158
159/**
160 * GpsNiType constants
161 */
162typedef uint32_t GpsNiType;
163#define GPS_NI_TYPE_VOICE 1
164#define GPS_NI_TYPE_UMTS_SUPL 2
165#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
166
167/**
168 * GpsNiNotifyFlags constants
169 */
170typedef uint32_t GpsNiNotifyFlags;
171/** NI requires notification */
172#define GPS_NI_NEED_NOTIFY 0x0001
173/** NI requires verification */
174#define GPS_NI_NEED_VERIFY 0x0002
175/** NI requires privacy override, no notification/minimal trace */
176#define GPS_NI_PRIVACY_OVERRIDE 0x0004
177
178/**
179 * GPS NI responses, used to define the response in
180 * NI structures
181 */
182typedef int GpsUserResponseType;
183#define GPS_NI_RESPONSE_ACCEPT 1
184#define GPS_NI_RESPONSE_DENY 2
185#define GPS_NI_RESPONSE_NORESP 3
186
187/**
188 * NI data encoding scheme
189 */
190typedef int GpsNiEncodingType;
191#define GPS_ENC_NONE 0
192#define GPS_ENC_SUPL_GSM_DEFAULT 1
193#define GPS_ENC_SUPL_UTF8 2
194#define GPS_ENC_SUPL_UCS2 3
195#define GPS_ENC_UNKNOWN -1
196
197/** AGPS status event values. */
198typedef uint16_t AGpsStatusValue;
199/** GPS requests data connection for AGPS. */
200#define GPS_REQUEST_AGPS_DATA_CONN 1
201/** GPS releases the AGPS data connection. */
202#define GPS_RELEASE_AGPS_DATA_CONN 2
203/** AGPS data connection initiated */
204#define GPS_AGPS_DATA_CONNECTED 3
205/** AGPS data connection completed */
206#define GPS_AGPS_DATA_CONN_DONE 4
207/** AGPS data connection failed */
208#define GPS_AGPS_DATA_CONN_FAILED 5
209
Miguel Torroja5f404f52010-07-27 06:34:15 +0200210#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
211#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
212#define AGPS_REG_LOCATION_TYPE_MAC 3
213
Mike Lockwood455e83b2010-10-11 06:16:57 -0400214/** Network types for update_network_state "type" parameter */
215#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
216#define AGPS_RIL_NETWORK_TYPE_WIFI 1
217#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
218#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
219#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
220#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
221#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
222
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500223/**
destradaa9f7c3732014-04-29 10:50:22 -0700224 * Flags to indicate what fields in GpsClock are valid.
225 */
226typedef uint16_t GpsClockFlags;
227/** A valid 'leap second' is stored in the data structure. */
228#define GPS_CLOCK_HAS_LEAP_SECOND (1<<0)
229/** A valid 'time uncertainty' is stored in the data structure. */
230#define GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
destradaa75843eb2014-07-17 14:04:50 -0700231/** A valid 'full bias' is stored in the data structure. */
232#define GPS_CLOCK_HAS_FULL_BIAS (1<<2)
destradaa9f7c3732014-04-29 10:50:22 -0700233/** A valid 'bias' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700234#define GPS_CLOCK_HAS_BIAS (1<<3)
destradaa9f7c3732014-04-29 10:50:22 -0700235/** A valid 'bias uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700236#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
destradaa9f7c3732014-04-29 10:50:22 -0700237/** A valid 'drift' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700238#define GPS_CLOCK_HAS_DRIFT (1<<5)
destradaa9f7c3732014-04-29 10:50:22 -0700239/** A valid 'drift uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700240#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
241
242/**
243 * Enumeration of the available values for the GPS Clock type.
244 */
245typedef uint8_t GpsClockType;
246/** The type is not available ot it is unknown. */
247#define GPS_CLOCK_TYPE_UNKNOWN 0
248/** The source of the time value reported by GPS clock is the local hardware clock. */
249#define GPS_CLOCK_TYPE_LOCAL_HW_TIME 1
250/**
251 * The source of the time value reported by GPS clock is the GPS time derived from satellites
252 * (epoch = Jan 6, 1980)
253 */
254#define GPS_CLOCK_TYPE_GPS_TIME 2
destradaa9f7c3732014-04-29 10:50:22 -0700255
256/**
257 * Flags to indicate what fields in GpsMeasurement are valid.
258 */
259typedef uint32_t GpsMeasurementFlags;
260/** A valid 'snr' is stored in the data structure. */
261#define GPS_MEASUREMENT_HAS_SNR (1<<0)
262/** A valid 'elevation' is stored in the data structure. */
263#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
264/** A valid 'elevation uncertainty' is stored in the data structure. */
265#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
266/** A valid 'azimuth' is stored in the data structure. */
267#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
268/** A valid 'azimuth uncertainty' is stored in the data structure. */
269#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
270/** A valid 'pseudorange' is stored in the data structure. */
271#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
272/** A valid 'pseudorange uncertainty' is stored in the data structure. */
273#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
274/** A valid 'code phase' is stored in the data structure. */
275#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
276/** A valid 'code phase uncertainty' is stored in the data structure. */
277#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
278/** A valid 'carrier frequency' is stored in the data structure. */
279#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
280/** A valid 'carrier cycles' is stored in the data structure. */
281#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
282/** A valid 'carrier phase' is stored in the data structure. */
283#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
284/** A valid 'carrier phase uncertainty' is stored in the data structure. */
285#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
286/** A valid 'bit number' is stored in the data structure. */
287#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
288/** A valid 'time from last bit' is stored in the data structure. */
289#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
290/** A valid 'doppler shift' is stored in the data structure. */
291#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
292/** A valid 'doppler shift uncertainty' is stored in the data structure. */
293#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
294/** A valid 'used in fix' flag is stored in the data structure. */
295#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
destradaa00caa892015-04-09 18:41:46 -0700296/** The value of 'pseudorange rate' is uncorrected. */
297#define GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE (1<<18)
destradaa9f7c3732014-04-29 10:50:22 -0700298
299/**
destradaa75843eb2014-07-17 14:04:50 -0700300 * Enumeration of the available values for the GPS Measurement's loss of lock.
destradaa9f7c3732014-04-29 10:50:22 -0700301 */
302typedef uint8_t GpsLossOfLock;
303/** The indicator is not available or it is unknown. */
304#define GPS_LOSS_OF_LOCK_UNKNOWN 0
305/** The measurement does not present any indication of loss of lock. */
306#define GPS_LOSS_OF_LOCK_OK 1
307/** Loss of lock between previous and current observation: cycle slip possible. */
308#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
309
310/**
destradaa75843eb2014-07-17 14:04:50 -0700311 * Enumeration of available values for the GPS Measurement's multipath indicator.
destradaa9f7c3732014-04-29 10:50:22 -0700312 */
313typedef uint8_t GpsMultipathIndicator;
314/** The indicator is not available or unknown. */
315#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
316/** The measurement has been indicated to use multipath. */
317#define GPS_MULTIPATH_INDICATOR_DETECTED 1
318/** The measurement has been indicated Not to use multipath. */
319#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
320
321/**
destradaa75843eb2014-07-17 14:04:50 -0700322 * Flags indicating the GPS measurement state.
Tsuwei Chena90cf192014-10-23 12:49:12 -0700323 * The expected behavior here is for GPS HAL to set all the flags that applies. For
324 * example, if the state for a satellite is only C/A code locked and bit synchronized,
325 * and there is still millisecond ambiguity, the state should be set as:
326 * GPS_MEASUREMENT_STATE_CODE_LOCK|GPS_MEASUREMENT_STATE_BIT_SYNC|GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS
327 * If GPS is still searching for a satellite, the corresponding state should be set to
328 * GPS_MEASUREMENT_STATE_UNKNOWN(0).
destradaa75843eb2014-07-17 14:04:50 -0700329 */
330typedef uint16_t GpsMeasurementState;
331#define GPS_MEASUREMENT_STATE_UNKNOWN 0
332#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
333#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
334#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
335#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
Tsuwei Chena90cf192014-10-23 12:49:12 -0700336#define GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4)
destradaa75843eb2014-07-17 14:04:50 -0700337
338/**
339 * Flags indicating the Accumulated Delta Range's states.
340 */
341typedef uint16_t GpsAccumulatedDeltaRangeState;
342#define GPS_ADR_STATE_UNKNOWN 0
343#define GPS_ADR_STATE_VALID (1<<0)
344#define GPS_ADR_STATE_RESET (1<<1)
345#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
346
347/**
Tsuwei Chena90cf192014-10-23 12:49:12 -0700348 * Enumeration of available values to indicate the available GPS Navigation message types.
destradaa9f7c3732014-04-29 10:50:22 -0700349 */
350typedef uint8_t GpsNavigationMessageType;
351/** The message type is unknown. */
352#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
353/** L1 C/A message contained in the structure. */
354#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
355/** L2-CNAV message contained in the structure. */
356#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
357/** L5-CNAV message contained in the structure. */
358#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
359/** CNAV-2 message contained in the structure. */
360#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
361
Tsuwei Chena90cf192014-10-23 12:49:12 -0700362/**
363 * Status of Navigation Message
364 * When a message is received properly without any parity error in its navigation words, the
365 * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received
366 * with words that failed parity check, but GPS is able to correct those words, the status
367 * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT.
368 * No need to send any navigation message that contains words with parity error and cannot be
369 * corrected.
370 */
371typedef uint16_t NavigationMessageStatus;
372#define NAV_MESSAGE_STATUS_UNKONW 0
373#define NAV_MESSAGE_STATUS_PARITY_PASSED (1<<0)
374#define NAV_MESSAGE_STATUS_PARITY_REBUILT (1<<1)
destradaa9f7c3732014-04-29 10:50:22 -0700375
376/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500377 * Name for the GPS XTRA interface.
378 */
379#define GPS_XTRA_INTERFACE "gps-xtra"
380
381/**
382 * Name for the GPS DEBUG interface.
383 */
384#define GPS_DEBUG_INTERFACE "gps-debug"
385
386/**
387 * Name for the AGPS interface.
388 */
389#define AGPS_INTERFACE "agps"
390
391/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700392 * Name of the Supl Certificate interface.
393 */
394#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
395
396/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500397 * Name for NI interface
398 */
399#define GPS_NI_INTERFACE "gps-ni"
400
Miguel Torroja5f404f52010-07-27 06:34:15 +0200401/**
402 * Name for the AGPS-RIL interface.
403 */
404#define AGPS_RIL_INTERFACE "agps_ril"
405
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800406/**
407 * Name for the GPS_Geofencing interface.
408 */
409#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
410
destradaa9f7c3732014-04-29 10:50:22 -0700411/**
412 * Name of the GPS Measurements interface.
413 */
414#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
415
416/**
417 * Name of the GPS navigation message interface.
418 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -0700419#define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
420
421/**
422 * Name of the GNSS/GPS configuration interface.
423 */
424#define GNSS_CONFIGURATION_INTERFACE "gnss_configuration"
destradaa9f7c3732014-04-29 10:50:22 -0700425
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800426
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500427/** Represents a location. */
428typedef struct {
429 /** set to sizeof(GpsLocation) */
430 size_t size;
431 /** Contains GpsLocationFlags bits. */
432 uint16_t flags;
433 /** Represents latitude in degrees. */
434 double latitude;
435 /** Represents longitude in degrees. */
436 double longitude;
437 /** Represents altitude in meters above the WGS 84 reference
438 * ellipsoid. */
439 double altitude;
440 /** Represents speed in meters per second. */
441 float speed;
442 /** Represents heading in degrees. */
443 float bearing;
444 /** Represents expected accuracy in meters. */
445 float accuracy;
446 /** Timestamp for the location fix. */
447 GpsUtcTime timestamp;
448} GpsLocation;
449
450/** Represents the status. */
451typedef struct {
452 /** set to sizeof(GpsStatus) */
453 size_t size;
454 GpsStatusValue status;
455} GpsStatus;
456
457/** Represents SV information. */
458typedef struct {
459 /** set to sizeof(GpsSvInfo) */
460 size_t size;
461 /** Pseudo-random number for the SV. */
462 int prn;
463 /** Signal to noise ratio. */
464 float snr;
465 /** Elevation of SV in degrees. */
466 float elevation;
467 /** Azimuth of SV in degrees. */
468 float azimuth;
469} GpsSvInfo;
470
471/** Represents SV status. */
472typedef struct {
473 /** set to sizeof(GpsSvStatus) */
474 size_t size;
475
476 /** Number of SVs currently visible. */
477 int num_svs;
478
479 /** Contains an array of SV information. */
480 GpsSvInfo sv_list[GPS_MAX_SVS];
481
482 /** Represents a bit mask indicating which SVs
483 * have ephemeris data.
484 */
485 uint32_t ephemeris_mask;
486
487 /** Represents a bit mask indicating which SVs
488 * have almanac data.
489 */
490 uint32_t almanac_mask;
491
492 /**
493 * Represents a bit mask indicating which SVs
494 * were used for computing the most recent position fix.
495 */
496 uint32_t used_in_fix_mask;
497} GpsSvStatus;
498
destradaa9f7c3732014-04-29 10:50:22 -0700499
Miguel Torroja5f404f52010-07-27 06:34:15 +0200500/* 2G and 3G */
501/* In 3G lac is discarded */
502typedef struct {
503 uint16_t type;
504 uint16_t mcc;
505 uint16_t mnc;
506 uint16_t lac;
507 uint32_t cid;
508} AGpsRefLocationCellID;
509
510typedef struct {
511 uint8_t mac[6];
512} AGpsRefLocationMac;
513
514/** Represents ref locations */
515typedef struct {
516 uint16_t type;
517 union {
518 AGpsRefLocationCellID cellID;
519 AGpsRefLocationMac mac;
520 } u;
521} AGpsRefLocation;
522
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700523/** Callback with location information.
524 * Can only be called from a thread created by create_thread_cb.
525 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500526typedef void (* gps_location_callback)(GpsLocation* location);
527
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700528/** Callback with status information.
529 * Can only be called from a thread created by create_thread_cb.
530 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500531typedef void (* gps_status_callback)(GpsStatus* status);
532
destradaa9f7c3732014-04-29 10:50:22 -0700533/**
534 * Callback with SV status information.
535 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700536 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500537typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
538
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700539/** Callback for reporting NMEA sentences.
540 * Can only be called from a thread created by create_thread_cb.
541 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500542typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
543
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400544/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700545 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
546 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400547typedef void (* gps_set_capabilities)(uint32_t capabilities);
548
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400549/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700550 * This can be used to prevent the CPU from suspending while handling GPS events.
551 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400552typedef void (* gps_acquire_wakelock)();
553
554/** Callback utility for releasing the GPS wakelock. */
555typedef void (* gps_release_wakelock)();
556
Mike Lockwood8aac5912011-06-29 15:10:36 -0400557/** Callback for requesting NTP time */
558typedef void (* gps_request_utc_time)();
559
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700560/** Callback for creating a thread that can call into the Java framework code.
561 * This must be used to create any threads that report events up to the framework.
562 */
563typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
564
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500565/** GPS callback structure. */
566typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400567 /** set to sizeof(GpsCallbacks) */
568 size_t size;
569 gps_location_callback location_cb;
570 gps_status_callback status_cb;
571 gps_sv_status_callback sv_status_cb;
572 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400573 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400574 gps_acquire_wakelock acquire_wakelock_cb;
575 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700576 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400577 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500578} GpsCallbacks;
579
580
581/** Represents the standard GPS interface. */
582typedef struct {
583 /** set to sizeof(GpsInterface) */
584 size_t size;
585 /**
586 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700587 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500588 */
589 int (*init)( GpsCallbacks* callbacks );
590
591 /** Starts navigating. */
592 int (*start)( void );
593
594 /** Stops navigating. */
595 int (*stop)( void );
596
597 /** Closes the interface. */
598 void (*cleanup)( void );
599
600 /** Injects the current time. */
601 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
602 int uncertainty);
603
604 /** Injects current location from another location provider
605 * (typically cell ID).
606 * latitude and longitude are measured in degrees
607 * expected accuracy is measured in meters
608 */
609 int (*inject_location)(double latitude, double longitude, float accuracy);
610
611 /**
612 * Specifies that the next call to start will not use the
613 * information defined in the flags. GPS_DELETE_ALL is passed for
614 * a cold start.
615 */
616 void (*delete_aiding_data)(GpsAidingData flags);
617
618 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400619 * min_interval represents the time between fixes in milliseconds.
620 * preferred_accuracy represents the requested fix accuracy in meters.
621 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500622 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400623 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
624 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500625
626 /** Get a pointer to extension information. */
627 const void* (*get_extension)(const char* name);
628} GpsInterface;
629
630/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700631 * The client should download XTRA data and inject it by calling inject_xtra_data().
632 * Can only be called from a thread created by create_thread_cb.
633 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500634typedef void (* gps_xtra_download_request)();
635
636/** Callback structure for the XTRA interface. */
637typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700638 gps_xtra_download_request download_request_cb;
639 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500640} GpsXtraCallbacks;
641
642/** Extended interface for XTRA support. */
643typedef struct {
644 /** set to sizeof(GpsXtraInterface) */
645 size_t size;
646 /**
647 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700648 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500649 */
650 int (*init)( GpsXtraCallbacks* callbacks );
651 /** Injects XTRA data into the GPS. */
652 int (*inject_xtra_data)( char* data, int length );
653} GpsXtraInterface;
654
655/** Extended interface for DEBUG support. */
656typedef struct {
657 /** set to sizeof(GpsDebugInterface) */
658 size_t size;
659
660 /**
661 * This function should return any information that the native
662 * implementation wishes to include in a bugreport.
663 */
664 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
665} GpsDebugInterface;
666
667/** Represents the status of AGPS. */
668typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700669 /** set to sizeof(AGpsStatus_v1) */
670 size_t size;
671
672 AGpsType type;
673 AGpsStatusValue status;
674} AGpsStatus_v1;
675
676/** Represents the status of AGPS augmented with a IPv4 address field. */
677typedef struct {
678 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500679 size_t size;
680
681 AGpsType type;
682 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800683 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700684} AGpsStatus_v2;
685
686/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
687typedef struct {
688 /** set to sizeof(AGpsStatus_v3) */
689 size_t size;
690
691 AGpsType type;
692 AGpsStatusValue status;
693
694 /**
695 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
696 * address, or set to INADDR_NONE otherwise.
697 */
698 uint32_t ipaddr;
699
700 /**
701 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
702 * Any other value of addr.ss_family will be rejected.
703 * */
704 struct sockaddr_storage addr;
705} AGpsStatus_v3;
706
707typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500708
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700709/** Callback with AGPS status information.
710 * Can only be called from a thread created by create_thread_cb.
711 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500712typedef void (* agps_status_callback)(AGpsStatus* status);
713
714/** Callback structure for the AGPS interface. */
715typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700716 agps_status_callback status_cb;
717 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500718} AGpsCallbacks;
719
720
721/** Extended interface for AGPS support. */
722typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700723 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500724 size_t size;
725
726 /**
727 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700728 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500729 */
730 void (*init)( AGpsCallbacks* callbacks );
731 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700732 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500733 * the name of the APN to be used for SUPL.
734 */
735 int (*data_conn_open)( const char* apn );
736 /**
737 * Notifies that the AGPS data connection has been closed.
738 */
739 int (*data_conn_closed)();
740 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700741 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500742 */
743 int (*data_conn_failed)();
744 /**
745 * Sets the hostname and port for the AGPS server.
746 */
747 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700748} AGpsInterface_v1;
749
750/**
751 * Extended interface for AGPS support, it is augmented to enable to pass
752 * extra APN data.
753 */
754typedef struct {
755 /** set to sizeof(AGpsInterface_v2) */
756 size_t size;
757
758 /**
759 * Opens the AGPS interface and provides the callback routines to the
760 * implementation of this interface.
761 */
762 void (*init)(AGpsCallbacks* callbacks);
763 /**
764 * Deprecated.
765 * If the HAL supports AGpsInterface_v2 this API will not be used, see
766 * data_conn_open_with_apn_ip_type for more information.
767 */
768 int (*data_conn_open)(const char* apn);
769 /**
770 * Notifies that the AGPS data connection has been closed.
771 */
772 int (*data_conn_closed)();
773 /**
774 * Notifies that a data connection is not available for AGPS.
775 */
776 int (*data_conn_failed)();
777 /**
778 * Sets the hostname and port for the AGPS server.
779 */
780 int (*set_server)(AGpsType type, const char* hostname, int port);
781
782 /**
783 * Notifies that a data connection is available and sets the name of the
784 * APN, and its IP type, to be used for SUPL connections.
785 */
786 int (*data_conn_open_with_apn_ip_type)(
787 const char* apn,
788 ApnIpType apnIpType);
789} AGpsInterface_v2;
790
791typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500792
destradaaa1f4c0a2013-09-13 15:45:03 -0700793/** Error codes associated with certificate operations */
794#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
795#define AGPS_CERTIFICATE_ERROR_GENERIC -100
796#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
797
798/** A data structure that represents an X.509 certificate using DER encoding */
799typedef struct {
800 size_t length;
801 u_char* data;
802} DerEncodedCertificate;
803
804/**
805 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
806 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
807 */
808typedef struct {
809 u_char data[20];
810} Sha1CertificateFingerprint;
811
destradaa9f7c3732014-04-29 10:50:22 -0700812/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700813typedef struct {
814 /** set to sizeof(SuplCertificateInterface) */
815 size_t size;
816
817 /**
818 * Installs a set of Certificates used for SUPL connections to the AGPS server.
819 * If needed the HAL should find out internally any certificates that need to be removed to
820 * accommodate the certificates to install.
821 * The certificates installed represent a full set of valid certificates needed to connect to
822 * AGPS SUPL servers.
823 * The list of certificates is required, and all must be available at the same time, when trying
824 * to establish a connection with the AGPS Server.
825 *
826 * Parameters:
827 * certificates - A pointer to an array of DER encoded certificates that are need to be
828 * installed in the HAL.
829 * length - The number of certificates to install.
830 * Returns:
831 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
832 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
833 * certificates attempted to be installed, the state of the certificates stored should
834 * remain the same as before on this error case.
835 *
836 * IMPORTANT:
837 * If needed the HAL should find out internally the set of certificates that need to be
838 * removed to accommodate the certificates to install.
839 */
840 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
841
842 /**
843 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
844 * expected that the given set of certificates is removed from the internal store of the HAL.
845 *
846 * Parameters:
847 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
848 * certificates to revoke.
849 * length - The number of fingerprints provided.
850 * Returns:
851 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
852 *
853 * IMPORTANT:
854 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
855 * it should be ignored and continue revoking/deleting the rest of them.
856 */
857 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800858} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500859
860/** Represents an NI request */
861typedef struct {
862 /** set to sizeof(GpsNiNotification) */
863 size_t size;
864
865 /**
866 * An ID generated by HAL to associate NI notifications and UI
867 * responses
868 */
869 int notification_id;
870
871 /**
872 * An NI type used to distinguish different categories of NI
873 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
874 */
875 GpsNiType ni_type;
876
877 /**
878 * Notification/verification options, combinations of GpsNiNotifyFlags constants
879 */
880 GpsNiNotifyFlags notify_flags;
881
882 /**
883 * Timeout period to wait for user response.
884 * Set to 0 for no time out limit.
885 */
886 int timeout;
887
888 /**
889 * Default response when time out.
890 */
891 GpsUserResponseType default_response;
892
893 /**
894 * Requestor ID
895 */
896 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
897
898 /**
899 * Notification message. It can also be used to store client_id in some cases
900 */
901 char text[GPS_NI_LONG_STRING_MAXLEN];
902
903 /**
904 * Client name decoding scheme
905 */
906 GpsNiEncodingType requestor_id_encoding;
907
908 /**
909 * Client name decoding scheme
910 */
911 GpsNiEncodingType text_encoding;
912
913 /**
914 * A pointer to extra data. Format:
915 * key_1 = value_1
916 * key_2 = value_2
917 */
918 char extras[GPS_NI_LONG_STRING_MAXLEN];
919
920} GpsNiNotification;
921
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700922/** Callback with NI notification.
923 * Can only be called from a thread created by create_thread_cb.
924 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500925typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
926
927/** GPS NI callback structure. */
928typedef struct
929{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700930 /**
931 * Sends the notification request from HAL to GPSLocationProvider.
932 */
933 gps_ni_notify_callback notify_cb;
934 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500935} GpsNiCallbacks;
936
937/**
938 * Extended interface for Network-initiated (NI) support.
939 */
940typedef struct
941{
942 /** set to sizeof(GpsNiInterface) */
943 size_t size;
944
945 /** Registers the callbacks for HAL to use. */
946 void (*init) (GpsNiCallbacks *callbacks);
947
948 /** Sends a response to HAL. */
949 void (*respond) (int notif_id, GpsUserResponseType user_response);
950} GpsNiInterface;
951
952struct gps_device_t {
953 struct hw_device_t common;
954
955 /**
956 * Set the provided lights to the provided values.
957 *
958 * Returns: 0 on succes, error code on failure.
959 */
960 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
961};
962
Miguel Torroja5f404f52010-07-27 06:34:15 +0200963#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
964#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
965
966#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
967#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
968
969typedef void (*agps_ril_request_set_id)(uint32_t flags);
970typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
971
972typedef struct {
973 agps_ril_request_set_id request_setid;
974 agps_ril_request_ref_loc request_refloc;
975 gps_create_thread create_thread_cb;
976} AGpsRilCallbacks;
977
978/** Extended interface for AGPS_RIL support. */
979typedef struct {
980 /** set to sizeof(AGpsRilInterface) */
981 size_t size;
982 /**
983 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700984 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +0200985 */
986 void (*init)( AGpsRilCallbacks* callbacks );
987
988 /**
989 * Sets the reference location.
990 */
991 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
992 /**
993 * Sets the set ID.
994 */
995 void (*set_set_id) (AGpsSetIDType type, const char* setid);
996
997 /**
998 * Send network initiated message.
999 */
1000 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -04001001
1002 /**
1003 * Notify GPS of network status changes.
1004 * These parameters match values in the android.net.NetworkInfo class.
1005 */
1006 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -07001007
1008 /**
1009 * Notify GPS of network status changes.
1010 * These parameters match values in the android.net.NetworkInfo class.
1011 */
1012 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +02001013} AGpsRilInterface;
1014
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001015/**
1016 * GPS Geofence.
1017 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1018 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1019 *
1020 * An example state diagram with confidence level: 95% and Unknown time limit
1021 * set as 30 secs is shown below. (confidence level and Unknown time limit are
1022 * explained latter)
1023 * ____________________________
1024 * | Unknown (30 secs) |
1025 * """"""""""""""""""""""""""""
1026 * ^ | | ^
1027 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
1028 * | v v |
1029 * ________ EXITED _________
1030 * | Inside | -----------> | Outside |
1031 * | | <----------- | |
1032 * """""""" ENTERED """""""""
1033 *
1034 * Inside state: We are 95% confident that the user is inside the geofence.
1035 * Outside state: We are 95% confident that the user is outside the geofence
1036 * Unknown state: Rest of the time.
1037 *
1038 * The Unknown state is better explained with an example:
1039 *
1040 * __________
1041 * | c|
1042 * | ___ | _______
1043 * | |a| | | b |
1044 * | """ | """""""
1045 * | |
1046 * """"""""""
1047 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1048 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1049 * confident that the user is outside. But with regard to "a" is not confident
1050 * whether it is inside or outside the geofence. If the accuracy remains the
1051 * same for a sufficient period of time, the UNCERTAIN transition would be
1052 * triggered with the state set to Unknown. If the accuracy improves later, an
1053 * appropriate transition should be triggered. This "sufficient period of time"
1054 * is defined by the parameter in the add_geofence_area API.
1055 * In other words, Unknown state can be interpreted as a state in which the
1056 * GPS subsystem isn't confident enough that the user is either inside or
1057 * outside the Geofence. It moves to Unknown state only after the expiry of the
1058 * timeout.
1059 *
1060 * The geofence callback needs to be triggered for the ENTERED and EXITED
1061 * transitions, when the GPS system is confident that the user has entered
1062 * (Inside state) or exited (Outside state) the Geofence. An implementation
1063 * which uses a value of 95% as the confidence is recommended. The callback
1064 * should be triggered only for the transitions requested by the
1065 * add_geofence_area call.
1066 *
1067 * Even though the diagram and explanation talks about states and transitions,
1068 * the callee is only interested in the transistions. The states are mentioned
1069 * here for illustrative purposes.
1070 *
1071 * Startup Scenario: When the device boots up, if an application adds geofences,
1072 * and then we get an accurate GPS location fix, it needs to trigger the
1073 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1074 * By default, all the Geofences will be in the Unknown state.
1075 *
1076 * When the GPS system is unavailable, gps_geofence_status_callback should be
1077 * called to inform the upper layers of the same. Similarly, when it becomes
1078 * available the callback should be called. This is a global state while the
1079 * UNKNOWN transition described above is per geofence.
1080 *
1081 * An important aspect to note is that users of this API (framework), will use
1082 * other subsystems like wifi, sensors, cell to handle Unknown case and
1083 * hopefully provide a definitive state transition to the third party
1084 * application. GPS Geofence will just be a signal indicating what the GPS
1085 * subsystem knows about the Geofence.
1086 *
1087 */
1088#define GPS_GEOFENCE_ENTERED (1<<0L)
1089#define GPS_GEOFENCE_EXITED (1<<1L)
1090#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1091
1092#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1093#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1094
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001095#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1096#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1097#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1098#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1099#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1100#define GPS_GEOFENCE_ERROR_GENERIC -149
1101
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001102/**
1103 * The callback associated with the geofence.
1104 * Parameters:
1105 * geofence_id - The id associated with the add_geofence_area.
1106 * location - The current GPS location.
1107 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1108 * GPS_GEOFENCE_UNCERTAIN.
1109 * timestamp - Timestamp when the transition was detected.
1110 *
1111 * The callback should only be called when the caller is interested in that
1112 * particular transition. For instance, if the caller is interested only in
1113 * ENTERED transition, then the callback should NOT be called with the EXITED
1114 * transition.
1115 *
1116 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1117 * subsystem will wake up the application processor, if its in suspend state.
1118 */
1119typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1120 int32_t transition, GpsUtcTime timestamp);
1121
1122/**
destradaa9f7c3732014-04-29 10:50:22 -07001123 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001124 * monitoring. If the GPS system determines that it cannot monitor geofences
1125 * because of lack of reliability or unavailability of the GPS signals, it will
1126 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1127 *
1128 * Parameters:
1129 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1130 * last_location - Last known location.
1131 */
1132typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1133
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001134/**
1135 * The callback associated with the add_geofence call.
1136 *
1137 * Parameter:
1138 * geofence_id - Id of the geofence.
1139 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1140 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1141 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1142 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1143 * invalid transition
1144 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1145 */
1146typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1147
1148/**
1149 * The callback associated with the remove_geofence call.
1150 *
1151 * Parameter:
1152 * geofence_id - Id of the geofence.
1153 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1154 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1155 * GPS_GEOFENCE_ERROR_GENERIC for others.
1156 */
1157typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1158
1159
1160/**
1161 * The callback associated with the pause_geofence call.
1162 *
1163 * Parameter:
1164 * geofence_id - Id of the geofence.
1165 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1166 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1167 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1168 * when monitor_transitions is invalid
1169 * GPS_GEOFENCE_ERROR_GENERIC for others.
1170 */
1171typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1172
1173/**
1174 * The callback associated with the resume_geofence call.
1175 *
1176 * Parameter:
1177 * geofence_id - Id of the geofence.
1178 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1179 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1180 * GPS_GEOFENCE_ERROR_GENERIC for others.
1181 */
1182typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1183
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001184typedef struct {
1185 gps_geofence_transition_callback geofence_transition_callback;
1186 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001187 gps_geofence_add_callback geofence_add_callback;
1188 gps_geofence_remove_callback geofence_remove_callback;
1189 gps_geofence_pause_callback geofence_pause_callback;
1190 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001191 gps_create_thread create_thread_cb;
1192} GpsGeofenceCallbacks;
1193
1194/** Extended interface for GPS_Geofencing support */
1195typedef struct {
1196 /** set to sizeof(GpsGeofencingInterface) */
1197 size_t size;
1198
1199 /**
1200 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001201 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001202 */
1203 void (*init)( GpsGeofenceCallbacks* callbacks );
1204
1205 /**
1206 * Add a geofence area. This api currently supports circular geofences.
1207 * Parameters:
1208 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001209 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1210 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001211 * latitude, longtitude, radius_meters - The lat, long and radius
1212 * (in meters) for the geofence
1213 * last_transition - The current state of the geofence. For example, if
1214 * the system already knows that the user is inside the geofence,
1215 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1216 * will be GPS_GEOFENCE_UNCERTAIN.
1217 * monitor_transition - Which transitions to monitor. Bitwise OR of
1218 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1219 * GPS_GEOFENCE_UNCERTAIN.
1220 * notification_responsiveness_ms - Defines the best-effort description
1221 * of how soon should the callback be called when the transition
1222 * associated with the Geofence is triggered. For instance, if set
1223 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1224 * should be called 1000 milliseconds within entering the geofence.
1225 * This parameter is defined in milliseconds.
1226 * NOTE: This is not to be confused with the rate that the GPS is
1227 * polled at. It is acceptable to dynamically vary the rate of
1228 * sampling the GPS for power-saving reasons; thus the rate of
1229 * sampling may be faster or slower than this.
1230 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001231 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001232 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001233 */
destradaa9f7c3732014-04-29 10:50:22 -07001234 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1235 double radius_meters, int last_transition, int monitor_transitions,
1236 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001237
1238 /**
1239 * Pause monitoring a particular geofence.
1240 * Parameters:
1241 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001242 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001243 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001244
1245 /**
1246 * Resume monitoring a particular geofence.
1247 * Parameters:
1248 * geofence_id - The id for the geofence.
1249 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1250 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1251 * GPS_GEOFENCE_UNCERTAIN.
1252 * This supersedes the value associated provided in the
1253 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001254 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001255 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001256
1257 /**
1258 * Remove a geofence area. After the function returns, no notifications
1259 * should be sent.
1260 * Parameter:
1261 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001262 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001263 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001264} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001265
1266
1267/**
1268 * Represents an estimate of the GPS clock time.
1269 */
1270typedef struct {
1271 /** set to sizeof(GpsClock) */
1272 size_t size;
1273
1274 /** A set of flags indicating the validity of the fields in this data structure. */
1275 GpsClockFlags flags;
1276
1277 /**
1278 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001279 * The sign of the value is defined by the following equation:
1280 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second * 1,000,000,000
1281 *
destradaa9f7c3732014-04-29 10:50:22 -07001282 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1283 */
1284 int16_t leap_second;
1285
1286 /**
destradaa75843eb2014-07-17 14:04:50 -07001287 * Indicates the type of time reported by the 'time_ns' field.
1288 * This is a Mandatory field.
1289 */
1290 GpsClockType type;
1291
1292 /**
1293 * The GPS receiver internal clock value. This can be either the local hardware clock value
1294 * (GPS_CLOCK_TYPE_LOCAL_HW_TIME), or the current GPS time derived inside GPS receiver
1295 * (GPS_CLOCK_TYPE_GPS_TIME). The field 'type' defines the time reported.
destradaa9f7c3732014-04-29 10:50:22 -07001296 *
destradaa75843eb2014-07-17 14:04:50 -07001297 * For local hardware clock, this value is expected to be monotonically increasing during
1298 * the reporting session. The real GPS time can be derived by compensating the 'full bias'
1299 * (when it is available) from this value.
destradaa9f7c3732014-04-29 10:50:22 -07001300 *
destradaa75843eb2014-07-17 14:04:50 -07001301 * For GPS time, this value is expected to be the best estimation of current GPS time that GPS
1302 * receiver can achieve. Set the 'time uncertainty' appropriately when GPS time is specified.
1303 *
1304 * Sub-nanosecond accuracy can be provided by means of the 'bias' field.
destradaa9f7c3732014-04-29 10:50:22 -07001305 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001306 *
destradaa9f7c3732014-04-29 10:50:22 -07001307 * This is a Mandatory field.
1308 */
1309 int64_t time_ns;
1310
1311 /**
1312 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1313 * The uncertainty is represented as an absolute (single sided) value.
1314 *
destradaa75843eb2014-07-17 14:04:50 -07001315 * This value should be set if GPS_CLOCK_TYPE_GPS_TIME is set.
destradaa9f7c3732014-04-29 10:50:22 -07001316 * If the data is available 'flags' must contain GPS_CLOCK_HAS_TIME_UNCERTAINTY.
1317 */
1318 double time_uncertainty_ns;
1319
1320 /**
destradaa75843eb2014-07-17 14:04:50 -07001321 * The difference between hardware clock ('time' field) inside GPS receiver and the true GPS
1322 * time since 0000Z, January 6, 1980, in nanoseconds.
1323 * This value is used if and only if GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, and GPS receiver
1324 * has solved the clock for GPS time.
1325 * The caller is responsible for using the 'bias uncertainty' field for quality check.
destradaa9f7c3732014-04-29 10:50:22 -07001326 *
destradaa75843eb2014-07-17 14:04:50 -07001327 * The sign of the value is defined by the following equation:
1328 * true time (GPS time) = time_ns + (full_bias_ns + bias_ns)
1329 *
1330 * This value contains the 'bias uncertainty' in it.
1331 * If the data is available 'flags' must contain GPS_CLOCK_HAS_FULL_BIAS.
1332
1333 */
1334 int64_t full_bias_ns;
1335
1336 /**
1337 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001338 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001339 *
destradaa9f7c3732014-04-29 10:50:22 -07001340 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS.
1341 */
1342 double bias_ns;
1343
1344 /**
1345 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1346 * The uncertainty is represented as an absolute (single sided) value.
1347 *
1348 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS_UNCERTAINTY.
1349 */
1350 double bias_uncertainty_ns;
1351
1352 /**
1353 * The clock's drift in nanoseconds (per second).
1354 * A positive value means that the frequency is higher than the nominal frequency.
1355 *
1356 * The value contains the 'drift uncertainty' in it.
1357 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
destradaa00caa892015-04-09 18:41:46 -07001358 *
1359 * If GpsMeasurement's 'flags' field contains GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE,
1360 * it is encouraged that this field is also provided.
destradaa9f7c3732014-04-29 10:50:22 -07001361 */
1362 double drift_nsps;
1363
1364 /**
1365 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1366 * The uncertainty is represented as an absolute (single sided) value.
1367 *
1368 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT_UNCERTAINTY.
1369 */
1370 double drift_uncertainty_nsps;
1371} GpsClock;
1372
1373/**
1374 * Represents a GPS Measurement, it contains raw and computed information.
1375 */
1376typedef struct {
1377 /** set to sizeof(GpsMeasurement) */
1378 size_t size;
1379
1380 /** A set of flags indicating the validity of the fields in this data structure. */
1381 GpsMeasurementFlags flags;
1382
1383 /**
1384 * Pseudo-random number in the range of [1, 32]
1385 * This is a Mandatory value.
1386 */
1387 int8_t prn;
1388
1389 /**
destradaa75843eb2014-07-17 14:04:50 -07001390 * Time offset at which the measurement was taken in nanoseconds.
1391 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1392 * interpreted in the same way as indicated by GpsClock::type.
1393 *
destradaa9f7c3732014-04-29 10:50:22 -07001394 * The sign of time_offset_ns is given by the following equation:
1395 * measurement time = GpsClock::time_ns + time_offset_ns
1396 *
1397 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1398 * This is a Mandatory value.
1399 */
destradaa75843eb2014-07-17 14:04:50 -07001400 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001401
1402 /**
destradaa75843eb2014-07-17 14:04:50 -07001403 * Per satellite sync state. It represents the current sync state for the associated satellite.
1404 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001405 *
1406 * This is a Mandatory value.
1407 */
destradaa75843eb2014-07-17 14:04:50 -07001408 GpsMeasurementState state;
1409
1410 /**
1411 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1412 * The value is relative to the beginning of the current GPS week.
1413 *
Tsuwei Chena90cf192014-10-23 12:49:12 -07001414 * Given the highest sync state that can be achieved, per each satellite, valid range for
1415 * this field can be:
1416 * Searching : [ 0 ] : GPS_MEASUREMENT_STATE_UNKNOWN
1417 * C/A code lock : [ 0 1ms ] : GPS_MEASUREMENT_STATE_CODE_LOCK is set
1418 * Bit sync : [ 0 20ms ] : GPS_MEASUREMENT_STATE_BIT_SYNC is set
1419 * Subframe sync : [ 0 6s ] : GPS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1420 * TOW decoded : [ 0 1week ] : GPS_MEASUREMENT_STATE_TOW_DECODED is set
1421 *
1422 * However, if there is any ambiguity in integer millisecond,
1423 * GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field.
destradaa00caa892015-04-09 18:41:46 -07001424 *
1425 * This value must be populated if 'state' != GPS_MEASUREMENT_STATE_UNKNOWN.
destradaa75843eb2014-07-17 14:04:50 -07001426 */
destradaa9f7c3732014-04-29 10:50:22 -07001427 int64_t received_gps_tow_ns;
1428
1429 /**
destradaa941c9282014-07-21 18:13:42 -07001430 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
destradaa00caa892015-04-09 18:41:46 -07001431 *
1432 * This value must be populated if 'state' != GPS_MEASUREMENT_STATE_UNKNOWN.
destradaa941c9282014-07-21 18:13:42 -07001433 */
1434 int64_t received_gps_tow_uncertainty_ns;
1435
1436 /**
destradaa9f7c3732014-04-29 10:50:22 -07001437 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1438 * It contains the measured C/N0 value for the signal at the antenna input.
1439 *
1440 * This is a Mandatory value.
1441 */
1442 double c_n0_dbhz;
1443
1444 /**
1445 * Pseudorange rate at the timestamp in m/s.
destradaa00caa892015-04-09 18:41:46 -07001446 * The effects of the receiver clock frequency and satellite clock frequency errors, are known
1447 * as the correction of a given Pseudorange rate value.
1448 *
1449 * If GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE is set in 'flags' field, this field must
1450 * be populated with the 'uncorrected' reading.
1451 * If GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE is not set in 'flags' field, this field
1452 * must be populated with the 'corrected' reading. This is the default behavior.
1453 *
1454 * It is encouraged to provide the 'uncorrected' 'pseudorange rate', and provide GpsClock's
1455 * 'drift' field as well.
destradaa9f7c3732014-04-29 10:50:22 -07001456 *
1457 * The value includes the 'pseudorange rate uncertainty' in it.
destradaa00caa892015-04-09 18:41:46 -07001458 * A positive 'uncorrected' value indicates that the SV is moving away from the receiver.
1459 *
1460 * The sign of the 'uncorrected' 'pseudorange rate' and its correlation to the sign of 'doppler
1461 * shift' is given by the equation:
1462 * pseudorange rate = -k * doppler shift
destradaa9f7c3732014-04-29 10:50:22 -07001463 *
1464 * This is a Mandatory value.
1465 */
destradaa75843eb2014-07-17 14:04:50 -07001466 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001467
1468 /**
1469 * 1-Sigma uncertainty of the pseudurange rate in m/s.
1470 * The uncertainty is represented as an absolute (single sided) value.
1471 *
1472 * This is a Mandatory value.
1473 */
destradaa75843eb2014-07-17 14:04:50 -07001474 double pseudorange_rate_uncertainty_mps;
1475
1476 /**
1477 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1478 * (indicating loss of lock).
1479 *
1480 * This is a Mandatory value.
1481 */
1482 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001483
1484 /**
1485 * Accumulated delta range since the last channel reset in meters.
destradaa00caa892015-04-09 18:41:46 -07001486 * A positive value indicates that the SV is moving away fro the receiver.
1487 *
1488 * The sign of the 'accumulated delta range' and its correlation to the sign of 'carrier phase'
1489 * is given by the equation:
1490 * accumulated delta range = -k * carrier phase
1491 *
1492 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
1493 * However, it is expected that the data is only accurate when:
1494 * 'accumulated delta range state' == GPS_ADR_STATE_VALID.
destradaa9f7c3732014-04-29 10:50:22 -07001495 */
1496 double accumulated_delta_range_m;
1497
1498 /**
1499 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa00caa892015-04-09 18:41:46 -07001500 * This value must be populated if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001501 */
1502 double accumulated_delta_range_uncertainty_m;
1503
1504 /**
1505 * Best derived Pseudorange by the chip-set, in meters.
1506 * The value contains the 'pseudorange uncertainty' in it.
1507 *
1508 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1509 */
1510 double pseudorange_m;
1511
1512 /**
1513 * 1-Sigma uncertainty of the pseudorange in meters.
1514 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1515 * The uncertainty is represented as an absolute (single sided) value.
1516 *
1517 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1518 */
1519 double pseudorange_uncertainty_m;
1520
1521 /**
1522 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1523 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1524 *
1525 * The reference frequency is given by the field 'carrier_frequency_hz'.
1526 * The value contains the 'code-phase uncertainty' in it.
1527 *
1528 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1529 */
1530 double code_phase_chips;
1531
1532 /**
1533 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1534 * The uncertainty is represented as an absolute (single sided) value.
1535 *
1536 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1537 */
1538 double code_phase_uncertainty_chips;
1539
1540 /**
1541 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1542 * If the field is not set, the carrier frequency is assumed to be L1.
1543 *
1544 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1545 */
1546 float carrier_frequency_hz;
1547
1548 /**
1549 * The number of full carrier cycles between the satellite and the receiver.
1550 * The reference frequency is given by the field 'carrier_frequency_hz'.
1551 *
1552 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1553 */
1554 int64_t carrier_cycles;
1555
1556 /**
1557 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1558 * This is usually the fractional part of the complete carrier phase measurement.
1559 *
1560 * The reference frequency is given by the field 'carrier_frequency_hz'.
1561 * The value contains the 'carrier-phase uncertainty' in it.
1562 *
1563 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1564 */
1565 double carrier_phase;
1566
1567 /**
1568 * 1-Sigma uncertainty of the carrier-phase.
1569 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1570 */
1571 double carrier_phase_uncertainty;
1572
1573 /**
1574 * An enumeration that indicates the 'loss of lock' state of the event.
1575 */
1576 GpsLossOfLock loss_of_lock;
1577
1578 /**
1579 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1580 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1581 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001582 int32_t bit_number;
destradaa9f7c3732014-04-29 10:50:22 -07001583
1584 /**
destradaa75843eb2014-07-17 14:04:50 -07001585 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
destradaa9f7c3732014-04-29 10:50:22 -07001586 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1587 */
destradaa75843eb2014-07-17 14:04:50 -07001588 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001589
1590 /**
1591 * Doppler shift in Hz.
1592 * A positive value indicates that the SV is moving toward the receiver.
1593 *
1594 * The reference frequency is given by the field 'carrier_frequency_hz'.
1595 * The value contains the 'doppler shift uncertainty' in it.
1596 *
1597 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1598 */
1599 double doppler_shift_hz;
1600
1601 /**
1602 * 1-Sigma uncertainty of the doppler shift in Hz.
1603 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1604 */
1605 double doppler_shift_uncertainty_hz;
1606
1607 /**
1608 * An enumeration that indicates the 'multipath' state of the event.
1609 */
1610 GpsMultipathIndicator multipath_indicator;
1611
1612 /**
1613 * Signal-to-noise ratio in dB.
1614 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1615 */
1616 double snr_db;
1617
1618 /**
1619 * Elevation in degrees, the valid range is [-90, 90].
1620 * The value contains the 'elevation uncertainty' in it.
1621 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1622 */
1623 double elevation_deg;
1624
1625 /**
1626 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1627 * The uncertainty is represented as the absolute (single sided) value.
1628 *
1629 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1630 */
1631 double elevation_uncertainty_deg;
1632
1633 /**
1634 * Azimuth in degrees, in the range [0, 360).
1635 * The value contains the 'azimuth uncertainty' in it.
1636 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
1637 * */
1638 double azimuth_deg;
1639
1640 /**
1641 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1642 * The uncertainty is represented as an absolute (single sided) value.
1643 *
1644 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1645 */
1646 double azimuth_uncertainty_deg;
1647
1648 /**
1649 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1650 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1651 */
1652 bool used_in_fix;
1653} GpsMeasurement;
1654
1655/** Represents a reading of GPS measurements. */
1656typedef struct {
1657 /** set to sizeof(GpsData) */
1658 size_t size;
1659
1660 /** Number of measurements. */
1661 size_t measurement_count;
1662
1663 /** The array of measurements. */
1664 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1665
1666 /** The GPS clock time reading. */
1667 GpsClock clock;
1668} GpsData;
1669
1670/**
1671 * The callback for to report measurements from the HAL.
1672 *
1673 * Parameters:
1674 * data - A data structure containing the measurements.
1675 */
1676typedef void (*gps_measurement_callback) (GpsData* data);
1677
1678typedef struct {
1679 /** set to sizeof(GpsMeasurementCallbacks) */
1680 size_t size;
1681 gps_measurement_callback measurement_callback;
1682} GpsMeasurementCallbacks;
1683
1684#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1685#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1686#define GPS_MEASUREMENT_ERROR_GENERIC -101
1687
1688/**
1689 * Extended interface for GPS Measurements support.
1690 */
1691typedef struct {
1692 /** Set to sizeof(GpsMeasurementInterface) */
1693 size_t size;
1694
1695 /**
1696 * Initializes the interface and registers the callback routines with the HAL.
1697 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1698 *
1699 * Status:
1700 * GPS_MEASUREMENT_OPERATION_SUCCESS
1701 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1702 * corresponding call to 'close'
1703 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1704 * will not generate any updates upon returning this error code.
1705 */
1706 int (*init) (GpsMeasurementCallbacks* callbacks);
1707
1708 /**
1709 * Stops updates from the HAL, and unregisters the callback routines.
1710 * After a call to stop, the previously registered callbacks must be considered invalid by the
1711 * HAL.
1712 * If stop is invoked without a previous 'init', this function should perform no work.
1713 */
1714 void (*close) ();
1715
1716} GpsMeasurementInterface;
1717
1718
1719/** Represents a GPS navigation message (or a fragment of it). */
1720typedef struct {
1721 /** set to sizeof(GpsNavigationMessage) */
1722 size_t size;
1723
1724 /**
1725 * Pseudo-random number in the range of [1, 32]
1726 * This is a Mandatory value.
1727 */
1728 int8_t prn;
1729
1730 /**
1731 * The type of message contained in the structure.
1732 * This is a Mandatory value.
1733 */
1734 GpsNavigationMessageType type;
1735
1736 /**
Tsuwei Chena90cf192014-10-23 12:49:12 -07001737 * The status of the received navigation message.
1738 * No need to send any navigation message that contains words with parity error and cannot be
1739 * corrected.
1740 */
1741 NavigationMessageStatus status;
1742
1743 /**
destradaa9f7c3732014-04-29 10:50:22 -07001744 * Message identifier.
destradaa75843eb2014-07-17 14:04:50 -07001745 * It provides an index so the complete Navigation Message can be assembled. i.e. fo L1 C/A
1746 * subframe 4 and 5, this value corresponds to the 'frame id' of the navigation message.
1747 * Subframe 1, 2, 3 does not contain a 'frame id' and this value can be set to -1.
destradaa9f7c3732014-04-29 10:50:22 -07001748 */
1749 int16_t message_id;
1750
1751 /**
1752 * Sub-message identifier.
1753 * If required by the message 'type', this value contains a sub-index within the current
1754 * message (or frame) that is being transmitted.
1755 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1756 */
1757 int16_t submessage_id;
1758
1759 /**
1760 * The length of the data (in bytes) contained in the current message.
1761 * If this value is different from zero, 'data' must point to an array of the same size.
destradaa69d5ea52014-07-31 16:34:09 -07001762 * 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 -07001763 *
1764 * This is a Mandatory value.
1765 */
1766 size_t data_length;
1767
1768 /**
1769 * The data of the reported GPS message.
1770 * The bytes (or words) specified using big endian format (MSB first).
destradaa69d5ea52014-07-31 16:34:09 -07001771 *
1772 * For L1 C/A, each subframe contains 10 30-bit GPS words. Each GPS word (30 bits) should be
1773 * fitted into the last 30 bits in a 4-byte word (skip B31 and B32), with MSB first.
destradaa9f7c3732014-04-29 10:50:22 -07001774 */
1775 uint8_t* data;
1776
1777} GpsNavigationMessage;
1778
1779/**
1780 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1781 *
1782 * Parameters:
1783 * message - The GPS navigation submessage/subframe representation.
1784 */
1785typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1786
1787typedef struct {
1788 /** set to sizeof(GpsNavigationMessageCallbacks) */
1789 size_t size;
1790 gps_navigation_message_callback navigation_message_callback;
1791} GpsNavigationMessageCallbacks;
1792
1793#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
1794#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
1795#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
1796
1797/**
1798 * Extended interface for GPS navigation message reporting support.
1799 */
1800typedef struct {
1801 /** Set to sizeof(GpsNavigationMessageInterface) */
1802 size_t size;
1803
1804 /**
1805 * Initializes the interface and registers the callback routines with the HAL.
1806 * After a successful call to 'init' the HAL must begin to provide updates as they become
1807 * available.
1808 *
1809 * Status:
1810 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
1811 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
1812 * without a corresponding call to 'close'.
1813 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
1814 * the HAL will not generate any updates upon returning this error code.
1815 */
1816 int (*init) (GpsNavigationMessageCallbacks* callbacks);
1817
1818 /**
1819 * Stops updates from the HAL, and unregisters the callback routines.
1820 * After a call to stop, the previously registered callbacks must be considered invalid by the
1821 * HAL.
1822 * If stop is invoked without a previous 'init', this function should perform no work.
1823 */
1824 void (*close) ();
1825
1826} GpsNavigationMessageInterface;
1827
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001828/**
1829 * Interface for passing GNSS configuration contents from platform to HAL.
1830 */
1831typedef struct {
1832 /** Set to sizeof(GnssConfigurationInterface) */
1833 size_t size;
1834
1835 /**
1836 * Deliver GNSS configuration contents to HAL.
1837 * Parameters:
1838 * config_data - a pointer to a char array which holds what usually is expected from
1839 file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
1840 * length - total number of UTF8 characters in configuraiton data.
1841 *
1842 * IMPORTANT:
1843 * GPS HAL should expect this function can be called multiple times. And it may be
1844 * called even when GpsLocationProvider is already constructed and enabled. GPS HAL
1845 * should maintain the existing requests for various callback regardless the change
1846 * in configuration data.
1847 */
1848 void (*configuration_update) (const char* config_data, int32_t length);
1849} GnssConfigurationInterface;
1850
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001851__END_DECLS
1852
1853#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1854