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