blob: 59da5ddc7309fcb51afccd86969d15ffa0276a6d [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.
337 */
338typedef uint16_t GpsMeasurementState;
339#define GPS_MEASUREMENT_STATE_UNKNOWN 0
340#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
341#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
342#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
343#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
344
345/**
346 * Flags indicating the Accumulated Delta Range's states.
347 */
348typedef uint16_t GpsAccumulatedDeltaRangeState;
349#define GPS_ADR_STATE_UNKNOWN 0
350#define GPS_ADR_STATE_VALID (1<<0)
351#define GPS_ADR_STATE_RESET (1<<1)
352#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
353
354/**
355 * Enumeration of available values to indicate the available GPS Natigation message types.
destradaa9f7c3732014-04-29 10:50:22 -0700356 */
357typedef uint8_t GpsNavigationMessageType;
358/** The message type is unknown. */
359#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
360/** L1 C/A message contained in the structure. */
361#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
362/** L2-CNAV message contained in the structure. */
363#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
364/** L5-CNAV message contained in the structure. */
365#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
366/** CNAV-2 message contained in the structure. */
367#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
368
369
370/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500371 * Name for the GPS XTRA interface.
372 */
373#define GPS_XTRA_INTERFACE "gps-xtra"
374
375/**
376 * Name for the GPS DEBUG interface.
377 */
378#define GPS_DEBUG_INTERFACE "gps-debug"
379
380/**
381 * Name for the AGPS interface.
382 */
383#define AGPS_INTERFACE "agps"
384
385/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700386 * Name of the Supl Certificate interface.
387 */
388#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
389
390/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500391 * Name for NI interface
392 */
393#define GPS_NI_INTERFACE "gps-ni"
394
Miguel Torroja5f404f52010-07-27 06:34:15 +0200395/**
396 * Name for the AGPS-RIL interface.
397 */
398#define AGPS_RIL_INTERFACE "agps_ril"
399
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800400/**
401 * Name for the GPS_Geofencing interface.
402 */
403#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
404
destradaa9f7c3732014-04-29 10:50:22 -0700405/**
406 * Name of the GPS Measurements interface.
407 */
408#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
409
410/**
411 * Name of the GPS navigation message interface.
412 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -0700413#define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
414
415/**
416 * Name of the GNSS/GPS configuration interface.
417 */
418#define GNSS_CONFIGURATION_INTERFACE "gnss_configuration"
destradaa9f7c3732014-04-29 10:50:22 -0700419
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800420
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500421/** Represents a location. */
422typedef struct {
423 /** set to sizeof(GpsLocation) */
424 size_t size;
425 /** Contains GpsLocationFlags bits. */
426 uint16_t flags;
427 /** Represents latitude in degrees. */
428 double latitude;
429 /** Represents longitude in degrees. */
430 double longitude;
431 /** Represents altitude in meters above the WGS 84 reference
432 * ellipsoid. */
433 double altitude;
434 /** Represents speed in meters per second. */
435 float speed;
436 /** Represents heading in degrees. */
437 float bearing;
438 /** Represents expected accuracy in meters. */
439 float accuracy;
440 /** Timestamp for the location fix. */
441 GpsUtcTime timestamp;
442} GpsLocation;
443
444/** Represents the status. */
445typedef struct {
446 /** set to sizeof(GpsStatus) */
447 size_t size;
448 GpsStatusValue status;
449} GpsStatus;
450
451/** Represents SV information. */
452typedef struct {
453 /** set to sizeof(GpsSvInfo) */
454 size_t size;
455 /** Pseudo-random number for the SV. */
456 int prn;
457 /** Signal to noise ratio. */
458 float snr;
459 /** Elevation of SV in degrees. */
460 float elevation;
461 /** Azimuth of SV in degrees. */
462 float azimuth;
463} GpsSvInfo;
464
465/** Represents SV status. */
466typedef struct {
467 /** set to sizeof(GpsSvStatus) */
468 size_t size;
469
470 /** Number of SVs currently visible. */
471 int num_svs;
472
473 /** Contains an array of SV information. */
474 GpsSvInfo sv_list[GPS_MAX_SVS];
475
476 /** Represents a bit mask indicating which SVs
477 * have ephemeris data.
478 */
479 uint32_t ephemeris_mask;
480
481 /** Represents a bit mask indicating which SVs
482 * have almanac data.
483 */
484 uint32_t almanac_mask;
485
486 /**
487 * Represents a bit mask indicating which SVs
488 * were used for computing the most recent position fix.
489 */
490 uint32_t used_in_fix_mask;
491} GpsSvStatus;
492
destradaa9f7c3732014-04-29 10:50:22 -0700493
Miguel Torroja5f404f52010-07-27 06:34:15 +0200494/* 2G and 3G */
495/* In 3G lac is discarded */
496typedef struct {
497 uint16_t type;
498 uint16_t mcc;
499 uint16_t mnc;
500 uint16_t lac;
501 uint32_t cid;
502} AGpsRefLocationCellID;
503
504typedef struct {
505 uint8_t mac[6];
506} AGpsRefLocationMac;
507
508/** Represents ref locations */
509typedef struct {
510 uint16_t type;
511 union {
512 AGpsRefLocationCellID cellID;
513 AGpsRefLocationMac mac;
514 } u;
515} AGpsRefLocation;
516
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700517/** Callback with location information.
518 * Can only be called from a thread created by create_thread_cb.
519 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500520typedef void (* gps_location_callback)(GpsLocation* location);
521
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700522/** Callback with status information.
523 * Can only be called from a thread created by create_thread_cb.
524 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500525typedef void (* gps_status_callback)(GpsStatus* status);
526
destradaa9f7c3732014-04-29 10:50:22 -0700527/**
528 * Callback with SV status information.
529 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700530 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500531typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
532
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700533/** Callback for reporting NMEA sentences.
534 * Can only be called from a thread created by create_thread_cb.
535 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500536typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
537
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400538/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700539 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
540 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400541typedef void (* gps_set_capabilities)(uint32_t capabilities);
542
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400543/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700544 * This can be used to prevent the CPU from suspending while handling GPS events.
545 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400546typedef void (* gps_acquire_wakelock)();
547
548/** Callback utility for releasing the GPS wakelock. */
549typedef void (* gps_release_wakelock)();
550
Mike Lockwood8aac5912011-06-29 15:10:36 -0400551/** Callback for requesting NTP time */
552typedef void (* gps_request_utc_time)();
553
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700554/** Callback for creating a thread that can call into the Java framework code.
555 * This must be used to create any threads that report events up to the framework.
556 */
557typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
558
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500559/** GPS callback structure. */
560typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400561 /** set to sizeof(GpsCallbacks) */
562 size_t size;
563 gps_location_callback location_cb;
564 gps_status_callback status_cb;
565 gps_sv_status_callback sv_status_cb;
566 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400567 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400568 gps_acquire_wakelock acquire_wakelock_cb;
569 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700570 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400571 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500572} GpsCallbacks;
573
574
575/** Represents the standard GPS interface. */
576typedef struct {
577 /** set to sizeof(GpsInterface) */
578 size_t size;
579 /**
580 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700581 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500582 */
583 int (*init)( GpsCallbacks* callbacks );
584
585 /** Starts navigating. */
586 int (*start)( void );
587
588 /** Stops navigating. */
589 int (*stop)( void );
590
591 /** Closes the interface. */
592 void (*cleanup)( void );
593
594 /** Injects the current time. */
595 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
596 int uncertainty);
597
598 /** Injects current location from another location provider
599 * (typically cell ID).
600 * latitude and longitude are measured in degrees
601 * expected accuracy is measured in meters
602 */
603 int (*inject_location)(double latitude, double longitude, float accuracy);
604
605 /**
606 * Specifies that the next call to start will not use the
607 * information defined in the flags. GPS_DELETE_ALL is passed for
608 * a cold start.
609 */
610 void (*delete_aiding_data)(GpsAidingData flags);
611
612 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400613 * min_interval represents the time between fixes in milliseconds.
614 * preferred_accuracy represents the requested fix accuracy in meters.
615 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500616 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400617 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
618 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500619
620 /** Get a pointer to extension information. */
621 const void* (*get_extension)(const char* name);
622} GpsInterface;
623
624/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700625 * The client should download XTRA data and inject it by calling inject_xtra_data().
626 * Can only be called from a thread created by create_thread_cb.
627 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500628typedef void (* gps_xtra_download_request)();
629
630/** Callback structure for the XTRA interface. */
631typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700632 gps_xtra_download_request download_request_cb;
633 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500634} GpsXtraCallbacks;
635
636/** Extended interface for XTRA support. */
637typedef struct {
638 /** set to sizeof(GpsXtraInterface) */
639 size_t size;
640 /**
641 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700642 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500643 */
644 int (*init)( GpsXtraCallbacks* callbacks );
645 /** Injects XTRA data into the GPS. */
646 int (*inject_xtra_data)( char* data, int length );
647} GpsXtraInterface;
648
649/** Extended interface for DEBUG support. */
650typedef struct {
651 /** set to sizeof(GpsDebugInterface) */
652 size_t size;
653
654 /**
655 * This function should return any information that the native
656 * implementation wishes to include in a bugreport.
657 */
658 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
659} GpsDebugInterface;
660
661/** Represents the status of AGPS. */
662typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700663 /** set to sizeof(AGpsStatus_v1) */
664 size_t size;
665
666 AGpsType type;
667 AGpsStatusValue status;
668} AGpsStatus_v1;
669
670/** Represents the status of AGPS augmented with a IPv4 address field. */
671typedef struct {
672 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500673 size_t size;
674
675 AGpsType type;
676 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800677 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700678} AGpsStatus_v2;
679
680/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
681typedef struct {
682 /** set to sizeof(AGpsStatus_v3) */
683 size_t size;
684
685 AGpsType type;
686 AGpsStatusValue status;
687
688 /**
689 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
690 * address, or set to INADDR_NONE otherwise.
691 */
692 uint32_t ipaddr;
693
694 /**
695 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
696 * Any other value of addr.ss_family will be rejected.
697 * */
698 struct sockaddr_storage addr;
699} AGpsStatus_v3;
700
701typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500702
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700703/** Callback with AGPS status information.
704 * Can only be called from a thread created by create_thread_cb.
705 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500706typedef void (* agps_status_callback)(AGpsStatus* status);
707
708/** Callback structure for the AGPS interface. */
709typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700710 agps_status_callback status_cb;
711 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500712} AGpsCallbacks;
713
714
715/** Extended interface for AGPS support. */
716typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700717 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500718 size_t size;
719
720 /**
721 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700722 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500723 */
724 void (*init)( AGpsCallbacks* callbacks );
725 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700726 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500727 * the name of the APN to be used for SUPL.
728 */
729 int (*data_conn_open)( const char* apn );
730 /**
731 * Notifies that the AGPS data connection has been closed.
732 */
733 int (*data_conn_closed)();
734 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700735 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500736 */
737 int (*data_conn_failed)();
738 /**
739 * Sets the hostname and port for the AGPS server.
740 */
741 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700742} AGpsInterface_v1;
743
744/**
745 * Extended interface for AGPS support, it is augmented to enable to pass
746 * extra APN data.
747 */
748typedef struct {
749 /** set to sizeof(AGpsInterface_v2) */
750 size_t size;
751
752 /**
753 * Opens the AGPS interface and provides the callback routines to the
754 * implementation of this interface.
755 */
756 void (*init)(AGpsCallbacks* callbacks);
757 /**
758 * Deprecated.
759 * If the HAL supports AGpsInterface_v2 this API will not be used, see
760 * data_conn_open_with_apn_ip_type for more information.
761 */
762 int (*data_conn_open)(const char* apn);
763 /**
764 * Notifies that the AGPS data connection has been closed.
765 */
766 int (*data_conn_closed)();
767 /**
768 * Notifies that a data connection is not available for AGPS.
769 */
770 int (*data_conn_failed)();
771 /**
772 * Sets the hostname and port for the AGPS server.
773 */
774 int (*set_server)(AGpsType type, const char* hostname, int port);
775
776 /**
777 * Notifies that a data connection is available and sets the name of the
778 * APN, and its IP type, to be used for SUPL connections.
779 */
780 int (*data_conn_open_with_apn_ip_type)(
781 const char* apn,
782 ApnIpType apnIpType);
783} AGpsInterface_v2;
784
785typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500786
destradaaa1f4c0a2013-09-13 15:45:03 -0700787/** Error codes associated with certificate operations */
788#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
789#define AGPS_CERTIFICATE_ERROR_GENERIC -100
790#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
791
792/** A data structure that represents an X.509 certificate using DER encoding */
793typedef struct {
794 size_t length;
795 u_char* data;
796} DerEncodedCertificate;
797
798/**
799 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
800 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
801 */
802typedef struct {
803 u_char data[20];
804} Sha1CertificateFingerprint;
805
destradaa9f7c3732014-04-29 10:50:22 -0700806/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700807typedef struct {
808 /** set to sizeof(SuplCertificateInterface) */
809 size_t size;
810
811 /**
812 * Installs a set of Certificates used for SUPL connections to the AGPS server.
813 * If needed the HAL should find out internally any certificates that need to be removed to
814 * accommodate the certificates to install.
815 * The certificates installed represent a full set of valid certificates needed to connect to
816 * AGPS SUPL servers.
817 * The list of certificates is required, and all must be available at the same time, when trying
818 * to establish a connection with the AGPS Server.
819 *
820 * Parameters:
821 * certificates - A pointer to an array of DER encoded certificates that are need to be
822 * installed in the HAL.
823 * length - The number of certificates to install.
824 * Returns:
825 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
826 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
827 * certificates attempted to be installed, the state of the certificates stored should
828 * remain the same as before on this error case.
829 *
830 * IMPORTANT:
831 * If needed the HAL should find out internally the set of certificates that need to be
832 * removed to accommodate the certificates to install.
833 */
834 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
835
836 /**
837 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
838 * expected that the given set of certificates is removed from the internal store of the HAL.
839 *
840 * Parameters:
841 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
842 * certificates to revoke.
843 * length - The number of fingerprints provided.
844 * Returns:
845 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
846 *
847 * IMPORTANT:
848 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
849 * it should be ignored and continue revoking/deleting the rest of them.
850 */
851 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800852} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500853
854/** Represents an NI request */
855typedef struct {
856 /** set to sizeof(GpsNiNotification) */
857 size_t size;
858
859 /**
860 * An ID generated by HAL to associate NI notifications and UI
861 * responses
862 */
863 int notification_id;
864
865 /**
866 * An NI type used to distinguish different categories of NI
867 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
868 */
869 GpsNiType ni_type;
870
871 /**
872 * Notification/verification options, combinations of GpsNiNotifyFlags constants
873 */
874 GpsNiNotifyFlags notify_flags;
875
876 /**
877 * Timeout period to wait for user response.
878 * Set to 0 for no time out limit.
879 */
880 int timeout;
881
882 /**
883 * Default response when time out.
884 */
885 GpsUserResponseType default_response;
886
887 /**
888 * Requestor ID
889 */
890 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
891
892 /**
893 * Notification message. It can also be used to store client_id in some cases
894 */
895 char text[GPS_NI_LONG_STRING_MAXLEN];
896
897 /**
898 * Client name decoding scheme
899 */
900 GpsNiEncodingType requestor_id_encoding;
901
902 /**
903 * Client name decoding scheme
904 */
905 GpsNiEncodingType text_encoding;
906
907 /**
908 * A pointer to extra data. Format:
909 * key_1 = value_1
910 * key_2 = value_2
911 */
912 char extras[GPS_NI_LONG_STRING_MAXLEN];
913
914} GpsNiNotification;
915
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700916/** Callback with NI notification.
917 * Can only be called from a thread created by create_thread_cb.
918 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500919typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
920
921/** GPS NI callback structure. */
922typedef struct
923{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700924 /**
925 * Sends the notification request from HAL to GPSLocationProvider.
926 */
927 gps_ni_notify_callback notify_cb;
928 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500929} GpsNiCallbacks;
930
931/**
932 * Extended interface for Network-initiated (NI) support.
933 */
934typedef struct
935{
936 /** set to sizeof(GpsNiInterface) */
937 size_t size;
938
939 /** Registers the callbacks for HAL to use. */
940 void (*init) (GpsNiCallbacks *callbacks);
941
942 /** Sends a response to HAL. */
943 void (*respond) (int notif_id, GpsUserResponseType user_response);
944} GpsNiInterface;
945
946struct gps_device_t {
947 struct hw_device_t common;
948
949 /**
950 * Set the provided lights to the provided values.
951 *
952 * Returns: 0 on succes, error code on failure.
953 */
954 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
955};
956
Miguel Torroja5f404f52010-07-27 06:34:15 +0200957#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
958#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
959
960#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
961#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
962
963typedef void (*agps_ril_request_set_id)(uint32_t flags);
964typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
965
966typedef struct {
967 agps_ril_request_set_id request_setid;
968 agps_ril_request_ref_loc request_refloc;
969 gps_create_thread create_thread_cb;
970} AGpsRilCallbacks;
971
972/** Extended interface for AGPS_RIL support. */
973typedef struct {
974 /** set to sizeof(AGpsRilInterface) */
975 size_t size;
976 /**
977 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700978 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +0200979 */
980 void (*init)( AGpsRilCallbacks* callbacks );
981
982 /**
983 * Sets the reference location.
984 */
985 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
986 /**
987 * Sets the set ID.
988 */
989 void (*set_set_id) (AGpsSetIDType type, const char* setid);
990
991 /**
992 * Send network initiated message.
993 */
994 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -0400995
996 /**
997 * Notify GPS of network status changes.
998 * These parameters match values in the android.net.NetworkInfo class.
999 */
1000 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -07001001
1002 /**
1003 * Notify GPS of network status changes.
1004 * These parameters match values in the android.net.NetworkInfo class.
1005 */
1006 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +02001007} AGpsRilInterface;
1008
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001009/**
1010 * GPS Geofence.
1011 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
1012 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
1013 *
1014 * An example state diagram with confidence level: 95% and Unknown time limit
1015 * set as 30 secs is shown below. (confidence level and Unknown time limit are
1016 * explained latter)
1017 * ____________________________
1018 * | Unknown (30 secs) |
1019 * """"""""""""""""""""""""""""
1020 * ^ | | ^
1021 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
1022 * | v v |
1023 * ________ EXITED _________
1024 * | Inside | -----------> | Outside |
1025 * | | <----------- | |
1026 * """""""" ENTERED """""""""
1027 *
1028 * Inside state: We are 95% confident that the user is inside the geofence.
1029 * Outside state: We are 95% confident that the user is outside the geofence
1030 * Unknown state: Rest of the time.
1031 *
1032 * The Unknown state is better explained with an example:
1033 *
1034 * __________
1035 * | c|
1036 * | ___ | _______
1037 * | |a| | | b |
1038 * | """ | """""""
1039 * | |
1040 * """"""""""
1041 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1042 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1043 * confident that the user is outside. But with regard to "a" is not confident
1044 * whether it is inside or outside the geofence. If the accuracy remains the
1045 * same for a sufficient period of time, the UNCERTAIN transition would be
1046 * triggered with the state set to Unknown. If the accuracy improves later, an
1047 * appropriate transition should be triggered. This "sufficient period of time"
1048 * is defined by the parameter in the add_geofence_area API.
1049 * In other words, Unknown state can be interpreted as a state in which the
1050 * GPS subsystem isn't confident enough that the user is either inside or
1051 * outside the Geofence. It moves to Unknown state only after the expiry of the
1052 * timeout.
1053 *
1054 * The geofence callback needs to be triggered for the ENTERED and EXITED
1055 * transitions, when the GPS system is confident that the user has entered
1056 * (Inside state) or exited (Outside state) the Geofence. An implementation
1057 * which uses a value of 95% as the confidence is recommended. The callback
1058 * should be triggered only for the transitions requested by the
1059 * add_geofence_area call.
1060 *
1061 * Even though the diagram and explanation talks about states and transitions,
1062 * the callee is only interested in the transistions. The states are mentioned
1063 * here for illustrative purposes.
1064 *
1065 * Startup Scenario: When the device boots up, if an application adds geofences,
1066 * and then we get an accurate GPS location fix, it needs to trigger the
1067 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1068 * By default, all the Geofences will be in the Unknown state.
1069 *
1070 * When the GPS system is unavailable, gps_geofence_status_callback should be
1071 * called to inform the upper layers of the same. Similarly, when it becomes
1072 * available the callback should be called. This is a global state while the
1073 * UNKNOWN transition described above is per geofence.
1074 *
1075 * An important aspect to note is that users of this API (framework), will use
1076 * other subsystems like wifi, sensors, cell to handle Unknown case and
1077 * hopefully provide a definitive state transition to the third party
1078 * application. GPS Geofence will just be a signal indicating what the GPS
1079 * subsystem knows about the Geofence.
1080 *
1081 */
1082#define GPS_GEOFENCE_ENTERED (1<<0L)
1083#define GPS_GEOFENCE_EXITED (1<<1L)
1084#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1085
1086#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1087#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1088
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001089#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1090#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1091#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1092#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1093#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1094#define GPS_GEOFENCE_ERROR_GENERIC -149
1095
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001096/**
1097 * The callback associated with the geofence.
1098 * Parameters:
1099 * geofence_id - The id associated with the add_geofence_area.
1100 * location - The current GPS location.
1101 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1102 * GPS_GEOFENCE_UNCERTAIN.
1103 * timestamp - Timestamp when the transition was detected.
1104 *
1105 * The callback should only be called when the caller is interested in that
1106 * particular transition. For instance, if the caller is interested only in
1107 * ENTERED transition, then the callback should NOT be called with the EXITED
1108 * transition.
1109 *
1110 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1111 * subsystem will wake up the application processor, if its in suspend state.
1112 */
1113typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1114 int32_t transition, GpsUtcTime timestamp);
1115
1116/**
destradaa9f7c3732014-04-29 10:50:22 -07001117 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001118 * monitoring. If the GPS system determines that it cannot monitor geofences
1119 * because of lack of reliability or unavailability of the GPS signals, it will
1120 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1121 *
1122 * Parameters:
1123 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1124 * last_location - Last known location.
1125 */
1126typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1127
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001128/**
1129 * The callback associated with the add_geofence call.
1130 *
1131 * Parameter:
1132 * geofence_id - Id of the geofence.
1133 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1134 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1135 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1136 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1137 * invalid transition
1138 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1139 */
1140typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1141
1142/**
1143 * The callback associated with the remove_geofence call.
1144 *
1145 * Parameter:
1146 * geofence_id - Id of the geofence.
1147 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1148 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1149 * GPS_GEOFENCE_ERROR_GENERIC for others.
1150 */
1151typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1152
1153
1154/**
1155 * The callback associated with the pause_geofence call.
1156 *
1157 * Parameter:
1158 * geofence_id - Id of the geofence.
1159 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1160 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1161 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1162 * when monitor_transitions is invalid
1163 * GPS_GEOFENCE_ERROR_GENERIC for others.
1164 */
1165typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1166
1167/**
1168 * The callback associated with the resume_geofence call.
1169 *
1170 * Parameter:
1171 * geofence_id - Id of the geofence.
1172 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1173 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1174 * GPS_GEOFENCE_ERROR_GENERIC for others.
1175 */
1176typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1177
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001178typedef struct {
1179 gps_geofence_transition_callback geofence_transition_callback;
1180 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001181 gps_geofence_add_callback geofence_add_callback;
1182 gps_geofence_remove_callback geofence_remove_callback;
1183 gps_geofence_pause_callback geofence_pause_callback;
1184 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001185 gps_create_thread create_thread_cb;
1186} GpsGeofenceCallbacks;
1187
1188/** Extended interface for GPS_Geofencing support */
1189typedef struct {
1190 /** set to sizeof(GpsGeofencingInterface) */
1191 size_t size;
1192
1193 /**
1194 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001195 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001196 */
1197 void (*init)( GpsGeofenceCallbacks* callbacks );
1198
1199 /**
1200 * Add a geofence area. This api currently supports circular geofences.
1201 * Parameters:
1202 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001203 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1204 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001205 * latitude, longtitude, radius_meters - The lat, long and radius
1206 * (in meters) for the geofence
1207 * last_transition - The current state of the geofence. For example, if
1208 * the system already knows that the user is inside the geofence,
1209 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1210 * will be GPS_GEOFENCE_UNCERTAIN.
1211 * monitor_transition - Which transitions to monitor. Bitwise OR of
1212 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1213 * GPS_GEOFENCE_UNCERTAIN.
1214 * notification_responsiveness_ms - Defines the best-effort description
1215 * of how soon should the callback be called when the transition
1216 * associated with the Geofence is triggered. For instance, if set
1217 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1218 * should be called 1000 milliseconds within entering the geofence.
1219 * This parameter is defined in milliseconds.
1220 * NOTE: This is not to be confused with the rate that the GPS is
1221 * polled at. It is acceptable to dynamically vary the rate of
1222 * sampling the GPS for power-saving reasons; thus the rate of
1223 * sampling may be faster or slower than this.
1224 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001225 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001226 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001227 */
destradaa9f7c3732014-04-29 10:50:22 -07001228 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1229 double radius_meters, int last_transition, int monitor_transitions,
1230 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001231
1232 /**
1233 * Pause monitoring a particular geofence.
1234 * Parameters:
1235 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001236 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001237 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001238
1239 /**
1240 * Resume monitoring a particular geofence.
1241 * Parameters:
1242 * geofence_id - The id for the geofence.
1243 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1244 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1245 * GPS_GEOFENCE_UNCERTAIN.
1246 * This supersedes the value associated provided in the
1247 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001248 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001249 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001250
1251 /**
1252 * Remove a geofence area. After the function returns, no notifications
1253 * should be sent.
1254 * Parameter:
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 (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001258} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001259
1260
1261/**
1262 * Represents an estimate of the GPS clock time.
1263 */
1264typedef struct {
1265 /** set to sizeof(GpsClock) */
1266 size_t size;
1267
1268 /** A set of flags indicating the validity of the fields in this data structure. */
1269 GpsClockFlags flags;
1270
1271 /**
1272 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001273 * The sign of the value is defined by the following equation:
1274 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second * 1,000,000,000
1275 *
destradaa9f7c3732014-04-29 10:50:22 -07001276 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1277 */
1278 int16_t leap_second;
1279
1280 /**
destradaa75843eb2014-07-17 14:04:50 -07001281 * Indicates the type of time reported by the 'time_ns' field.
1282 * This is a Mandatory field.
1283 */
1284 GpsClockType type;
1285
1286 /**
1287 * The GPS receiver internal clock value. This can be either the local hardware clock value
1288 * (GPS_CLOCK_TYPE_LOCAL_HW_TIME), or the current GPS time derived inside GPS receiver
1289 * (GPS_CLOCK_TYPE_GPS_TIME). The field 'type' defines the time reported.
destradaa9f7c3732014-04-29 10:50:22 -07001290 *
destradaa75843eb2014-07-17 14:04:50 -07001291 * For local hardware clock, this value is expected to be monotonically increasing during
1292 * the reporting session. The real GPS time can be derived by compensating the 'full bias'
1293 * (when it is available) from this value.
destradaa9f7c3732014-04-29 10:50:22 -07001294 *
destradaa75843eb2014-07-17 14:04:50 -07001295 * For GPS time, this value is expected to be the best estimation of current GPS time that GPS
1296 * receiver can achieve. Set the 'time uncertainty' appropriately when GPS time is specified.
1297 *
1298 * Sub-nanosecond accuracy can be provided by means of the 'bias' field.
destradaa9f7c3732014-04-29 10:50:22 -07001299 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001300 *
destradaa9f7c3732014-04-29 10:50:22 -07001301 * This is a Mandatory field.
1302 */
1303 int64_t time_ns;
1304
1305 /**
1306 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1307 * The uncertainty is represented as an absolute (single sided) value.
1308 *
destradaa75843eb2014-07-17 14:04:50 -07001309 * This value should be set if GPS_CLOCK_TYPE_GPS_TIME is set.
destradaa9f7c3732014-04-29 10:50:22 -07001310 * If the data is available 'flags' must contain GPS_CLOCK_HAS_TIME_UNCERTAINTY.
1311 */
1312 double time_uncertainty_ns;
1313
1314 /**
destradaa75843eb2014-07-17 14:04:50 -07001315 * The difference between hardware clock ('time' field) inside GPS receiver and the true GPS
1316 * time since 0000Z, January 6, 1980, in nanoseconds.
1317 * This value is used if and only if GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, and GPS receiver
1318 * has solved the clock for GPS time.
1319 * The caller is responsible for using the 'bias uncertainty' field for quality check.
destradaa9f7c3732014-04-29 10:50:22 -07001320 *
destradaa75843eb2014-07-17 14:04:50 -07001321 * The sign of the value is defined by the following equation:
1322 * true time (GPS time) = time_ns + (full_bias_ns + bias_ns)
1323 *
1324 * This value contains the 'bias uncertainty' in it.
1325 * If the data is available 'flags' must contain GPS_CLOCK_HAS_FULL_BIAS.
1326
1327 */
1328 int64_t full_bias_ns;
1329
1330 /**
1331 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001332 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001333 *
destradaa9f7c3732014-04-29 10:50:22 -07001334 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS.
1335 */
1336 double bias_ns;
1337
1338 /**
1339 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1340 * The uncertainty is represented as an absolute (single sided) value.
1341 *
1342 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS_UNCERTAINTY.
1343 */
1344 double bias_uncertainty_ns;
1345
1346 /**
1347 * The clock's drift in nanoseconds (per second).
1348 * A positive value means that the frequency is higher than the nominal frequency.
1349 *
1350 * The value contains the 'drift uncertainty' in it.
1351 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
1352 */
1353 double drift_nsps;
1354
1355 /**
1356 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1357 * The uncertainty is represented as an absolute (single sided) value.
1358 *
1359 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT_UNCERTAINTY.
1360 */
1361 double drift_uncertainty_nsps;
1362} GpsClock;
1363
1364/**
1365 * Represents a GPS Measurement, it contains raw and computed information.
1366 */
1367typedef struct {
1368 /** set to sizeof(GpsMeasurement) */
1369 size_t size;
1370
1371 /** A set of flags indicating the validity of the fields in this data structure. */
1372 GpsMeasurementFlags flags;
1373
1374 /**
1375 * Pseudo-random number in the range of [1, 32]
1376 * This is a Mandatory value.
1377 */
1378 int8_t prn;
1379
1380 /**
destradaa75843eb2014-07-17 14:04:50 -07001381 * Time offset at which the measurement was taken in nanoseconds.
1382 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1383 * interpreted in the same way as indicated by GpsClock::type.
1384 *
destradaa9f7c3732014-04-29 10:50:22 -07001385 * The sign of time_offset_ns is given by the following equation:
1386 * measurement time = GpsClock::time_ns + time_offset_ns
1387 *
1388 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1389 * This is a Mandatory value.
1390 */
destradaa75843eb2014-07-17 14:04:50 -07001391 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001392
1393 /**
destradaa75843eb2014-07-17 14:04:50 -07001394 * Per satellite sync state. It represents the current sync state for the associated satellite.
1395 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001396 *
1397 * This is a Mandatory value.
1398 */
destradaa75843eb2014-07-17 14:04:50 -07001399 GpsMeasurementState state;
1400
1401 /**
1402 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1403 * The value is relative to the beginning of the current GPS week.
1404 *
1405 * Given the sync state of GPS receiver, per each satellite, valid range for this field can be:
1406 * Searching : [ 0 ] : GPS_MEASUREMENT_STATE_UNKNOWN
1407 * Ranging code lock : [ 0 1ms ] : GPS_MEASUREMENT_STATE_CODE_LOCK is set
1408 * Bit sync : [ 0 20ms ] : GPS_MEASUREMENT_STATE_BIT_SYNC is set
1409 * Subframe sync : [ 0 6ms ] : GPS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1410 * TOW decoded : [ 0 1week ] : GPS_MEASUREMENT_STATE_TOW_DECODED is set
1411 */
destradaa9f7c3732014-04-29 10:50:22 -07001412 int64_t received_gps_tow_ns;
1413
1414 /**
destradaa941c9282014-07-21 18:13:42 -07001415 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
1416 */
1417 int64_t received_gps_tow_uncertainty_ns;
1418
1419 /**
destradaa9f7c3732014-04-29 10:50:22 -07001420 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1421 * It contains the measured C/N0 value for the signal at the antenna input.
1422 *
1423 * This is a Mandatory value.
1424 */
1425 double c_n0_dbhz;
1426
1427 /**
1428 * Pseudorange rate at the timestamp in m/s.
1429 * The value also includes the effects of the receiver clock frequency and satellite clock
1430 * frequency errors.
1431 *
1432 * The value includes the 'pseudorange rate uncertainty' in it.
1433 * A positive value indicates that the pseudorange is getting larger.
1434 *
1435 * This is a Mandatory value.
1436 */
destradaa75843eb2014-07-17 14:04:50 -07001437 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001438
1439 /**
1440 * 1-Sigma uncertainty of the pseudurange rate in m/s.
1441 * The uncertainty is represented as an absolute (single sided) value.
1442 *
1443 * This is a Mandatory value.
1444 */
destradaa75843eb2014-07-17 14:04:50 -07001445 double pseudorange_rate_uncertainty_mps;
1446
1447 /**
1448 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1449 * (indicating loss of lock).
1450 *
1451 * This is a Mandatory value.
1452 */
1453 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001454
1455 /**
1456 * Accumulated delta range since the last channel reset in meters.
destradaa75843eb2014-07-17 14:04:50 -07001457 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001458 */
1459 double accumulated_delta_range_m;
1460
1461 /**
1462 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa75843eb2014-07-17 14:04:50 -07001463 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001464 */
1465 double accumulated_delta_range_uncertainty_m;
1466
1467 /**
1468 * Best derived Pseudorange by the chip-set, in meters.
1469 * The value contains the 'pseudorange uncertainty' in it.
1470 *
1471 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1472 */
1473 double pseudorange_m;
1474
1475 /**
1476 * 1-Sigma uncertainty of the pseudorange in meters.
1477 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1478 * The uncertainty is represented as an absolute (single sided) value.
1479 *
1480 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1481 */
1482 double pseudorange_uncertainty_m;
1483
1484 /**
1485 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1486 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1487 *
1488 * The reference frequency is given by the field 'carrier_frequency_hz'.
1489 * The value contains the 'code-phase uncertainty' in it.
1490 *
1491 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1492 */
1493 double code_phase_chips;
1494
1495 /**
1496 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1497 * The uncertainty is represented as an absolute (single sided) value.
1498 *
1499 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1500 */
1501 double code_phase_uncertainty_chips;
1502
1503 /**
1504 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1505 * If the field is not set, the carrier frequency is assumed to be L1.
1506 *
1507 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1508 */
1509 float carrier_frequency_hz;
1510
1511 /**
1512 * The number of full carrier cycles between the satellite and the receiver.
1513 * The reference frequency is given by the field 'carrier_frequency_hz'.
1514 *
1515 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1516 */
1517 int64_t carrier_cycles;
1518
1519 /**
1520 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1521 * This is usually the fractional part of the complete carrier phase measurement.
1522 *
1523 * The reference frequency is given by the field 'carrier_frequency_hz'.
1524 * The value contains the 'carrier-phase uncertainty' in it.
1525 *
1526 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1527 */
1528 double carrier_phase;
1529
1530 /**
1531 * 1-Sigma uncertainty of the carrier-phase.
1532 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1533 */
1534 double carrier_phase_uncertainty;
1535
1536 /**
1537 * An enumeration that indicates the 'loss of lock' state of the event.
1538 */
1539 GpsLossOfLock loss_of_lock;
1540
1541 /**
1542 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1543 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1544 */
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001545 int32_t bit_number;
destradaa9f7c3732014-04-29 10:50:22 -07001546
1547 /**
destradaa75843eb2014-07-17 14:04:50 -07001548 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
destradaa9f7c3732014-04-29 10:50:22 -07001549 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1550 */
destradaa75843eb2014-07-17 14:04:50 -07001551 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001552
1553 /**
1554 * Doppler shift in Hz.
1555 * A positive value indicates that the SV is moving toward the receiver.
1556 *
1557 * The reference frequency is given by the field 'carrier_frequency_hz'.
1558 * The value contains the 'doppler shift uncertainty' in it.
1559 *
1560 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1561 */
1562 double doppler_shift_hz;
1563
1564 /**
1565 * 1-Sigma uncertainty of the doppler shift in Hz.
1566 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1567 */
1568 double doppler_shift_uncertainty_hz;
1569
1570 /**
1571 * An enumeration that indicates the 'multipath' state of the event.
1572 */
1573 GpsMultipathIndicator multipath_indicator;
1574
1575 /**
1576 * Signal-to-noise ratio in dB.
1577 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1578 */
1579 double snr_db;
1580
1581 /**
1582 * Elevation in degrees, the valid range is [-90, 90].
1583 * The value contains the 'elevation uncertainty' in it.
1584 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1585 */
1586 double elevation_deg;
1587
1588 /**
1589 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1590 * The uncertainty is represented as the absolute (single sided) value.
1591 *
1592 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1593 */
1594 double elevation_uncertainty_deg;
1595
1596 /**
1597 * Azimuth in degrees, in the range [0, 360).
1598 * The value contains the 'azimuth uncertainty' in it.
1599 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
1600 * */
1601 double azimuth_deg;
1602
1603 /**
1604 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1605 * The uncertainty is represented as an absolute (single sided) value.
1606 *
1607 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1608 */
1609 double azimuth_uncertainty_deg;
1610
1611 /**
1612 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1613 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1614 */
1615 bool used_in_fix;
1616} GpsMeasurement;
1617
1618/** Represents a reading of GPS measurements. */
1619typedef struct {
1620 /** set to sizeof(GpsData) */
1621 size_t size;
1622
1623 /** Number of measurements. */
1624 size_t measurement_count;
1625
1626 /** The array of measurements. */
1627 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1628
1629 /** The GPS clock time reading. */
1630 GpsClock clock;
1631} GpsData;
1632
1633/**
1634 * The callback for to report measurements from the HAL.
1635 *
1636 * Parameters:
1637 * data - A data structure containing the measurements.
1638 */
1639typedef void (*gps_measurement_callback) (GpsData* data);
1640
1641typedef struct {
1642 /** set to sizeof(GpsMeasurementCallbacks) */
1643 size_t size;
1644 gps_measurement_callback measurement_callback;
1645} GpsMeasurementCallbacks;
1646
1647#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1648#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1649#define GPS_MEASUREMENT_ERROR_GENERIC -101
1650
1651/**
1652 * Extended interface for GPS Measurements support.
1653 */
1654typedef struct {
1655 /** Set to sizeof(GpsMeasurementInterface) */
1656 size_t size;
1657
1658 /**
1659 * Initializes the interface and registers the callback routines with the HAL.
1660 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1661 *
1662 * Status:
1663 * GPS_MEASUREMENT_OPERATION_SUCCESS
1664 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1665 * corresponding call to 'close'
1666 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1667 * will not generate any updates upon returning this error code.
1668 */
1669 int (*init) (GpsMeasurementCallbacks* callbacks);
1670
1671 /**
1672 * Stops updates from the HAL, and unregisters the callback routines.
1673 * After a call to stop, the previously registered callbacks must be considered invalid by the
1674 * HAL.
1675 * If stop is invoked without a previous 'init', this function should perform no work.
1676 */
1677 void (*close) ();
1678
1679} GpsMeasurementInterface;
1680
1681
1682/** Represents a GPS navigation message (or a fragment of it). */
1683typedef struct {
1684 /** set to sizeof(GpsNavigationMessage) */
1685 size_t size;
1686
1687 /**
1688 * Pseudo-random number in the range of [1, 32]
1689 * This is a Mandatory value.
1690 */
1691 int8_t prn;
1692
1693 /**
1694 * The type of message contained in the structure.
1695 * This is a Mandatory value.
1696 */
1697 GpsNavigationMessageType type;
1698
1699 /**
1700 * Message identifier.
destradaa75843eb2014-07-17 14:04:50 -07001701 * It provides an index so the complete Navigation Message can be assembled. i.e. fo L1 C/A
1702 * subframe 4 and 5, this value corresponds to the 'frame id' of the navigation message.
1703 * Subframe 1, 2, 3 does not contain a 'frame id' and this value can be set to -1.
destradaa9f7c3732014-04-29 10:50:22 -07001704 */
1705 int16_t message_id;
1706
1707 /**
1708 * Sub-message identifier.
1709 * If required by the message 'type', this value contains a sub-index within the current
1710 * message (or frame) that is being transmitted.
1711 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1712 */
1713 int16_t submessage_id;
1714
1715 /**
1716 * The length of the data (in bytes) contained in the current message.
1717 * If this value is different from zero, 'data' must point to an array of the same size.
destradaa69d5ea52014-07-31 16:34:09 -07001718 * 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 -07001719 *
1720 * This is a Mandatory value.
1721 */
1722 size_t data_length;
1723
1724 /**
1725 * The data of the reported GPS message.
1726 * The bytes (or words) specified using big endian format (MSB first).
destradaa69d5ea52014-07-31 16:34:09 -07001727 *
1728 * For L1 C/A, each subframe contains 10 30-bit GPS words. Each GPS word (30 bits) should be
1729 * fitted into the last 30 bits in a 4-byte word (skip B31 and B32), with MSB first.
destradaa9f7c3732014-04-29 10:50:22 -07001730 */
1731 uint8_t* data;
1732
1733} GpsNavigationMessage;
1734
1735/**
1736 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1737 *
1738 * Parameters:
1739 * message - The GPS navigation submessage/subframe representation.
1740 */
1741typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1742
1743typedef struct {
1744 /** set to sizeof(GpsNavigationMessageCallbacks) */
1745 size_t size;
1746 gps_navigation_message_callback navigation_message_callback;
1747} GpsNavigationMessageCallbacks;
1748
1749#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
1750#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
1751#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
1752
1753/**
1754 * Extended interface for GPS navigation message reporting support.
1755 */
1756typedef struct {
1757 /** Set to sizeof(GpsNavigationMessageInterface) */
1758 size_t size;
1759
1760 /**
1761 * Initializes the interface and registers the callback routines with the HAL.
1762 * After a successful call to 'init' the HAL must begin to provide updates as they become
1763 * available.
1764 *
1765 * Status:
1766 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
1767 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
1768 * without a corresponding call to 'close'.
1769 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
1770 * the HAL will not generate any updates upon returning this error code.
1771 */
1772 int (*init) (GpsNavigationMessageCallbacks* callbacks);
1773
1774 /**
1775 * Stops updates from the HAL, and unregisters the callback routines.
1776 * After a call to stop, the previously registered callbacks must be considered invalid by the
1777 * HAL.
1778 * If stop is invoked without a previous 'init', this function should perform no work.
1779 */
1780 void (*close) ();
1781
1782} GpsNavigationMessageInterface;
1783
Tsuwei Chen167d31f2014-08-26 16:34:19 -07001784/**
1785 * Interface for passing GNSS configuration contents from platform to HAL.
1786 */
1787typedef struct {
1788 /** Set to sizeof(GnssConfigurationInterface) */
1789 size_t size;
1790
1791 /**
1792 * Deliver GNSS configuration contents to HAL.
1793 * Parameters:
1794 * config_data - a pointer to a char array which holds what usually is expected from
1795 file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
1796 * length - total number of UTF8 characters in configuraiton data.
1797 *
1798 * IMPORTANT:
1799 * GPS HAL should expect this function can be called multiple times. And it may be
1800 * called even when GpsLocationProvider is already constructed and enabled. GPS HAL
1801 * should maintain the existing requests for various callback regardless the change
1802 * in configuration data.
1803 */
1804 void (*configuration_update) (const char* config_data, int32_t length);
1805} GnssConfigurationInterface;
1806
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001807__END_DECLS
1808
1809#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1810