blob: fb1f66923dbd2352000cebae27eeb42b8b892474 [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(). */
Dante Russo9c8ea822014-04-10 10:59:01 -0700120typedef uint32_t GpsAidingData;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500121// IMPORTANT: Note that the following values must match
122// constants in GpsLocationProvider.java.
Dante Russo9c8ea822014-04-10 10:59:01 -0700123#define GPS_DELETE_EPHEMERIS 0x00000001
124#define GPS_DELETE_ALMANAC 0x00000002
125#define GPS_DELETE_POSITION 0x00000004
126#define GPS_DELETE_TIME 0x00000008
127#define GPS_DELETE_IONO 0x00000010
128#define GPS_DELETE_UTC 0x00000020
129#define GPS_DELETE_HEALTH 0x00000040
130#define GPS_DELETE_SVDIR 0x00000080
131#define GPS_DELETE_SVSTEER 0x00000100
132#define GPS_DELETE_SADATA 0x00000200
133#define GPS_DELETE_RTI 0x00000400
134#define GPS_DELETE_CELLDB_INFO 0x00000800
135#define GPS_DELETE_ALMANAC_CORR 0x00001000
136#define GPS_DELETE_FREQ_BIAS_EST 0x00002000
137#define GLO_DELETE_EPHEMERIS 0x00004000
138#define GLO_DELETE_ALMANAC 0x00008000
139#define GLO_DELETE_SVDIR 0x00010000
140#define GLO_DELETE_SVSTEER 0x00020000
141#define GLO_DELETE_ALMANAC_CORR 0x00040000
142#define GPS_DELETE_TIME_GPS 0x00080000
143#define GLO_DELETE_TIME 0x00100000
144#define BDS_DELETE_SVDIR 0X00200000
145#define BDS_DELETE_SVSTEER 0X00400000
146#define BDS_DELETE_TIME 0X00800000
147#define BDS_DELETE_ALMANAC_CORR 0X01000000
148#define BDS_DELETE_EPHEMERIS 0X02000000
149#define BDS_DELETE_ALMANAC 0X04000000
150
151#define GPS_DELETE_ALL 0xFFFFFFFF
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500152
153/** AGPS type */
154typedef uint16_t AGpsType;
155#define AGPS_TYPE_SUPL 1
156#define AGPS_TYPE_C2K 2
157
Miguel Torroja5f404f52010-07-27 06:34:15 +0200158typedef uint16_t AGpsSetIDType;
159#define AGPS_SETID_TYPE_NONE 0
160#define AGPS_SETID_TYPE_IMSI 1
161#define AGPS_SETID_TYPE_MSISDN 2
162
destradaaf48cc672014-06-05 11:07:09 -0700163typedef uint16_t ApnIpType;
164#define APN_IP_INVALID 0
165#define APN_IP_IPV4 1
166#define APN_IP_IPV6 2
167#define APN_IP_IPV4V6 3
168
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500169/**
170 * String length constants
171 */
172#define GPS_NI_SHORT_STRING_MAXLEN 256
173#define GPS_NI_LONG_STRING_MAXLEN 2048
174
175/**
176 * GpsNiType constants
177 */
178typedef uint32_t GpsNiType;
179#define GPS_NI_TYPE_VOICE 1
180#define GPS_NI_TYPE_UMTS_SUPL 2
181#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
182
183/**
184 * GpsNiNotifyFlags constants
185 */
186typedef uint32_t GpsNiNotifyFlags;
187/** NI requires notification */
188#define GPS_NI_NEED_NOTIFY 0x0001
189/** NI requires verification */
190#define GPS_NI_NEED_VERIFY 0x0002
191/** NI requires privacy override, no notification/minimal trace */
192#define GPS_NI_PRIVACY_OVERRIDE 0x0004
193
194/**
195 * GPS NI responses, used to define the response in
196 * NI structures
197 */
198typedef int GpsUserResponseType;
199#define GPS_NI_RESPONSE_ACCEPT 1
200#define GPS_NI_RESPONSE_DENY 2
201#define GPS_NI_RESPONSE_NORESP 3
202
203/**
204 * NI data encoding scheme
205 */
206typedef int GpsNiEncodingType;
207#define GPS_ENC_NONE 0
208#define GPS_ENC_SUPL_GSM_DEFAULT 1
209#define GPS_ENC_SUPL_UTF8 2
210#define GPS_ENC_SUPL_UCS2 3
211#define GPS_ENC_UNKNOWN -1
212
213/** AGPS status event values. */
214typedef uint16_t AGpsStatusValue;
215/** GPS requests data connection for AGPS. */
216#define GPS_REQUEST_AGPS_DATA_CONN 1
217/** GPS releases the AGPS data connection. */
218#define GPS_RELEASE_AGPS_DATA_CONN 2
219/** AGPS data connection initiated */
220#define GPS_AGPS_DATA_CONNECTED 3
221/** AGPS data connection completed */
222#define GPS_AGPS_DATA_CONN_DONE 4
223/** AGPS data connection failed */
224#define GPS_AGPS_DATA_CONN_FAILED 5
225
Miguel Torroja5f404f52010-07-27 06:34:15 +0200226#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
227#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
228#define AGPS_REG_LOCATION_TYPE_MAC 3
229
Mike Lockwood455e83b2010-10-11 06:16:57 -0400230/** Network types for update_network_state "type" parameter */
231#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
232#define AGPS_RIL_NETWORK_TYPE_WIFI 1
233#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
234#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
235#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
236#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
237#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
238
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500239/**
destradaa9f7c3732014-04-29 10:50:22 -0700240 * Flags to indicate what fields in GpsClock are valid.
241 */
242typedef uint16_t GpsClockFlags;
243/** A valid 'leap second' is stored in the data structure. */
244#define GPS_CLOCK_HAS_LEAP_SECOND (1<<0)
245/** A valid 'time uncertainty' is stored in the data structure. */
246#define GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
destradaa75843eb2014-07-17 14:04:50 -0700247/** A valid 'full bias' is stored in the data structure. */
248#define GPS_CLOCK_HAS_FULL_BIAS (1<<2)
destradaa9f7c3732014-04-29 10:50:22 -0700249/** A valid 'bias' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700250#define GPS_CLOCK_HAS_BIAS (1<<3)
destradaa9f7c3732014-04-29 10:50:22 -0700251/** A valid 'bias uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700252#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
destradaa9f7c3732014-04-29 10:50:22 -0700253/** A valid 'drift' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700254#define GPS_CLOCK_HAS_DRIFT (1<<5)
destradaa9f7c3732014-04-29 10:50:22 -0700255/** A valid 'drift uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700256#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
257
258/**
259 * Enumeration of the available values for the GPS Clock type.
260 */
261typedef uint8_t GpsClockType;
262/** The type is not available ot it is unknown. */
263#define GPS_CLOCK_TYPE_UNKNOWN 0
264/** The source of the time value reported by GPS clock is the local hardware clock. */
265#define GPS_CLOCK_TYPE_LOCAL_HW_TIME 1
266/**
267 * The source of the time value reported by GPS clock is the GPS time derived from satellites
268 * (epoch = Jan 6, 1980)
269 */
270#define GPS_CLOCK_TYPE_GPS_TIME 2
destradaa9f7c3732014-04-29 10:50:22 -0700271
272/**
273 * Flags to indicate what fields in GpsMeasurement are valid.
274 */
275typedef uint32_t GpsMeasurementFlags;
276/** A valid 'snr' is stored in the data structure. */
277#define GPS_MEASUREMENT_HAS_SNR (1<<0)
278/** A valid 'elevation' is stored in the data structure. */
279#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
280/** A valid 'elevation uncertainty' is stored in the data structure. */
281#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
282/** A valid 'azimuth' is stored in the data structure. */
283#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
284/** A valid 'azimuth uncertainty' is stored in the data structure. */
285#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
286/** A valid 'pseudorange' is stored in the data structure. */
287#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
288/** A valid 'pseudorange uncertainty' is stored in the data structure. */
289#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
290/** A valid 'code phase' is stored in the data structure. */
291#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
292/** A valid 'code phase uncertainty' is stored in the data structure. */
293#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
294/** A valid 'carrier frequency' is stored in the data structure. */
295#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
296/** A valid 'carrier cycles' is stored in the data structure. */
297#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
298/** A valid 'carrier phase' is stored in the data structure. */
299#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
300/** A valid 'carrier phase uncertainty' is stored in the data structure. */
301#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
302/** A valid 'bit number' is stored in the data structure. */
303#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
304/** A valid 'time from last bit' is stored in the data structure. */
305#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
306/** A valid 'doppler shift' is stored in the data structure. */
307#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
308/** A valid 'doppler shift uncertainty' is stored in the data structure. */
309#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
310/** A valid 'used in fix' flag is stored in the data structure. */
311#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
312
313/**
destradaa75843eb2014-07-17 14:04:50 -0700314 * Enumeration of the available values for the GPS Measurement's loss of lock.
destradaa9f7c3732014-04-29 10:50:22 -0700315 */
316typedef uint8_t GpsLossOfLock;
317/** The indicator is not available or it is unknown. */
318#define GPS_LOSS_OF_LOCK_UNKNOWN 0
319/** The measurement does not present any indication of loss of lock. */
320#define GPS_LOSS_OF_LOCK_OK 1
321/** Loss of lock between previous and current observation: cycle slip possible. */
322#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
323
324/**
destradaa75843eb2014-07-17 14:04:50 -0700325 * Enumeration of available values for the GPS Measurement's multipath indicator.
destradaa9f7c3732014-04-29 10:50:22 -0700326 */
327typedef uint8_t GpsMultipathIndicator;
328/** The indicator is not available or unknown. */
329#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
330/** The measurement has been indicated to use multipath. */
331#define GPS_MULTIPATH_INDICATOR_DETECTED 1
332/** The measurement has been indicated Not to use multipath. */
333#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
334
335/**
destradaa75843eb2014-07-17 14:04:50 -0700336 * Flags indicating the GPS measurement state.
Tsuwei Chena90cf192014-10-23 12:49:12 -0700337 * The expected behavior here is for GPS HAL to set all the flags that applies. For
338 * example, if the state for a satellite is only C/A code locked and bit synchronized,
339 * and there is still millisecond ambiguity, the state should be set as:
340 * GPS_MEASUREMENT_STATE_CODE_LOCK|GPS_MEASUREMENT_STATE_BIT_SYNC|GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS
341 * If GPS is still searching for a satellite, the corresponding state should be set to
342 * GPS_MEASUREMENT_STATE_UNKNOWN(0).
destradaa75843eb2014-07-17 14:04:50 -0700343 */
344typedef uint16_t GpsMeasurementState;
345#define GPS_MEASUREMENT_STATE_UNKNOWN 0
346#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
347#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
348#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
349#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
Tsuwei Chena90cf192014-10-23 12:49:12 -0700350#define GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4)
destradaa75843eb2014-07-17 14:04:50 -0700351
352/**
353 * Flags indicating the Accumulated Delta Range's states.
354 */
355typedef uint16_t GpsAccumulatedDeltaRangeState;
356#define GPS_ADR_STATE_UNKNOWN 0
357#define GPS_ADR_STATE_VALID (1<<0)
358#define GPS_ADR_STATE_RESET (1<<1)
359#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
360
361/**
Tsuwei Chena90cf192014-10-23 12:49:12 -0700362 * Enumeration of available values to indicate the available GPS Navigation message types.
destradaa9f7c3732014-04-29 10:50:22 -0700363 */
364typedef uint8_t GpsNavigationMessageType;
365/** The message type is unknown. */
366#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
367/** L1 C/A message contained in the structure. */
368#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
369/** L2-CNAV message contained in the structure. */
370#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
371/** L5-CNAV message contained in the structure. */
372#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
373/** CNAV-2 message contained in the structure. */
374#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
375
Tsuwei Chena90cf192014-10-23 12:49:12 -0700376/**
377 * Status of Navigation Message
378 * When a message is received properly without any parity error in its navigation words, the
379 * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received
380 * with words that failed parity check, but GPS is able to correct those words, the status
381 * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT.
382 * No need to send any navigation message that contains words with parity error and cannot be
383 * corrected.
384 */
385typedef uint16_t NavigationMessageStatus;
386#define NAV_MESSAGE_STATUS_UNKONW 0
387#define NAV_MESSAGE_STATUS_PARITY_PASSED (1<<0)
388#define NAV_MESSAGE_STATUS_PARITY_REBUILT (1<<1)
destradaa9f7c3732014-04-29 10:50:22 -0700389
390/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500391 * Name for the GPS XTRA interface.
392 */
393#define GPS_XTRA_INTERFACE "gps-xtra"
394
395/**
396 * Name for the GPS DEBUG interface.
397 */
398#define GPS_DEBUG_INTERFACE "gps-debug"
399
400/**
401 * Name for the AGPS interface.
402 */
403#define AGPS_INTERFACE "agps"
404
405/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700406 * Name of the Supl Certificate interface.
407 */
408#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
409
410/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500411 * Name for NI interface
412 */
413#define GPS_NI_INTERFACE "gps-ni"
414
Miguel Torroja5f404f52010-07-27 06:34:15 +0200415/**
416 * Name for the AGPS-RIL interface.
417 */
418#define AGPS_RIL_INTERFACE "agps_ril"
419
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800420/**
421 * Name for the GPS_Geofencing interface.
422 */
423#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
424
destradaa9f7c3732014-04-29 10:50:22 -0700425/**
426 * Name of the GPS Measurements interface.
427 */
428#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
429
430/**
431 * Name of the GPS navigation message interface.
432 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -0700433#define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
434
435/**
436 * Name of the GNSS/GPS configuration interface.
437 */
438#define GNSS_CONFIGURATION_INTERFACE "gnss_configuration"
destradaa9f7c3732014-04-29 10:50:22 -0700439
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800440
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500441/** Represents a location. */
442typedef struct {
443 /** set to sizeof(GpsLocation) */
444 size_t size;
445 /** Contains GpsLocationFlags bits. */
446 uint16_t flags;
447 /** Represents latitude in degrees. */
448 double latitude;
449 /** Represents longitude in degrees. */
450 double longitude;
451 /** Represents altitude in meters above the WGS 84 reference
452 * ellipsoid. */
453 double altitude;
454 /** Represents speed in meters per second. */
455 float speed;
456 /** Represents heading in degrees. */
457 float bearing;
458 /** Represents expected accuracy in meters. */
459 float accuracy;
460 /** Timestamp for the location fix. */
461 GpsUtcTime timestamp;
462} GpsLocation;
463
464/** Represents the status. */
465typedef struct {
466 /** set to sizeof(GpsStatus) */
467 size_t size;
468 GpsStatusValue status;
469} GpsStatus;
470
471/** Represents SV information. */
472typedef struct {
473 /** set to sizeof(GpsSvInfo) */
474 size_t size;
475 /** Pseudo-random number for the SV. */
476 int prn;
477 /** Signal to noise ratio. */
478 float snr;
479 /** Elevation of SV in degrees. */
480 float elevation;
481 /** Azimuth of SV in degrees. */
482 float azimuth;
483} GpsSvInfo;
484
485/** Represents SV status. */
486typedef struct {
487 /** set to sizeof(GpsSvStatus) */
488 size_t size;
489
490 /** Number of SVs currently visible. */
491 int num_svs;
492
493 /** Contains an array of SV information. */
494 GpsSvInfo sv_list[GPS_MAX_SVS];
495
496 /** Represents a bit mask indicating which SVs
497 * have ephemeris data.
498 */
499 uint32_t ephemeris_mask;
500
501 /** Represents a bit mask indicating which SVs
502 * have almanac data.
503 */
504 uint32_t almanac_mask;
505
506 /**
507 * Represents a bit mask indicating which SVs
508 * were used for computing the most recent position fix.
509 */
510 uint32_t used_in_fix_mask;
511} GpsSvStatus;
512
destradaa9f7c3732014-04-29 10:50:22 -0700513
Miguel Torroja5f404f52010-07-27 06:34:15 +0200514/* 2G and 3G */
515/* In 3G lac is discarded */
516typedef struct {
517 uint16_t type;
518 uint16_t mcc;
519 uint16_t mnc;
520 uint16_t lac;
521 uint32_t cid;
522} AGpsRefLocationCellID;
523
524typedef struct {
525 uint8_t mac[6];
526} AGpsRefLocationMac;
527
528/** Represents ref locations */
529typedef struct {
530 uint16_t type;
531 union {
532 AGpsRefLocationCellID cellID;
533 AGpsRefLocationMac mac;
534 } u;
535} AGpsRefLocation;
536
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700537/** Callback with location information.
538 * Can only be called from a thread created by create_thread_cb.
539 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500540typedef void (* gps_location_callback)(GpsLocation* location);
541
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700542/** Callback with status information.
543 * Can only be called from a thread created by create_thread_cb.
544 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500545typedef void (* gps_status_callback)(GpsStatus* status);
546
destradaa9f7c3732014-04-29 10:50:22 -0700547/**
548 * Callback with SV status information.
549 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700550 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500551typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
552
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700553/** Callback for reporting NMEA sentences.
554 * Can only be called from a thread created by create_thread_cb.
555 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500556typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
557
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400558/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700559 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
560 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400561typedef void (* gps_set_capabilities)(uint32_t capabilities);
562
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400563/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700564 * This can be used to prevent the CPU from suspending while handling GPS events.
565 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400566typedef void (* gps_acquire_wakelock)();
567
568/** Callback utility for releasing the GPS wakelock. */
569typedef void (* gps_release_wakelock)();
570
Mike Lockwood8aac5912011-06-29 15:10:36 -0400571/** Callback for requesting NTP time */
572typedef void (* gps_request_utc_time)();
573
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700574/** Callback for creating a thread that can call into the Java framework code.
575 * This must be used to create any threads that report events up to the framework.
576 */
577typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
578
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500579/** GPS callback structure. */
580typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400581 /** set to sizeof(GpsCallbacks) */
582 size_t size;
583 gps_location_callback location_cb;
584 gps_status_callback status_cb;
585 gps_sv_status_callback sv_status_cb;
586 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400587 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400588 gps_acquire_wakelock acquire_wakelock_cb;
589 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700590 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400591 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500592} GpsCallbacks;
593
594
595/** Represents the standard GPS interface. */
596typedef struct {
597 /** set to sizeof(GpsInterface) */
598 size_t size;
599 /**
600 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700601 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500602 */
603 int (*init)( GpsCallbacks* callbacks );
604
605 /** Starts navigating. */
606 int (*start)( void );
607
608 /** Stops navigating. */
609 int (*stop)( void );
610
611 /** Closes the interface. */
612 void (*cleanup)( void );
613
614 /** Injects the current time. */
615 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
616 int uncertainty);
617
618 /** Injects current location from another location provider
619 * (typically cell ID).
620 * latitude and longitude are measured in degrees
621 * expected accuracy is measured in meters
622 */
623 int (*inject_location)(double latitude, double longitude, float accuracy);
624
625 /**
626 * Specifies that the next call to start will not use the
627 * information defined in the flags. GPS_DELETE_ALL is passed for
628 * a cold start.
629 */
630 void (*delete_aiding_data)(GpsAidingData flags);
631
632 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400633 * min_interval represents the time between fixes in milliseconds.
634 * preferred_accuracy represents the requested fix accuracy in meters.
635 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500636 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400637 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
638 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500639
640 /** Get a pointer to extension information. */
641 const void* (*get_extension)(const char* name);
642} GpsInterface;
643
644/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700645 * The client should download XTRA data and inject it by calling inject_xtra_data().
646 * Can only be called from a thread created by create_thread_cb.
647 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500648typedef void (* gps_xtra_download_request)();
649
650/** Callback structure for the XTRA interface. */
651typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700652 gps_xtra_download_request download_request_cb;
653 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500654} GpsXtraCallbacks;
655
656/** Extended interface for XTRA support. */
657typedef struct {
658 /** set to sizeof(GpsXtraInterface) */
659 size_t size;
660 /**
661 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700662 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500663 */
664 int (*init)( GpsXtraCallbacks* callbacks );
665 /** Injects XTRA data into the GPS. */
666 int (*inject_xtra_data)( char* data, int length );
667} GpsXtraInterface;
668
669/** Extended interface for DEBUG support. */
670typedef struct {
671 /** set to sizeof(GpsDebugInterface) */
672 size_t size;
673
674 /**
675 * This function should return any information that the native
676 * implementation wishes to include in a bugreport.
677 */
678 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
679} GpsDebugInterface;
680
681/** Represents the status of AGPS. */
682typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700683 /** set to sizeof(AGpsStatus_v1) */
684 size_t size;
685
686 AGpsType type;
687 AGpsStatusValue status;
688} AGpsStatus_v1;
689
690/** Represents the status of AGPS augmented with a IPv4 address field. */
691typedef struct {
692 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500693 size_t size;
694
695 AGpsType type;
696 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800697 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700698} AGpsStatus_v2;
699
700/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
701typedef struct {
702 /** set to sizeof(AGpsStatus_v3) */
703 size_t size;
704
705 AGpsType type;
706 AGpsStatusValue status;
707
708 /**
709 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
710 * address, or set to INADDR_NONE otherwise.
711 */
712 uint32_t ipaddr;
713
714 /**
715 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
716 * Any other value of addr.ss_family will be rejected.
717 * */
718 struct sockaddr_storage addr;
719} AGpsStatus_v3;
720
721typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500722
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700723/** Callback with AGPS status information.
724 * Can only be called from a thread created by create_thread_cb.
725 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500726typedef void (* agps_status_callback)(AGpsStatus* status);
727
728/** Callback structure for the AGPS interface. */
729typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700730 agps_status_callback status_cb;
731 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500732} AGpsCallbacks;
733
734
735/** Extended interface for AGPS support. */
736typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700737 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500738 size_t size;
739
740 /**
741 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700742 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500743 */
744 void (*init)( AGpsCallbacks* callbacks );
745 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700746 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500747 * the name of the APN to be used for SUPL.
748 */
749 int (*data_conn_open)( const char* apn );
750 /**
751 * Notifies that the AGPS data connection has been closed.
752 */
753 int (*data_conn_closed)();
754 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700755 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500756 */
757 int (*data_conn_failed)();
758 /**
759 * Sets the hostname and port for the AGPS server.
760 */
761 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700762} AGpsInterface_v1;
763
764/**
765 * Extended interface for AGPS support, it is augmented to enable to pass
766 * extra APN data.
767 */
768typedef struct {
769 /** set to sizeof(AGpsInterface_v2) */
770 size_t size;
771
772 /**
773 * Opens the AGPS interface and provides the callback routines to the
774 * implementation of this interface.
775 */
776 void (*init)(AGpsCallbacks* callbacks);
777 /**
778 * Deprecated.
779 * If the HAL supports AGpsInterface_v2 this API will not be used, see
780 * data_conn_open_with_apn_ip_type for more information.
781 */
782 int (*data_conn_open)(const char* apn);
783 /**
784 * Notifies that the AGPS data connection has been closed.
785 */
786 int (*data_conn_closed)();
787 /**
788 * Notifies that a data connection is not available for AGPS.
789 */
790 int (*data_conn_failed)();
791 /**
792 * Sets the hostname and port for the AGPS server.
793 */
794 int (*set_server)(AGpsType type, const char* hostname, int port);
795
796 /**
797 * Notifies that a data connection is available and sets the name of the
798 * APN, and its IP type, to be used for SUPL connections.
799 */
800 int (*data_conn_open_with_apn_ip_type)(
801 const char* apn,
802 ApnIpType apnIpType);
803} AGpsInterface_v2;
804
805typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500806
destradaaa1f4c0a2013-09-13 15:45:03 -0700807/** Error codes associated with certificate operations */
808#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
809#define AGPS_CERTIFICATE_ERROR_GENERIC -100
810#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
811
812/** A data structure that represents an X.509 certificate using DER encoding */
813typedef struct {
814 size_t length;
815 u_char* data;
816} DerEncodedCertificate;
817
818/**
819 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
820 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
821 */
822typedef struct {
823 u_char data[20];
824} Sha1CertificateFingerprint;
825
destradaa9f7c3732014-04-29 10:50:22 -0700826/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700827typedef struct {
828 /** set to sizeof(SuplCertificateInterface) */
829 size_t size;
830
831 /**
832 * Installs a set of Certificates used for SUPL connections to the AGPS server.
833 * If needed the HAL should find out internally any certificates that need to be removed to
834 * accommodate the certificates to install.
835 * The certificates installed represent a full set of valid certificates needed to connect to
836 * AGPS SUPL servers.
837 * The list of certificates is required, and all must be available at the same time, when trying
838 * to establish a connection with the AGPS Server.
839 *
840 * Parameters:
841 * certificates - A pointer to an array of DER encoded certificates that are need to be
842 * installed in the HAL.
843 * length - The number of certificates to install.
844 * Returns:
845 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
846 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
847 * certificates attempted to be installed, the state of the certificates stored should
848 * remain the same as before on this error case.
849 *
850 * IMPORTANT:
851 * If needed the HAL should find out internally the set of certificates that need to be
852 * removed to accommodate the certificates to install.
853 */
854 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
855
856 /**
857 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
858 * expected that the given set of certificates is removed from the internal store of the HAL.
859 *
860 * Parameters:
861 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
862 * certificates to revoke.
863 * length - The number of fingerprints provided.
864 * Returns:
865 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
866 *
867 * IMPORTANT:
868 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
869 * it should be ignored and continue revoking/deleting the rest of them.
870 */
871 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800872} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500873
874/** Represents an NI request */
875typedef struct {
876 /** set to sizeof(GpsNiNotification) */
877 size_t size;
878
879 /**
880 * An ID generated by HAL to associate NI notifications and UI
881 * responses
882 */
883 int notification_id;
884
885 /**
886 * An NI type used to distinguish different categories of NI
887 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
888 */
889 GpsNiType ni_type;
890
891 /**
892 * Notification/verification options, combinations of GpsNiNotifyFlags constants
893 */
894 GpsNiNotifyFlags notify_flags;
895
896 /**
897 * Timeout period to wait for user response.
898 * Set to 0 for no time out limit.
899 */
900 int timeout;
901
902 /**
903 * Default response when time out.
904 */
905 GpsUserResponseType default_response;
906
907 /**
908 * Requestor ID
909 */
910 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
911
912 /**
913 * Notification message. It can also be used to store client_id in some cases
914 */
915 char text[GPS_NI_LONG_STRING_MAXLEN];
916
917 /**
918 * Client name decoding scheme
919 */
920 GpsNiEncodingType requestor_id_encoding;
921
922 /**
923 * Client name decoding scheme
924 */
925 GpsNiEncodingType text_encoding;
926
927 /**
928 * A pointer to extra data. Format:
929 * key_1 = value_1
930 * key_2 = value_2
931 */
932 char extras[GPS_NI_LONG_STRING_MAXLEN];
933
934} GpsNiNotification;
935
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700936/** Callback with NI notification.
937 * Can only be called from a thread created by create_thread_cb.
938 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500939typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
940
941/** GPS NI callback structure. */
942typedef struct
943{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700944 /**
945 * Sends the notification request from HAL to GPSLocationProvider.
946 */
947 gps_ni_notify_callback notify_cb;
948 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500949} GpsNiCallbacks;
950
951/**
952 * Extended interface for Network-initiated (NI) support.
953 */
954typedef struct
955{
956 /** set to sizeof(GpsNiInterface) */
957 size_t size;
958
959 /** Registers the callbacks for HAL to use. */
960 void (*init) (GpsNiCallbacks *callbacks);
961
962 /** Sends a response to HAL. */
963 void (*respond) (int notif_id, GpsUserResponseType user_response);
964} GpsNiInterface;
965
966struct gps_device_t {
967 struct hw_device_t common;
968
969 /**
970 * Set the provided lights to the provided values.
971 *
972 * Returns: 0 on succes, error code on failure.
973 */
974 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
975};
976
Miguel Torroja5f404f52010-07-27 06:34:15 +0200977#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
978#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
979
980#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
981#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
982
983typedef void (*agps_ril_request_set_id)(uint32_t flags);
984typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
985
986typedef struct {
987 agps_ril_request_set_id request_setid;
988 agps_ril_request_ref_loc request_refloc;
989 gps_create_thread create_thread_cb;
990} AGpsRilCallbacks;
991
992/** Extended interface for AGPS_RIL support. */
993typedef struct {
994 /** set to sizeof(AGpsRilInterface) */
995 size_t size;
996 /**
997 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700998 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +0200999 */
1000 void (*init)( AGpsRilCallbacks* callbacks );
1001
1002 /**
1003 * Sets the reference location.
1004 */
1005 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
1006 /**
1007 * Sets the set ID.
1008 */
1009 void (*set_set_id) (AGpsSetIDType type, const char* setid);
1010
1011 /**
1012 * Send network initiated message.
1013 */
1014 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -04001015
1016 /**
1017 * Notify GPS of network status changes.
1018 * These parameters match values in the android.net.NetworkInfo class.
1019 */
1020 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -07001021
1022 /**
1023 * Notify GPS of network status changes.
1024 * These parameters match values in the android.net.NetworkInfo class.
1025 */
1026 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +02001027} AGpsRilInterface;
1028
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001029/**
1030 * GPS Geofence.
1031 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1032 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1033 *
1034 * An example state diagram with confidence level: 95% and Unknown time limit
1035 * set as 30 secs is shown below. (confidence level and Unknown time limit are
1036 * explained latter)
1037 * ____________________________
1038 * | Unknown (30 secs) |
1039 * """"""""""""""""""""""""""""
1040 * ^ | | ^
1041 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
1042 * | v v |
1043 * ________ EXITED _________
1044 * | Inside | -----------> | Outside |
1045 * | | <----------- | |
1046 * """""""" ENTERED """""""""
1047 *
1048 * Inside state: We are 95% confident that the user is inside the geofence.
1049 * Outside state: We are 95% confident that the user is outside the geofence
1050 * Unknown state: Rest of the time.
1051 *
1052 * The Unknown state is better explained with an example:
1053 *
1054 * __________
1055 * | c|
1056 * | ___ | _______
1057 * | |a| | | b |
1058 * | """ | """""""
1059 * | |
1060 * """"""""""
1061 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1062 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1063 * confident that the user is outside. But with regard to "a" is not confident
1064 * whether it is inside or outside the geofence. If the accuracy remains the
1065 * same for a sufficient period of time, the UNCERTAIN transition would be
1066 * triggered with the state set to Unknown. If the accuracy improves later, an
1067 * appropriate transition should be triggered. This "sufficient period of time"
1068 * is defined by the parameter in the add_geofence_area API.
1069 * In other words, Unknown state can be interpreted as a state in which the
1070 * GPS subsystem isn't confident enough that the user is either inside or
1071 * outside the Geofence. It moves to Unknown state only after the expiry of the
1072 * timeout.
1073 *
1074 * The geofence callback needs to be triggered for the ENTERED and EXITED
1075 * transitions, when the GPS system is confident that the user has entered
1076 * (Inside state) or exited (Outside state) the Geofence. An implementation
1077 * which uses a value of 95% as the confidence is recommended. The callback
1078 * should be triggered only for the transitions requested by the
1079 * add_geofence_area call.
1080 *
1081 * Even though the diagram and explanation talks about states and transitions,
1082 * the callee is only interested in the transistions. The states are mentioned
1083 * here for illustrative purposes.
1084 *
1085 * Startup Scenario: When the device boots up, if an application adds geofences,
1086 * and then we get an accurate GPS location fix, it needs to trigger the
1087 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1088 * By default, all the Geofences will be in the Unknown state.
1089 *
1090 * When the GPS system is unavailable, gps_geofence_status_callback should be
1091 * called to inform the upper layers of the same. Similarly, when it becomes
1092 * available the callback should be called. This is a global state while the
1093 * UNKNOWN transition described above is per geofence.
1094 *
1095 * An important aspect to note is that users of this API (framework), will use
1096 * other subsystems like wifi, sensors, cell to handle Unknown case and
1097 * hopefully provide a definitive state transition to the third party
1098 * application. GPS Geofence will just be a signal indicating what the GPS
1099 * subsystem knows about the Geofence.
1100 *
1101 */
1102#define GPS_GEOFENCE_ENTERED (1<<0L)
1103#define GPS_GEOFENCE_EXITED (1<<1L)
1104#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1105
1106#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1107#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1108
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001109#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1110#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1111#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1112#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1113#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1114#define GPS_GEOFENCE_ERROR_GENERIC -149
1115
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001116/**
1117 * The callback associated with the geofence.
1118 * Parameters:
1119 * geofence_id - The id associated with the add_geofence_area.
1120 * location - The current GPS location.
1121 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1122 * GPS_GEOFENCE_UNCERTAIN.
1123 * timestamp - Timestamp when the transition was detected.
1124 *
1125 * The callback should only be called when the caller is interested in that
1126 * particular transition. For instance, if the caller is interested only in
1127 * ENTERED transition, then the callback should NOT be called with the EXITED
1128 * transition.
1129 *
1130 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1131 * subsystem will wake up the application processor, if its in suspend state.
1132 */
1133typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1134 int32_t transition, GpsUtcTime timestamp);
1135
1136/**
destradaa9f7c3732014-04-29 10:50:22 -07001137 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001138 * monitoring. If the GPS system determines that it cannot monitor geofences
1139 * because of lack of reliability or unavailability of the GPS signals, it will
1140 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1141 *
1142 * Parameters:
1143 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1144 * last_location - Last known location.
1145 */
1146typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1147
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001148/**
1149 * The callback associated with the add_geofence call.
1150 *
1151 * Parameter:
1152 * geofence_id - Id of the geofence.
1153 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1154 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1155 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1156 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1157 * invalid transition
1158 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1159 */
1160typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1161
1162/**
1163 * The callback associated with the remove_geofence call.
1164 *
1165 * Parameter:
1166 * geofence_id - Id of the geofence.
1167 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1168 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1169 * GPS_GEOFENCE_ERROR_GENERIC for others.
1170 */
1171typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1172
1173
1174/**
1175 * The callback associated with the pause_geofence call.
1176 *
1177 * Parameter:
1178 * geofence_id - Id of the geofence.
1179 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1180 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1181 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1182 * when monitor_transitions is invalid
1183 * GPS_GEOFENCE_ERROR_GENERIC for others.
1184 */
1185typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1186
1187/**
1188 * The callback associated with the resume_geofence call.
1189 *
1190 * Parameter:
1191 * geofence_id - Id of the geofence.
1192 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1193 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1194 * GPS_GEOFENCE_ERROR_GENERIC for others.
1195 */
1196typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1197
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001198typedef struct {
1199 gps_geofence_transition_callback geofence_transition_callback;
1200 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001201 gps_geofence_add_callback geofence_add_callback;
1202 gps_geofence_remove_callback geofence_remove_callback;
1203 gps_geofence_pause_callback geofence_pause_callback;
1204 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001205 gps_create_thread create_thread_cb;
1206} GpsGeofenceCallbacks;
1207
1208/** Extended interface for GPS_Geofencing support */
1209typedef struct {
1210 /** set to sizeof(GpsGeofencingInterface) */
1211 size_t size;
1212
1213 /**
1214 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001215 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001216 */
1217 void (*init)( GpsGeofenceCallbacks* callbacks );
1218
1219 /**
1220 * Add a geofence area. This api currently supports circular geofences.
1221 * Parameters:
1222 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001223 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1224 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001225 * latitude, longtitude, radius_meters - The lat, long and radius
1226 * (in meters) for the geofence
1227 * last_transition - The current state of the geofence. For example, if
1228 * the system already knows that the user is inside the geofence,
1229 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1230 * will be GPS_GEOFENCE_UNCERTAIN.
1231 * monitor_transition - Which transitions to monitor. Bitwise OR of
1232 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1233 * GPS_GEOFENCE_UNCERTAIN.
1234 * notification_responsiveness_ms - Defines the best-effort description
1235 * of how soon should the callback be called when the transition
1236 * associated with the Geofence is triggered. For instance, if set
1237 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1238 * should be called 1000 milliseconds within entering the geofence.
1239 * This parameter is defined in milliseconds.
1240 * NOTE: This is not to be confused with the rate that the GPS is
1241 * polled at. It is acceptable to dynamically vary the rate of
1242 * sampling the GPS for power-saving reasons; thus the rate of
1243 * sampling may be faster or slower than this.
1244 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001245 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001246 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001247 */
destradaa9f7c3732014-04-29 10:50:22 -07001248 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1249 double radius_meters, int last_transition, int monitor_transitions,
1250 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001251
1252 /**
1253 * Pause monitoring a particular geofence.
1254 * Parameters:
1255 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001256 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001257 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001258
1259 /**
1260 * Resume monitoring a particular geofence.
1261 * Parameters:
1262 * geofence_id - The id for the geofence.
1263 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1264 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1265 * GPS_GEOFENCE_UNCERTAIN.
1266 * This supersedes the value associated provided in the
1267 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001268 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001269 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001270
1271 /**
1272 * Remove a geofence area. After the function returns, no notifications
1273 * should be sent.
1274 * Parameter:
1275 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001276 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001277 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001278} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001279
1280
1281/**
1282 * Represents an estimate of the GPS clock time.
1283 */
1284typedef struct {
1285 /** set to sizeof(GpsClock) */
1286 size_t size;
1287
1288 /** A set of flags indicating the validity of the fields in this data structure. */
1289 GpsClockFlags flags;
1290
1291 /**
1292 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001293 * The sign of the value is defined by the following equation:
1294 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second * 1,000,000,000
1295 *
destradaa9f7c3732014-04-29 10:50:22 -07001296 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1297 */
1298 int16_t leap_second;
1299
1300 /**
destradaa75843eb2014-07-17 14:04:50 -07001301 * Indicates the type of time reported by the 'time_ns' field.
1302 * This is a Mandatory field.
1303 */
1304 GpsClockType type;
1305
1306 /**
1307 * The GPS receiver internal clock value. This can be either the local hardware clock value
1308 * (GPS_CLOCK_TYPE_LOCAL_HW_TIME), or the current GPS time derived inside GPS receiver
1309 * (GPS_CLOCK_TYPE_GPS_TIME). The field 'type' defines the time reported.
destradaa9f7c3732014-04-29 10:50:22 -07001310 *
destradaa75843eb2014-07-17 14:04:50 -07001311 * For local hardware clock, this value is expected to be monotonically increasing during
1312 * the reporting session. The real GPS time can be derived by compensating the 'full bias'
1313 * (when it is available) from this value.
destradaa9f7c3732014-04-29 10:50:22 -07001314 *
destradaa75843eb2014-07-17 14:04:50 -07001315 * For GPS time, this value is expected to be the best estimation of current GPS time that GPS
1316 * receiver can achieve. Set the 'time uncertainty' appropriately when GPS time is specified.
1317 *
1318 * Sub-nanosecond accuracy can be provided by means of the 'bias' field.
destradaa9f7c3732014-04-29 10:50:22 -07001319 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001320 *
destradaa9f7c3732014-04-29 10:50:22 -07001321 * This is a Mandatory field.
1322 */
1323 int64_t time_ns;
1324
1325 /**
1326 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1327 * The uncertainty is represented as an absolute (single sided) value.
1328 *
destradaa75843eb2014-07-17 14:04:50 -07001329 * This value should be set if GPS_CLOCK_TYPE_GPS_TIME is set.
destradaa9f7c3732014-04-29 10:50:22 -07001330 * If the data is available 'flags' must contain GPS_CLOCK_HAS_TIME_UNCERTAINTY.
1331 */
1332 double time_uncertainty_ns;
1333
1334 /**
destradaa75843eb2014-07-17 14:04:50 -07001335 * The difference between hardware clock ('time' field) inside GPS receiver and the true GPS
1336 * time since 0000Z, January 6, 1980, in nanoseconds.
1337 * This value is used if and only if GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, and GPS receiver
1338 * has solved the clock for GPS time.
1339 * The caller is responsible for using the 'bias uncertainty' field for quality check.
destradaa9f7c3732014-04-29 10:50:22 -07001340 *
destradaa75843eb2014-07-17 14:04:50 -07001341 * The sign of the value is defined by the following equation:
1342 * true time (GPS time) = time_ns + (full_bias_ns + bias_ns)
1343 *
1344 * This value contains the 'bias uncertainty' in it.
1345 * If the data is available 'flags' must contain GPS_CLOCK_HAS_FULL_BIAS.
1346
1347 */
1348 int64_t full_bias_ns;
1349
1350 /**
1351 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001352 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001353 *
destradaa9f7c3732014-04-29 10:50:22 -07001354 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS.
1355 */
1356 double bias_ns;
1357
1358 /**
1359 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1360 * The uncertainty is represented as an absolute (single sided) value.
1361 *
1362 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS_UNCERTAINTY.
1363 */
1364 double bias_uncertainty_ns;
1365
1366 /**
1367 * The clock's drift in nanoseconds (per second).
1368 * A positive value means that the frequency is higher than the nominal frequency.
1369 *
1370 * The value contains the 'drift uncertainty' in it.
1371 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
1372 */
1373 double drift_nsps;
1374
1375 /**
1376 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1377 * The uncertainty is represented as an absolute (single sided) value.
1378 *
1379 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT_UNCERTAINTY.
1380 */
1381 double drift_uncertainty_nsps;
1382} GpsClock;
1383
1384/**
1385 * Represents a GPS Measurement, it contains raw and computed information.
1386 */
1387typedef struct {
1388 /** set to sizeof(GpsMeasurement) */
1389 size_t size;
1390
1391 /** A set of flags indicating the validity of the fields in this data structure. */
1392 GpsMeasurementFlags flags;
1393
1394 /**
1395 * Pseudo-random number in the range of [1, 32]
1396 * This is a Mandatory value.
1397 */
1398 int8_t prn;
1399
1400 /**
destradaa75843eb2014-07-17 14:04:50 -07001401 * Time offset at which the measurement was taken in nanoseconds.
1402 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1403 * interpreted in the same way as indicated by GpsClock::type.
1404 *
destradaa9f7c3732014-04-29 10:50:22 -07001405 * The sign of time_offset_ns is given by the following equation:
1406 * measurement time = GpsClock::time_ns + time_offset_ns
1407 *
1408 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1409 * This is a Mandatory value.
1410 */
destradaa75843eb2014-07-17 14:04:50 -07001411 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001412
1413 /**
destradaa75843eb2014-07-17 14:04:50 -07001414 * Per satellite sync state. It represents the current sync state for the associated satellite.
1415 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001416 *
1417 * This is a Mandatory value.
1418 */
destradaa75843eb2014-07-17 14:04:50 -07001419 GpsMeasurementState state;
1420
1421 /**
1422 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1423 * The value is relative to the beginning of the current GPS week.
1424 *
Tsuwei Chena90cf192014-10-23 12:49:12 -07001425 * Given the highest sync state that can be achieved, per each satellite, valid range for
1426 * this field can be:
1427 * Searching : [ 0 ] : GPS_MEASUREMENT_STATE_UNKNOWN
1428 * C/A code lock : [ 0 1ms ] : GPS_MEASUREMENT_STATE_CODE_LOCK is set
1429 * Bit sync : [ 0 20ms ] : GPS_MEASUREMENT_STATE_BIT_SYNC is set
1430 * Subframe sync : [ 0 6s ] : GPS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1431 * TOW decoded : [ 0 1week ] : GPS_MEASUREMENT_STATE_TOW_DECODED is set
1432 *
1433 * However, if there is any ambiguity in integer millisecond,
1434 * GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field.
destradaa75843eb2014-07-17 14:04:50 -07001435 */
destradaa9f7c3732014-04-29 10:50:22 -07001436 int64_t received_gps_tow_ns;
1437
1438 /**
destradaa941c9282014-07-21 18:13:42 -07001439 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
1440 */
1441 int64_t received_gps_tow_uncertainty_ns;
1442
1443 /**
destradaa9f7c3732014-04-29 10:50:22 -07001444 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1445 * It contains the measured C/N0 value for the signal at the antenna input.
1446 *
1447 * This is a Mandatory value.
1448 */
1449 double c_n0_dbhz;
1450
1451 /**
1452 * Pseudorange rate at the timestamp in m/s.
1453 * The value also includes the effects of the receiver clock frequency and satellite clock
1454 * frequency errors.
1455 *
1456 * The value includes the 'pseudorange rate uncertainty' in it.
1457 * A positive value indicates that the pseudorange is getting larger.
1458 *
1459 * This is a Mandatory value.
1460 */
destradaa75843eb2014-07-17 14:04:50 -07001461 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001462
1463 /**
1464 * 1-Sigma uncertainty of the pseudurange rate in m/s.
1465 * The uncertainty is represented as an absolute (single sided) value.
1466 *
1467 * This is a Mandatory value.
1468 */
destradaa75843eb2014-07-17 14:04:50 -07001469 double pseudorange_rate_uncertainty_mps;
1470
1471 /**
1472 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1473 * (indicating loss of lock).
1474 *
1475 * This is a Mandatory value.
1476 */
1477 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001478
1479 /**
1480 * Accumulated delta range since the last channel reset in meters.
destradaa75843eb2014-07-17 14:04:50 -07001481 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001482 */
1483 double accumulated_delta_range_m;
1484
1485 /**
1486 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa75843eb2014-07-17 14:04:50 -07001487 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001488 */
1489 double accumulated_delta_range_uncertainty_m;
1490
1491 /**
1492 * Best derived Pseudorange by the chip-set, in meters.
1493 * The value contains the 'pseudorange uncertainty' in it.
1494 *
1495 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1496 */
1497 double pseudorange_m;
1498
1499 /**
1500 * 1-Sigma uncertainty of the pseudorange in meters.
1501 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1502 * The uncertainty is represented as an absolute (single sided) value.
1503 *
1504 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1505 */
1506 double pseudorange_uncertainty_m;
1507
1508 /**
1509 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1510 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1511 *
1512 * The reference frequency is given by the field 'carrier_frequency_hz'.
1513 * The value contains the 'code-phase uncertainty' in it.
1514 *
1515 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1516 */
1517 double code_phase_chips;
1518
1519 /**
1520 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1521 * The uncertainty is represented as an absolute (single sided) value.
1522 *
1523 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1524 */
1525 double code_phase_uncertainty_chips;
1526
1527 /**
1528 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1529 * If the field is not set, the carrier frequency is assumed to be L1.
1530 *
1531 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1532 */
1533 float carrier_frequency_hz;
1534
1535 /**
1536 * The number of full carrier cycles between the satellite and the receiver.
1537 * The reference frequency is given by the field 'carrier_frequency_hz'.
1538 *
1539 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1540 */
1541 int64_t carrier_cycles;
1542
1543 /**
1544 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1545 * This is usually the fractional part of the complete carrier phase measurement.
1546 *
1547 * The reference frequency is given by the field 'carrier_frequency_hz'.
1548 * The value contains the 'carrier-phase uncertainty' in it.
1549 *
1550 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1551 */
1552 double carrier_phase;
1553
1554 /**
1555 * 1-Sigma uncertainty of the carrier-phase.
1556 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1557 */
1558 double carrier_phase_uncertainty;
1559
1560 /**
1561 * An enumeration that indicates the 'loss of lock' state of the event.
1562 */
1563 GpsLossOfLock loss_of_lock;
1564
1565 /**
1566 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1567 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1568 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001569 int32_t bit_number;
destradaa9f7c3732014-04-29 10:50:22 -07001570
1571 /**
destradaa75843eb2014-07-17 14:04:50 -07001572 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
destradaa9f7c3732014-04-29 10:50:22 -07001573 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1574 */
destradaa75843eb2014-07-17 14:04:50 -07001575 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001576
1577 /**
1578 * Doppler shift in Hz.
1579 * A positive value indicates that the SV is moving toward the receiver.
1580 *
1581 * The reference frequency is given by the field 'carrier_frequency_hz'.
1582 * The value contains the 'doppler shift uncertainty' in it.
1583 *
1584 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1585 */
1586 double doppler_shift_hz;
1587
1588 /**
1589 * 1-Sigma uncertainty of the doppler shift in Hz.
1590 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1591 */
1592 double doppler_shift_uncertainty_hz;
1593
1594 /**
1595 * An enumeration that indicates the 'multipath' state of the event.
1596 */
1597 GpsMultipathIndicator multipath_indicator;
1598
1599 /**
1600 * Signal-to-noise ratio in dB.
1601 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1602 */
1603 double snr_db;
1604
1605 /**
1606 * Elevation in degrees, the valid range is [-90, 90].
1607 * The value contains the 'elevation uncertainty' in it.
1608 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1609 */
1610 double elevation_deg;
1611
1612 /**
1613 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1614 * The uncertainty is represented as the absolute (single sided) value.
1615 *
1616 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1617 */
1618 double elevation_uncertainty_deg;
1619
1620 /**
1621 * Azimuth in degrees, in the range [0, 360).
1622 * The value contains the 'azimuth uncertainty' in it.
1623 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
1624 * */
1625 double azimuth_deg;
1626
1627 /**
1628 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1629 * The uncertainty is represented as an absolute (single sided) value.
1630 *
1631 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1632 */
1633 double azimuth_uncertainty_deg;
1634
1635 /**
1636 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1637 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1638 */
1639 bool used_in_fix;
1640} GpsMeasurement;
1641
1642/** Represents a reading of GPS measurements. */
1643typedef struct {
1644 /** set to sizeof(GpsData) */
1645 size_t size;
1646
1647 /** Number of measurements. */
1648 size_t measurement_count;
1649
1650 /** The array of measurements. */
1651 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1652
1653 /** The GPS clock time reading. */
1654 GpsClock clock;
1655} GpsData;
1656
1657/**
1658 * The callback for to report measurements from the HAL.
1659 *
1660 * Parameters:
1661 * data - A data structure containing the measurements.
1662 */
1663typedef void (*gps_measurement_callback) (GpsData* data);
1664
1665typedef struct {
1666 /** set to sizeof(GpsMeasurementCallbacks) */
1667 size_t size;
1668 gps_measurement_callback measurement_callback;
1669} GpsMeasurementCallbacks;
1670
1671#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1672#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1673#define GPS_MEASUREMENT_ERROR_GENERIC -101
1674
1675/**
1676 * Extended interface for GPS Measurements support.
1677 */
1678typedef struct {
1679 /** Set to sizeof(GpsMeasurementInterface) */
1680 size_t size;
1681
1682 /**
1683 * Initializes the interface and registers the callback routines with the HAL.
1684 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1685 *
1686 * Status:
1687 * GPS_MEASUREMENT_OPERATION_SUCCESS
1688 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1689 * corresponding call to 'close'
1690 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1691 * will not generate any updates upon returning this error code.
1692 */
1693 int (*init) (GpsMeasurementCallbacks* callbacks);
1694
1695 /**
1696 * Stops updates from the HAL, and unregisters the callback routines.
1697 * After a call to stop, the previously registered callbacks must be considered invalid by the
1698 * HAL.
1699 * If stop is invoked without a previous 'init', this function should perform no work.
1700 */
1701 void (*close) ();
1702
1703} GpsMeasurementInterface;
1704
1705
1706/** Represents a GPS navigation message (or a fragment of it). */
1707typedef struct {
1708 /** set to sizeof(GpsNavigationMessage) */
1709 size_t size;
1710
1711 /**
1712 * Pseudo-random number in the range of [1, 32]
1713 * This is a Mandatory value.
1714 */
1715 int8_t prn;
1716
1717 /**
1718 * The type of message contained in the structure.
1719 * This is a Mandatory value.
1720 */
1721 GpsNavigationMessageType type;
1722
1723 /**
Tsuwei Chena90cf192014-10-23 12:49:12 -07001724 * The status of the received navigation message.
1725 * No need to send any navigation message that contains words with parity error and cannot be
1726 * corrected.
1727 */
1728 NavigationMessageStatus status;
1729
1730 /**
destradaa9f7c3732014-04-29 10:50:22 -07001731 * Message identifier.
destradaa75843eb2014-07-17 14:04:50 -07001732 * It provides an index so the complete Navigation Message can be assembled. i.e. fo L1 C/A
1733 * subframe 4 and 5, this value corresponds to the 'frame id' of the navigation message.
1734 * Subframe 1, 2, 3 does not contain a 'frame id' and this value can be set to -1.
destradaa9f7c3732014-04-29 10:50:22 -07001735 */
1736 int16_t message_id;
1737
1738 /**
1739 * Sub-message identifier.
1740 * If required by the message 'type', this value contains a sub-index within the current
1741 * message (or frame) that is being transmitted.
1742 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1743 */
1744 int16_t submessage_id;
1745
1746 /**
1747 * The length of the data (in bytes) contained in the current message.
1748 * If this value is different from zero, 'data' must point to an array of the same size.
destradaa69d5ea52014-07-31 16:34:09 -07001749 * 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 -07001750 *
1751 * This is a Mandatory value.
1752 */
1753 size_t data_length;
1754
1755 /**
1756 * The data of the reported GPS message.
1757 * The bytes (or words) specified using big endian format (MSB first).
destradaa69d5ea52014-07-31 16:34:09 -07001758 *
1759 * For L1 C/A, each subframe contains 10 30-bit GPS words. Each GPS word (30 bits) should be
1760 * fitted into the last 30 bits in a 4-byte word (skip B31 and B32), with MSB first.
destradaa9f7c3732014-04-29 10:50:22 -07001761 */
1762 uint8_t* data;
1763
1764} GpsNavigationMessage;
1765
1766/**
1767 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1768 *
1769 * Parameters:
1770 * message - The GPS navigation submessage/subframe representation.
1771 */
1772typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1773
1774typedef struct {
1775 /** set to sizeof(GpsNavigationMessageCallbacks) */
1776 size_t size;
1777 gps_navigation_message_callback navigation_message_callback;
1778} GpsNavigationMessageCallbacks;
1779
1780#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
1781#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
1782#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
1783
1784/**
1785 * Extended interface for GPS navigation message reporting support.
1786 */
1787typedef struct {
1788 /** Set to sizeof(GpsNavigationMessageInterface) */
1789 size_t size;
1790
1791 /**
1792 * Initializes the interface and registers the callback routines with the HAL.
1793 * After a successful call to 'init' the HAL must begin to provide updates as they become
1794 * available.
1795 *
1796 * Status:
1797 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
1798 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
1799 * without a corresponding call to 'close'.
1800 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
1801 * the HAL will not generate any updates upon returning this error code.
1802 */
1803 int (*init) (GpsNavigationMessageCallbacks* callbacks);
1804
1805 /**
1806 * Stops updates from the HAL, and unregisters the callback routines.
1807 * After a call to stop, the previously registered callbacks must be considered invalid by the
1808 * HAL.
1809 * If stop is invoked without a previous 'init', this function should perform no work.
1810 */
1811 void (*close) ();
1812
1813} GpsNavigationMessageInterface;
1814
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001815/**
1816 * Interface for passing GNSS configuration contents from platform to HAL.
1817 */
1818typedef struct {
1819 /** Set to sizeof(GnssConfigurationInterface) */
1820 size_t size;
1821
1822 /**
1823 * Deliver GNSS configuration contents to HAL.
1824 * Parameters:
1825 * config_data - a pointer to a char array which holds what usually is expected from
1826 file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
1827 * length - total number of UTF8 characters in configuraiton data.
1828 *
1829 * IMPORTANT:
1830 * GPS HAL should expect this function can be called multiple times. And it may be
1831 * called even when GpsLocationProvider is already constructed and enabled. GPS HAL
1832 * should maintain the existing requests for various callback regardless the change
1833 * in configuration data.
1834 */
1835 void (*configuration_update) (const char* config_data, int32_t length);
1836} GnssConfigurationInterface;
1837
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001838__END_DECLS
1839
1840#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1841