gps.h revision b15879a589bb5ce350869e1a735840679e4b2aaa
1/*
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>
23
24#include <hardware/hardware.h>
25
26__BEGIN_DECLS
27
28/**
29 * The id of this module
30 */
31#define GPS_HARDWARE_MODULE_ID "gps"
32
33
34/** Milliseconds since January 1, 1970 */
35typedef int64_t GpsUtcTime;
36
37/** Maximum number of SVs for gps_sv_status_callback(). */
38#define GPS_MAX_SVS 32
39
40/** Requested operational mode for GPS operation. */
41typedef uint32_t GpsPositionMode;
42// IMPORTANT: Note that the following values must match
43// constants in GpsLocationProvider.java.
44/** Mode for running GPS standalone (no assistance). */
45#define GPS_POSITION_MODE_STANDALONE    0
46/** AGPS MS-Based mode. */
47#define GPS_POSITION_MODE_MS_BASED      1
48/** AGPS MS-Assisted mode. */
49#define GPS_POSITION_MODE_MS_ASSISTED   2
50
51/** Requested recurrence mode for GPS operation. */
52typedef uint32_t GpsPositionRecurrence;
53// IMPORTANT: Note that the following values must match
54// constants in GpsLocationProvider.java.
55/** Receive GPS fixes on a recurring basis at a specified period. */
56#define GPS_POSITION_RECURRENCE_PERIODIC    0
57/** Request a single shot GPS fix. */
58#define GPS_POSITION_RECURRENCE_SINGLE      1
59
60/** GPS status event values. */
61typedef uint16_t GpsStatusValue;
62// IMPORTANT: Note that the following values must match
63// constants in GpsLocationProvider.java.
64/** GPS status unknown. */
65#define GPS_STATUS_NONE             0
66/** GPS has begun navigating. */
67#define GPS_STATUS_SESSION_BEGIN    1
68/** GPS has stopped navigating. */
69#define GPS_STATUS_SESSION_END      2
70/** GPS has powered on but is not navigating. */
71#define GPS_STATUS_ENGINE_ON        3
72/** GPS is powered off. */
73#define GPS_STATUS_ENGINE_OFF       4
74
75/** Flags to indicate which values are valid in a GpsLocation. */
76typedef uint16_t GpsLocationFlags;
77// IMPORTANT: Note that the following values must match
78// constants in GpsLocationProvider.java.
79/** GpsLocation has valid latitude and longitude. */
80#define GPS_LOCATION_HAS_LAT_LONG   0x0001
81/** GpsLocation has valid altitude. */
82#define GPS_LOCATION_HAS_ALTITUDE   0x0002
83/** GpsLocation has valid speed. */
84#define GPS_LOCATION_HAS_SPEED      0x0004
85/** GpsLocation has valid bearing. */
86#define GPS_LOCATION_HAS_BEARING    0x0008
87/** GpsLocation has valid accuracy. */
88#define GPS_LOCATION_HAS_ACCURACY   0x0010
89
90/** Flags for the gps_set_capabilities callback. */
91
92/** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
93    If this is not set, then the framework will use 1000ms for min_interval
94    and will start and call start() and stop() to schedule the GPS.
95 */
96#define GPS_CAPABILITY_SCHEDULING       0x0000001
97/** GPS supports MS-Based AGPS mode */
98#define GPS_CAPABILITY_MSB              0x0000002
99/** GPS supports MS-Assisted AGPS mode */
100#define GPS_CAPABILITY_MSA              0x0000004
101/** GPS supports single-shot fixes */
102#define GPS_CAPABILITY_SINGLE_SHOT      0x0000008
103
104/** Flags used to specify which aiding data to delete
105    when calling delete_aiding_data(). */
106typedef uint16_t GpsAidingData;
107// IMPORTANT: Note that the following values must match
108// constants in GpsLocationProvider.java.
109#define GPS_DELETE_EPHEMERIS        0x0001
110#define GPS_DELETE_ALMANAC          0x0002
111#define GPS_DELETE_POSITION         0x0004
112#define GPS_DELETE_TIME             0x0008
113#define GPS_DELETE_IONO             0x0010
114#define GPS_DELETE_UTC              0x0020
115#define GPS_DELETE_HEALTH           0x0040
116#define GPS_DELETE_SVDIR            0x0080
117#define GPS_DELETE_SVSTEER          0x0100
118#define GPS_DELETE_SADATA           0x0200
119#define GPS_DELETE_RTI              0x0400
120#define GPS_DELETE_CELLDB_INFO      0x8000
121#define GPS_DELETE_ALL              0xFFFF
122
123/** AGPS type */
124typedef uint16_t AGpsType;
125#define AGPS_TYPE_SUPL          1
126#define AGPS_TYPE_C2K           2
127
128/**
129 * String length constants
130 */
131#define GPS_NI_SHORT_STRING_MAXLEN      256
132#define GPS_NI_LONG_STRING_MAXLEN       2048
133
134/**
135 * GpsNiType constants
136 */
137typedef uint32_t GpsNiType;
138#define GPS_NI_TYPE_VOICE              1
139#define GPS_NI_TYPE_UMTS_SUPL          2
140#define GPS_NI_TYPE_UMTS_CTRL_PLANE    3
141
142/**
143 * GpsNiNotifyFlags constants
144 */
145typedef uint32_t GpsNiNotifyFlags;
146/** NI requires notification */
147#define GPS_NI_NEED_NOTIFY          0x0001
148/** NI requires verification */
149#define GPS_NI_NEED_VERIFY          0x0002
150/** NI requires privacy override, no notification/minimal trace */
151#define GPS_NI_PRIVACY_OVERRIDE     0x0004
152
153/**
154 * GPS NI responses, used to define the response in
155 * NI structures
156 */
157typedef int GpsUserResponseType;
158#define GPS_NI_RESPONSE_ACCEPT         1
159#define GPS_NI_RESPONSE_DENY           2
160#define GPS_NI_RESPONSE_NORESP         3
161
162/**
163 * NI data encoding scheme
164 */
165typedef int GpsNiEncodingType;
166#define GPS_ENC_NONE                   0
167#define GPS_ENC_SUPL_GSM_DEFAULT       1
168#define GPS_ENC_SUPL_UTF8              2
169#define GPS_ENC_SUPL_UCS2              3
170#define GPS_ENC_UNKNOWN                -1
171
172/** AGPS status event values. */
173typedef uint16_t AGpsStatusValue;
174/** GPS requests data connection for AGPS. */
175#define GPS_REQUEST_AGPS_DATA_CONN  1
176/** GPS releases the AGPS data connection. */
177#define GPS_RELEASE_AGPS_DATA_CONN  2
178/** AGPS data connection initiated */
179#define GPS_AGPS_DATA_CONNECTED     3
180/** AGPS data connection completed */
181#define GPS_AGPS_DATA_CONN_DONE     4
182/** AGPS data connection failed */
183#define GPS_AGPS_DATA_CONN_FAILED   5
184
185/**
186 * Name for the GPS XTRA interface.
187 */
188#define GPS_XTRA_INTERFACE      "gps-xtra"
189
190/**
191 * Name for the GPS DEBUG interface.
192 */
193#define GPS_DEBUG_INTERFACE      "gps-debug"
194
195/**
196 * Name for the AGPS interface.
197 */
198#define AGPS_INTERFACE      "agps"
199
200/**
201 * Name for NI interface
202 */
203#define GPS_NI_INTERFACE "gps-ni"
204
205/** Represents a location. */
206typedef struct {
207    /** set to sizeof(GpsLocation) */
208    size_t          size;
209    /** Contains GpsLocationFlags bits. */
210    uint16_t        flags;
211    /** Represents latitude in degrees. */
212    double          latitude;
213    /** Represents longitude in degrees. */
214    double          longitude;
215    /** Represents altitude in meters above the WGS 84 reference
216     * ellipsoid. */
217    double          altitude;
218    /** Represents speed in meters per second. */
219    float           speed;
220    /** Represents heading in degrees. */
221    float           bearing;
222    /** Represents expected accuracy in meters. */
223    float           accuracy;
224    /** Timestamp for the location fix. */
225    GpsUtcTime      timestamp;
226} GpsLocation;
227
228/** Represents the status. */
229typedef struct {
230    /** set to sizeof(GpsStatus) */
231    size_t          size;
232    GpsStatusValue status;
233} GpsStatus;
234
235/** Represents SV information. */
236typedef struct {
237    /** set to sizeof(GpsSvInfo) */
238    size_t          size;
239    /** Pseudo-random number for the SV. */
240    int     prn;
241    /** Signal to noise ratio. */
242    float   snr;
243    /** Elevation of SV in degrees. */
244    float   elevation;
245    /** Azimuth of SV in degrees. */
246    float   azimuth;
247} GpsSvInfo;
248
249/** Represents SV status. */
250typedef struct {
251    /** set to sizeof(GpsSvStatus) */
252    size_t          size;
253
254    /** Number of SVs currently visible. */
255    int         num_svs;
256
257    /** Contains an array of SV information. */
258    GpsSvInfo   sv_list[GPS_MAX_SVS];
259
260    /** Represents a bit mask indicating which SVs
261     * have ephemeris data.
262     */
263    uint32_t    ephemeris_mask;
264
265    /** Represents a bit mask indicating which SVs
266     * have almanac data.
267     */
268    uint32_t    almanac_mask;
269
270    /**
271     * Represents a bit mask indicating which SVs
272     * were used for computing the most recent position fix.
273     */
274    uint32_t    used_in_fix_mask;
275} GpsSvStatus;
276
277/** Callback with location information. */
278typedef void (* gps_location_callback)(GpsLocation* location);
279
280/** Callback with status information. */
281typedef void (* gps_status_callback)(GpsStatus* status);
282
283/** Callback with SV status information. */
284typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
285
286/** Callback for reporting NMEA sentences. */
287typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
288
289/** Callback to inform framework of the GPS engine's capabilities.
290    capability parameter is a bit field of GPS_CAPABILITY_* flags */
291typedef void (* gps_set_capabilities)(uint32_t capabilities);
292
293/** Callback utility for acquiring the GPS wakelock.
294    This can be used to prevent the CPU from suspending while handling GPS events. */
295typedef void (* gps_acquire_wakelock)();
296
297/** Callback utility for releasing the GPS wakelock. */
298typedef void (* gps_release_wakelock)();
299
300/** GPS callback structure. */
301typedef struct {
302    /** set to sizeof(GpsCallbacks) */
303    size_t      size;
304    gps_location_callback location_cb;
305    gps_status_callback status_cb;
306    gps_sv_status_callback sv_status_cb;
307    gps_nmea_callback nmea_cb;
308    gps_set_capabilities set_capabilities_cb;
309    gps_acquire_wakelock acquire_wakelock_cb;
310    gps_release_wakelock release_wakelock_cb;
311} GpsCallbacks;
312
313
314/** Represents the standard GPS interface. */
315typedef struct {
316    /** set to sizeof(GpsInterface) */
317    size_t          size;
318    /**
319     * Opens the interface and provides the callback routines
320     * to the implemenation of this interface.
321     */
322    int   (*init)( GpsCallbacks* callbacks );
323
324    /** Starts navigating. */
325    int   (*start)( void );
326
327    /** Stops navigating. */
328    int   (*stop)( void );
329
330    /** Closes the interface. */
331    void  (*cleanup)( void );
332
333    /** Injects the current time. */
334    int   (*inject_time)(GpsUtcTime time, int64_t timeReference,
335                         int uncertainty);
336
337    /** Injects current location from another location provider
338     *  (typically cell ID).
339     *  latitude and longitude are measured in degrees
340     *  expected accuracy is measured in meters
341     */
342    int  (*inject_location)(double latitude, double longitude, float accuracy);
343
344    /**
345     * Specifies that the next call to start will not use the
346     * information defined in the flags. GPS_DELETE_ALL is passed for
347     * a cold start.
348     */
349    void  (*delete_aiding_data)(GpsAidingData flags);
350
351    /**
352     * min_interval represents the time between fixes in milliseconds.
353     * preferred_accuracy represents the requested fix accuracy in meters.
354     * preferred_time represents the requested time to first fix in milliseconds.
355     */
356    int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
357            uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
358
359    /** Get a pointer to extension information. */
360    const void* (*get_extension)(const char* name);
361} GpsInterface;
362
363/** Callback to request the client to download XTRA data.
364    The client should download XTRA data and inject it by calling
365     inject_xtra_data(). */
366typedef void (* gps_xtra_download_request)();
367
368/** Callback structure for the XTRA interface. */
369typedef struct {
370        gps_xtra_download_request download_request_cb;
371} GpsXtraCallbacks;
372
373/** Extended interface for XTRA support. */
374typedef struct {
375    /** set to sizeof(GpsXtraInterface) */
376    size_t          size;
377    /**
378     * Opens the XTRA interface and provides the callback routines
379     * to the implemenation of this interface.
380     */
381    int  (*init)( GpsXtraCallbacks* callbacks );
382    /** Injects XTRA data into the GPS. */
383    int  (*inject_xtra_data)( char* data, int length );
384} GpsXtraInterface;
385
386/** Extended interface for DEBUG support. */
387typedef struct {
388    /** set to sizeof(GpsDebugInterface) */
389    size_t          size;
390
391    /**
392     * This function should return any information that the native
393     * implementation wishes to include in a bugreport.
394     */
395    size_t (*get_internal_state)(char* buffer, size_t bufferSize);
396} GpsDebugInterface;
397
398/** Represents the status of AGPS. */
399typedef struct {
400    /** set to sizeof(AGpsStatus) */
401    size_t          size;
402
403    AGpsType        type;
404    AGpsStatusValue status;
405} AGpsStatus;
406
407/** Callback with AGPS status information. */
408typedef void (* agps_status_callback)(AGpsStatus* status);
409
410/** Callback structure for the AGPS interface. */
411typedef struct {
412        agps_status_callback status_cb;
413} AGpsCallbacks;
414
415
416/** Extended interface for AGPS support. */
417typedef struct {
418    /** set to sizeof(AGpsInterface) */
419    size_t          size;
420
421    /**
422     * Opens the AGPS interface and provides the callback routines
423     * to the implemenation of this interface.
424     */
425    void  (*init)( AGpsCallbacks* callbacks );
426    /**
427     * Notifies that a data connection is available and sets
428     * the name of the APN to be used for SUPL.
429     */
430    int  (*data_conn_open)( const char* apn );
431    /**
432     * Notifies that the AGPS data connection has been closed.
433     */
434    int  (*data_conn_closed)();
435    /**
436     * Notifies that a data connection is not available for AGPS.
437     */
438    int  (*data_conn_failed)();
439    /**
440     * Sets the hostname and port for the AGPS server.
441     */
442    int  (*set_server)( AGpsType type, const char* hostname, int port );
443} AGpsInterface;
444
445
446/** Represents an NI request */
447typedef struct {
448    /** set to sizeof(GpsNiNotification) */
449    size_t          size;
450
451    /**
452     * An ID generated by HAL to associate NI notifications and UI
453     * responses
454     */
455    int             notification_id;
456
457    /**
458     * An NI type used to distinguish different categories of NI
459     * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
460     */
461    GpsNiType       ni_type;
462
463    /**
464     * Notification/verification options, combinations of GpsNiNotifyFlags constants
465     */
466    GpsNiNotifyFlags notify_flags;
467
468    /**
469     * Timeout period to wait for user response.
470     * Set to 0 for no time out limit.
471     */
472    int             timeout;
473
474    /**
475     * Default response when time out.
476     */
477    GpsUserResponseType default_response;
478
479    /**
480     * Requestor ID
481     */
482    char            requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
483
484    /**
485     * Notification message. It can also be used to store client_id in some cases
486     */
487    char            text[GPS_NI_LONG_STRING_MAXLEN];
488
489    /**
490     * Client name decoding scheme
491     */
492    GpsNiEncodingType requestor_id_encoding;
493
494    /**
495     * Client name decoding scheme
496     */
497    GpsNiEncodingType text_encoding;
498
499    /**
500     * A pointer to extra data. Format:
501     * key_1 = value_1
502     * key_2 = value_2
503     */
504    char           extras[GPS_NI_LONG_STRING_MAXLEN];
505
506} GpsNiNotification;
507
508/** Callback with NI notification. */
509typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
510
511/** GPS NI callback structure. */
512typedef struct
513{
514   /**
515    * Sends the notification request from HAL to GPSLocationProvider.
516    */
517   gps_ni_notify_callback notify_cb;
518} GpsNiCallbacks;
519
520/**
521 * Extended interface for Network-initiated (NI) support.
522 */
523typedef struct
524{
525    /** set to sizeof(GpsNiInterface) */
526    size_t          size;
527
528   /** Registers the callbacks for HAL to use. */
529   void (*init) (GpsNiCallbacks *callbacks);
530
531   /** Sends a response to HAL. */
532   void (*respond) (int notif_id, GpsUserResponseType user_response);
533} GpsNiInterface;
534
535struct gps_device_t {
536    struct hw_device_t common;
537
538    /**
539     * Set the provided lights to the provided values.
540     *
541     * Returns: 0 on succes, error code on failure.
542     */
543    const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
544};
545
546__END_DECLS
547
548#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
549
550