blob: 7244738b8ee8a5382769c88fbc1be3cb7ef772a6 [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>
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050025
26#include <hardware/hardware.h>
27
28__BEGIN_DECLS
29
30/**
31 * The id of this module
32 */
33#define GPS_HARDWARE_MODULE_ID "gps"
34
35
36/** Milliseconds since January 1, 1970 */
37typedef int64_t GpsUtcTime;
38
39/** Maximum number of SVs for gps_sv_status_callback(). */
40#define GPS_MAX_SVS 32
41
Mike Lockwoodb15879a2010-04-14 15:36:34 -040042/** Requested operational mode for GPS operation. */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050043typedef uint32_t GpsPositionMode;
44// IMPORTANT: Note that the following values must match
45// constants in GpsLocationProvider.java.
46/** Mode for running GPS standalone (no assistance). */
47#define GPS_POSITION_MODE_STANDALONE 0
48/** AGPS MS-Based mode. */
49#define GPS_POSITION_MODE_MS_BASED 1
50/** AGPS MS-Assisted mode. */
51#define GPS_POSITION_MODE_MS_ASSISTED 2
52
Mike Lockwoodb15879a2010-04-14 15:36:34 -040053/** Requested recurrence mode for GPS operation. */
54typedef uint32_t GpsPositionRecurrence;
55// IMPORTANT: Note that the following values must match
56// constants in GpsLocationProvider.java.
57/** Receive GPS fixes on a recurring basis at a specified period. */
58#define GPS_POSITION_RECURRENCE_PERIODIC 0
59/** Request a single shot GPS fix. */
60#define GPS_POSITION_RECURRENCE_SINGLE 1
61
Mike Lockwood9b0b1c32010-02-23 18:42:37 -050062/** GPS status event values. */
63typedef uint16_t GpsStatusValue;
64// IMPORTANT: Note that the following values must match
65// constants in GpsLocationProvider.java.
66/** GPS status unknown. */
67#define GPS_STATUS_NONE 0
68/** GPS has begun navigating. */
69#define GPS_STATUS_SESSION_BEGIN 1
70/** GPS has stopped navigating. */
71#define GPS_STATUS_SESSION_END 2
72/** GPS has powered on but is not navigating. */
73#define GPS_STATUS_ENGINE_ON 3
74/** GPS is powered off. */
75#define GPS_STATUS_ENGINE_OFF 4
76
77/** Flags to indicate which values are valid in a GpsLocation. */
78typedef uint16_t GpsLocationFlags;
79// IMPORTANT: Note that the following values must match
80// constants in GpsLocationProvider.java.
81/** GpsLocation has valid latitude and longitude. */
82#define GPS_LOCATION_HAS_LAT_LONG 0x0001
83/** GpsLocation has valid altitude. */
84#define GPS_LOCATION_HAS_ALTITUDE 0x0002
85/** GpsLocation has valid speed. */
86#define GPS_LOCATION_HAS_SPEED 0x0004
87/** GpsLocation has valid bearing. */
88#define GPS_LOCATION_HAS_BEARING 0x0008
89/** GpsLocation has valid accuracy. */
90#define GPS_LOCATION_HAS_ACCURACY 0x0010
91
Mike Lockwoodb15879a2010-04-14 15:36:34 -040092/** Flags for the gps_set_capabilities callback. */
93
94/** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
95 If this is not set, then the framework will use 1000ms for min_interval
96 and will start and call start() and stop() to schedule the GPS.
97 */
98#define GPS_CAPABILITY_SCHEDULING 0x0000001
99/** GPS supports MS-Based AGPS mode */
100#define GPS_CAPABILITY_MSB 0x0000002
101/** GPS supports MS-Assisted AGPS mode */
102#define GPS_CAPABILITY_MSA 0x0000004
103/** GPS supports single-shot fixes */
104#define GPS_CAPABILITY_SINGLE_SHOT 0x0000008
Mike Lockwood8aac5912011-06-29 15:10:36 -0400105/** GPS supports on demand time injection */
106#define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800107/** GPS supports Geofencing */
108#define GPS_CAPABILITY_GEOFENCING 0x0000020
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400109
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500110/** Flags used to specify which aiding data to delete
111 when calling delete_aiding_data(). */
112typedef uint16_t GpsAidingData;
113// IMPORTANT: Note that the following values must match
114// constants in GpsLocationProvider.java.
115#define GPS_DELETE_EPHEMERIS 0x0001
116#define GPS_DELETE_ALMANAC 0x0002
117#define GPS_DELETE_POSITION 0x0004
118#define GPS_DELETE_TIME 0x0008
119#define GPS_DELETE_IONO 0x0010
120#define GPS_DELETE_UTC 0x0020
121#define GPS_DELETE_HEALTH 0x0040
122#define GPS_DELETE_SVDIR 0x0080
123#define GPS_DELETE_SVSTEER 0x0100
124#define GPS_DELETE_SADATA 0x0200
125#define GPS_DELETE_RTI 0x0400
126#define GPS_DELETE_CELLDB_INFO 0x8000
127#define GPS_DELETE_ALL 0xFFFF
128
129/** AGPS type */
130typedef uint16_t AGpsType;
131#define AGPS_TYPE_SUPL 1
132#define AGPS_TYPE_C2K 2
133
Miguel Torroja5f404f52010-07-27 06:34:15 +0200134typedef uint16_t AGpsSetIDType;
135#define AGPS_SETID_TYPE_NONE 0
136#define AGPS_SETID_TYPE_IMSI 1
137#define AGPS_SETID_TYPE_MSISDN 2
138
destradaaf48cc672014-06-05 11:07:09 -0700139typedef uint16_t ApnIpType;
140#define APN_IP_INVALID 0
141#define APN_IP_IPV4 1
142#define APN_IP_IPV6 2
143#define APN_IP_IPV4V6 3
144
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500145/**
146 * String length constants
147 */
148#define GPS_NI_SHORT_STRING_MAXLEN 256
149#define GPS_NI_LONG_STRING_MAXLEN 2048
150
151/**
152 * GpsNiType constants
153 */
154typedef uint32_t GpsNiType;
155#define GPS_NI_TYPE_VOICE 1
156#define GPS_NI_TYPE_UMTS_SUPL 2
157#define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
158
159/**
160 * GpsNiNotifyFlags constants
161 */
162typedef uint32_t GpsNiNotifyFlags;
163/** NI requires notification */
164#define GPS_NI_NEED_NOTIFY 0x0001
165/** NI requires verification */
166#define GPS_NI_NEED_VERIFY 0x0002
167/** NI requires privacy override, no notification/minimal trace */
168#define GPS_NI_PRIVACY_OVERRIDE 0x0004
169
170/**
171 * GPS NI responses, used to define the response in
172 * NI structures
173 */
174typedef int GpsUserResponseType;
175#define GPS_NI_RESPONSE_ACCEPT 1
176#define GPS_NI_RESPONSE_DENY 2
177#define GPS_NI_RESPONSE_NORESP 3
178
179/**
180 * NI data encoding scheme
181 */
182typedef int GpsNiEncodingType;
183#define GPS_ENC_NONE 0
184#define GPS_ENC_SUPL_GSM_DEFAULT 1
185#define GPS_ENC_SUPL_UTF8 2
186#define GPS_ENC_SUPL_UCS2 3
187#define GPS_ENC_UNKNOWN -1
188
189/** AGPS status event values. */
190typedef uint16_t AGpsStatusValue;
191/** GPS requests data connection for AGPS. */
192#define GPS_REQUEST_AGPS_DATA_CONN 1
193/** GPS releases the AGPS data connection. */
194#define GPS_RELEASE_AGPS_DATA_CONN 2
195/** AGPS data connection initiated */
196#define GPS_AGPS_DATA_CONNECTED 3
197/** AGPS data connection completed */
198#define GPS_AGPS_DATA_CONN_DONE 4
199/** AGPS data connection failed */
200#define GPS_AGPS_DATA_CONN_FAILED 5
201
Miguel Torroja5f404f52010-07-27 06:34:15 +0200202#define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
203#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
204#define AGPS_REG_LOCATION_TYPE_MAC 3
205
Mike Lockwood455e83b2010-10-11 06:16:57 -0400206/** Network types for update_network_state "type" parameter */
207#define AGPS_RIL_NETWORK_TYPE_MOBILE 0
208#define AGPS_RIL_NETWORK_TYPE_WIFI 1
209#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
210#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
211#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
212#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
213#define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
214
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500215/**
216 * Name for the GPS XTRA interface.
217 */
218#define GPS_XTRA_INTERFACE "gps-xtra"
219
220/**
221 * Name for the GPS DEBUG interface.
222 */
223#define GPS_DEBUG_INTERFACE "gps-debug"
224
225/**
226 * Name for the AGPS interface.
227 */
228#define AGPS_INTERFACE "agps"
229
230/**
destradaaa1f4c0a2013-09-13 15:45:03 -0700231 * Name of the Supl Certificate interface.
232 */
233#define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
234
235/**
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500236 * Name for NI interface
237 */
238#define GPS_NI_INTERFACE "gps-ni"
239
Miguel Torroja5f404f52010-07-27 06:34:15 +0200240/**
241 * Name for the AGPS-RIL interface.
242 */
243#define AGPS_RIL_INTERFACE "agps_ril"
244
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800245/**
246 * Name for the GPS_Geofencing interface.
247 */
248#define GPS_GEOFENCING_INTERFACE "gps_geofencing"
249
250
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500251/** Represents a location. */
252typedef struct {
253 /** set to sizeof(GpsLocation) */
254 size_t size;
255 /** Contains GpsLocationFlags bits. */
256 uint16_t flags;
257 /** Represents latitude in degrees. */
258 double latitude;
259 /** Represents longitude in degrees. */
260 double longitude;
261 /** Represents altitude in meters above the WGS 84 reference
262 * ellipsoid. */
263 double altitude;
264 /** Represents speed in meters per second. */
265 float speed;
266 /** Represents heading in degrees. */
267 float bearing;
268 /** Represents expected accuracy in meters. */
269 float accuracy;
270 /** Timestamp for the location fix. */
271 GpsUtcTime timestamp;
272} GpsLocation;
273
274/** Represents the status. */
275typedef struct {
276 /** set to sizeof(GpsStatus) */
277 size_t size;
278 GpsStatusValue status;
279} GpsStatus;
280
281/** Represents SV information. */
282typedef struct {
283 /** set to sizeof(GpsSvInfo) */
284 size_t size;
285 /** Pseudo-random number for the SV. */
286 int prn;
287 /** Signal to noise ratio. */
288 float snr;
289 /** Elevation of SV in degrees. */
290 float elevation;
291 /** Azimuth of SV in degrees. */
292 float azimuth;
293} GpsSvInfo;
294
295/** Represents SV status. */
296typedef struct {
297 /** set to sizeof(GpsSvStatus) */
298 size_t size;
299
300 /** Number of SVs currently visible. */
301 int num_svs;
302
303 /** Contains an array of SV information. */
304 GpsSvInfo sv_list[GPS_MAX_SVS];
305
306 /** Represents a bit mask indicating which SVs
307 * have ephemeris data.
308 */
309 uint32_t ephemeris_mask;
310
311 /** Represents a bit mask indicating which SVs
312 * have almanac data.
313 */
314 uint32_t almanac_mask;
315
316 /**
317 * Represents a bit mask indicating which SVs
318 * were used for computing the most recent position fix.
319 */
320 uint32_t used_in_fix_mask;
321} GpsSvStatus;
322
Miguel Torroja5f404f52010-07-27 06:34:15 +0200323/* 2G and 3G */
324/* In 3G lac is discarded */
325typedef struct {
326 uint16_t type;
327 uint16_t mcc;
328 uint16_t mnc;
329 uint16_t lac;
330 uint32_t cid;
331} AGpsRefLocationCellID;
332
333typedef struct {
334 uint8_t mac[6];
335} AGpsRefLocationMac;
336
337/** Represents ref locations */
338typedef struct {
339 uint16_t type;
340 union {
341 AGpsRefLocationCellID cellID;
342 AGpsRefLocationMac mac;
343 } u;
344} AGpsRefLocation;
345
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700346/** Callback with location information.
347 * Can only be called from a thread created by create_thread_cb.
348 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500349typedef void (* gps_location_callback)(GpsLocation* location);
350
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700351/** Callback with status information.
352 * Can only be called from a thread created by create_thread_cb.
353 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500354typedef void (* gps_status_callback)(GpsStatus* status);
355
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700356/** Callback with SV status information.
357 * Can only be called from a thread created by create_thread_cb.
358 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500359typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
360
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700361/** Callback for reporting NMEA sentences.
362 * Can only be called from a thread created by create_thread_cb.
363 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500364typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
365
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400366/** Callback to inform framework of the GPS engine's capabilities.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700367 * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
368 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400369typedef void (* gps_set_capabilities)(uint32_t capabilities);
370
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400371/** Callback utility for acquiring the GPS wakelock.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700372 * This can be used to prevent the CPU from suspending while handling GPS events.
373 */
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400374typedef void (* gps_acquire_wakelock)();
375
376/** Callback utility for releasing the GPS wakelock. */
377typedef void (* gps_release_wakelock)();
378
Mike Lockwood8aac5912011-06-29 15:10:36 -0400379/** Callback for requesting NTP time */
380typedef void (* gps_request_utc_time)();
381
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700382/** Callback for creating a thread that can call into the Java framework code.
383 * This must be used to create any threads that report events up to the framework.
384 */
385typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
386
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500387/** GPS callback structure. */
388typedef struct {
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400389 /** set to sizeof(GpsCallbacks) */
390 size_t size;
391 gps_location_callback location_cb;
392 gps_status_callback status_cb;
393 gps_sv_status_callback sv_status_cb;
394 gps_nmea_callback nmea_cb;
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400395 gps_set_capabilities set_capabilities_cb;
Mike Lockwoodd20bbae2010-04-07 09:04:25 -0400396 gps_acquire_wakelock acquire_wakelock_cb;
397 gps_release_wakelock release_wakelock_cb;
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700398 gps_create_thread create_thread_cb;
Mike Lockwood8aac5912011-06-29 15:10:36 -0400399 gps_request_utc_time request_utc_time_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500400} GpsCallbacks;
401
402
403/** Represents the standard GPS interface. */
404typedef struct {
405 /** set to sizeof(GpsInterface) */
406 size_t size;
407 /**
408 * Opens the interface and provides the callback routines
409 * to the implemenation of this interface.
410 */
411 int (*init)( GpsCallbacks* callbacks );
412
413 /** Starts navigating. */
414 int (*start)( void );
415
416 /** Stops navigating. */
417 int (*stop)( void );
418
419 /** Closes the interface. */
420 void (*cleanup)( void );
421
422 /** Injects the current time. */
423 int (*inject_time)(GpsUtcTime time, int64_t timeReference,
424 int uncertainty);
425
426 /** Injects current location from another location provider
427 * (typically cell ID).
428 * latitude and longitude are measured in degrees
429 * expected accuracy is measured in meters
430 */
431 int (*inject_location)(double latitude, double longitude, float accuracy);
432
433 /**
434 * Specifies that the next call to start will not use the
435 * information defined in the flags. GPS_DELETE_ALL is passed for
436 * a cold start.
437 */
438 void (*delete_aiding_data)(GpsAidingData flags);
439
440 /**
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400441 * min_interval represents the time between fixes in milliseconds.
442 * preferred_accuracy represents the requested fix accuracy in meters.
443 * preferred_time represents the requested time to first fix in milliseconds.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500444 */
Mike Lockwoodb15879a2010-04-14 15:36:34 -0400445 int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
446 uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500447
448 /** Get a pointer to extension information. */
449 const void* (*get_extension)(const char* name);
450} GpsInterface;
451
452/** Callback to request the client to download XTRA data.
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700453 * The client should download XTRA data and inject it by calling inject_xtra_data().
454 * Can only be called from a thread created by create_thread_cb.
455 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500456typedef void (* gps_xtra_download_request)();
457
458/** Callback structure for the XTRA interface. */
459typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700460 gps_xtra_download_request download_request_cb;
461 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500462} GpsXtraCallbacks;
463
464/** Extended interface for XTRA support. */
465typedef struct {
466 /** set to sizeof(GpsXtraInterface) */
467 size_t size;
468 /**
469 * Opens the XTRA interface and provides the callback routines
470 * to the implemenation of this interface.
471 */
472 int (*init)( GpsXtraCallbacks* callbacks );
473 /** Injects XTRA data into the GPS. */
474 int (*inject_xtra_data)( char* data, int length );
475} GpsXtraInterface;
476
477/** Extended interface for DEBUG support. */
478typedef struct {
479 /** set to sizeof(GpsDebugInterface) */
480 size_t size;
481
482 /**
483 * This function should return any information that the native
484 * implementation wishes to include in a bugreport.
485 */
486 size_t (*get_internal_state)(char* buffer, size_t bufferSize);
487} GpsDebugInterface;
488
489/** Represents the status of AGPS. */
490typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700491 /** set to sizeof(AGpsStatus_v1) */
492 size_t size;
493
494 AGpsType type;
495 AGpsStatusValue status;
496} AGpsStatus_v1;
497
498/** Represents the status of AGPS augmented with a IPv4 address field. */
499typedef struct {
500 /** set to sizeof(AGpsStatus_v2) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500501 size_t size;
502
503 AGpsType type;
504 AGpsStatusValue status;
Stephen Li9e48a972011-03-03 15:40:47 -0800505 uint32_t ipaddr;
destradaaf48cc672014-06-05 11:07:09 -0700506} AGpsStatus_v2;
507
508/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
509typedef struct {
510 /** set to sizeof(AGpsStatus_v3) */
511 size_t size;
512
513 AGpsType type;
514 AGpsStatusValue status;
515
516 /**
517 * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
518 * address, or set to INADDR_NONE otherwise.
519 */
520 uint32_t ipaddr;
521
522 /**
523 * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
524 * Any other value of addr.ss_family will be rejected.
525 * */
526 struct sockaddr_storage addr;
527} AGpsStatus_v3;
528
529typedef AGpsStatus_v3 AGpsStatus;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500530
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700531/** Callback with AGPS status information.
532 * Can only be called from a thread created by create_thread_cb.
533 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500534typedef void (* agps_status_callback)(AGpsStatus* status);
535
536/** Callback structure for the AGPS interface. */
537typedef struct {
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700538 agps_status_callback status_cb;
539 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500540} AGpsCallbacks;
541
542
543/** Extended interface for AGPS support. */
544typedef struct {
destradaaf48cc672014-06-05 11:07:09 -0700545 /** set to sizeof(AGpsInterface_v1) */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500546 size_t size;
547
548 /**
549 * Opens the AGPS interface and provides the callback routines
550 * to the implemenation of this interface.
551 */
552 void (*init)( AGpsCallbacks* callbacks );
553 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700554 * Notifies that a data connection is available and sets
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500555 * the name of the APN to be used for SUPL.
556 */
557 int (*data_conn_open)( const char* apn );
558 /**
559 * Notifies that the AGPS data connection has been closed.
560 */
561 int (*data_conn_closed)();
562 /**
destradaaa1f4c0a2013-09-13 15:45:03 -0700563 * Notifies that a data connection is not available for AGPS.
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500564 */
565 int (*data_conn_failed)();
566 /**
567 * Sets the hostname and port for the AGPS server.
568 */
569 int (*set_server)( AGpsType type, const char* hostname, int port );
destradaaf48cc672014-06-05 11:07:09 -0700570} AGpsInterface_v1;
571
572/**
573 * Extended interface for AGPS support, it is augmented to enable to pass
574 * extra APN data.
575 */
576typedef struct {
577 /** set to sizeof(AGpsInterface_v2) */
578 size_t size;
579
580 /**
581 * Opens the AGPS interface and provides the callback routines to the
582 * implementation of this interface.
583 */
584 void (*init)(AGpsCallbacks* callbacks);
585 /**
586 * Deprecated.
587 * If the HAL supports AGpsInterface_v2 this API will not be used, see
588 * data_conn_open_with_apn_ip_type for more information.
589 */
590 int (*data_conn_open)(const char* apn);
591 /**
592 * Notifies that the AGPS data connection has been closed.
593 */
594 int (*data_conn_closed)();
595 /**
596 * Notifies that a data connection is not available for AGPS.
597 */
598 int (*data_conn_failed)();
599 /**
600 * Sets the hostname and port for the AGPS server.
601 */
602 int (*set_server)(AGpsType type, const char* hostname, int port);
603
604 /**
605 * Notifies that a data connection is available and sets the name of the
606 * APN, and its IP type, to be used for SUPL connections.
607 */
608 int (*data_conn_open_with_apn_ip_type)(
609 const char* apn,
610 ApnIpType apnIpType);
611} AGpsInterface_v2;
612
613typedef AGpsInterface_v2 AGpsInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500614
destradaaa1f4c0a2013-09-13 15:45:03 -0700615/** Error codes associated with certificate operations */
616#define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
617#define AGPS_CERTIFICATE_ERROR_GENERIC -100
618#define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
619
620/** A data structure that represents an X.509 certificate using DER encoding */
621typedef struct {
622 size_t length;
623 u_char* data;
624} DerEncodedCertificate;
625
626/**
627 * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
628 * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
629 */
630typedef struct {
631 u_char data[20];
632} Sha1CertificateFingerprint;
633
634/** AGPS Inteface to handle SUPL certificate operations */
635typedef struct {
636 /** set to sizeof(SuplCertificateInterface) */
637 size_t size;
638
639 /**
640 * Installs a set of Certificates used for SUPL connections to the AGPS server.
641 * If needed the HAL should find out internally any certificates that need to be removed to
642 * accommodate the certificates to install.
643 * The certificates installed represent a full set of valid certificates needed to connect to
644 * AGPS SUPL servers.
645 * The list of certificates is required, and all must be available at the same time, when trying
646 * to establish a connection with the AGPS Server.
647 *
648 * Parameters:
649 * certificates - A pointer to an array of DER encoded certificates that are need to be
650 * installed in the HAL.
651 * length - The number of certificates to install.
652 * Returns:
653 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
654 * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
655 * certificates attempted to be installed, the state of the certificates stored should
656 * remain the same as before on this error case.
657 *
658 * IMPORTANT:
659 * If needed the HAL should find out internally the set of certificates that need to be
660 * removed to accommodate the certificates to install.
661 */
662 int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
663
664 /**
665 * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
666 * expected that the given set of certificates is removed from the internal store of the HAL.
667 *
668 * Parameters:
669 * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
670 * certificates to revoke.
671 * length - The number of fingerprints provided.
672 * Returns:
673 * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
674 *
675 * IMPORTANT:
676 * If any of the certificates provided (through its fingerprint) is not known by the HAL,
677 * it should be ignored and continue revoking/deleting the rest of them.
678 */
679 int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
destradaa7ddd4d72013-11-07 13:47:59 -0800680} SuplCertificateInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500681
682/** Represents an NI request */
683typedef struct {
684 /** set to sizeof(GpsNiNotification) */
685 size_t size;
686
687 /**
688 * An ID generated by HAL to associate NI notifications and UI
689 * responses
690 */
691 int notification_id;
692
693 /**
694 * An NI type used to distinguish different categories of NI
695 * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
696 */
697 GpsNiType ni_type;
698
699 /**
700 * Notification/verification options, combinations of GpsNiNotifyFlags constants
701 */
702 GpsNiNotifyFlags notify_flags;
703
704 /**
705 * Timeout period to wait for user response.
706 * Set to 0 for no time out limit.
707 */
708 int timeout;
709
710 /**
711 * Default response when time out.
712 */
713 GpsUserResponseType default_response;
714
715 /**
716 * Requestor ID
717 */
718 char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
719
720 /**
721 * Notification message. It can also be used to store client_id in some cases
722 */
723 char text[GPS_NI_LONG_STRING_MAXLEN];
724
725 /**
726 * Client name decoding scheme
727 */
728 GpsNiEncodingType requestor_id_encoding;
729
730 /**
731 * Client name decoding scheme
732 */
733 GpsNiEncodingType text_encoding;
734
735 /**
736 * A pointer to extra data. Format:
737 * key_1 = value_1
738 * key_2 = value_2
739 */
740 char extras[GPS_NI_LONG_STRING_MAXLEN];
741
742} GpsNiNotification;
743
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700744/** Callback with NI notification.
745 * Can only be called from a thread created by create_thread_cb.
746 */
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500747typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
748
749/** GPS NI callback structure. */
750typedef struct
751{
Mike Lockwood4453b5b2010-06-20 14:23:10 -0700752 /**
753 * Sends the notification request from HAL to GPSLocationProvider.
754 */
755 gps_ni_notify_callback notify_cb;
756 gps_create_thread create_thread_cb;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -0500757} GpsNiCallbacks;
758
759/**
760 * Extended interface for Network-initiated (NI) support.
761 */
762typedef struct
763{
764 /** set to sizeof(GpsNiInterface) */
765 size_t size;
766
767 /** Registers the callbacks for HAL to use. */
768 void (*init) (GpsNiCallbacks *callbacks);
769
770 /** Sends a response to HAL. */
771 void (*respond) (int notif_id, GpsUserResponseType user_response);
772} GpsNiInterface;
773
774struct gps_device_t {
775 struct hw_device_t common;
776
777 /**
778 * Set the provided lights to the provided values.
779 *
780 * Returns: 0 on succes, error code on failure.
781 */
782 const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
783};
784
Miguel Torroja5f404f52010-07-27 06:34:15 +0200785#define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
786#define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
787
788#define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
789#define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
790
791typedef void (*agps_ril_request_set_id)(uint32_t flags);
792typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
793
794typedef struct {
795 agps_ril_request_set_id request_setid;
796 agps_ril_request_ref_loc request_refloc;
797 gps_create_thread create_thread_cb;
798} AGpsRilCallbacks;
799
800/** Extended interface for AGPS_RIL support. */
801typedef struct {
802 /** set to sizeof(AGpsRilInterface) */
803 size_t size;
804 /**
805 * Opens the AGPS interface and provides the callback routines
806 * to the implemenation of this interface.
807 */
808 void (*init)( AGpsRilCallbacks* callbacks );
809
810 /**
811 * Sets the reference location.
812 */
813 void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
814 /**
815 * Sets the set ID.
816 */
817 void (*set_set_id) (AGpsSetIDType type, const char* setid);
818
819 /**
820 * Send network initiated message.
821 */
822 void (*ni_message) (uint8_t *msg, size_t len);
Mike Lockwood455e83b2010-10-11 06:16:57 -0400823
824 /**
825 * Notify GPS of network status changes.
826 * These parameters match values in the android.net.NetworkInfo class.
827 */
828 void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
Kevin Tangb82c2db2011-04-13 17:15:55 -0700829
830 /**
831 * Notify GPS of network status changes.
832 * These parameters match values in the android.net.NetworkInfo class.
833 */
834 void (*update_network_availability) (int avaiable, const char* apn);
Miguel Torroja5f404f52010-07-27 06:34:15 +0200835} AGpsRilInterface;
836
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800837/**
838 * GPS Geofence.
839 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
840 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
841 *
842 * An example state diagram with confidence level: 95% and Unknown time limit
843 * set as 30 secs is shown below. (confidence level and Unknown time limit are
844 * explained latter)
845 * ____________________________
846 * | Unknown (30 secs) |
847 * """"""""""""""""""""""""""""
848 * ^ | | ^
849 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
850 * | v v |
851 * ________ EXITED _________
852 * | Inside | -----------> | Outside |
853 * | | <----------- | |
854 * """""""" ENTERED """""""""
855 *
856 * Inside state: We are 95% confident that the user is inside the geofence.
857 * Outside state: We are 95% confident that the user is outside the geofence
858 * Unknown state: Rest of the time.
859 *
860 * The Unknown state is better explained with an example:
861 *
862 * __________
863 * | c|
864 * | ___ | _______
865 * | |a| | | b |
866 * | """ | """""""
867 * | |
868 * """"""""""
869 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
870 * circle reported by the GPS subsystem. Now with regard to "b", the system is
871 * confident that the user is outside. But with regard to "a" is not confident
872 * whether it is inside or outside the geofence. If the accuracy remains the
873 * same for a sufficient period of time, the UNCERTAIN transition would be
874 * triggered with the state set to Unknown. If the accuracy improves later, an
875 * appropriate transition should be triggered. This "sufficient period of time"
876 * is defined by the parameter in the add_geofence_area API.
877 * In other words, Unknown state can be interpreted as a state in which the
878 * GPS subsystem isn't confident enough that the user is either inside or
879 * outside the Geofence. It moves to Unknown state only after the expiry of the
880 * timeout.
881 *
882 * The geofence callback needs to be triggered for the ENTERED and EXITED
883 * transitions, when the GPS system is confident that the user has entered
884 * (Inside state) or exited (Outside state) the Geofence. An implementation
885 * which uses a value of 95% as the confidence is recommended. The callback
886 * should be triggered only for the transitions requested by the
887 * add_geofence_area call.
888 *
889 * Even though the diagram and explanation talks about states and transitions,
890 * the callee is only interested in the transistions. The states are mentioned
891 * here for illustrative purposes.
892 *
893 * Startup Scenario: When the device boots up, if an application adds geofences,
894 * and then we get an accurate GPS location fix, it needs to trigger the
895 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
896 * By default, all the Geofences will be in the Unknown state.
897 *
898 * When the GPS system is unavailable, gps_geofence_status_callback should be
899 * called to inform the upper layers of the same. Similarly, when it becomes
900 * available the callback should be called. This is a global state while the
901 * UNKNOWN transition described above is per geofence.
902 *
903 * An important aspect to note is that users of this API (framework), will use
904 * other subsystems like wifi, sensors, cell to handle Unknown case and
905 * hopefully provide a definitive state transition to the third party
906 * application. GPS Geofence will just be a signal indicating what the GPS
907 * subsystem knows about the Geofence.
908 *
909 */
910#define GPS_GEOFENCE_ENTERED (1<<0L)
911#define GPS_GEOFENCE_EXITED (1<<1L)
912#define GPS_GEOFENCE_UNCERTAIN (1<<2L)
913
914#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
915#define GPS_GEOFENCE_AVAILABLE (1<<1L)
916
Jaikumar Ganesh5824b402013-02-25 11:43:33 -0800917#define GPS_GEOFENCE_OPERATION_SUCCESS 0
918#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
919#define GPS_GEOFENCE_ERROR_ID_EXISTS -101
920#define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
921#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
922#define GPS_GEOFENCE_ERROR_GENERIC -149
923
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -0800924/**
925 * The callback associated with the geofence.
926 * Parameters:
927 * geofence_id - The id associated with the add_geofence_area.
928 * location - The current GPS location.
929 * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
930 * GPS_GEOFENCE_UNCERTAIN.
931 * timestamp - Timestamp when the transition was detected.
932 *
933 * The callback should only be called when the caller is interested in that
934 * particular transition. For instance, if the caller is interested only in
935 * ENTERED transition, then the callback should NOT be called with the EXITED
936 * transition.
937 *
938 * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
939 * subsystem will wake up the application processor, if its in suspend state.
940 */
941typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
942 int32_t transition, GpsUtcTime timestamp);
943
944/**
945 * The callback associated with the availablity of the GPS system for geofencing
946 * monitoring. If the GPS system determines that it cannot monitor geofences
947 * because of lack of reliability or unavailability of the GPS signals, it will
948 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
949 *
950 * Parameters:
951 * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
952 * last_location - Last known location.
953 */
954typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
955
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -0700956/**
957 * The callback associated with the add_geofence call.
958 *
959 * Parameter:
960 * geofence_id - Id of the geofence.
961 * status - GPS_GEOFENCE_OPERATION_SUCCESS
962 * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
963 * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
964 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
965 * invalid transition
966 * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
967 */
968typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
969
970/**
971 * The callback associated with the remove_geofence call.
972 *
973 * Parameter:
974 * geofence_id - Id of the geofence.
975 * status - GPS_GEOFENCE_OPERATION_SUCCESS
976 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
977 * GPS_GEOFENCE_ERROR_GENERIC for others.
978 */
979typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
980
981
982/**
983 * The callback associated with the pause_geofence call.
984 *
985 * Parameter:
986 * geofence_id - Id of the geofence.
987 * status - GPS_GEOFENCE_OPERATION_SUCCESS
988 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
989 * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
990 * when monitor_transitions is invalid
991 * GPS_GEOFENCE_ERROR_GENERIC for others.
992 */
993typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
994
995/**
996 * The callback associated with the resume_geofence call.
997 *
998 * Parameter:
999 * geofence_id - Id of the geofence.
1000 * status - GPS_GEOFENCE_OPERATION_SUCCESS
1001 * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
1002 * GPS_GEOFENCE_ERROR_GENERIC for others.
1003 */
1004typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
1005
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001006typedef struct {
1007 gps_geofence_transition_callback geofence_transition_callback;
1008 gps_geofence_status_callback geofence_status_callback;
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001009 gps_geofence_add_callback geofence_add_callback;
1010 gps_geofence_remove_callback geofence_remove_callback;
1011 gps_geofence_pause_callback geofence_pause_callback;
1012 gps_geofence_resume_callback geofence_resume_callback;
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001013 gps_create_thread create_thread_cb;
1014} GpsGeofenceCallbacks;
1015
1016/** Extended interface for GPS_Geofencing support */
1017typedef struct {
1018 /** set to sizeof(GpsGeofencingInterface) */
1019 size_t size;
1020
1021 /**
1022 * Opens the geofence interface and provides the callback routines
1023 * to the implemenation of this interface.
1024 */
1025 void (*init)( GpsGeofenceCallbacks* callbacks );
1026
1027 /**
1028 * Add a geofence area. This api currently supports circular geofences.
1029 * Parameters:
1030 * geofence_id - The id for the geofence. If a geofence with this id
Jaikumar Ganesh5824b402013-02-25 11:43:33 -08001031 * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
1032 * should be returned.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001033 * latitude, longtitude, radius_meters - The lat, long and radius
1034 * (in meters) for the geofence
1035 * last_transition - The current state of the geofence. For example, if
1036 * the system already knows that the user is inside the geofence,
1037 * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
1038 * will be GPS_GEOFENCE_UNCERTAIN.
1039 * monitor_transition - Which transitions to monitor. Bitwise OR of
1040 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1041 * GPS_GEOFENCE_UNCERTAIN.
1042 * notification_responsiveness_ms - Defines the best-effort description
1043 * of how soon should the callback be called when the transition
1044 * associated with the Geofence is triggered. For instance, if set
1045 * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
1046 * should be called 1000 milliseconds within entering the geofence.
1047 * This parameter is defined in milliseconds.
1048 * NOTE: This is not to be confused with the rate that the GPS is
1049 * polled at. It is acceptable to dynamically vary the rate of
1050 * sampling the GPS for power-saving reasons; thus the rate of
1051 * sampling may be faster or slower than this.
1052 * unknown_timer_ms - The time limit after which the UNCERTAIN transition
1053 * should be triggered. This paramter is defined in milliseconds.
1054 * See above for a detailed explanation.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001055 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001056 void (*add_geofence_area) (int32_t geofence_id, double latitude,
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001057 double longitude, double radius_meters,
1058 int last_transition, int monitor_transitions,
1059 int notification_responsiveness_ms,
1060 int unknown_timer_ms);
1061
1062 /**
1063 * Pause monitoring a particular geofence.
1064 * Parameters:
1065 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001066 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001067 void (*pause_geofence) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001068
1069 /**
1070 * Resume monitoring a particular geofence.
1071 * Parameters:
1072 * geofence_id - The id for the geofence.
1073 * monitor_transitions - Which transitions to monitor. Bitwise OR of
1074 * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
1075 * GPS_GEOFENCE_UNCERTAIN.
1076 * This supersedes the value associated provided in the
1077 * add_geofence_area call.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001078 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001079 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001080
1081 /**
1082 * Remove a geofence area. After the function returns, no notifications
1083 * should be sent.
1084 * Parameter:
1085 * geofence_id - The id for the geofence.
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001086 */
Jaikumar Ganesh3e39c492013-03-29 11:56:36 -07001087 void (*remove_geofence_area) (int32_t geofence_id);
Jaikumar Ganesh052a20a2013-02-04 17:22:04 -08001088} GpsGeofencingInterface;
Mike Lockwood9b0b1c32010-02-23 18:42:37 -05001089__END_DECLS
1090
1091#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1092