blob: 3cb006b99bda912f4efc6b878495d6a7709e690c [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)
227/** A valid 'bias' is stored in the data structure. */
228#define GPS_CLOCK_HAS_BIAS (1<<2)
229/** A valid 'bias uncertainty' is stored in the data structure. */
230#define GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<3)
231/** A valid 'drift' is stored in the data structure. */
232#define GPS_CLOCK_HAS_DRIFT (1<<4)
233/** A valid 'drift uncertainty' is stored in the data structure. */
234#define GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<5)
235
236/**
237 * Flags to indicate what fields in GpsMeasurement are valid.
238 */
239typedef uint32_t GpsMeasurementFlags;
240/** A valid 'snr' is stored in the data structure. */
241#define GPS_MEASUREMENT_HAS_SNR (1<<0)
242/** A valid 'elevation' is stored in the data structure. */
243#define GPS_MEASUREMENT_HAS_ELEVATION (1<<1)
244/** A valid 'elevation uncertainty' is stored in the data structure. */
245#define GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2)
246/** A valid 'azimuth' is stored in the data structure. */
247#define GPS_MEASUREMENT_HAS_AZIMUTH (1<<3)
248/** A valid 'azimuth uncertainty' is stored in the data structure. */
249#define GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4)
250/** A valid 'pseudorange' is stored in the data structure. */
251#define GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5)
252/** A valid 'pseudorange uncertainty' is stored in the data structure. */
253#define GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6)
254/** A valid 'code phase' is stored in the data structure. */
255#define GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7)
256/** A valid 'code phase uncertainty' is stored in the data structure. */
257#define GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8)
258/** A valid 'carrier frequency' is stored in the data structure. */
259#define GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9)
260/** A valid 'carrier cycles' is stored in the data structure. */
261#define GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10)
262/** A valid 'carrier phase' is stored in the data structure. */
263#define GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11)
264/** A valid 'carrier phase uncertainty' is stored in the data structure. */
265#define GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12)
266/** A valid 'bit number' is stored in the data structure. */
267#define GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13)
268/** A valid 'time from last bit' is stored in the data structure. */
269#define GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14)
270/** A valid 'doppler shift' is stored in the data structure. */
271#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15)
272/** A valid 'doppler shift uncertainty' is stored in the data structure. */
273#define GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16)
274/** A valid 'used in fix' flag is stored in the data structure. */
275#define GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17)
276
277/**
278 * Flags that indicate the available values for the GPS Measurement's loss of lock.
279 */
280typedef uint8_t GpsLossOfLock;
281/** The indicator is not available or it is unknown. */
282#define GPS_LOSS_OF_LOCK_UNKNOWN 0
283/** The measurement does not present any indication of loss of lock. */
284#define GPS_LOSS_OF_LOCK_OK 1
285/** Loss of lock between previous and current observation: cycle slip possible. */
286#define GPS_LOSS_OF_LOCK_CYCLE_SLIP 2
287
288/**
289 * Flags that indicate the available values for the GPS Measurement's multipath indicator.
290 */
291typedef uint8_t GpsMultipathIndicator;
292/** The indicator is not available or unknown. */
293#define GPS_MULTIPATH_INDICATOR_UNKNOWN 0
294/** The measurement has been indicated to use multipath. */
295#define GPS_MULTIPATH_INDICATOR_DETECTED 1
296/** The measurement has been indicated Not to use multipath. */
297#define GPS_MULTIPATH_INDICATOR_NOT_USED 2
298
299/**
300 * Flags to indicate the available GPS Natigation message types.
301 */
302typedef uint8_t GpsNavigationMessageType;
303/** The message type is unknown. */
304#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0
305/** L1 C/A message contained in the structure. */
306#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1
307/** L2-CNAV message contained in the structure. */
308#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2
309/** L5-CNAV message contained in the structure. */
310#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3
311/** CNAV-2 message contained in the structure. */
312#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4
313
314
315/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500316 * Name for the GPS XTRA interface.
317 */
318#define GPS_XTRA_INTERFACE "gps-xtra"
319
320/**
321 * Name for the GPS DEBUG interface.
322 */
323#define GPS_DEBUG_INTERFACE "gps-debug"
324
325/**
326 * Name for the AGPS interface.
327 */
328#define AGPS_INTERFACE "agps"
329
330/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700331 * Name of the Supl Certificate interface.
332 */
333#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
334
335/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500336 * Name for NI interface
337 */
338#define GPS_NI_INTERFACE "gps-ni"
339
Miguel Torroja5f404f52010-07-27 06:34:15 +0200340/**
341 * Name for the AGPS-RIL interface.
342 */
343#define AGPS_RIL_INTERFACE "agps_ril"
344
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800345/**
346 * Name for the GPS_Geofencing interface.
347 */
348#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
349
destradaa9f7c3732014-04-29 10:50:22 -0700350/**
351 * Name of the GPS Measurements interface.
352 */
353#define GPS_MEASUREMENT_INTERFACE "gps_measurement"
354
355/**
356 * Name of the GPS navigation message interface.
357 */
358 #define GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message"
359
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800360
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500361/** Represents a location. */
362typedef struct {
363 /** set to sizeof(GpsLocation) */
364 size_t size;
365 /** Contains GpsLocationFlags bits. */
366 uint16_t flags;
367 /** Represents latitude in degrees. */
368 double latitude;
369 /** Represents longitude in degrees. */
370 double longitude;
371 /** Represents altitude in meters above the WGS 84 reference
372 * ellipsoid. */
373 double altitude;
374 /** Represents speed in meters per second. */
375 float speed;
376 /** Represents heading in degrees. */
377 float bearing;
378 /** Represents expected accuracy in meters. */
379 float accuracy;
380 /** Timestamp for the location fix. */
381 GpsUtcTime timestamp;
382} GpsLocation;
383
384/** Represents the status. */
385typedef struct {
386 /** set to sizeof(GpsStatus) */
387 size_t size;
388 GpsStatusValue status;
389} GpsStatus;
390
391/** Represents SV information. */
392typedef struct {
393 /** set to sizeof(GpsSvInfo) */
394 size_t size;
395 /** Pseudo-random number for the SV. */
396 int prn;
397 /** Signal to noise ratio. */
398 float snr;
399 /** Elevation of SV in degrees. */
400 float elevation;
401 /** Azimuth of SV in degrees. */
402 float azimuth;
403} GpsSvInfo;
404
405/** Represents SV status. */
406typedef struct {
407 /** set to sizeof(GpsSvStatus) */
408 size_t size;
409
410 /** Number of SVs currently visible. */
411 int num_svs;
412
413 /** Contains an array of SV information. */
414 GpsSvInfo sv_list[GPS_MAX_SVS];
415
416 /** Represents a bit mask indicating which SVs
417 * have ephemeris data.
418 */
419 uint32_t ephemeris_mask;
420
421 /** Represents a bit mask indicating which SVs
422 * have almanac data.
423 */
424 uint32_t almanac_mask;
425
426 /**
427 * Represents a bit mask indicating which SVs
428 * were used for computing the most recent position fix.
429 */
430 uint32_t used_in_fix_mask;
431} GpsSvStatus;
432
destradaa9f7c3732014-04-29 10:50:22 -0700433
Miguel Torroja5f404f52010-07-27 06:34:15 +0200434/* 2G and 3G */
435/* In 3G lac is discarded */
436typedef struct {
437 uint16_t type;
438 uint16_t mcc;
439 uint16_t mnc;
440 uint16_t lac;
441 uint32_t cid;
442} AGpsRefLocationCellID;
443
444typedef struct {
445 uint8_t mac[6];
446} AGpsRefLocationMac;
447
448/** Represents ref locations */
449typedef struct {
450 uint16_t type;
451 union {
452 AGpsRefLocationCellID cellID;
453 AGpsRefLocationMac mac;
454 } u;
455} AGpsRefLocation;
456
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700457/** Callback with location information.
458 * Can only be called from a thread created by create_thread_cb.
459 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500460typedef void (* gps_location_callback)(GpsLocation* location);
461
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700462/** Callback with status information.
463 * Can only be called from a thread created by create_thread_cb.
464 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500465typedef void (* gps_status_callback)(GpsStatus* status);
466
destradaa9f7c3732014-04-29 10:50:22 -0700467/**
468 * Callback with SV status information.
469 * Can only be called from a thread created by create_thread_cb.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700470 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500471typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
472
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700473/** Callback for reporting NMEA sentences.
474 * Can only be called from a thread created by create_thread_cb.
475 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500476typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
477
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400478/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700479 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
480 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400481typedef void (* gps_set_capabilities)(uint32_t capabilities);
482
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400483/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700484 * This can be used to prevent the CPU from suspending while handling GPS events.
485 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400486typedef void (* gps_acquire_wakelock)();
487
488/** Callback utility for releasing the GPS wakelock. */
489typedef void (* gps_release_wakelock)();
490
Mike Lockwood8aac5912011-06-29 15:10:36 -0400491/** Callback for requesting NTP time */
492typedef void (* gps_request_utc_time)();
493
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700494/** Callback for creating a thread that can call into the Java framework code.
495 * This must be used to create any threads that report events up to the framework.
496 */
497typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
498
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500499/** GPS callback structure. */
500typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400501 /** set to sizeof(GpsCallbacks) */
502 size_t size;
503 gps_location_callback location_cb;
504 gps_status_callback status_cb;
505 gps_sv_status_callback sv_status_cb;
506 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400507 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400508 gps_acquire_wakelock acquire_wakelock_cb;
509 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700510 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400511 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500512} GpsCallbacks;
513
514
515/** Represents the standard GPS interface. */
516typedef struct {
517 /** set to sizeof(GpsInterface) */
518 size_t size;
519 /**
520 * Opens the interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700521 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500522 */
523 int (*init)( GpsCallbacks* callbacks );
524
525 /** Starts navigating. */
526 int (*start)( void );
527
528 /** Stops navigating. */
529 int (*stop)( void );
530
531 /** Closes the interface. */
532 void (*cleanup)( void );
533
534 /** Injects the current time. */
535 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
536 int uncertainty);
537
538 /** Injects current location from another location provider
539 * (typically cell ID).
540 * latitude and longitude are measured in degrees
541 * expected accuracy is measured in meters
542 */
543 int (*inject_location)(double latitude, double longitude, float accuracy);
544
545 /**
546 * Specifies that the next call to start will not use the
547 * information defined in the flags. GPS_DELETE_ALL is passed for
548 * a cold start.
549 */
550 void (*delete_aiding_data)(GpsAidingData flags);
551
552 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400553 * min_interval represents the time between fixes in milliseconds.
554 * preferred_accuracy represents the requested fix accuracy in meters.
555 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500556 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400557 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
558 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500559
560 /** Get a pointer to extension information. */
561 const void* (*get_extension)(const char* name);
562} GpsInterface;
563
564/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700565 * The client should download XTRA data and inject it by calling inject_xtra_data().
566 * Can only be called from a thread created by create_thread_cb.
567 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500568typedef void (* gps_xtra_download_request)();
569
570/** Callback structure for the XTRA interface. */
571typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700572 gps_xtra_download_request download_request_cb;
573 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500574} GpsXtraCallbacks;
575
576/** Extended interface for XTRA support. */
577typedef struct {
578 /** set to sizeof(GpsXtraInterface) */
579 size_t size;
580 /**
581 * Opens the XTRA interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700582 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500583 */
584 int (*init)( GpsXtraCallbacks* callbacks );
585 /** Injects XTRA data into the GPS. */
586 int (*inject_xtra_data)( char* data, int length );
587} GpsXtraInterface;
588
589/** Extended interface for DEBUG support. */
590typedef struct {
591 /** set to sizeof(GpsDebugInterface) */
592 size_t size;
593
594 /**
595 * This function should return any information that the native
596 * implementation wishes to include in a bugreport.
597 */
598 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
599} GpsDebugInterface;
600
601/** Represents the status of AGPS. */
602typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700603 /** set to sizeof(AGpsStatus_v1) */
604 size_t size;
605
606 AGpsType type;
607 AGpsStatusValue status;
608} AGpsStatus_v1;
609
610/** Represents the status of AGPS augmented with a IPv4 address field. */
611typedef struct {
612 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500613 size_t size;
614
615 AGpsType type;
616 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800617 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700618} AGpsStatus_v2;
619
620/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
621typedef struct {
622 /** set to sizeof(AGpsStatus_v3) */
623 size_t size;
624
625 AGpsType type;
626 AGpsStatusValue status;
627
628 /**
629 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
630 * address, or set to INADDR_NONE otherwise.
631 */
632 uint32_t ipaddr;
633
634 /**
635 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
636 * Any other value of addr.ss_family will be rejected.
637 * */
638 struct sockaddr_storage addr;
639} AGpsStatus_v3;
640
641typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500642
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700643/** Callback with AGPS status information.
644 * Can only be called from a thread created by create_thread_cb.
645 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500646typedef void (* agps_status_callback)(AGpsStatus* status);
647
648/** Callback structure for the AGPS interface. */
649typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700650 agps_status_callback status_cb;
651 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500652} AGpsCallbacks;
653
654
655/** Extended interface for AGPS support. */
656typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700657 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500658 size_t size;
659
660 /**
661 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700662 * to the implementation of this interface.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500663 */
664 void (*init)( AGpsCallbacks* callbacks );
665 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700666 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500667 * the name of the APN to be used for SUPL.
668 */
669 int (*data_conn_open)( const char* apn );
670 /**
671 * Notifies that the AGPS data connection has been closed.
672 */
673 int (*data_conn_closed)();
674 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700675 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500676 */
677 int (*data_conn_failed)();
678 /**
679 * Sets the hostname and port for the AGPS server.
680 */
681 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700682} AGpsInterface_v1;
683
684/**
685 * Extended interface for AGPS support, it is augmented to enable to pass
686 * extra APN data.
687 */
688typedef struct {
689 /** set to sizeof(AGpsInterface_v2) */
690 size_t size;
691
692 /**
693 * Opens the AGPS interface and provides the callback routines to the
694 * implementation of this interface.
695 */
696 void (*init)(AGpsCallbacks* callbacks);
697 /**
698 * Deprecated.
699 * If the HAL supports AGpsInterface_v2 this API will not be used, see
700 * data_conn_open_with_apn_ip_type for more information.
701 */
702 int (*data_conn_open)(const char* apn);
703 /**
704 * Notifies that the AGPS data connection has been closed.
705 */
706 int (*data_conn_closed)();
707 /**
708 * Notifies that a data connection is not available for AGPS.
709 */
710 int (*data_conn_failed)();
711 /**
712 * Sets the hostname and port for the AGPS server.
713 */
714 int (*set_server)(AGpsType type, const char* hostname, int port);
715
716 /**
717 * Notifies that a data connection is available and sets the name of the
718 * APN, and its IP type, to be used for SUPL connections.
719 */
720 int (*data_conn_open_with_apn_ip_type)(
721 const char* apn,
722 ApnIpType apnIpType);
723} AGpsInterface_v2;
724
725typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500726
destradaaa1f4c0a2013-09-13 15:45:03 -0700727/** Error codes associated with certificate operations */
728#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
729#define AGPS_CERTIFICATE_ERROR_GENERIC -100
730#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
731
732/** A data structure that represents an X.509 certificate using DER encoding */
733typedef struct {
734 size_t length;
735 u_char* data;
736} DerEncodedCertificate;
737
738/**
739 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
740 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
741 */
742typedef struct {
743 u_char data[20];
744} Sha1CertificateFingerprint;
745
destradaa9f7c3732014-04-29 10:50:22 -0700746/** AGPS Interface to handle SUPL certificate operations */
destradaaa1f4c0a2013-09-13 15:45:03 -0700747typedef struct {
748 /** set to sizeof(SuplCertificateInterface) */
749 size_t size;
750
751 /**
752 * Installs a set of Certificates used for SUPL connections to the AGPS server.
753 * If needed the HAL should find out internally any certificates that need to be removed to
754 * accommodate the certificates to install.
755 * The certificates installed represent a full set of valid certificates needed to connect to
756 * AGPS SUPL servers.
757 * The list of certificates is required, and all must be available at the same time, when trying
758 * to establish a connection with the AGPS Server.
759 *
760 * Parameters:
761 * certificates - A pointer to an array of DER encoded certificates that are need to be
762 * installed in the HAL.
763 * length - The number of certificates to install.
764 * Returns:
765 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
766 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
767 * certificates attempted to be installed, the state of the certificates stored should
768 * remain the same as before on this error case.
769 *
770 * IMPORTANT:
771 * If needed the HAL should find out internally the set of certificates that need to be
772 * removed to accommodate the certificates to install.
773 */
774 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
775
776 /**
777 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
778 * expected that the given set of certificates is removed from the internal store of the HAL.
779 *
780 * Parameters:
781 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
782 * certificates to revoke.
783 * length - The number of fingerprints provided.
784 * Returns:
785 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
786 *
787 * IMPORTANT:
788 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
789 * it should be ignored and continue revoking/deleting the rest of them.
790 */
791 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800792} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500793
794/** Represents an NI request */
795typedef struct {
796 /** set to sizeof(GpsNiNotification) */
797 size_t size;
798
799 /**
800 * An ID generated by HAL to associate NI notifications and UI
801 * responses
802 */
803 int notification_id;
804
805 /**
806 * An NI type used to distinguish different categories of NI
807 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
808 */
809 GpsNiType ni_type;
810
811 /**
812 * Notification/verification options, combinations of GpsNiNotifyFlags constants
813 */
814 GpsNiNotifyFlags notify_flags;
815
816 /**
817 * Timeout period to wait for user response.
818 * Set to 0 for no time out limit.
819 */
820 int timeout;
821
822 /**
823 * Default response when time out.
824 */
825 GpsUserResponseType default_response;
826
827 /**
828 * Requestor ID
829 */
830 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
831
832 /**
833 * Notification message. It can also be used to store client_id in some cases
834 */
835 char text[GPS_NI_LONG_STRING_MAXLEN];
836
837 /**
838 * Client name decoding scheme
839 */
840 GpsNiEncodingType requestor_id_encoding;
841
842 /**
843 * Client name decoding scheme
844 */
845 GpsNiEncodingType text_encoding;
846
847 /**
848 * A pointer to extra data. Format:
849 * key_1 = value_1
850 * key_2 = value_2
851 */
852 char extras[GPS_NI_LONG_STRING_MAXLEN];
853
854} GpsNiNotification;
855
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700856/** Callback with NI notification.
857 * Can only be called from a thread created by create_thread_cb.
858 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500859typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
860
861/** GPS NI callback structure. */
862typedef struct
863{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700864 /**
865 * Sends the notification request from HAL to GPSLocationProvider.
866 */
867 gps_ni_notify_callback notify_cb;
868 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500869} GpsNiCallbacks;
870
871/**
872 * Extended interface for Network-initiated (NI) support.
873 */
874typedef struct
875{
876 /** set to sizeof(GpsNiInterface) */
877 size_t size;
878
879 /** Registers the callbacks for HAL to use. */
880 void (*init) (GpsNiCallbacks *callbacks);
881
882 /** Sends a response to HAL. */
883 void (*respond) (int notif_id, GpsUserResponseType user_response);
884} GpsNiInterface;
885
886struct gps_device_t {
887 struct hw_device_t common;
888
889 /**
890 * Set the provided lights to the provided values.
891 *
892 * Returns: 0 on succes, error code on failure.
893 */
894 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
895};
896
Miguel Torroja5f404f52010-07-27 06:34:15 +0200897#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
898#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
899
900#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
901#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
902
903typedef void (*agps_ril_request_set_id)(uint32_t flags);
904typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
905
906typedef struct {
907 agps_ril_request_set_id request_setid;
908 agps_ril_request_ref_loc request_refloc;
909 gps_create_thread create_thread_cb;
910} AGpsRilCallbacks;
911
912/** Extended interface for AGPS_RIL support. */
913typedef struct {
914 /** set to sizeof(AGpsRilInterface) */
915 size_t size;
916 /**
917 * Opens the AGPS interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -0700918 * to the implementation of this interface.
Miguel Torroja5f404f52010-07-27 06:34:15 +0200919 */
920 void (*init)( AGpsRilCallbacks* callbacks );
921
922 /**
923 * Sets the reference location.
924 */
925 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
926 /**
927 * Sets the set ID.
928 */
929 void (*set_set_id) (AGpsSetIDType type, const char* setid);
930
931 /**
932 * Send network initiated message.
933 */
934 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -0400935
936 /**
937 * Notify GPS of network status changes.
938 * These parameters match values in the android.net.NetworkInfo class.
939 */
940 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -0700941
942 /**
943 * Notify GPS of network status changes.
944 * These parameters match values in the android.net.NetworkInfo class.
945 */
946 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +0200947} AGpsRilInterface;
948
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800949/**
950 * GPS Geofence.
951 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
952 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
953 *
954 * An example state diagram with confidence level: 95% and Unknown time limit
955 * set as 30 secs is shown below. (confidence level and Unknown time limit are
956 * explained latter)
957 * ____________________________
958 * | Unknown (30 secs) |
959 * """"""""""""""""""""""""""""
960 * ^ | | ^
961 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
962 * | v v |
963 * ________ EXITED _________
964 * | Inside | -----------> | Outside |
965 * | | <----------- | |
966 * """""""" ENTERED """""""""
967 *
968 * Inside state: We are 95% confident that the user is inside the geofence.
969 * Outside state: We are 95% confident that the user is outside the geofence
970 * Unknown state: Rest of the time.
971 *
972 * The Unknown state is better explained with an example:
973 *
974 * __________
975 * | c|
976 * | ___ | _______
977 * | |a| | | b |
978 * | """ | """""""
979 * | |
980 * """"""""""
981 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
982 * circle reported by the GPS subsystem. Now with regard to "b", the system is
983 * confident that the user is outside. But with regard to "a" is not confident
984 * whether it is inside or outside the geofence. If the accuracy remains the
985 * same for a sufficient period of time, the UNCERTAIN transition would be
986 * triggered with the state set to Unknown. If the accuracy improves later, an
987 * appropriate transition should be triggered. This "sufficient period of time"
988 * is defined by the parameter in the add_geofence_area API.
989 * In other words, Unknown state can be interpreted as a state in which the
990 * GPS subsystem isn't confident enough that the user is either inside or
991 * outside the Geofence. It moves to Unknown state only after the expiry of the
992 * timeout.
993 *
994 * The geofence callback needs to be triggered for the ENTERED and EXITED
995 * transitions, when the GPS system is confident that the user has entered
996 * (Inside state) or exited (Outside state) the Geofence. An implementation
997 * which uses a value of 95% as the confidence is recommended. The callback
998 * should be triggered only for the transitions requested by the
999 * add_geofence_area call.
1000 *
1001 * Even though the diagram and explanation talks about states and transitions,
1002 * the callee is only interested in the transistions. The states are mentioned
1003 * here for illustrative purposes.
1004 *
1005 * Startup Scenario: When the device boots up, if an application adds geofences,
1006 * and then we get an accurate GPS location fix, it needs to trigger the
1007 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
1008 * By default, all the Geofences will be in the Unknown state.
1009 *
1010 * When the GPS system is unavailable, gps_geofence_status_callback should be
1011 * called to inform the upper layers of the same. Similarly, when it becomes
1012 * available the callback should be called. This is a global state while the
1013 * UNKNOWN transition described above is per geofence.
1014 *
1015 * An important aspect to note is that users of this API (framework), will use
1016 * other subsystems like wifi, sensors, cell to handle Unknown case and
1017 * hopefully provide a definitive state transition to the third party
1018 * application. GPS Geofence will just be a signal indicating what the GPS
1019 * subsystem knows about the Geofence.
1020 *
1021 */
1022#define GPS_GEOFENCE_ENTERED (1<<0L)
1023#define GPS_GEOFENCE_EXITED (1<<1L)
1024#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
1025
1026#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
1027#define GPS_GEOFENCE_AVAILABLE (1<<1L)
1028
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001029#define GPS_GEOFENCE_OPERATION_SUCCESS 0
1030#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
1031#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
1032#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
1033#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
1034#define GPS_GEOFENCE_ERROR_GENERIC -149
1035
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001036/**
1037 * The callback associated with the geofence.
1038 * Parameters:
1039 * geofence_id - The id associated with the add_geofence_area.
1040 * location - The current GPS location.
1041 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
1042 * GPS_GEOFENCE_UNCERTAIN.
1043 * timestamp - Timestamp when the transition was detected.
1044 *
1045 * The callback should only be called when the caller is interested in that
1046 * particular transition. For instance, if the caller is interested only in
1047 * ENTERED transition, then the callback should NOT be called with the EXITED
1048 * transition.
1049 *
1050 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
1051 * subsystem will wake up the application processor, if its in suspend state.
1052 */
1053typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
1054 int32_t transition, GpsUtcTime timestamp);
1055
1056/**
destradaa9f7c3732014-04-29 10:50:22 -07001057 * The callback associated with the availability of the GPS system for geofencing
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001058 * monitoring. If the GPS system determines that it cannot monitor geofences
1059 * because of lack of reliability or unavailability of the GPS signals, it will
1060 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
1061 *
1062 * Parameters:
1063 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
1064 * last_location - Last known location.
1065 */
1066typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
1067
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001068/**
1069 * The callback associated with the add_geofence call.
1070 *
1071 * Parameter:
1072 * geofence_id - Id of the geofence.
1073 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1074 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
1075 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
1076 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
1077 * invalid transition
1078 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
1079 */
1080typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
1081
1082/**
1083 * The callback associated with the remove_geofence call.
1084 *
1085 * Parameter:
1086 * geofence_id - Id of the geofence.
1087 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1088 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1089 * GPS_GEOFENCE_ERROR_GENERIC for others.
1090 */
1091typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
1092
1093
1094/**
1095 * The callback associated with the pause_geofence call.
1096 *
1097 * Parameter:
1098 * geofence_id - Id of the geofence.
1099 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1100 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1101 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
1102 * when monitor_transitions is invalid
1103 * GPS_GEOFENCE_ERROR_GENERIC for others.
1104 */
1105typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
1106
1107/**
1108 * The callback associated with the resume_geofence call.
1109 *
1110 * Parameter:
1111 * geofence_id - Id of the geofence.
1112 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1113 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1114 * GPS_GEOFENCE_ERROR_GENERIC for others.
1115 */
1116typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1117
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001118typedef struct {
1119 gps_geofence_transition_callback geofence_transition_callback;
1120 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001121 gps_geofence_add_callback geofence_add_callback;
1122 gps_geofence_remove_callback geofence_remove_callback;
1123 gps_geofence_pause_callback geofence_pause_callback;
1124 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001125 gps_create_thread create_thread_cb;
1126} GpsGeofenceCallbacks;
1127
1128/** Extended interface for GPS_Geofencing support */
1129typedef struct {
1130 /** set to sizeof(GpsGeofencingInterface) */
1131 size_t size;
1132
1133 /**
1134 * Opens the geofence interface and provides the callback routines
destradaa9f7c3732014-04-29 10:50:22 -07001135 * to the implementation of this interface.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001136 */
1137 void (*init)( GpsGeofenceCallbacks* callbacks );
1138
1139 /**
1140 * Add a geofence area. This api currently supports circular geofences.
1141 * Parameters:
1142 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001143 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1144 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001145 * latitude, longtitude, radius_meters - The lat, long and radius
1146 * (in meters) for the geofence
1147 * last_transition - The current state of the geofence. For example, if
1148 * the system already knows that the user is inside the geofence,
1149 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1150 * will be GPS_GEOFENCE_UNCERTAIN.
1151 * monitor_transition - Which transitions to monitor. Bitwise OR of
1152 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1153 * GPS_GEOFENCE_UNCERTAIN.
1154 * notification_responsiveness_ms - Defines the best-effort description
1155 * of how soon should the callback be called when the transition
1156 * associated with the Geofence is triggered. For instance, if set
1157 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1158 * should be called 1000 milliseconds within entering the geofence.
1159 * This parameter is defined in milliseconds.
1160 * NOTE: This is not to be confused with the rate that the GPS is
1161 * polled at. It is acceptable to dynamically vary the rate of
1162 * sampling the GPS for power-saving reasons; thus the rate of
1163 * sampling may be faster or slower than this.
1164 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
destradaa9f7c3732014-04-29 10:50:22 -07001165 * should be triggered. This parameter is defined in milliseconds.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001166 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001167 */
destradaa9f7c3732014-04-29 10:50:22 -07001168 void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude,
1169 double radius_meters, int last_transition, int monitor_transitions,
1170 int notification_responsiveness_ms, int unknown_timer_ms);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001171
1172 /**
1173 * Pause monitoring a particular geofence.
1174 * Parameters:
1175 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001176 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001177 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001178
1179 /**
1180 * Resume monitoring a particular geofence.
1181 * Parameters:
1182 * geofence_id - The id for the geofence.
1183 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1184 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1185 * GPS_GEOFENCE_UNCERTAIN.
1186 * This supersedes the value associated provided in the
1187 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001188 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001189 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001190
1191 /**
1192 * Remove a geofence area. After the function returns, no notifications
1193 * should be sent.
1194 * Parameter:
1195 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001196 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001197 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001198} GpsGeofencingInterface;
destradaa9f7c3732014-04-29 10:50:22 -07001199
1200
1201/**
1202 * Represents an estimate of the GPS clock time.
1203 */
1204typedef struct {
1205 /** set to sizeof(GpsClock) */
1206 size_t size;
1207
1208 /** A set of flags indicating the validity of the fields in this data structure. */
1209 GpsClockFlags flags;
1210
1211 /**
1212 * Leap second data.
1213 * If the data is available 'flags' must contain GPS_CLOCK_HAS_LEAP_SECOND.
1214 */
1215 int16_t leap_second;
1216
1217 /**
1218 * The receiver's GPS time since 0000Z, January 6, 1980 in nanoseconds.
1219 * It is referenced using the uncorrected receiver's clock ('bias_ns' included).
1220 * The current precision allows a range that spans approximately to the end of the year 2272.
1221 *
1222 * Sub-nanosecond accuracy can be provided for each individual measurement using the field
1223 * GpsMeasurement::time_offset_ns.
1224 *
1225 * The value contains the 'time uncertainty' in it.
1226 * This is a Mandatory field.
1227 */
1228 int64_t time_ns;
1229
1230 /**
1231 * 1-Sigma uncertainty associated with the clock's time in nanoseconds.
1232 * The uncertainty is represented as an absolute (single sided) value.
1233 *
1234 * If the data is available 'flags' must contain GPS_CLOCK_HAS_TIME_UNCERTAINTY.
1235 */
1236 double time_uncertainty_ns;
1237
1238 /**
1239 * The clock's bias in nanoseconds.
1240 * The sign of the value is defined by the following equation:
1241 * true time = time - bias.
1242 *
1243 * The value contains the 'bias uncertainty' in it.
1244 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS.
1245 */
1246 double bias_ns;
1247
1248 /**
1249 * 1-Sigma uncertainty associated with the clock's bias in nanoseconds.
1250 * The uncertainty is represented as an absolute (single sided) value.
1251 *
1252 * If the data is available 'flags' must contain GPS_CLOCK_HAS_BIAS_UNCERTAINTY.
1253 */
1254 double bias_uncertainty_ns;
1255
1256 /**
1257 * The clock's drift in nanoseconds (per second).
1258 * A positive value means that the frequency is higher than the nominal frequency.
1259 *
1260 * The value contains the 'drift uncertainty' in it.
1261 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT.
1262 */
1263 double drift_nsps;
1264
1265 /**
1266 * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second).
1267 * The uncertainty is represented as an absolute (single sided) value.
1268 *
1269 * If the data is available 'flags' must contain GPS_CLOCK_HAS_DRIFT_UNCERTAINTY.
1270 */
1271 double drift_uncertainty_nsps;
1272} GpsClock;
1273
1274/**
1275 * Represents a GPS Measurement, it contains raw and computed information.
1276 */
1277typedef struct {
1278 /** set to sizeof(GpsMeasurement) */
1279 size_t size;
1280
1281 /** A set of flags indicating the validity of the fields in this data structure. */
1282 GpsMeasurementFlags flags;
1283
1284 /**
1285 * Pseudo-random number in the range of [1, 32]
1286 * This is a Mandatory value.
1287 */
1288 int8_t prn;
1289
1290 /**
1291 * Local hardware time offset at which the measurement was taken in nanoseconds.
1292 * The reference receiver's time is specified by GpsData::clock.
1293 * The sign of time_offset_ns is given by the following equation:
1294 * measurement time = GpsClock::time_ns + time_offset_ns
1295 *
1296 * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy.
1297 * This is a Mandatory value.
1298 */
1299 int64_t time_offset_ns;
1300
1301 /**
1302 * Received GPS Time-of-Week in nanoseconds.
1303 * The value is relative to the beginning of the current GPS week.
1304 *
1305 * This is a Mandatory value.
1306 */
1307 int64_t received_gps_tow_ns;
1308
1309 /**
1310 * Carrier-to-noise density in dB-Hz, in the range [0, 63].
1311 * It contains the measured C/N0 value for the signal at the antenna input.
1312 *
1313 * This is a Mandatory value.
1314 */
1315 double c_n0_dbhz;
1316
1317 /**
1318 * Pseudorange rate at the timestamp in m/s.
1319 * The value also includes the effects of the receiver clock frequency and satellite clock
1320 * frequency errors.
1321 *
1322 * The value includes the 'pseudorange rate uncertainty' in it.
1323 * A positive value indicates that the pseudorange is getting larger.
1324 *
1325 * This is a Mandatory value.
1326 */
1327 double pseudorange_rate_mpersec;
1328
1329 /**
1330 * 1-Sigma uncertainty of the pseudurange rate in m/s.
1331 * The uncertainty is represented as an absolute (single sided) value.
1332 *
1333 * This is a Mandatory value.
1334 */
1335 double pseudorange_rate_uncertainty_mpersec;
1336
1337 /**
1338 * Accumulated delta range since the last channel reset in meters.
1339 *
1340 * This is a Mandatory value.
1341 */
1342 double accumulated_delta_range_m;
1343
1344 /**
1345 * 1-Sigma uncertainty of the accumulated delta range in meters.
1346 *
1347 * This is a Mandatory value.
1348 */
1349 double accumulated_delta_range_uncertainty_m;
1350
1351 /**
1352 * Best derived Pseudorange by the chip-set, in meters.
1353 * The value contains the 'pseudorange uncertainty' in it.
1354 *
1355 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE.
1356 */
1357 double pseudorange_m;
1358
1359 /**
1360 * 1-Sigma uncertainty of the pseudorange in meters.
1361 * The value contains the 'pseudorange' and 'clock' uncertainty in it.
1362 * The uncertainty is represented as an absolute (single sided) value.
1363 *
1364 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY.
1365 */
1366 double pseudorange_uncertainty_m;
1367
1368 /**
1369 * A fraction of the current C/A code cycle, in the range [0.0, 1023.0]
1370 * This value contains the time (in Chip units) since the last C/A code cycle (GPS Msec epoch).
1371 *
1372 * The reference frequency is given by the field 'carrier_frequency_hz'.
1373 * The value contains the 'code-phase uncertainty' in it.
1374 *
1375 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE.
1376 */
1377 double code_phase_chips;
1378
1379 /**
1380 * 1-Sigma uncertainty of the code-phase, in a fraction of chips.
1381 * The uncertainty is represented as an absolute (single sided) value.
1382 *
1383 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY.
1384 */
1385 double code_phase_uncertainty_chips;
1386
1387 /**
1388 * Carrier frequency at which codes and messages are modulated, it can be L1 or L2.
1389 * If the field is not set, the carrier frequency is assumed to be L1.
1390 *
1391 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY.
1392 */
1393 float carrier_frequency_hz;
1394
1395 /**
1396 * The number of full carrier cycles between the satellite and the receiver.
1397 * The reference frequency is given by the field 'carrier_frequency_hz'.
1398 *
1399 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_CYCLES.
1400 */
1401 int64_t carrier_cycles;
1402
1403 /**
1404 * The RF phase detected by the receiver, in the range [0.0, 1.0].
1405 * This is usually the fractional part of the complete carrier phase measurement.
1406 *
1407 * The reference frequency is given by the field 'carrier_frequency_hz'.
1408 * The value contains the 'carrier-phase uncertainty' in it.
1409 *
1410 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE.
1411 */
1412 double carrier_phase;
1413
1414 /**
1415 * 1-Sigma uncertainty of the carrier-phase.
1416 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY.
1417 */
1418 double carrier_phase_uncertainty;
1419
1420 /**
1421 * An enumeration that indicates the 'loss of lock' state of the event.
1422 */
1423 GpsLossOfLock loss_of_lock;
1424
1425 /**
1426 * The number of GPS bits transmitted since Sat-Sun midnight (GPS week).
1427 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_BIT_NUMBER.
1428 */
1429 int16_t bit_number;
1430
1431 /**
1432 * The elapsed time since the last received bit in nanoseconds, in the range [0, 20,000,000]
1433 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT.
1434 */
1435 int64_t time_from_last_bit_ns;
1436
1437 /**
1438 * Doppler shift in Hz.
1439 * A positive value indicates that the SV is moving toward the receiver.
1440 *
1441 * The reference frequency is given by the field 'carrier_frequency_hz'.
1442 * The value contains the 'doppler shift uncertainty' in it.
1443 *
1444 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT.
1445 */
1446 double doppler_shift_hz;
1447
1448 /**
1449 * 1-Sigma uncertainty of the doppler shift in Hz.
1450 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY.
1451 */
1452 double doppler_shift_uncertainty_hz;
1453
1454 /**
1455 * An enumeration that indicates the 'multipath' state of the event.
1456 */
1457 GpsMultipathIndicator multipath_indicator;
1458
1459 /**
1460 * Signal-to-noise ratio in dB.
1461 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_SNR.
1462 */
1463 double snr_db;
1464
1465 /**
1466 * Elevation in degrees, the valid range is [-90, 90].
1467 * The value contains the 'elevation uncertainty' in it.
1468 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION.
1469 */
1470 double elevation_deg;
1471
1472 /**
1473 * 1-Sigma uncertainty of the elevation in degrees, the valid range is [0, 90].
1474 * The uncertainty is represented as the absolute (single sided) value.
1475 *
1476 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY.
1477 */
1478 double elevation_uncertainty_deg;
1479
1480 /**
1481 * Azimuth in degrees, in the range [0, 360).
1482 * The value contains the 'azimuth uncertainty' in it.
1483 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH.
1484 * */
1485 double azimuth_deg;
1486
1487 /**
1488 * 1-Sigma uncertainty of the azimuth in degrees, the valid range is [0, 180].
1489 * The uncertainty is represented as an absolute (single sided) value.
1490 *
1491 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY.
1492 */
1493 double azimuth_uncertainty_deg;
1494
1495 /**
1496 * Whether the GPS represented by the measurement was used for computing the most recent fix.
1497 * If the data is available, 'flags' must contain GPS_MEASUREMENT_HAS_USED_IN_FIX.
1498 */
1499 bool used_in_fix;
1500} GpsMeasurement;
1501
1502/** Represents a reading of GPS measurements. */
1503typedef struct {
1504 /** set to sizeof(GpsData) */
1505 size_t size;
1506
1507 /** Number of measurements. */
1508 size_t measurement_count;
1509
1510 /** The array of measurements. */
1511 GpsMeasurement measurements[GPS_MAX_MEASUREMENT];
1512
1513 /** The GPS clock time reading. */
1514 GpsClock clock;
1515} GpsData;
1516
1517/**
1518 * The callback for to report measurements from the HAL.
1519 *
1520 * Parameters:
1521 * data - A data structure containing the measurements.
1522 */
1523typedef void (*gps_measurement_callback) (GpsData* data);
1524
1525typedef struct {
1526 /** set to sizeof(GpsMeasurementCallbacks) */
1527 size_t size;
1528 gps_measurement_callback measurement_callback;
1529} GpsMeasurementCallbacks;
1530
1531#define GPS_MEASUREMENT_OPERATION_SUCCESS 0
1532#define GPS_MEASUREMENT_ERROR_ALREADY_INIT -100
1533#define GPS_MEASUREMENT_ERROR_GENERIC -101
1534
1535/**
1536 * Extended interface for GPS Measurements support.
1537 */
1538typedef struct {
1539 /** Set to sizeof(GpsMeasurementInterface) */
1540 size_t size;
1541
1542 /**
1543 * Initializes the interface and registers the callback routines with the HAL.
1544 * After a successful call to 'init' the HAL must begin to provide updates at its own phase.
1545 *
1546 * Status:
1547 * GPS_MEASUREMENT_OPERATION_SUCCESS
1548 * GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a
1549 * corresponding call to 'close'
1550 * GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL
1551 * will not generate any updates upon returning this error code.
1552 */
1553 int (*init) (GpsMeasurementCallbacks* callbacks);
1554
1555 /**
1556 * Stops updates from the HAL, and unregisters the callback routines.
1557 * After a call to stop, the previously registered callbacks must be considered invalid by the
1558 * HAL.
1559 * If stop is invoked without a previous 'init', this function should perform no work.
1560 */
1561 void (*close) ();
1562
1563} GpsMeasurementInterface;
1564
1565
1566/** Represents a GPS navigation message (or a fragment of it). */
1567typedef struct {
1568 /** set to sizeof(GpsNavigationMessage) */
1569 size_t size;
1570
1571 /**
1572 * Pseudo-random number in the range of [1, 32]
1573 * This is a Mandatory value.
1574 */
1575 int8_t prn;
1576
1577 /**
1578 * The type of message contained in the structure.
1579 * This is a Mandatory value.
1580 */
1581 GpsNavigationMessageType type;
1582
1583 /**
1584 * Message identifier.
1585 * It provides an index so the complete Navigation Message can be assembled.
1586 * i.e. for L1 C/A the message id corresponds to the frame id of the navigation message.
1587 */
1588 int16_t message_id;
1589
1590 /**
1591 * Sub-message identifier.
1592 * If required by the message 'type', this value contains a sub-index within the current
1593 * message (or frame) that is being transmitted.
1594 * i.e. for L1 C/A the submessage id corresponds to the sub-frame id of the navigation message.
1595 */
1596 int16_t submessage_id;
1597
1598 /**
1599 * The length of the data (in bytes) contained in the current message.
1600 * If this value is different from zero, 'data' must point to an array of the same size.
1601 * i.e. for L1 C/A the size of the sub-frame will be 40 bytes (10 words).
1602 *
1603 * This is a Mandatory value.
1604 */
1605 size_t data_length;
1606
1607 /**
1608 * The data of the reported GPS message.
1609 * The bytes (or words) specified using big endian format (MSB first).
1610 */
1611 uint8_t* data;
1612
1613} GpsNavigationMessage;
1614
1615/**
1616 * The callback to report an available fragment of a GPS navigation messages from the HAL.
1617 *
1618 * Parameters:
1619 * message - The GPS navigation submessage/subframe representation.
1620 */
1621typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message);
1622
1623typedef struct {
1624 /** set to sizeof(GpsNavigationMessageCallbacks) */
1625 size_t size;
1626 gps_navigation_message_callback navigation_message_callback;
1627} GpsNavigationMessageCallbacks;
1628
1629#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0
1630#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100
1631#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101
1632
1633/**
1634 * Extended interface for GPS navigation message reporting support.
1635 */
1636typedef struct {
1637 /** Set to sizeof(GpsNavigationMessageInterface) */
1638 size_t size;
1639
1640 /**
1641 * Initializes the interface and registers the callback routines with the HAL.
1642 * After a successful call to 'init' the HAL must begin to provide updates as they become
1643 * available.
1644 *
1645 * Status:
1646 * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS
1647 * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered
1648 * without a corresponding call to 'close'.
1649 * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that
1650 * the HAL will not generate any updates upon returning this error code.
1651 */
1652 int (*init) (GpsNavigationMessageCallbacks* callbacks);
1653
1654 /**
1655 * Stops updates from the HAL, and unregisters the callback routines.
1656 * After a call to stop, the previously registered callbacks must be considered invalid by the
1657 * HAL.
1658 * If stop is invoked without a previous 'init', this function should perform no work.
1659 */
1660 void (*close) ();
1661
1662} GpsNavigationMessageInterface;
1663
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001664__END_DECLS
1665
1666#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1667