blob: 11223fb4e4a3669983167bec847ac69e3cbbb3b7 [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
266/** GPS callback structure. */
267typedef struct {
268 gps_location_callback location_cb;
269 gps_status_callback status_cb;
270 gps_sv_status_callback sv_status_cb;
271 gps_nmea_callback nmea_cb;
272} GpsCallbacks;
273
274
275/** Represents the standard GPS interface. */
276typedef struct {
277 /** set to sizeof(GpsInterface) */
278 size_t size;
279 /**
280 * Opens the interface and provides the callback routines
281 * to the implemenation of this interface.
282 */
283 int (*init)( GpsCallbacks* callbacks );
284
285 /** Starts navigating. */
286 int (*start)( void );
287
288 /** Stops navigating. */
289 int (*stop)( void );
290
291 /** Closes the interface. */
292 void (*cleanup)( void );
293
294 /** Injects the current time. */
295 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
296 int uncertainty);
297
298 /** Injects current location from another location provider
299 * (typically cell ID).
300 * latitude and longitude are measured in degrees
301 * expected accuracy is measured in meters
302 */
303 int (*inject_location)(double latitude, double longitude, float accuracy);
304
305 /**
306 * Specifies that the next call to start will not use the
307 * information defined in the flags. GPS_DELETE_ALL is passed for
308 * a cold start.
309 */
310 void (*delete_aiding_data)(GpsAidingData flags);
311
312 /**
313 * fix_frequency represents the time between fixes in seconds.
314 * Set fix_frequency to zero for a single-shot fix.
315 */
316 int (*set_position_mode)(GpsPositionMode mode, int fix_frequency);
317
318 /** Get a pointer to extension information. */
319 const void* (*get_extension)(const char* name);
320} GpsInterface;
321
322/** Callback to request the client to download XTRA data.
323 The client should download XTRA data and inject it by calling
324 inject_xtra_data(). */
325typedef void (* gps_xtra_download_request)();
326
327/** Callback structure for the XTRA interface. */
328typedef struct {
329 gps_xtra_download_request download_request_cb;
330} GpsXtraCallbacks;
331
332/** Extended interface for XTRA support. */
333typedef struct {
334 /** set to sizeof(GpsXtraInterface) */
335 size_t size;
336 /**
337 * Opens the XTRA interface and provides the callback routines
338 * to the implemenation of this interface.
339 */
340 int (*init)( GpsXtraCallbacks* callbacks );
341 /** Injects XTRA data into the GPS. */
342 int (*inject_xtra_data)( char* data, int length );
343} GpsXtraInterface;
344
345/** Extended interface for DEBUG support. */
346typedef struct {
347 /** set to sizeof(GpsDebugInterface) */
348 size_t size;
349
350 /**
351 * This function should return any information that the native
352 * implementation wishes to include in a bugreport.
353 */
354 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
355} GpsDebugInterface;
356
357/** Represents the status of AGPS. */
358typedef struct {
359 /** set to sizeof(AGpsStatus) */
360 size_t size;
361
362 AGpsType type;
363 AGpsStatusValue status;
364} AGpsStatus;
365
366/** Callback with AGPS status information. */
367typedef void (* agps_status_callback)(AGpsStatus* status);
368
369/** Callback structure for the AGPS interface. */
370typedef struct {
371 agps_status_callback status_cb;
372} AGpsCallbacks;
373
374
375/** Extended interface for AGPS support. */
376typedef struct {
377 /** set to sizeof(AGpsInterface) */
378 size_t size;
379
380 /**
381 * Opens the AGPS interface and provides the callback routines
382 * to the implemenation of this interface.
383 */
384 void (*init)( AGpsCallbacks* callbacks );
385 /**
386 * Notifies that a data connection is available and sets
387 * the name of the APN to be used for SUPL.
388 */
389 int (*data_conn_open)( const char* apn );
390 /**
391 * Notifies that the AGPS data connection has been closed.
392 */
393 int (*data_conn_closed)();
394 /**
395 * Notifies that a data connection is not available for AGPS.
396 */
397 int (*data_conn_failed)();
398 /**
399 * Sets the hostname and port for the AGPS server.
400 */
401 int (*set_server)( AGpsType type, const char* hostname, int port );
402} AGpsInterface;
403
404
405/** Represents an NI request */
406typedef struct {
407 /** set to sizeof(GpsNiNotification) */
408 size_t size;
409
410 /**
411 * An ID generated by HAL to associate NI notifications and UI
412 * responses
413 */
414 int notification_id;
415
416 /**
417 * An NI type used to distinguish different categories of NI
418 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
419 */
420 GpsNiType ni_type;
421
422 /**
423 * Notification/verification options, combinations of GpsNiNotifyFlags constants
424 */
425 GpsNiNotifyFlags notify_flags;
426
427 /**
428 * Timeout period to wait for user response.
429 * Set to 0 for no time out limit.
430 */
431 int timeout;
432
433 /**
434 * Default response when time out.
435 */
436 GpsUserResponseType default_response;
437
438 /**
439 * Requestor ID
440 */
441 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
442
443 /**
444 * Notification message. It can also be used to store client_id in some cases
445 */
446 char text[GPS_NI_LONG_STRING_MAXLEN];
447
448 /**
449 * Client name decoding scheme
450 */
451 GpsNiEncodingType requestor_id_encoding;
452
453 /**
454 * Client name decoding scheme
455 */
456 GpsNiEncodingType text_encoding;
457
458 /**
459 * A pointer to extra data. Format:
460 * key_1 = value_1
461 * key_2 = value_2
462 */
463 char extras[GPS_NI_LONG_STRING_MAXLEN];
464
465} GpsNiNotification;
466
467/** Callback with NI notification. */
468typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
469
470/** GPS NI callback structure. */
471typedef struct
472{
473 /**
474 * Sends the notification request from HAL to GPSLocationProvider.
475 */
476 gps_ni_notify_callback notify_cb;
477} GpsNiCallbacks;
478
479/**
480 * Extended interface for Network-initiated (NI) support.
481 */
482typedef struct
483{
484 /** set to sizeof(GpsNiInterface) */
485 size_t size;
486
487 /** Registers the callbacks for HAL to use. */
488 void (*init) (GpsNiCallbacks *callbacks);
489
490 /** Sends a response to HAL. */
491 void (*respond) (int notif_id, GpsUserResponseType user_response);
492} GpsNiInterface;
493
494struct gps_device_t {
495 struct hw_device_t common;
496
497 /**
498 * Set the provided lights to the provided values.
499 *
500 * Returns: 0 on succes, error code on failure.
501 */
502 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
503};
504
505__END_DECLS
506
507#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
508