blob: 5747faafc939e6526f6288c5d1e11d8023c795c4 [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
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400113
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500114/** Flags used to specify which aiding data to delete
115 when calling delete_aiding_data(). */
116typedef uint16_t GpsAidingData;
117// IMPORTANT: Note that the following values must match
118// constants in GpsLocationProvider.java.
119#define GPS_DELETE_EPHEMERIS 0x0001
120#define GPS_DELETE_ALMANAC 0x0002
121#define GPS_DELETE_POSITION 0x0004
122#define GPS_DELETE_TIME 0x0008
123#define GPS_DELETE_IONO 0x0010
124#define GPS_DELETE_UTC 0x0020
125#define GPS_DELETE_HEALTH 0x0040
126#define GPS_DELETE_SVDIR 0x0080
127#define GPS_DELETE_SVSTEER 0x0100
128#define GPS_DELETE_SADATA 0x0200
129#define GPS_DELETE_RTI 0x0400
130#define GPS_DELETE_CELLDB_INFO 0x8000
131#define GPS_DELETE_ALL 0xFFFF
132
133/** AGPS type */
134typedef uint16_t AGpsType;
135#define AGPS_TYPE_SUPL 1
136#define AGPS_TYPE_C2K 2
137
Miguel Torroja5f404f52010-07-27 06:34:15 +0200138typedef uint16_t AGpsSetIDType;
139#define AGPS_SETID_TYPE_NONE 0
140#define AGPS_SETID_TYPE_IMSI 1
141#define AGPS_SETID_TYPE_MSISDN 2
142
destradaaf48cc672014-06-05 11:07:09 -0700143typedef uint16_t ApnIpType;
144#define APN_IP_INVALID 0
145#define APN_IP_IPV4 1
146#define APN_IP_IPV6 2
147#define APN_IP_IPV4V6 3
148
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500149/**
150 * String length constants
151 */
152#define GPS_NI_SHORT_STRING_MAXLEN 256
153#define GPS_NI_LONG_STRING_MAXLEN 2048
154
155/**
156 * GpsNiType constants
157 */
158typedef uint32_t GpsNiType;
159#define GPS_NI_TYPE_VOICE 1
160#define GPS_NI_TYPE_UMTS_SUPL 2
161#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
162
163/**
164 * GpsNiNotifyFlags constants
165 */
166typedef uint32_t GpsNiNotifyFlags;
167/** NI requires notification */
168#define GPS_NI_NEED_NOTIFY 0x0001
169/** NI requires verification */
170#define GPS_NI_NEED_VERIFY 0x0002
171/** NI requires privacy override, no notification/minimal trace */
172#define GPS_NI_PRIVACY_OVERRIDE 0x0004
173
174/**
175 * GPS NI responses, used to define the response in
176 * NI structures
177 */
178typedef int GpsUserResponseType;
179#define GPS_NI_RESPONSE_ACCEPT 1
180#define GPS_NI_RESPONSE_DENY 2
181#define GPS_NI_RESPONSE_NORESP 3
182
183/**
184 * NI data encoding scheme
185 */
186typedef int GpsNiEncodingType;
187#define GPS_ENC_NONE 0
188#define GPS_ENC_SUPL_GSM_DEFAULT 1
189#define GPS_ENC_SUPL_UTF8 2
190#define GPS_ENC_SUPL_UCS2 3
191#define GPS_ENC_UNKNOWN -1
192
193/** AGPS status event values. */
194typedef uint16_t AGpsStatusValue;
195/** GPS requests data connection for AGPS. */
196#define GPS_REQUEST_AGPS_DATA_CONN 1
197/** GPS releases the AGPS data connection. */
198#define GPS_RELEASE_AGPS_DATA_CONN 2
199/** AGPS data connection initiated */
200#define GPS_AGPS_DATA_CONNECTED 3
201/** AGPS data connection completed */
202#define GPS_AGPS_DATA_CONN_DONE 4
203/** AGPS data connection failed */
204#define GPS_AGPS_DATA_CONN_FAILED 5
205
Miguel Torroja5f404f52010-07-27 06:34:15 +0200206#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
207#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
208#define AGPS_REG_LOCATION_TYPE_MAC 3
209
Mike Lockwood455e83b2010-10-11 06:16:57 -0400210/** Network types for update_network_state "type" parameter */
211#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
212#define AGPS_RIL_NETWORK_TYPE_WIFI 1
213#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
214#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
215#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
216#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
217#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
218
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500219/**
destradaa9f7c3732014-04-29 10:50:22 -0700220 * Flags to indicate what fields in GpsClock are valid.
221 */
222typedef uint16_t GpsClockFlags;
223/** A valid 'leap second' is stored in the data structure. */
224#define GPS_CLOCK_HAS_LEAP_SECOND (1<<0)
225/** A valid 'time uncertainty' is stored in the data structure. */
226#define GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1)
destradaa75843eb2014-07-17 14:04:50 -0700227/** A valid 'full bias' is stored in the data structure. */
228#define GPS_CLOCK_HAS_FULL_BIAS (1<<2)
destradaa9f7c3732014-04-29 10:50:22 -0700229/** A valid 'bias' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700230#define GPS_CLOCK_HAS_BIAS (1<<3)
destradaa9f7c3732014-04-29 10:50:22 -0700231/** A valid 'bias uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700232#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4)
destradaa9f7c3732014-04-29 10:50:22 -0700233/** A valid 'drift' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700234#define GPS_CLOCK_HAS_DRIFT (1<<5)
destradaa9f7c3732014-04-29 10:50:22 -0700235/** A valid 'drift uncertainty' is stored in the data structure. */
destradaa75843eb2014-07-17 14:04:50 -0700236#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6)
237
238/**
239 * Enumeration of the available values for the GPS Clock type.
240 */
241typedef uint8_t GpsClockType;
242/** The type is not available ot it is unknown. */
243#define GPS_CLOCK_TYPE_UNKNOWN 0
244/** The source of the time value reported by GPS clock is the local hardware clock. */
245#define GPS_CLOCK_TYPE_LOCAL_HW_TIME 1
246/**
247 * The source of the time value reported by GPS clock is the GPS time derived from satellites
248 * (epoch = Jan 6, 1980)
249 */
250#define GPS_CLOCK_TYPE_GPS_TIME 2
destradaa9f7c3732014-04-29 10:50:22 -0700251
252/**
253 * Flags to indicate what fields in GpsMeasurement are valid.
254 */
255typedef uint32_t GpsMeasurementFlags;
256/** A valid 'snr' is stored in the data structure. */
257#define GPS_MEASUREMENT_HAS_SNR (1<<0)
258/** A valid 'elevation' is stored in the data structure. */
259#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
260/** A valid 'elevation uncertainty' is stored in the data structure. */
261#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
262/** A valid 'azimuth' is stored in the data structure. */
263#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
264/** A valid 'azimuth uncertainty' is stored in the data structure. */
265#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
266/** A valid 'pseudorange' is stored in the data structure. */
267#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
268/** A valid 'pseudorange uncertainty' is stored in the data structure. */
269#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
270/** A valid 'code phase' is stored in the data structure. */
271#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
272/** A valid 'code phase uncertainty' is stored in the data structure. */
273#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
274/** A valid 'carrier frequency' is stored in the data structure. */
275#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
276/** A valid 'carrier cycles' is stored in the data structure. */
277#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
278/** A valid 'carrier phase' is stored in the data structure. */
279#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
280/** A valid 'carrier phase uncertainty' is stored in the data structure. */
281#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
282/** A valid 'bit number' is stored in the data structure. */
283#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
284/** A valid 'time from last bit' is stored in the data structure. */
285#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
286/** A valid 'doppler shift' is stored in the data structure. */
287#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
288/** A valid 'doppler shift uncertainty' is stored in the data structure. */
289#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
290/** A valid 'used in fix' flag is stored in the data structure. */
291#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
292
293/**
destradaa75843eb2014-07-17 14:04:50 -0700294 * Enumeration of the available values for the GPS Measurement's loss of lock.
destradaa9f7c3732014-04-29 10:50:22 -0700295 */
296typedef uint8_t GpsLossOfLock;
297/** The indicator is not available or it is unknown. */
298#define GPS_LOSS_OF_LOCK_UNKNOWN 0
299/** The measurement does not present any indication of loss of lock. */
300#define GPS_LOSS_OF_LOCK_OK 1
301/** Loss of lock between previous and current observation: cycle slip possible. */
302#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
303
304/**
destradaa75843eb2014-07-17 14:04:50 -0700305 * Enumeration of available values for the GPS Measurement's multipath indicator.
destradaa9f7c3732014-04-29 10:50:22 -0700306 */
307typedef uint8_t GpsMultipathIndicator;
308/** The indicator is not available or unknown. */
309#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
310/** The measurement has been indicated to use multipath. */
311#define GPS_MULTIPATH_INDICATOR_DETECTED 1
312/** The measurement has been indicated Not to use multipath. */
313#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
314
315/**
destradaa75843eb2014-07-17 14:04:50 -0700316 * Flags indicating the GPS measurement state.
317 */
318typedef uint16_t GpsMeasurementState;
319#define GPS_MEASUREMENT_STATE_UNKNOWN 0
320#define GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0)
321#define GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1)
322#define GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2)
323#define GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3)
324
325/**
326 * Flags indicating the Accumulated Delta Range's states.
327 */
328typedef uint16_t GpsAccumulatedDeltaRangeState;
329#define GPS_ADR_STATE_UNKNOWN 0
330#define GPS_ADR_STATE_VALID (1<<0)
331#define GPS_ADR_STATE_RESET (1<<1)
332#define GPS_ADR_STATE_CYCLE_SLIP (1<<2)
333
334/**
335 * Enumeration of available values to indicate the available GPS Natigation message types.
destradaa9f7c3732014-04-29 10:50:22 -0700336 */
337typedef uint8_t GpsNavigationMessageType;
338/** The message type is unknown. */
339#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
340/** L1 C/A message contained in the structure. */
341#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
342/** L2-CNAV message contained in the structure. */
343#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
344/** L5-CNAV message contained in the structure. */
345#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
346/** CNAV-2 message contained in the structure. */
347#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
348
349
350/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500351 * Name for the GPS XTRA interface.
352 */
353#define GPS_XTRA_INTERFACE "gps-xtra"
354
355/**
356 * Name for the GPS DEBUG interface.
357 */
358#define GPS_DEBUG_INTERFACE "gps-debug"
359
360/**
361 * Name for the AGPS interface.
362 */
363#define AGPS_INTERFACE "agps"
364
365/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700366 * Name of the Supl Certificate interface.
367 */
368#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
369
370/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500371 * Name for NI interface
372 */
373#define GPS_NI_INTERFACE "gps-ni"
374
Miguel Torroja5f404f52010-07-27 06:34:15 +0200375/**
376 * Name for the AGPS-RIL interface.
377 */
378#define AGPS_RIL_INTERFACE "agps_ril"
379
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800380/**
381 * Name for the GPS_Geofencing interface.
382 */
383#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
384
destradaa9f7c3732014-04-29 10:50:22 -0700385/**
386 * Name of the GPS Measurements interface.
387 */
388#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
389
390/**
391 * Name of the GPS navigation message interface.
392 */
393 #define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
394
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800395
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500396/** Represents a location. */
397typedef struct {
398 /** set to sizeof(GpsLocation) */
399 size_t size;
400 /** Contains GpsLocationFlags bits. */
401 uint16_t flags;
402 /** Represents latitude in degrees. */
403 double latitude;
404 /** Represents longitude in degrees. */
405 double longitude;
406 /** Represents altitude in meters above the WGS 84 reference
407 * ellipsoid. */
408 double altitude;
409 /** Represents speed in meters per second. */
410 float speed;
411 /** Represents heading in degrees. */
412 float bearing;
413 /** Represents expected accuracy in meters. */
414 float accuracy;
415 /** Timestamp for the location fix. */
416 GpsUtcTime timestamp;
417} GpsLocation;
418
419/** Represents the status. */
420typedef struct {
421 /** set to sizeof(GpsStatus) */
422 size_t size;
423 GpsStatusValue status;
424} GpsStatus;
425
426/** Represents SV information. */
427typedef struct {
428 /** set to sizeof(GpsSvInfo) */
429 size_t size;
430 /** Pseudo-random number for the SV. */
431 int prn;
432 /** Signal to noise ratio. */
433 float snr;
434 /** Elevation of SV in degrees. */
435 float elevation;
436 /** Azimuth of SV in degrees. */
437 float azimuth;
438} GpsSvInfo;
439
440/** Represents SV status. */
441typedef struct {
442 /** set to sizeof(GpsSvStatus) */
443 size_t size;
444
445 /** Number of SVs currently visible. */
446 int num_svs;
447
448 /** Contains an array of SV information. */
449 GpsSvInfo sv_list[GPS_MAX_SVS];
450
451 /** Represents a bit mask indicating which SVs
452 * have ephemeris data.
453 */
454 uint32_t ephemeris_mask;
455
456 /** Represents a bit mask indicating which SVs
457 * have almanac data.
458 */
459 uint32_t almanac_mask;
460
461 /**
462 * Represents a bit mask indicating which SVs
463 * were used for computing the most recent position fix.
464 */
465 uint32_t used_in_fix_mask;
466} GpsSvStatus;
467
destradaa9f7c3732014-04-29 10:50:22 -0700468
Miguel Torroja5f404f52010-07-27 06:34:15 +0200469/* 2G and 3G */
470/* In 3G lac is discarded */
471typedef struct {
472 uint16_t type;
473 uint16_t mcc;
474 uint16_t mnc;
475 uint16_t lac;
476 uint32_t cid;
477} AGpsRefLocationCellID;
478
479typedef struct {
480 uint8_t mac[6];
481} AGpsRefLocationMac;
482
483/** Represents ref locations */
484typedef struct {
485 uint16_t type;
486 union {
487 AGpsRefLocationCellID cellID;
488 AGpsRefLocationMac mac;
489 } u;
490} AGpsRefLocation;
491
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700492/** Callback with location information.
493 * Can only be called from a thread created by create_thread_cb.
494 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500495typedef void (* gps_location_callback)(GpsLocation* location);
496
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700497/** Callback with status information.
498 * Can only be called from a thread created by create_thread_cb.
499 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500500typedef void (* gps_status_callback)(GpsStatus* status);
501
destradaa9f7c3732014-04-29 10:50:22 -0700502/**
503 * Callback with SV status information.
504 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700505 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500506typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
507
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700508/** Callback for reporting NMEA sentences.
509 * Can only be called from a thread created by create_thread_cb.
510 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500511typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
512
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400513/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700514 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
515 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400516typedef void (* gps_set_capabilities)(uint32_t capabilities);
517
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400518/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700519 * This can be used to prevent the CPU from suspending while handling GPS events.
520 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400521typedef void (* gps_acquire_wakelock)();
522
523/** Callback utility for releasing the GPS wakelock. */
524typedef void (* gps_release_wakelock)();
525
Mike Lockwood8aac5912011-06-29 15:10:36 -0400526/** Callback for requesting NTP time */
527typedef void (* gps_request_utc_time)();
528
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700529/** Callback for creating a thread that can call into the Java framework code.
530 * This must be used to create any threads that report events up to the framework.
531 */
532typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
533
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500534/** GPS callback structure. */
535typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400536 /** set to sizeof(GpsCallbacks) */
537 size_t size;
538 gps_location_callback location_cb;
539 gps_status_callback status_cb;
540 gps_sv_status_callback sv_status_cb;
541 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400542 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400543 gps_acquire_wakelock acquire_wakelock_cb;
544 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700545 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400546 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500547} GpsCallbacks;
548
549
550/** Represents the standard GPS interface. */
551typedef struct {
552 /** set to sizeof(GpsInterface) */
553 size_t size;
554 /**
555 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700556 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500557 */
558 int (*init)( GpsCallbacks* callbacks );
559
560 /** Starts navigating. */
561 int (*start)( void );
562
563 /** Stops navigating. */
564 int (*stop)( void );
565
566 /** Closes the interface. */
567 void (*cleanup)( void );
568
569 /** Injects the current time. */
570 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
571 int uncertainty);
572
573 /** Injects current location from another location provider
574 * (typically cell ID).
575 * latitude and longitude are measured in degrees
576 * expected accuracy is measured in meters
577 */
578 int (*inject_location)(double latitude, double longitude, float accuracy);
579
580 /**
581 * Specifies that the next call to start will not use the
582 * information defined in the flags. GPS_DELETE_ALL is passed for
583 * a cold start.
584 */
585 void (*delete_aiding_data)(GpsAidingData flags);
586
587 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400588 * min_interval represents the time between fixes in milliseconds.
589 * preferred_accuracy represents the requested fix accuracy in meters.
590 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500591 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400592 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
593 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500594
595 /** Get a pointer to extension information. */
596 const void* (*get_extension)(const char* name);
597} GpsInterface;
598
599/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700600 * The client should download XTRA data and inject it by calling inject_xtra_data().
601 * Can only be called from a thread created by create_thread_cb.
602 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500603typedef void (* gps_xtra_download_request)();
604
605/** Callback structure for the XTRA interface. */
606typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700607 gps_xtra_download_request download_request_cb;
608 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500609} GpsXtraCallbacks;
610
611/** Extended interface for XTRA support. */
612typedef struct {
613 /** set to sizeof(GpsXtraInterface) */
614 size_t size;
615 /**
616 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700617 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500618 */
619 int (*init)( GpsXtraCallbacks* callbacks );
620 /** Injects XTRA data into the GPS. */
621 int (*inject_xtra_data)( char* data, int length );
622} GpsXtraInterface;
623
624/** Extended interface for DEBUG support. */
625typedef struct {
626 /** set to sizeof(GpsDebugInterface) */
627 size_t size;
628
629 /**
630 * This function should return any information that the native
631 * implementation wishes to include in a bugreport.
632 */
633 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
634} GpsDebugInterface;
635
636/** Represents the status of AGPS. */
637typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700638 /** set to sizeof(AGpsStatus_v1) */
639 size_t size;
640
641 AGpsType type;
642 AGpsStatusValue status;
643} AGpsStatus_v1;
644
645/** Represents the status of AGPS augmented with a IPv4 address field. */
646typedef struct {
647 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500648 size_t size;
649
650 AGpsType type;
651 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800652 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700653} AGpsStatus_v2;
654
655/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
656typedef struct {
657 /** set to sizeof(AGpsStatus_v3) */
658 size_t size;
659
660 AGpsType type;
661 AGpsStatusValue status;
662
663 /**
664 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
665 * address, or set to INADDR_NONE otherwise.
666 */
667 uint32_t ipaddr;
668
669 /**
670 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
671 * Any other value of addr.ss_family will be rejected.
672 * */
673 struct sockaddr_storage addr;
674} AGpsStatus_v3;
675
676typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500677
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700678/** Callback with AGPS status information.
679 * Can only be called from a thread created by create_thread_cb.
680 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500681typedef void (* agps_status_callback)(AGpsStatus* status);
682
683/** Callback structure for the AGPS interface. */
684typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700685 agps_status_callback status_cb;
686 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500687} AGpsCallbacks;
688
689
690/** Extended interface for AGPS support. */
691typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700692 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500693 size_t size;
694
695 /**
696 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700697 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500698 */
699 void (*init)( AGpsCallbacks* callbacks );
700 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700701 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500702 * the name of the APN to be used for SUPL.
703 */
704 int (*data_conn_open)( const char* apn );
705 /**
706 * Notifies that the AGPS data connection has been closed.
707 */
708 int (*data_conn_closed)();
709 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700710 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500711 */
712 int (*data_conn_failed)();
713 /**
714 * Sets the hostname and port for the AGPS server.
715 */
716 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700717} AGpsInterface_v1;
718
719/**
720 * Extended interface for AGPS support, it is augmented to enable to pass
721 * extra APN data.
722 */
723typedef struct {
724 /** set to sizeof(AGpsInterface_v2) */
725 size_t size;
726
727 /**
728 * Opens the AGPS interface and provides the callback routines to the
729 * implementation of this interface.
730 */
731 void (*init)(AGpsCallbacks* callbacks);
732 /**
733 * Deprecated.
734 * If the HAL supports AGpsInterface_v2 this API will not be used, see
735 * data_conn_open_with_apn_ip_type for more information.
736 */
737 int (*data_conn_open)(const char* apn);
738 /**
739 * Notifies that the AGPS data connection has been closed.
740 */
741 int (*data_conn_closed)();
742 /**
743 * Notifies that a data connection is not available for AGPS.
744 */
745 int (*data_conn_failed)();
746 /**
747 * Sets the hostname and port for the AGPS server.
748 */
749 int (*set_server)(AGpsType type, const char* hostname, int port);
750
751 /**
752 * Notifies that a data connection is available and sets the name of the
753 * APN, and its IP type, to be used for SUPL connections.
754 */
755 int (*data_conn_open_with_apn_ip_type)(
756 const char* apn,
757 ApnIpType apnIpType);
758} AGpsInterface_v2;
759
760typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500761
destradaaa1f4c0a2013-09-13 15:45:03 -0700762/** Error codes associated with certificate operations */
763#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
764#define AGPS_CERTIFICATE_ERROR_GENERIC -100
765#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
766
767/** A data structure that represents an X.509 certificate using DER encoding */
768typedef struct {
769 size_t length;
770 u_char* data;
771} DerEncodedCertificate;
772
773/**
774 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
775 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
776 */
777typedef struct {
778 u_char data[20];
779} Sha1CertificateFingerprint;
780
destradaa9f7c3732014-04-29 10:50:22 -0700781/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700782typedef struct {
783 /** set to sizeof(SuplCertificateInterface) */
784 size_t size;
785
786 /**
787 * Installs a set of Certificates used for SUPL connections to the AGPS server.
788 * If needed the HAL should find out internally any certificates that need to be removed to
789 * accommodate the certificates to install.
790 * The certificates installed represent a full set of valid certificates needed to connect to
791 * AGPS SUPL servers.
792 * The list of certificates is required, and all must be available at the same time, when trying
793 * to establish a connection with the AGPS Server.
794 *
795 * Parameters:
796 * certificates - A pointer to an array of DER encoded certificates that are need to be
797 * installed in the HAL.
798 * length - The number of certificates to install.
799 * Returns:
800 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
801 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
802 * certificates attempted to be installed, the state of the certificates stored should
803 * remain the same as before on this error case.
804 *
805 * IMPORTANT:
806 * If needed the HAL should find out internally the set of certificates that need to be
807 * removed to accommodate the certificates to install.
808 */
809 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
810
811 /**
812 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
813 * expected that the given set of certificates is removed from the internal store of the HAL.
814 *
815 * Parameters:
816 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
817 * certificates to revoke.
818 * length - The number of fingerprints provided.
819 * Returns:
820 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
821 *
822 * IMPORTANT:
823 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
824 * it should be ignored and continue revoking/deleting the rest of them.
825 */
826 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800827} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500828
829/** Represents an NI request */
830typedef struct {
831 /** set to sizeof(GpsNiNotification) */
832 size_t size;
833
834 /**
835 * An ID generated by HAL to associate NI notifications and UI
836 * responses
837 */
838 int notification_id;
839
840 /**
841 * An NI type used to distinguish different categories of NI
842 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
843 */
844 GpsNiType ni_type;
845
846 /**
847 * Notification/verification options, combinations of GpsNiNotifyFlags constants
848 */
849 GpsNiNotifyFlags notify_flags;
850
851 /**
852 * Timeout period to wait for user response.
853 * Set to 0 for no time out limit.
854 */
855 int timeout;
856
857 /**
858 * Default response when time out.
859 */
860 GpsUserResponseType default_response;
861
862 /**
863 * Requestor ID
864 */
865 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
866
867 /**
868 * Notification message. It can also be used to store client_id in some cases
869 */
870 char text[GPS_NI_LONG_STRING_MAXLEN];
871
872 /**
873 * Client name decoding scheme
874 */
875 GpsNiEncodingType requestor_id_encoding;
876
877 /**
878 * Client name decoding scheme
879 */
880 GpsNiEncodingType text_encoding;
881
882 /**
883 * A pointer to extra data. Format:
884 * key_1 = value_1
885 * key_2 = value_2
886 */
887 char extras[GPS_NI_LONG_STRING_MAXLEN];
888
889} GpsNiNotification;
890
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700891/** Callback with NI notification.
892 * Can only be called from a thread created by create_thread_cb.
893 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500894typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
895
896/** GPS NI callback structure. */
897typedef struct
898{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700899 /**
900 * Sends the notification request from HAL to GPSLocationProvider.
901 */
902 gps_ni_notify_callback notify_cb;
903 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500904} GpsNiCallbacks;
905
906/**
907 * Extended interface for Network-initiated (NI) support.
908 */
909typedef struct
910{
911 /** set to sizeof(GpsNiInterface) */
912 size_t size;
913
914 /** Registers the callbacks for HAL to use. */
915 void (*init) (GpsNiCallbacks *callbacks);
916
917 /** Sends a response to HAL. */
918 void (*respond) (int notif_id, GpsUserResponseType user_response);
919} GpsNiInterface;
920
921struct gps_device_t {
922 struct hw_device_t common;
923
924 /**
925 * Set the provided lights to the provided values.
926 *
927 * Returns: 0 on succes, error code on failure.
928 */
929 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
930};
931
Miguel Torroja5f404f52010-07-27 06:34:15 +0200932#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
933#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
934
935#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
936#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
937
938typedef void (*agps_ril_request_set_id)(uint32_t flags);
939typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
940
941typedef struct {
942 agps_ril_request_set_id request_setid;
943 agps_ril_request_ref_loc request_refloc;
944 gps_create_thread create_thread_cb;
945} AGpsRilCallbacks;
946
947/** Extended interface for AGPS_RIL support. */
948typedef struct {
949 /** set to sizeof(AGpsRilInterface) */
950 size_t size;
951 /**
952 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700953 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +0200954 */
955 void (*init)( AGpsRilCallbacks* callbacks );
956
957 /**
958 * Sets the reference location.
959 */
960 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
961 /**
962 * Sets the set ID.
963 */
964 void (*set_set_id) (AGpsSetIDType type, const char* setid);
965
966 /**
967 * Send network initiated message.
968 */
969 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -0400970
971 /**
972 * Notify GPS of network status changes.
973 * These parameters match values in the android.net.NetworkInfo class.
974 */
975 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -0700976
977 /**
978 * Notify GPS of network status changes.
979 * These parameters match values in the android.net.NetworkInfo class.
980 */
981 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +0200982} AGpsRilInterface;
983
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800984/**
985 * GPS Geofence.
986 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
987 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
988 *
989 * An example state diagram with confidence level: 95% and Unknown time limit
990 * set as 30 secs is shown below. (confidence level and Unknown time limit are
991 * explained latter)
992 * ____________________________
993 * | Unknown (30 secs) |
994 * """"""""""""""""""""""""""""
995 * ^ | | ^
996 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
997 * | v v |
998 * ________ EXITED _________
999 * | Inside | -----------> | Outside |
1000 * | | <----------- | |
1001 * """""""" ENTERED """""""""
1002 *
1003 * Inside state: We are 95% confident that the user is inside the geofence.
1004 * Outside state: We are 95% confident that the user is outside the geofence
1005 * Unknown state: Rest of the time.
1006 *
1007 * The Unknown state is better explained with an example:
1008 *
1009 * __________
1010 * | c|
1011 * | ___ | _______
1012 * | |a| | | b |
1013 * | """ | """""""
1014 * | |
1015 * """"""""""
1016 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
1017 * circle reported by the GPS subsystem. Now with regard to "b", the system is
1018 * confident that the user is outside. But with regard to "a" is not confident
1019 * whether it is inside or outside the geofence. If the accuracy remains the
1020 * same for a sufficient period of time, the UNCERTAIN transition would be
1021 * triggered with the state set to Unknown. If the accuracy improves later, an
1022 * appropriate transition should be triggered. This "sufficient period of time"
1023 * is defined by the parameter in the add_geofence_area API.
1024 * In other words, Unknown state can be interpreted as a state in which the
1025 * GPS subsystem isn't confident enough that the user is either inside or
1026 * outside the Geofence. It moves to Unknown state only after the expiry of the
1027 * timeout.
1028 *
1029 * The geofence callback needs to be triggered for the ENTERED and EXITED
1030 * transitions, when the GPS system is confident that the user has entered
1031 * (Inside state) or exited (Outside state) the Geofence. An implementation
1032 * which uses a value of 95% as the confidence is recommended. The callback
1033 * should be triggered only for the transitions requested by the
1034 * add_geofence_area call.
1035 *
1036 * Even though the diagram and explanation talks about states and transitions,
1037 * the callee is only interested in the transistions. The states are mentioned
1038 * here for illustrative purposes.
1039 *
1040 * Startup Scenario: When the device boots up, if an application adds geofences,
1041 * and then we get an accurate GPS location fix, it needs to trigger the
1042 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1043 * By default, all the Geofences will be in the Unknown state.
1044 *
1045 * When the GPS system is unavailable, gps_geofence_status_callback should be
1046 * called to inform the upper layers of the same. Similarly, when it becomes
1047 * available the callback should be called. This is a global state while the
1048 * UNKNOWN transition described above is per geofence.
1049 *
1050 * An important aspect to note is that users of this API (framework), will use
1051 * other subsystems like wifi, sensors, cell to handle Unknown case and
1052 * hopefully provide a definitive state transition to the third party
1053 * application. GPS Geofence will just be a signal indicating what the GPS
1054 * subsystem knows about the Geofence.
1055 *
1056 */
1057#define GPS_GEOFENCE_ENTERED (1<<0L)
1058#define GPS_GEOFENCE_EXITED (1<<1L)
1059#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1060
1061#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1062#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1063
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001064#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1065#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1066#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1067#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1068#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1069#define GPS_GEOFENCE_ERROR_GENERIC -149
1070
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001071/**
1072 * The callback associated with the geofence.
1073 * Parameters:
1074 * geofence_id - The id associated with the add_geofence_area.
1075 * location - The current GPS location.
1076 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1077 * GPS_GEOFENCE_UNCERTAIN.
1078 * timestamp - Timestamp when the transition was detected.
1079 *
1080 * The callback should only be called when the caller is interested in that
1081 * particular transition. For instance, if the caller is interested only in
1082 * ENTERED transition, then the callback should NOT be called with the EXITED
1083 * transition.
1084 *
1085 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1086 * subsystem will wake up the application processor, if its in suspend state.
1087 */
1088typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1089 int32_t transition, GpsUtcTime timestamp);
1090
1091/**
destradaa9f7c3732014-04-29 10:50:22 -07001092 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001093 * monitoring. If the GPS system determines that it cannot monitor geofences
1094 * because of lack of reliability or unavailability of the GPS signals, it will
1095 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1096 *
1097 * Parameters:
1098 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1099 * last_location - Last known location.
1100 */
1101typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1102
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001103/**
1104 * The callback associated with the add_geofence call.
1105 *
1106 * Parameter:
1107 * geofence_id - Id of the geofence.
1108 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1109 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1110 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1111 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1112 * invalid transition
1113 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1114 */
1115typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1116
1117/**
1118 * The callback associated with the remove_geofence call.
1119 *
1120 * Parameter:
1121 * geofence_id - Id of the geofence.
1122 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1123 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1124 * GPS_GEOFENCE_ERROR_GENERIC for others.
1125 */
1126typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1127
1128
1129/**
1130 * The callback associated with the pause_geofence call.
1131 *
1132 * Parameter:
1133 * geofence_id - Id of the geofence.
1134 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1135 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1136 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1137 * when monitor_transitions is invalid
1138 * GPS_GEOFENCE_ERROR_GENERIC for others.
1139 */
1140typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1141
1142/**
1143 * The callback associated with the resume_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_resume_callback) (int32_t geofence_id, int32_t status);
1152
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001153typedef struct {
1154 gps_geofence_transition_callback geofence_transition_callback;
1155 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001156 gps_geofence_add_callback geofence_add_callback;
1157 gps_geofence_remove_callback geofence_remove_callback;
1158 gps_geofence_pause_callback geofence_pause_callback;
1159 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001160 gps_create_thread create_thread_cb;
1161} GpsGeofenceCallbacks;
1162
1163/** Extended interface for GPS_Geofencing support */
1164typedef struct {
1165 /** set to sizeof(GpsGeofencingInterface) */
1166 size_t size;
1167
1168 /**
1169 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001170 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001171 */
1172 void (*init)( GpsGeofenceCallbacks* callbacks );
1173
1174 /**
1175 * Add a geofence area. This api currently supports circular geofences.
1176 * Parameters:
1177 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001178 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1179 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001180 * latitude, longtitude, radius_meters - The lat, long and radius
1181 * (in meters) for the geofence
1182 * last_transition - The current state of the geofence. For example, if
1183 * the system already knows that the user is inside the geofence,
1184 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1185 * will be GPS_GEOFENCE_UNCERTAIN.
1186 * monitor_transition - Which transitions to monitor. Bitwise OR of
1187 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1188 * GPS_GEOFENCE_UNCERTAIN.
1189 * notification_responsiveness_ms - Defines the best-effort description
1190 * of how soon should the callback be called when the transition
1191 * associated with the Geofence is triggered. For instance, if set
1192 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1193 * should be called 1000 milliseconds within entering the geofence.
1194 * This parameter is defined in milliseconds.
1195 * NOTE: This is not to be confused with the rate that the GPS is
1196 * polled at. It is acceptable to dynamically vary the rate of
1197 * sampling the GPS for power-saving reasons; thus the rate of
1198 * sampling may be faster or slower than this.
1199 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001200 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001201 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001202 */
destradaa9f7c3732014-04-29 10:50:22 -07001203 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1204 double radius_meters, int last_transition, int monitor_transitions,
1205 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001206
1207 /**
1208 * Pause monitoring a particular geofence.
1209 * Parameters:
1210 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001211 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001212 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001213
1214 /**
1215 * Resume monitoring a particular geofence.
1216 * Parameters:
1217 * geofence_id - The id for the geofence.
1218 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1219 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1220 * GPS_GEOFENCE_UNCERTAIN.
1221 * This supersedes the value associated provided in the
1222 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001223 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001224 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001225
1226 /**
1227 * Remove a geofence area. After the function returns, no notifications
1228 * should be sent.
1229 * Parameter:
1230 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001231 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001232 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001233} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001234
1235
1236/**
1237 * Represents an estimate of the GPS clock time.
1238 */
1239typedef struct {
1240 /** set to sizeof(GpsClock) */
1241 size_t size;
1242
1243 /** A set of flags indicating the validity of the fields in this data structure. */
1244 GpsClockFlags flags;
1245
1246 /**
1247 * Leap second data.
destradaa75843eb2014-07-17 14:04:50 -07001248 * The sign of the value is defined by the following equation:
1249 * utc_time_ns = time_ns + (full_bias_ns + bias_ns) - leap_second * 1,000,000,000
1250 *
destradaa9f7c3732014-04-29 10:50:22 -07001251 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1252 */
1253 int16_t leap_second;
1254
1255 /**
destradaa75843eb2014-07-17 14:04:50 -07001256 * Indicates the type of time reported by the 'time_ns' field.
1257 * This is a Mandatory field.
1258 */
1259 GpsClockType type;
1260
1261 /**
1262 * The GPS receiver internal clock value. This can be either the local hardware clock value
1263 * (GPS_CLOCK_TYPE_LOCAL_HW_TIME), or the current GPS time derived inside GPS receiver
1264 * (GPS_CLOCK_TYPE_GPS_TIME). The field 'type' defines the time reported.
destradaa9f7c3732014-04-29 10:50:22 -07001265 *
destradaa75843eb2014-07-17 14:04:50 -07001266 * For local hardware clock, this value is expected to be monotonically increasing during
1267 * the reporting session. The real GPS time can be derived by compensating the 'full bias'
1268 * (when it is available) from this value.
destradaa9f7c3732014-04-29 10:50:22 -07001269 *
destradaa75843eb2014-07-17 14:04:50 -07001270 * For GPS time, this value is expected to be the best estimation of current GPS time that GPS
1271 * receiver can achieve. Set the 'time uncertainty' appropriately when GPS time is specified.
1272 *
1273 * Sub-nanosecond accuracy can be provided by means of the 'bias' field.
destradaa9f7c3732014-04-29 10:50:22 -07001274 * The value contains the 'time uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001275 *
destradaa9f7c3732014-04-29 10:50:22 -07001276 * This is a Mandatory field.
1277 */
1278 int64_t time_ns;
1279
1280 /**
1281 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1282 * The uncertainty is represented as an absolute (single sided) value.
1283 *
destradaa75843eb2014-07-17 14:04:50 -07001284 * This value should be set if GPS_CLOCK_TYPE_GPS_TIME is set.
destradaa9f7c3732014-04-29 10:50:22 -07001285 * If the data is available 'flags' must contain GPS_CLOCK_HAS_TIME_UNCERTAINTY.
1286 */
1287 double time_uncertainty_ns;
1288
1289 /**
destradaa75843eb2014-07-17 14:04:50 -07001290 * The difference between hardware clock ('time' field) inside GPS receiver and the true GPS
1291 * time since 0000Z, January 6, 1980, in nanoseconds.
1292 * This value is used if and only if GPS_CLOCK_TYPE_LOCAL_HW_TIME is set, and GPS receiver
1293 * has solved the clock for GPS time.
1294 * The caller is responsible for using the 'bias uncertainty' field for quality check.
destradaa9f7c3732014-04-29 10:50:22 -07001295 *
destradaa75843eb2014-07-17 14:04:50 -07001296 * The sign of the value is defined by the following equation:
1297 * true time (GPS time) = time_ns + (full_bias_ns + bias_ns)
1298 *
1299 * This value contains the 'bias uncertainty' in it.
1300 * If the data is available 'flags' must contain GPS_CLOCK_HAS_FULL_BIAS.
1301
1302 */
1303 int64_t full_bias_ns;
1304
1305 /**
1306 * Sub-nanosecond bias.
destradaa9f7c3732014-04-29 10:50:22 -07001307 * The value contains the 'bias uncertainty' in it.
destradaa75843eb2014-07-17 14:04:50 -07001308 *
destradaa9f7c3732014-04-29 10:50:22 -07001309 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS.
1310 */
1311 double bias_ns;
1312
1313 /**
1314 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1315 * The uncertainty is represented as an absolute (single sided) value.
1316 *
1317 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS_UNCERTAINTY.
1318 */
1319 double bias_uncertainty_ns;
1320
1321 /**
1322 * The clock's drift in nanoseconds (per second).
1323 * A positive value means that the frequency is higher than the nominal frequency.
1324 *
1325 * The value contains the 'drift uncertainty' in it.
1326 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
1327 */
1328 double drift_nsps;
1329
1330 /**
1331 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1332 * The uncertainty is represented as an absolute (single sided) value.
1333 *
1334 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT_UNCERTAINTY.
1335 */
1336 double drift_uncertainty_nsps;
1337} GpsClock;
1338
1339/**
1340 * Represents a GPS Measurement, it contains raw and computed information.
1341 */
1342typedef struct {
1343 /** set to sizeof(GpsMeasurement) */
1344 size_t size;
1345
1346 /** A set of flags indicating the validity of the fields in this data structure. */
1347 GpsMeasurementFlags flags;
1348
1349 /**
1350 * Pseudo-random number in the range of [1, 32]
1351 * This is a Mandatory value.
1352 */
1353 int8_t prn;
1354
1355 /**
destradaa75843eb2014-07-17 14:04:50 -07001356 * Time offset at which the measurement was taken in nanoseconds.
1357 * The reference receiver's time is specified by GpsData::clock::time_ns and should be
1358 * interpreted in the same way as indicated by GpsClock::type.
1359 *
destradaa9f7c3732014-04-29 10:50:22 -07001360 * The sign of time_offset_ns is given by the following equation:
1361 * measurement time = GpsClock::time_ns + time_offset_ns
1362 *
1363 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1364 * This is a Mandatory value.
1365 */
destradaa75843eb2014-07-17 14:04:50 -07001366 double time_offset_ns;
destradaa9f7c3732014-04-29 10:50:22 -07001367
1368 /**
destradaa75843eb2014-07-17 14:04:50 -07001369 * Per satellite sync state. It represents the current sync state for the associated satellite.
1370 * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly.
destradaa9f7c3732014-04-29 10:50:22 -07001371 *
1372 * This is a Mandatory value.
1373 */
destradaa75843eb2014-07-17 14:04:50 -07001374 GpsMeasurementState state;
1375
1376 /**
1377 * Received GPS Time-of-Week at the measurement time, in nanoseconds.
1378 * The value is relative to the beginning of the current GPS week.
1379 *
1380 * Given the sync state of GPS receiver, per each satellite, valid range for this field can be:
1381 * Searching : [ 0 ] : GPS_MEASUREMENT_STATE_UNKNOWN
1382 * Ranging code lock : [ 0 1ms ] : GPS_MEASUREMENT_STATE_CODE_LOCK is set
1383 * Bit sync : [ 0 20ms ] : GPS_MEASUREMENT_STATE_BIT_SYNC is set
1384 * Subframe sync : [ 0 6ms ] : GPS_MEASUREMENT_STATE_SUBFRAME_SYNC is set
1385 * TOW decoded : [ 0 1week ] : GPS_MEASUREMENT_STATE_TOW_DECODED is set
1386 */
destradaa9f7c3732014-04-29 10:50:22 -07001387 int64_t received_gps_tow_ns;
1388
1389 /**
destradaa941c9282014-07-21 18:13:42 -07001390 * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds.
1391 */
1392 int64_t received_gps_tow_uncertainty_ns;
1393
1394 /**
destradaa9f7c3732014-04-29 10:50:22 -07001395 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1396 * It contains the measured C/N0 value for the signal at the antenna input.
1397 *
1398 * This is a Mandatory value.
1399 */
1400 double c_n0_dbhz;
1401
1402 /**
1403 * Pseudorange rate at the timestamp in m/s.
1404 * The value also includes the effects of the receiver clock frequency and satellite clock
1405 * frequency errors.
1406 *
1407 * The value includes the 'pseudorange rate uncertainty' in it.
1408 * A positive value indicates that the pseudorange is getting larger.
1409 *
1410 * This is a Mandatory value.
1411 */
destradaa75843eb2014-07-17 14:04:50 -07001412 double pseudorange_rate_mps;
destradaa9f7c3732014-04-29 10:50:22 -07001413
1414 /**
1415 * 1-Sigma uncertainty of the pseudurange rate in m/s.
1416 * The uncertainty is represented as an absolute (single sided) value.
1417 *
1418 * This is a Mandatory value.
1419 */
destradaa75843eb2014-07-17 14:04:50 -07001420 double pseudorange_rate_uncertainty_mps;
1421
1422 /**
1423 * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip
1424 * (indicating loss of lock).
1425 *
1426 * This is a Mandatory value.
1427 */
1428 GpsAccumulatedDeltaRangeState accumulated_delta_range_state;
destradaa9f7c3732014-04-29 10:50:22 -07001429
1430 /**
1431 * Accumulated delta range since the last channel reset in meters.
destradaa75843eb2014-07-17 14:04:50 -07001432 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001433 */
1434 double accumulated_delta_range_m;
1435
1436 /**
1437 * 1-Sigma uncertainty of the accumulated delta range in meters.
destradaa75843eb2014-07-17 14:04:50 -07001438 * The data is available if 'accumulated delta range state' != GPS_ADR_STATE_UNKNOWN.
destradaa9f7c3732014-04-29 10:50:22 -07001439 */
1440 double accumulated_delta_range_uncertainty_m;
1441
1442 /**
1443 * Best derived Pseudorange by the chip-set, in meters.
1444 * The value contains the 'pseudorange uncertainty' in it.
1445 *
1446 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1447 */
1448 double pseudorange_m;
1449
1450 /**
1451 * 1-Sigma uncertainty of the pseudorange in meters.
1452 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1453 * The uncertainty is represented as an absolute (single sided) value.
1454 *
1455 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1456 */
1457 double pseudorange_uncertainty_m;
1458
1459 /**
1460 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1461 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1462 *
1463 * The reference frequency is given by the field 'carrier_frequency_hz'.
1464 * The value contains the 'code-phase uncertainty' in it.
1465 *
1466 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1467 */
1468 double code_phase_chips;
1469
1470 /**
1471 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1472 * The uncertainty is represented as an absolute (single sided) value.
1473 *
1474 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1475 */
1476 double code_phase_uncertainty_chips;
1477
1478 /**
1479 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1480 * If the field is not set, the carrier frequency is assumed to be L1.
1481 *
1482 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1483 */
1484 float carrier_frequency_hz;
1485
1486 /**
1487 * The number of full carrier cycles between the satellite and the receiver.
1488 * The reference frequency is given by the field 'carrier_frequency_hz'.
1489 *
1490 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1491 */
1492 int64_t carrier_cycles;
1493
1494 /**
1495 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1496 * This is usually the fractional part of the complete carrier phase measurement.
1497 *
1498 * The reference frequency is given by the field 'carrier_frequency_hz'.
1499 * The value contains the 'carrier-phase uncertainty' in it.
1500 *
1501 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1502 */
1503 double carrier_phase;
1504
1505 /**
1506 * 1-Sigma uncertainty of the carrier-phase.
1507 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1508 */
1509 double carrier_phase_uncertainty;
1510
1511 /**
1512 * An enumeration that indicates the 'loss of lock' state of the event.
1513 */
1514 GpsLossOfLock loss_of_lock;
1515
1516 /**
1517 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1518 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1519 */
1520 int16_t bit_number;
1521
1522 /**
destradaa75843eb2014-07-17 14:04:50 -07001523 * The elapsed time since the last received bit in milliseconds, in the range [0, 20]
destradaa9f7c3732014-04-29 10:50:22 -07001524 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1525 */
destradaa75843eb2014-07-17 14:04:50 -07001526 int16_t time_from_last_bit_ms;
destradaa9f7c3732014-04-29 10:50:22 -07001527
1528 /**
1529 * Doppler shift in Hz.
1530 * A positive value indicates that the SV is moving toward the receiver.
1531 *
1532 * The reference frequency is given by the field 'carrier_frequency_hz'.
1533 * The value contains the 'doppler shift uncertainty' in it.
1534 *
1535 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1536 */
1537 double doppler_shift_hz;
1538
1539 /**
1540 * 1-Sigma uncertainty of the doppler shift in Hz.
1541 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1542 */
1543 double doppler_shift_uncertainty_hz;
1544
1545 /**
1546 * An enumeration that indicates the 'multipath' state of the event.
1547 */
1548 GpsMultipathIndicator multipath_indicator;
1549
1550 /**
1551 * Signal-to-noise ratio in dB.
1552 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1553 */
1554 double snr_db;
1555
1556 /**
1557 * Elevation in degrees, the valid range is [-90, 90].
1558 * The value contains the 'elevation uncertainty' in it.
1559 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1560 */
1561 double elevation_deg;
1562
1563 /**
1564 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1565 * The uncertainty is represented as the absolute (single sided) value.
1566 *
1567 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1568 */
1569 double elevation_uncertainty_deg;
1570
1571 /**
1572 * Azimuth in degrees, in the range [0, 360).
1573 * The value contains the 'azimuth uncertainty' in it.
1574 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
1575 * */
1576 double azimuth_deg;
1577
1578 /**
1579 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1580 * The uncertainty is represented as an absolute (single sided) value.
1581 *
1582 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1583 */
1584 double azimuth_uncertainty_deg;
1585
1586 /**
1587 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1588 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1589 */
1590 bool used_in_fix;
1591} GpsMeasurement;
1592
1593/** Represents a reading of GPS measurements. */
1594typedef struct {
1595 /** set to sizeof(GpsData) */
1596 size_t size;
1597
1598 /** Number of measurements. */
1599 size_t measurement_count;
1600
1601 /** The array of measurements. */
1602 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1603
1604 /** The GPS clock time reading. */
1605 GpsClock clock;
1606} GpsData;
1607
1608/**
1609 * The callback for to report measurements from the HAL.
1610 *
1611 * Parameters:
1612 * data - A data structure containing the measurements.
1613 */
1614typedef void (*gps_measurement_callback) (GpsData* data);
1615
1616typedef struct {
1617 /** set to sizeof(GpsMeasurementCallbacks) */
1618 size_t size;
1619 gps_measurement_callback measurement_callback;
1620} GpsMeasurementCallbacks;
1621
1622#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1623#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1624#define GPS_MEASUREMENT_ERROR_GENERIC -101
1625
1626/**
1627 * Extended interface for GPS Measurements support.
1628 */
1629typedef struct {
1630 /** Set to sizeof(GpsMeasurementInterface) */
1631 size_t size;
1632
1633 /**
1634 * Initializes the interface and registers the callback routines with the HAL.
1635 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1636 *
1637 * Status:
1638 * GPS_MEASUREMENT_OPERATION_SUCCESS
1639 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1640 * corresponding call to 'close'
1641 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1642 * will not generate any updates upon returning this error code.
1643 */
1644 int (*init) (GpsMeasurementCallbacks* callbacks);
1645
1646 /**
1647 * Stops updates from the HAL, and unregisters the callback routines.
1648 * After a call to stop, the previously registered callbacks must be considered invalid by the
1649 * HAL.
1650 * If stop is invoked without a previous 'init', this function should perform no work.
1651 */
1652 void (*close) ();
1653
1654} GpsMeasurementInterface;
1655
1656
1657/** Represents a GPS navigation message (or a fragment of it). */
1658typedef struct {
1659 /** set to sizeof(GpsNavigationMessage) */
1660 size_t size;
1661
1662 /**
1663 * Pseudo-random number in the range of [1, 32]
1664 * This is a Mandatory value.
1665 */
1666 int8_t prn;
1667
1668 /**
1669 * The type of message contained in the structure.
1670 * This is a Mandatory value.
1671 */
1672 GpsNavigationMessageType type;
1673
1674 /**
1675 * Message identifier.
destradaa75843eb2014-07-17 14:04:50 -07001676 * It provides an index so the complete Navigation Message can be assembled. i.e. fo L1 C/A
1677 * subframe 4 and 5, this value corresponds to the 'frame id' of the navigation message.
1678 * Subframe 1, 2, 3 does not contain a 'frame id' and this value can be set to -1.
destradaa9f7c3732014-04-29 10:50:22 -07001679 */
1680 int16_t message_id;
1681
1682 /**
1683 * Sub-message identifier.
1684 * If required by the message 'type', this value contains a sub-index within the current
1685 * message (or frame) that is being transmitted.
1686 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1687 */
1688 int16_t submessage_id;
1689
1690 /**
1691 * The length of the data (in bytes) contained in the current message.
1692 * If this value is different from zero, 'data' must point to an array of the same size.
1693 * i.e. for L1 C/A the size of the sub-frame will be 40 bytes (10 words).
1694 *
1695 * This is a Mandatory value.
1696 */
1697 size_t data_length;
1698
1699 /**
1700 * The data of the reported GPS message.
1701 * The bytes (or words) specified using big endian format (MSB first).
1702 */
1703 uint8_t* data;
1704
1705} GpsNavigationMessage;
1706
1707/**
1708 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1709 *
1710 * Parameters:
1711 * message - The GPS navigation submessage/subframe representation.
1712 */
1713typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1714
1715typedef struct {
1716 /** set to sizeof(GpsNavigationMessageCallbacks) */
1717 size_t size;
1718 gps_navigation_message_callback navigation_message_callback;
1719} GpsNavigationMessageCallbacks;
1720
1721#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
1722#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
1723#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
1724
1725/**
1726 * Extended interface for GPS navigation message reporting support.
1727 */
1728typedef struct {
1729 /** Set to sizeof(GpsNavigationMessageInterface) */
1730 size_t size;
1731
1732 /**
1733 * Initializes the interface and registers the callback routines with the HAL.
1734 * After a successful call to 'init' the HAL must begin to provide updates as they become
1735 * available.
1736 *
1737 * Status:
1738 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
1739 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
1740 * without a corresponding call to 'close'.
1741 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
1742 * the HAL will not generate any updates upon returning this error code.
1743 */
1744 int (*init) (GpsNavigationMessageCallbacks* callbacks);
1745
1746 /**
1747 * Stops updates from the HAL, and unregisters the callback routines.
1748 * After a call to stop, the previously registered callbacks must be considered invalid by the
1749 * HAL.
1750 * If stop is invoked without a previous 'init', this function should perform no work.
1751 */
1752 void (*close) ();
1753
1754} GpsNavigationMessageInterface;
1755
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001756__END_DECLS
1757
1758#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1759