Android Hardware Abstraction Layer
gps.h
Go to the documentation of this file.
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 */
36 typedef 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. */
42 typedef 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. */
53 typedef 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. */
62 typedef 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. */
77 typedef 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 /** GPS supports Geofencing */
107 #define GPS_CAPABILITY_GEOFENCING 0x0000020
108 
109 /** Flags used to specify which aiding data to delete
110  when calling delete_aiding_data(). */
111 typedef uint16_t GpsAidingData;
112 // IMPORTANT: Note that the following values must match
113 // constants in GpsLocationProvider.java.
114 #define GPS_DELETE_EPHEMERIS 0x0001
115 #define GPS_DELETE_ALMANAC 0x0002
116 #define GPS_DELETE_POSITION 0x0004
117 #define GPS_DELETE_TIME 0x0008
118 #define GPS_DELETE_IONO 0x0010
119 #define GPS_DELETE_UTC 0x0020
120 #define GPS_DELETE_HEALTH 0x0040
121 #define GPS_DELETE_SVDIR 0x0080
122 #define GPS_DELETE_SVSTEER 0x0100
123 #define GPS_DELETE_SADATA 0x0200
124 #define GPS_DELETE_RTI 0x0400
125 #define GPS_DELETE_CELLDB_INFO 0x8000
126 #define GPS_DELETE_ALL 0xFFFF
127 
128 /** AGPS type */
129 typedef uint16_t AGpsType;
130 #define AGPS_TYPE_SUPL 1
131 #define AGPS_TYPE_C2K 2
132 
133 typedef uint16_t AGpsSetIDType;
134 #define AGPS_SETID_TYPE_NONE 0
135 #define AGPS_SETID_TYPE_IMSI 1
136 #define AGPS_SETID_TYPE_MSISDN 2
137 
138 /**
139  * String length constants
140  */
141 #define GPS_NI_SHORT_STRING_MAXLEN 256
142 #define GPS_NI_LONG_STRING_MAXLEN 2048
143 
144 /**
145  * GpsNiType constants
146  */
147 typedef uint32_t GpsNiType;
148 #define GPS_NI_TYPE_VOICE 1
149 #define GPS_NI_TYPE_UMTS_SUPL 2
150 #define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
151 
152 /**
153  * GpsNiNotifyFlags constants
154  */
155 typedef uint32_t GpsNiNotifyFlags;
156 /** NI requires notification */
157 #define GPS_NI_NEED_NOTIFY 0x0001
158 /** NI requires verification */
159 #define GPS_NI_NEED_VERIFY 0x0002
160 /** NI requires privacy override, no notification/minimal trace */
161 #define GPS_NI_PRIVACY_OVERRIDE 0x0004
162 
163 /**
164  * GPS NI responses, used to define the response in
165  * NI structures
166  */
168 #define GPS_NI_RESPONSE_ACCEPT 1
169 #define GPS_NI_RESPONSE_DENY 2
170 #define GPS_NI_RESPONSE_NORESP 3
171 
172 /**
173  * NI data encoding scheme
174  */
175 typedef int GpsNiEncodingType;
176 #define GPS_ENC_NONE 0
177 #define GPS_ENC_SUPL_GSM_DEFAULT 1
178 #define GPS_ENC_SUPL_UTF8 2
179 #define GPS_ENC_SUPL_UCS2 3
180 #define GPS_ENC_UNKNOWN -1
181 
182 /** AGPS status event values. */
183 typedef uint16_t AGpsStatusValue;
184 /** GPS requests data connection for AGPS. */
185 #define GPS_REQUEST_AGPS_DATA_CONN 1
186 /** GPS releases the AGPS data connection. */
187 #define GPS_RELEASE_AGPS_DATA_CONN 2
188 /** AGPS data connection initiated */
189 #define GPS_AGPS_DATA_CONNECTED 3
190 /** AGPS data connection completed */
191 #define GPS_AGPS_DATA_CONN_DONE 4
192 /** AGPS data connection failed */
193 #define GPS_AGPS_DATA_CONN_FAILED 5
194 
195 #define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
196 #define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
197 #define AGPS_REG_LOCATION_TYPE_MAC 3
198 
199 /** Network types for update_network_state "type" parameter */
200 #define AGPS_RIL_NETWORK_TYPE_MOBILE 0
201 #define AGPS_RIL_NETWORK_TYPE_WIFI 1
202 #define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
203 #define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
204 #define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
205 #define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
206 #define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
207 
208 /**
209  * Name for the GPS XTRA interface.
210  */
211 #define GPS_XTRA_INTERFACE "gps-xtra"
212 
213 /**
214  * Name for the GPS DEBUG interface.
215  */
216 #define GPS_DEBUG_INTERFACE "gps-debug"
217 
218 /**
219  * Name for the AGPS interface.
220  */
221 #define AGPS_INTERFACE "agps"
222 
223 /**
224  * Name of the Supl Certificate interface.
225  */
226 #define SUPL_CERTIFICATE_INTERFACE "supl-certificate"
227 
228 /**
229  * Name for NI interface
230  */
231 #define GPS_NI_INTERFACE "gps-ni"
232 
233 /**
234  * Name for the AGPS-RIL interface.
235  */
236 #define AGPS_RIL_INTERFACE "agps_ril"
237 
238 /**
239  * Name for the GPS_Geofencing interface.
240  */
241 #define GPS_GEOFENCING_INTERFACE "gps_geofencing"
242 
243 
244 /** Represents a location. */
245 typedef struct {
246  /** set to sizeof(GpsLocation) */
247  size_t size;
248  /** Contains GpsLocationFlags bits. */
249  uint16_t flags;
250  /** Represents latitude in degrees. */
251  double latitude;
252  /** Represents longitude in degrees. */
253  double longitude;
254  /** Represents altitude in meters above the WGS 84 reference
255  * ellipsoid. */
256  double altitude;
257  /** Represents speed in meters per second. */
258  float speed;
259  /** Represents heading in degrees. */
260  float bearing;
261  /** Represents expected accuracy in meters. */
262  float accuracy;
263  /** Timestamp for the location fix. */
265 } GpsLocation;
266 
267 /** Represents the status. */
268 typedef struct {
269  /** set to sizeof(GpsStatus) */
270  size_t size;
272 } GpsStatus;
273 
274 /** Represents SV information. */
275 typedef struct {
276  /** set to sizeof(GpsSvInfo) */
277  size_t size;
278  /** Pseudo-random number for the SV. */
279  int prn;
280  /** Signal to noise ratio. */
281  float snr;
282  /** Elevation of SV in degrees. */
283  float elevation;
284  /** Azimuth of SV in degrees. */
285  float azimuth;
286 } GpsSvInfo;
287 
288 /** Represents SV status. */
289 typedef struct {
290  /** set to sizeof(GpsSvStatus) */
291  size_t size;
292 
293  /** Number of SVs currently visible. */
294  int num_svs;
295 
296  /** Contains an array of SV information. */
298 
299  /** Represents a bit mask indicating which SVs
300  * have ephemeris data.
301  */
302  uint32_t ephemeris_mask;
303 
304  /** Represents a bit mask indicating which SVs
305  * have almanac data.
306  */
307  uint32_t almanac_mask;
308 
309  /**
310  * Represents a bit mask indicating which SVs
311  * were used for computing the most recent position fix.
312  */
314 } GpsSvStatus;
315 
316 /* 2G and 3G */
317 /* In 3G lac is discarded */
318 typedef struct {
319  uint16_t type;
320  uint16_t mcc;
321  uint16_t mnc;
322  uint16_t lac;
323  uint32_t cid;
325 
326 typedef struct {
327  uint8_t mac[6];
329 
330 /** Represents ref locations */
331 typedef struct {
332  uint16_t type;
333  union {
336  } u;
338 
339 /** Callback with location information.
340  * Can only be called from a thread created by create_thread_cb.
341  */
342 typedef void (* gps_location_callback)(GpsLocation* location);
343 
344 /** Callback with status information.
345  * Can only be called from a thread created by create_thread_cb.
346  */
347 typedef void (* gps_status_callback)(GpsStatus* status);
348 
349 /** Callback with SV status information.
350  * Can only be called from a thread created by create_thread_cb.
351  */
352 typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
353 
354 /** Callback for reporting NMEA sentences.
355  * Can only be called from a thread created by create_thread_cb.
356  */
357 typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
358 
359 /** Callback to inform framework of the GPS engine's capabilities.
360  * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
361  */
362 typedef void (* gps_set_capabilities)(uint32_t capabilities);
363 
364 /** Callback utility for acquiring the GPS wakelock.
365  * This can be used to prevent the CPU from suspending while handling GPS events.
366  */
367 typedef void (* gps_acquire_wakelock)();
368 
369 /** Callback utility for releasing the GPS wakelock. */
370 typedef void (* gps_release_wakelock)();
371 
372 /** Callback for requesting NTP time */
373 typedef void (* gps_request_utc_time)();
374 
375 /** Callback for creating a thread that can call into the Java framework code.
376  * This must be used to create any threads that report events up to the framework.
377  */
378 typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
379 
380 /** GPS callback structure. */
381 typedef struct {
382  /** set to sizeof(GpsCallbacks) */
383  size_t size;
393 } GpsCallbacks;
394 
395 
396 /** Represents the standard GPS interface. */
397 typedef struct {
398  /** set to sizeof(GpsInterface) */
399  size_t size;
400  /**
401  * Opens the interface and provides the callback routines
402  * to the implemenation of this interface.
403  */
404  int (*init)( GpsCallbacks* callbacks );
405 
406  /** Starts navigating. */
407  int (*start)( void );
408 
409  /** Stops navigating. */
410  int (*stop)( void );
411 
412  /** Closes the interface. */
413  void (*cleanup)( void );
414 
415  /** Injects the current time. */
416  int (*inject_time)(GpsUtcTime time, int64_t timeReference,
417  int uncertainty);
418 
419  /** Injects current location from another location provider
420  * (typically cell ID).
421  * latitude and longitude are measured in degrees
422  * expected accuracy is measured in meters
423  */
424  int (*inject_location)(double latitude, double longitude, float accuracy);
425 
426  /**
427  * Specifies that the next call to start will not use the
428  * information defined in the flags. GPS_DELETE_ALL is passed for
429  * a cold start.
430  */
431  void (*delete_aiding_data)(GpsAidingData flags);
432 
433  /**
434  * min_interval represents the time between fixes in milliseconds.
435  * preferred_accuracy represents the requested fix accuracy in meters.
436  * preferred_time represents the requested time to first fix in milliseconds.
437  */
438  int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
439  uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
440 
441  /** Get a pointer to extension information. */
442  const void* (*get_extension)(const char* name);
443 } GpsInterface;
444 
445 /** Callback to request the client to download XTRA data.
446  * The client should download XTRA data and inject it by calling inject_xtra_data().
447  * Can only be called from a thread created by create_thread_cb.
448  */
449 typedef void (* gps_xtra_download_request)();
450 
451 /** Callback structure for the XTRA interface. */
452 typedef struct {
456 
457 /** Extended interface for XTRA support. */
458 typedef struct {
459  /** set to sizeof(GpsXtraInterface) */
460  size_t size;
461  /**
462  * Opens the XTRA interface and provides the callback routines
463  * to the implemenation of this interface.
464  */
465  int (*init)( GpsXtraCallbacks* callbacks );
466  /** Injects XTRA data into the GPS. */
467  int (*inject_xtra_data)( char* data, int length );
469 
470 /** Extended interface for DEBUG support. */
471 typedef struct {
472  /** set to sizeof(GpsDebugInterface) */
473  size_t size;
474 
475  /**
476  * This function should return any information that the native
477  * implementation wishes to include in a bugreport.
478  */
479  size_t (*get_internal_state)(char* buffer, size_t bufferSize);
481 
482 /** Represents the status of AGPS. */
483 typedef struct {
484  /** set to sizeof(AGpsStatus) */
485  size_t size;
486 
489  uint32_t ipaddr;
490 } AGpsStatus;
491 
492 /** Callback with AGPS status information.
493  * Can only be called from a thread created by create_thread_cb.
494  */
495 typedef void (* agps_status_callback)(AGpsStatus* status);
496 
497 /** Callback structure for the AGPS interface. */
498 typedef struct {
501 } AGpsCallbacks;
502 
503 
504 /** Extended interface for AGPS support. */
505 typedef struct {
506  /** set to sizeof(AGpsInterface) */
507  size_t size;
508 
509  /**
510  * Opens the AGPS interface and provides the callback routines
511  * to the implemenation of this interface.
512  */
513  void (*init)( AGpsCallbacks* callbacks );
514  /**
515  * Notifies that a data connection is available and sets
516  * the name of the APN to be used for SUPL.
517  */
518  int (*data_conn_open)( const char* apn );
519  /**
520  * Notifies that the AGPS data connection has been closed.
521  */
522  int (*data_conn_closed)();
523  /**
524  * Notifies that a data connection is not available for AGPS.
525  */
526  int (*data_conn_failed)();
527  /**
528  * Sets the hostname and port for the AGPS server.
529  */
530  int (*set_server)( AGpsType type, const char* hostname, int port );
531 } AGpsInterface;
532 
533 /** Error codes associated with certificate operations */
534 #define AGPS_CERTIFICATE_OPERATION_SUCCESS 0
535 #define AGPS_CERTIFICATE_ERROR_GENERIC -100
536 #define AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101
537 
538 /** A data structure that represents an X.509 certificate using DER encoding */
539 typedef struct {
540  size_t length;
541  u_char* data;
543 
544 /**
545  * A type definition for SHA1 Fingerprints used to identify X.509 Certificates
546  * The Fingerprint is a digest of the DER Certificate that uniquely identifies it.
547  */
548 typedef struct {
549  u_char data[20];
551 
552 /** AGPS Inteface to handle SUPL certificate operations */
553 typedef struct {
554  /** set to sizeof(SuplCertificateInterface) */
555  size_t size;
556 
557  /**
558  * Installs a set of Certificates used for SUPL connections to the AGPS server.
559  * If needed the HAL should find out internally any certificates that need to be removed to
560  * accommodate the certificates to install.
561  * The certificates installed represent a full set of valid certificates needed to connect to
562  * AGPS SUPL servers.
563  * The list of certificates is required, and all must be available at the same time, when trying
564  * to establish a connection with the AGPS Server.
565  *
566  * Parameters:
567  * certificates - A pointer to an array of DER encoded certificates that are need to be
568  * installed in the HAL.
569  * length - The number of certificates to install.
570  * Returns:
571  * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully
572  * AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of
573  * certificates attempted to be installed, the state of the certificates stored should
574  * remain the same as before on this error case.
575  *
576  * IMPORTANT:
577  * If needed the HAL should find out internally the set of certificates that need to be
578  * removed to accommodate the certificates to install.
579  */
580  int (*install_certificates) ( const DerEncodedCertificate* certificates, size_t length );
581 
582  /**
583  * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is
584  * expected that the given set of certificates is removed from the internal store of the HAL.
585  *
586  * Parameters:
587  * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of
588  * certificates to revoke.
589  * length - The number of fingerprints provided.
590  * Returns:
591  * AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully.
592  *
593  * IMPORTANT:
594  * If any of the certificates provided (through its fingerprint) is not known by the HAL,
595  * it should be ignored and continue revoking/deleting the rest of them.
596  */
597  int (*revoke_certificates) ( const Sha1CertificateFingerprint* fingerprints, size_t length );
599 
600 /** Represents an NI request */
601 typedef struct {
602  /** set to sizeof(GpsNiNotification) */
603  size_t size;
604 
605  /**
606  * An ID generated by HAL to associate NI notifications and UI
607  * responses
608  */
610 
611  /**
612  * An NI type used to distinguish different categories of NI
613  * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
614  */
616 
617  /**
618  * Notification/verification options, combinations of GpsNiNotifyFlags constants
619  */
621 
622  /**
623  * Timeout period to wait for user response.
624  * Set to 0 for no time out limit.
625  */
626  int timeout;
627 
628  /**
629  * Default response when time out.
630  */
632 
633  /**
634  * Requestor ID
635  */
636  char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
637 
638  /**
639  * Notification message. It can also be used to store client_id in some cases
640  */
642 
643  /**
644  * Client name decoding scheme
645  */
647 
648  /**
649  * Client name decoding scheme
650  */
652 
653  /**
654  * A pointer to extra data. Format:
655  * key_1 = value_1
656  * key_2 = value_2
657  */
659 
661 
662 /** Callback with NI notification.
663  * Can only be called from a thread created by create_thread_cb.
664  */
665 typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
666 
667 /** GPS NI callback structure. */
668 typedef struct
669 {
670  /**
671  * Sends the notification request from HAL to GPSLocationProvider.
672  */
676 
677 /**
678  * Extended interface for Network-initiated (NI) support.
679  */
680 typedef struct
681 {
682  /** set to sizeof(GpsNiInterface) */
683  size_t size;
684 
685  /** Registers the callbacks for HAL to use. */
686  void (*init) (GpsNiCallbacks *callbacks);
687 
688  /** Sends a response to HAL. */
689  void (*respond) (int notif_id, GpsUserResponseType user_response);
691 
692 struct gps_device_t {
694 
695  /**
696  * Set the provided lights to the provided values.
697  *
698  * Returns: 0 on succes, error code on failure.
699  */
700  const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
701 };
702 
703 #define AGPS_RIL_REQUEST_SETID_IMSI (1<<0L)
704 #define AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L)
705 
706 #define AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L)
707 #define AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L)
708 
709 typedef void (*agps_ril_request_set_id)(uint32_t flags);
710 typedef void (*agps_ril_request_ref_loc)(uint32_t flags);
711 
712 typedef struct {
717 
718 /** Extended interface for AGPS_RIL support. */
719 typedef struct {
720  /** set to sizeof(AGpsRilInterface) */
721  size_t size;
722  /**
723  * Opens the AGPS interface and provides the callback routines
724  * to the implemenation of this interface.
725  */
726  void (*init)( AGpsRilCallbacks* callbacks );
727 
728  /**
729  * Sets the reference location.
730  */
731  void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
732  /**
733  * Sets the set ID.
734  */
735  void (*set_set_id) (AGpsSetIDType type, const char* setid);
736 
737  /**
738  * Send network initiated message.
739  */
740  void (*ni_message) (uint8_t *msg, size_t len);
741 
742  /**
743  * Notify GPS of network status changes.
744  * These parameters match values in the android.net.NetworkInfo class.
745  */
746  void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);
747 
748  /**
749  * Notify GPS of network status changes.
750  * These parameters match values in the android.net.NetworkInfo class.
751  */
752  void (*update_network_availability) (int avaiable, const char* apn);
754 
755 /**
756  * GPS Geofence.
757  * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
758  * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
759  *
760  * An example state diagram with confidence level: 95% and Unknown time limit
761  * set as 30 secs is shown below. (confidence level and Unknown time limit are
762  * explained latter)
763  * ____________________________
764  * | Unknown (30 secs) |
765  * """"""""""""""""""""""""""""
766  * ^ | | ^
767  * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
768  * | v v |
769  * ________ EXITED _________
770  * | Inside | -----------> | Outside |
771  * | | <----------- | |
772  * """""""" ENTERED """""""""
773  *
774  * Inside state: We are 95% confident that the user is inside the geofence.
775  * Outside state: We are 95% confident that the user is outside the geofence
776  * Unknown state: Rest of the time.
777  *
778  * The Unknown state is better explained with an example:
779  *
780  * __________
781  * | c|
782  * | ___ | _______
783  * | |a| | | b |
784  * | """ | """""""
785  * | |
786  * """"""""""
787  * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
788  * circle reported by the GPS subsystem. Now with regard to "b", the system is
789  * confident that the user is outside. But with regard to "a" is not confident
790  * whether it is inside or outside the geofence. If the accuracy remains the
791  * same for a sufficient period of time, the UNCERTAIN transition would be
792  * triggered with the state set to Unknown. If the accuracy improves later, an
793  * appropriate transition should be triggered. This "sufficient period of time"
794  * is defined by the parameter in the add_geofence_area API.
795  * In other words, Unknown state can be interpreted as a state in which the
796  * GPS subsystem isn't confident enough that the user is either inside or
797  * outside the Geofence. It moves to Unknown state only after the expiry of the
798  * timeout.
799  *
800  * The geofence callback needs to be triggered for the ENTERED and EXITED
801  * transitions, when the GPS system is confident that the user has entered
802  * (Inside state) or exited (Outside state) the Geofence. An implementation
803  * which uses a value of 95% as the confidence is recommended. The callback
804  * should be triggered only for the transitions requested by the
805  * add_geofence_area call.
806  *
807  * Even though the diagram and explanation talks about states and transitions,
808  * the callee is only interested in the transistions. The states are mentioned
809  * here for illustrative purposes.
810  *
811  * Startup Scenario: When the device boots up, if an application adds geofences,
812  * and then we get an accurate GPS location fix, it needs to trigger the
813  * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
814  * By default, all the Geofences will be in the Unknown state.
815  *
816  * When the GPS system is unavailable, gps_geofence_status_callback should be
817  * called to inform the upper layers of the same. Similarly, when it becomes
818  * available the callback should be called. This is a global state while the
819  * UNKNOWN transition described above is per geofence.
820  *
821  * An important aspect to note is that users of this API (framework), will use
822  * other subsystems like wifi, sensors, cell to handle Unknown case and
823  * hopefully provide a definitive state transition to the third party
824  * application. GPS Geofence will just be a signal indicating what the GPS
825  * subsystem knows about the Geofence.
826  *
827  */
828 #define GPS_GEOFENCE_ENTERED (1<<0L)
829 #define GPS_GEOFENCE_EXITED (1<<1L)
830 #define GPS_GEOFENCE_UNCERTAIN (1<<2L)
831 
832 #define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
833 #define GPS_GEOFENCE_AVAILABLE (1<<1L)
834 
835 #define GPS_GEOFENCE_OPERATION_SUCCESS 0
836 #define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
837 #define GPS_GEOFENCE_ERROR_ID_EXISTS -101
838 #define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
839 #define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
840 #define GPS_GEOFENCE_ERROR_GENERIC -149
841 
842 /**
843  * The callback associated with the geofence.
844  * Parameters:
845  * geofence_id - The id associated with the add_geofence_area.
846  * location - The current GPS location.
847  * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
848  * GPS_GEOFENCE_UNCERTAIN.
849  * timestamp - Timestamp when the transition was detected.
850  *
851  * The callback should only be called when the caller is interested in that
852  * particular transition. For instance, if the caller is interested only in
853  * ENTERED transition, then the callback should NOT be called with the EXITED
854  * transition.
855  *
856  * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
857  * subsystem will wake up the application processor, if its in suspend state.
858  */
859 typedef void (*gps_geofence_transition_callback) (int32_t geofence_id, GpsLocation* location,
860  int32_t transition, GpsUtcTime timestamp);
861 
862 /**
863  * The callback associated with the availablity of the GPS system for geofencing
864  * monitoring. If the GPS system determines that it cannot monitor geofences
865  * because of lack of reliability or unavailability of the GPS signals, it will
866  * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
867  *
868  * Parameters:
869  * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
870  * last_location - Last known location.
871  */
872 typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);
873 
874 /**
875  * The callback associated with the add_geofence call.
876  *
877  * Parameter:
878  * geofence_id - Id of the geofence.
879  * status - GPS_GEOFENCE_OPERATION_SUCCESS
880  * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
881  * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
882  * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
883  * invalid transition
884  * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
885  */
886 typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);
887 
888 /**
889  * The callback associated with the remove_geofence call.
890  *
891  * Parameter:
892  * geofence_id - Id of the geofence.
893  * status - GPS_GEOFENCE_OPERATION_SUCCESS
894  * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
895  * GPS_GEOFENCE_ERROR_GENERIC for others.
896  */
897 typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);
898 
899 
900 /**
901  * The callback associated with the pause_geofence call.
902  *
903  * Parameter:
904  * geofence_id - Id of the geofence.
905  * status - GPS_GEOFENCE_OPERATION_SUCCESS
906  * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
907  * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
908  * when monitor_transitions is invalid
909  * GPS_GEOFENCE_ERROR_GENERIC for others.
910  */
911 typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);
912 
913 /**
914  * The callback associated with the resume_geofence call.
915  *
916  * Parameter:
917  * geofence_id - Id of the geofence.
918  * status - GPS_GEOFENCE_OPERATION_SUCCESS
919  * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
920  * GPS_GEOFENCE_ERROR_GENERIC for others.
921  */
922 typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);
923 
924 typedef struct {
933 
934 /** Extended interface for GPS_Geofencing support */
935 typedef struct {
936  /** set to sizeof(GpsGeofencingInterface) */
937  size_t size;
938 
939  /**
940  * Opens the geofence interface and provides the callback routines
941  * to the implemenation of this interface.
942  */
943  void (*init)( GpsGeofenceCallbacks* callbacks );
944 
945  /**
946  * Add a geofence area. This api currently supports circular geofences.
947  * Parameters:
948  * geofence_id - The id for the geofence. If a geofence with this id
949  * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
950  * should be returned.
951  * latitude, longtitude, radius_meters - The lat, long and radius
952  * (in meters) for the geofence
953  * last_transition - The current state of the geofence. For example, if
954  * the system already knows that the user is inside the geofence,
955  * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
956  * will be GPS_GEOFENCE_UNCERTAIN.
957  * monitor_transition - Which transitions to monitor. Bitwise OR of
958  * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
959  * GPS_GEOFENCE_UNCERTAIN.
960  * notification_responsiveness_ms - Defines the best-effort description
961  * of how soon should the callback be called when the transition
962  * associated with the Geofence is triggered. For instance, if set
963  * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
964  * should be called 1000 milliseconds within entering the geofence.
965  * This parameter is defined in milliseconds.
966  * NOTE: This is not to be confused with the rate that the GPS is
967  * polled at. It is acceptable to dynamically vary the rate of
968  * sampling the GPS for power-saving reasons; thus the rate of
969  * sampling may be faster or slower than this.
970  * unknown_timer_ms - The time limit after which the UNCERTAIN transition
971  * should be triggered. This paramter is defined in milliseconds.
972  * See above for a detailed explanation.
973  */
974  void (*add_geofence_area) (int32_t geofence_id, double latitude,
975  double longitude, double radius_meters,
976  int last_transition, int monitor_transitions,
977  int notification_responsiveness_ms,
978  int unknown_timer_ms);
979 
980  /**
981  * Pause monitoring a particular geofence.
982  * Parameters:
983  * geofence_id - The id for the geofence.
984  */
985  void (*pause_geofence) (int32_t geofence_id);
986 
987  /**
988  * Resume monitoring a particular geofence.
989  * Parameters:
990  * geofence_id - The id for the geofence.
991  * monitor_transitions - Which transitions to monitor. Bitwise OR of
992  * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
993  * GPS_GEOFENCE_UNCERTAIN.
994  * This supersedes the value associated provided in the
995  * add_geofence_area call.
996  */
997  void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
998 
999  /**
1000  * Remove a geofence area. After the function returns, no notifications
1001  * should be sent.
1002  * Parameter:
1003  * geofence_id - The id for the geofence.
1004  */
1005  void (*remove_geofence_area) (int32_t geofence_id);
1007 __END_DECLS
1008 
1009 #endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */
1010