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