summaryrefslogtreecommitdiffstats
path: root/include/hardware/gps.h
blob: 66519c1930f8d5d1a4601bf30f48e2c14049bc9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
/*
 * Copyright (C) 2010 The Android Open Source Project
 * Copyright (c) 2011,2012 Code Aurora Forum. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_INCLUDE_HARDWARE_GPS_H
#define ANDROID_INCLUDE_HARDWARE_GPS_H

#include <stdint.h>
#include <stdbool.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <pthread.h>

#include <hardware/hardware.h>

__BEGIN_DECLS

/**
 * The id of this module
 */
#define GPS_HARDWARE_MODULE_ID "gps"
#define ULP_NETWORK_INTERFACE "ulp-network-interface"

/** Milliseconds since January 1, 1970 */
typedef int64_t GpsUtcTime;

/** Maximum number of SVs for gps_sv_status_callback(). */
#define GPS_MAX_SVS 32

/** Requested operational mode for GPS operation. */
typedef uint32_t GpsPositionMode;
// IMPORTANT: Note that the following values must match
// constants in GpsLocationProvider.java.
/** Mode for running GPS standalone (no assistance). */
#define GPS_POSITION_MODE_STANDALONE    0
/** AGPS MS-Based mode. */
#define GPS_POSITION_MODE_MS_BASED      1
/** AGPS MS-Assisted mode. */
#define GPS_POSITION_MODE_MS_ASSISTED   2

/** Requested recurrence mode for GPS operation. */
typedef uint32_t GpsPositionRecurrence;
// IMPORTANT: Note that the following values must match
// constants in GpsLocationProvider.java.
/** Receive GPS fixes on a recurring basis at a specified period. */
#define GPS_POSITION_RECURRENCE_PERIODIC    0
/** Request a single shot GPS fix. */
#define GPS_POSITION_RECURRENCE_SINGLE      1

/** GPS status event values. */
typedef uint16_t GpsStatusValue;
// IMPORTANT: Note that the following values must match
// constants in GpsLocationProvider.java.
/** GPS status unknown. */
#define GPS_STATUS_NONE             0
/** GPS has begun navigating. */
#define GPS_STATUS_SESSION_BEGIN    1
/** GPS has stopped navigating. */
#define GPS_STATUS_SESSION_END      2
/** GPS has powered on but is not navigating. */
#define GPS_STATUS_ENGINE_ON        3
/** GPS is powered off. */
#define GPS_STATUS_ENGINE_OFF       4

/** Flags to indicate which values are valid in a GpsLocation. */
typedef uint16_t GpsLocationFlags;
// IMPORTANT: Note that the following values must match
// constants in GpsLocationProvider.java.
/** GpsLocation has valid latitude and longitude. */
#define GPS_LOCATION_HAS_LAT_LONG   0x0001
/** GpsLocation has valid altitude. */
#define GPS_LOCATION_HAS_ALTITUDE   0x0002
/** GpsLocation has valid speed. */
#define GPS_LOCATION_HAS_SPEED      0x0004
/** GpsLocation has valid bearing. */
#define GPS_LOCATION_HAS_BEARING    0x0008
/** GpsLocation has valid accuracy. */
#define GPS_LOCATION_HAS_ACCURACY   0x0010
/** Location has valid source information. */
#define LOCATION_HAS_SOURCE_INFO   0x0020
/** GpsLocation has valid "is indoor?" flag */
#define GPS_LOCATION_HAS_IS_INDOOR   0x0040
/** GpsLocation has valid floor number */
#define GPS_LOCATION_HAS_FLOOR_NUMBER   0x0080
/** GpsLocation has valid map URL*/
#define GPS_LOCATION_HAS_MAP_URL   0x0100
/** GpsLocation has valid map index */
#define GPS_LOCATION_HAS_MAP_INDEX   0x0200

/** Sizes for indoor fields */
#define GPS_LOCATION_MAP_URL_SIZE 400
#define GPS_LOCATION_MAP_INDEX_SIZE 16

/** Location Information Source */
/** Position source is ULP */
#define ULP_LOCATION_IS_FROM_HYBRID   0x0001
/** Position source is GNSS only */
#define ULP_LOCATION_IS_FROM_GNSS   0x0002

/** Flags for the gps_set_capabilities callback. */

/** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
    If this is not set, then the framework will use 1000ms for min_interval
    and will start and call start() and stop() to schedule the GPS.
 */
#define GPS_CAPABILITY_SCHEDULING       0x0000001
/** GPS supports MS-Based AGPS mode */
#define GPS_CAPABILITY_MSB              0x0000002
/** GPS supports MS-Assisted AGPS mode */
#define GPS_CAPABILITY_MSA              0x0000004
/** GPS supports single-shot fixes */
#define GPS_CAPABILITY_SINGLE_SHOT      0x0000008
/** GPS supports on demand time injection */
#define GPS_CAPABILITY_ON_DEMAND_TIME   0x0000010
/* Hybrid support, the Android Framework will query to see if this capability is set before using the ulp functionalities in HAL */
#define ULP_CAPABILITY                  0x0000020
/** Flags used to specify which aiding data to delete
    when calling delete_aiding_data(). */
typedef uint32_t GpsAidingData;
// IMPORTANT: Note that the following values must match
// constants in GpsLocationProvider.java.
#define GPS_DELETE_EPHEMERIS                     0x00000001
#define GPS_DELETE_ALMANAC                       0x00000002
#define GPS_DELETE_POSITION                      0x00000004
#define GPS_DELETE_TIME                          0x00000008
#define GPS_DELETE_IONO                          0x00000010
#define GPS_DELETE_UTC                           0x00000020
#define GPS_DELETE_HEALTH                        0x00000040
#define GPS_DELETE_SVDIR                         0x00000080
#define GPS_DELETE_SVSTEER                       0x00000100
#define GPS_DELETE_SADATA                        0x00000200
#define GPS_DELETE_RTI                           0x00000400
#define GPS_DELETE_CELLDB_INFO                   0x00000800
#define GPS_DELETE_ALMANAC_CORR                  0x00001000
#define GPS_DELETE_FREQ_BIAS_EST                 0x00002000
#define GPS_DELETE_EPHEMERIS_GLO                 0x00004000
#define GPS_DELETE_ALMANAC_GLO                   0x00008000
#define GPS_DELETE_SVDIR_GLO                     0x00010000
#define GPS_DELETE_SVSTEER_GLO                   0x00020000
#define GPS_DELETE_ALMANAC_CORR_GLO              0x00040000
#define GPS_DELETE_TIME_GPS                      0x00080000
#define GPS_DELETE_TIME_GLO                      0x00100000

#define GPS_DELETE_ALL                           0xFFFFFFFF

/** AGPS type */
typedef int16_t AGpsType;
#define AGPS_TYPE_INVALID       -1
#define AGPS_TYPE_ANY           0
#define AGPS_TYPE_SUPL          1
#define AGPS_TYPE_C2K           2
#define AGPS_TYPE_WWAN_ANY      3
#define AGPS_TYPE_WIFI          4

/** SSID length */
#define SSID_BUF_SIZE (32+1)

typedef uint16_t AGpsSetIDType;
#define AGPS_SETID_TYPE_NONE    0
#define AGPS_SETID_TYPE_IMSI    1
#define AGPS_SETID_TYPE_MSISDN  2

typedef int16_t AGpsBearerType;
#define AGPS_APN_BEARER_INVALID    -1
#define AGPS_APN_BEARER_IPV4        0
#define AGPS_APN_BEARER_IPV6        1
#define AGPS_APN_BEARER_IPV4V6      2

/**
 * String length constants
 */
#define GPS_NI_SHORT_STRING_MAXLEN      256
#define GPS_NI_LONG_STRING_MAXLEN       2048

/**
 * GpsNiType constants
 */
typedef uint32_t GpsNiType;
#define GPS_NI_TYPE_VOICE              1
#define GPS_NI_TYPE_UMTS_SUPL          2
#define GPS_NI_TYPE_UMTS_CTRL_PLANE    3

/**
 * GpsNiNotifyFlags constants
 */
typedef uint32_t GpsNiNotifyFlags;
/** NI requires notification */
#define GPS_NI_NEED_NOTIFY          0x0001
/** NI requires verification */
#define GPS_NI_NEED_VERIFY          0x0002
/** NI requires privacy override, no notification/minimal trace */
#define GPS_NI_PRIVACY_OVERRIDE     0x0004

/**
 * GPS NI responses, used to define the response in
 * NI structures
 */
typedef int GpsUserResponseType;
#define GPS_NI_RESPONSE_ACCEPT         1
#define GPS_NI_RESPONSE_DENY           2
#define GPS_NI_RESPONSE_NORESP         3

/**
 * NI data encoding scheme
 */
typedef int GpsNiEncodingType;
#define GPS_ENC_NONE                   0
#define GPS_ENC_SUPL_GSM_DEFAULT       1
#define GPS_ENC_SUPL_UTF8              2
#define GPS_ENC_SUPL_UCS2              3
#define GPS_ENC_UNKNOWN                -1

/** AGPS status event values. */
typedef uint16_t AGpsStatusValue;
/** GPS requests data connection for AGPS. */
#define GPS_REQUEST_AGPS_DATA_CONN  1
/** GPS releases the AGPS data connection. */
#define GPS_RELEASE_AGPS_DATA_CONN  2
/** AGPS data connection initiated */
#define GPS_AGPS_DATA_CONNECTED     3
/** AGPS data connection completed */
#define GPS_AGPS_DATA_CONN_DONE     4
/** AGPS data connection failed */
#define GPS_AGPS_DATA_CONN_FAILED   5

#define AGPS_REF_LOCATION_TYPE_GSM_CELLID   1
#define AGPS_REF_LOCATION_TYPE_UMTS_CELLID  2
#define AGPS_REG_LOCATION_TYPE_MAC          3

/** Network types for update_network_state "type" parameter */
#define AGPS_RIL_NETWORK_TYPE_MOBILE        0
#define AGPS_RIL_NETWORK_TYPE_WIFI          1
#define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS    2
#define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL   3
#define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN   4
#define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
#define AGPS_RIL_NETWORK_TTYPE_WIMAX        6

/**
 * Name for the EXTRA CMD interface. To pass from app to HAL
 */
#define ULP_RAW_CMD_INTERFACE      "ulp-raw-cmd"

/**
 * Name for the GPS XTRA interface.
 */
#define GPS_XTRA_INTERFACE      "gps-xtra"

/**
 * Name for the GPS DEBUG interface.
 */
#define GPS_DEBUG_INTERFACE      "gps-debug"

/**
 * Name for the AGPS interface.
 */
#define AGPS_INTERFACE      "agps"

/**
 * Name for NI interface
 */
#define GPS_NI_INTERFACE "gps-ni"

/**
 * Name for the AGPS-RIL interface.
 */
#define AGPS_RIL_INTERFACE      "agps_ril"

/**
 * The GPS chipset can use Psc for AGPS.
 */
#define AGPS_USE_PSC

/**
* Name for ULP Phone Context Interface
*/
#define ULP_PHONE_CONTEXT_INTERFACE "ulp-phone-context"

/*
 * Name for the GPS_Geofencing interface.
 */
#define GPS_GEOFENCING_INTERFACE   "gps_geofencing"

/** Represents recurrence of location */
typedef enum{
    ULP_LOC_RECURRENCE_PERIODIC = 0,
    ULP_LOC_RECURRENCE_SINGLE,
}UlpRecurrenceCriteria;

/** Represents horizontal accuracy options */
typedef enum {
    ULP_HORZ_ACCURACY_DONT_CARE = 0,
    ULP_HORZ_ACCURACY_LOW,
    ULP_HORZ_ACCURACY_MED,
    ULP_HORZ_ACCURACY_HIGH,
}UlpHorzAccuracyCriteria;

/** Represents accuracy options (for speed, altitude, and
 *  bearing) */
typedef enum {
    ULP_ACCURACY_DONT_CARE = 0,
    ULP_ACCURACY_LOW,
    ULP_ACCURACY_HIGH,
}UlpAccuracyCriteria;

/** Represents power consumption options */
typedef enum {
    ULP_POWER_REQ_DONT_CARE = 0,
    ULP_POWER_REQ_LOW,
    ULP_POWER_REQ_HIGH,
}UlpPowerCriteria;

/** Represents data usage options */
typedef enum {
    ULP_DATA_REQ_DONT_CARE = 0,
    ULP_DATA_ALLOW,
    ULP_DATA_DENY,
}UlpDataUsageCriteria;

/** Enable the reporting of altitude in location reports */
#define ULP_ENABLE_ALTITUDE_REPORT   0x01
/** Enable the reporting of speed in location reports */
#define ULP_ENABLE_SPEED_REPORT      0x02
/** Enable the reporting of bearing in location reports */
#define ULP_ENABLE_BEARING_REPORT    0x04

#define ULP_CRITERIA_HAS_ACTION                        0x00000001
#define ULP_CRITERIA_HAS_PROVIDER_SOURCE               0x00000002
#define ULP_CRITERIA_HAS_RECURRENCE_TYPE               0x00000004
#define ULP_CRITERIA_HAS_PREFERRED_RESPONSE_TIME       0x00000010
#define ULP_CRITERIA_HAS_MIN_INTERVAL                  0x00000020
#define ULP_CRITERIA_HAS_MIN_DISTANCE                  0x00000040
#define ULP_CRITERIA_HAS_MIN_DIST_SAMPLE_INTERVAL      0x00000080
#define ULP_CRITERIA_HAS_DESIRED_OUTPUT_PARAMETER      0x00000100
#define ULP_CRITERIA_HAS_PREFERRED_HORIZONTAL_ACCURACY 0x00000200
#define ULP_CRITERIA_HAS_PREFERRED_POWER_CONSUMPTION   0x00000400
#define ULP_CRITERIA_HAS_PREFERRED_ALTITUDE_ACCURACY   0x00000800
#define ULP_CRITERIA_HAS_PREFERRED_BEARING_ACCURACY    0x00001000
#define ULP_CRITERIA_HAS_PREFERRED_DATA_USAGE          0x00002000
#define ULP_CRITERIA_HAS_INTERMEDIATE_POS_REPORT_ENABLED    0x00004000

#define ULP_PROVIDER_SOURCE_GNSS                       0x00000001
#define ULP_PROVIDER_SOURCE_HYBRID                     0x00000002


#define ULP_ADD_CRITERIA     1
#define ULP_REMOVE_CRITERIA  2

typedef struct {

    uint32_t valid_mask;
    /* delete or add. This is a mandatory field */
    int action;
    /*via gps or hybrid provider*/
    int provider_source;
    /** PERIODIC or SINGLE */
    UlpRecurrenceCriteria recurrence_type;
    /** obtain position within the specified response time */
    uint32_t preferred_response_time;
    /** Send updates after the specified interval */
    uint32_t min_interval;
    /** Send updates after device moved a specified distance */
    float min_distance;
    uint32_t min_dist_sample_interval;
    /** Fields specfied in the mask should be reported in the
     *  position report (altitude, bearing and speed) */
    uint32_t desired_output_parameter;
    /** Desired accuracy for latitude, longitude */
    UlpHorzAccuracyCriteria preferred_horizontal_accuracy;
    /** Desired power consumption level */
    UlpPowerCriteria preferred_power_consumption;
    /** Desired accuracy for altitude */
    UlpAccuracyCriteria preferred_altitude_accuracy;
    /** Desired accuracy for bearing */
    UlpAccuracyCriteria preferred_bearing_accuracy;
    UlpDataUsageCriteria preferred_data_usage;
    bool intermediate_pos_report_enabled;
} UlpLocationCriteria;

/** Represents a location. */
typedef struct {
    /** set to sizeof(GpsLocation) */
    size_t          size;
    /** Contains GpsLocationFlags bits. */
    uint16_t        flags;
    /* Provider indicator for HYBRID or GPS */
    uint16_t        position_source;
    /** Represents latitude in degrees. */
    double          latitude;
    /** Represents longitude in degrees. */
    double          longitude;
    /** Represents altitude in meters above the WGS 84 reference
     * ellipsoid. */
    double          altitude;
    /** Represents speed in meters per second. */
    float           speed;
    /** Represents heading in degrees. */
    float           bearing;
    /** Represents expected accuracy in meters. */
    float           accuracy;
    /** Timestamp for the location fix. */
    GpsUtcTime      timestamp;
    /*allows HAL to pass additional information related to the location */
    int             rawDataSize;         /* in # of bytes */
    void            * rawData;
    bool            is_indoor;
    float           floor_number;
    char            map_url[GPS_LOCATION_MAP_URL_SIZE];
    unsigned char   map_index[GPS_LOCATION_MAP_INDEX_SIZE];
} GpsLocation;

/** Represents the status. */
typedef struct {
    /** set to sizeof(GpsStatus) */
    size_t          size;
    GpsStatusValue status;
} GpsStatus;

/** Represents SV information. */
typedef struct {
    /** set to sizeof(GpsSvInfo) */
    size_t          size;
    /** Pseudo-random number for the SV. */
    int     prn;
    /** Signal to noise ratio. */
    float   snr;
    /** Elevation of SV in degrees. */
    float   elevation;
    /** Azimuth of SV in degrees. */
    float   azimuth;
#if 1
    /** Placeholder for Samsung ABI compat */
    int     unknown;
#endif
} GpsSvInfo;

/** Represents SV status. */
typedef struct {
    /** set to sizeof(GpsSvStatus) */
    size_t          size;

    /** Number of SVs currently visible. */
    int         num_svs;

    /** Contains an array of SV information. */
    GpsSvInfo   sv_list[GPS_MAX_SVS];

    /** Represents a bit mask indicating which SVs
     * have ephemeris data.
     */
    uint32_t    ephemeris_mask;

    /** Represents a bit mask indicating which SVs
     * have almanac data.
     */
    uint32_t    almanac_mask;

    /**
     * Represents a bit mask indicating which SVs
     * were used for computing the most recent position fix.
     */
    uint32_t    used_in_fix_mask;
} GpsSvStatus;

/* 2G and 3G */
/* In 3G lac is discarded */
typedef struct {
    uint16_t type;
    uint16_t mcc;
    uint16_t mnc;
    uint16_t lac;
#ifdef AGPS_USE_PSC
    uint16_t psc;
#endif
    uint32_t cid;
} AGpsRefLocationCellID;

typedef struct {
    uint8_t mac[6];
} AGpsRefLocationMac;

/** Represents ref locations */
typedef struct {
    uint16_t type;
    union {
        AGpsRefLocationCellID   cellID;
        AGpsRefLocationMac      mac;
    } u;
} AGpsRefLocation;

/** Callback with location information.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* gps_location_callback)(GpsLocation* location);

/** Callback with status information.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* gps_status_callback)(GpsStatus* status);

/** Callback with SV status information.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);

/** Callback for reporting NMEA sentences.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);

/** Callback to inform framework of the GPS engine's capabilities.
 *  Capability parameter is a bit field of GPS_CAPABILITY_* flags.
 */
typedef void (* gps_set_capabilities)(uint32_t capabilities);

/** Callback utility for acquiring the GPS wakelock.
 *  This can be used to prevent the CPU from suspending while handling GPS events.
 */
typedef void (* gps_acquire_wakelock)();

/** Callback utility for releasing the GPS wakelock. */
typedef void (* gps_release_wakelock)();

/** Callback for requesting NTP time */
typedef void (* gps_request_utc_time)();

/** Callback for creating a thread that can call into the Java framework code.
 *  This must be used to create any threads that report events up to the framework.
 */
typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);

/** GPS callback structure. */
typedef struct {
    /** set to sizeof(GpsCallbacks) */
    size_t      size;
    gps_location_callback location_cb;
    gps_status_callback status_cb;
    gps_sv_status_callback sv_status_cb;
    gps_nmea_callback nmea_cb;
    gps_set_capabilities set_capabilities_cb;
    gps_acquire_wakelock acquire_wakelock_cb;
    gps_release_wakelock release_wakelock_cb;
    gps_create_thread create_thread_cb;
    gps_request_utc_time request_utc_time_cb;
} GpsCallbacks;


/** Represents the standard GPS interface. */
typedef struct {
    /** set to sizeof(GpsInterface) */
    size_t          size;
    /**
     * Opens the interface and provides the callback routines
     * to the implemenation of this interface.
     */
    int   (*init)( GpsCallbacks* callbacks );

    /** Starts navigating. */
    int   (*start)( void );

    /** Stops navigating. */
    int   (*stop)( void );

    /** Closes the interface. */
    void  (*cleanup)( void );

    /** Injects the current time. */
    int   (*inject_time)(GpsUtcTime time, int64_t timeReference,
                         int uncertainty);

    /** Injects current location from another location provider
     *  (typically cell ID).
     *  latitude and longitude are measured in degrees
     *  expected accuracy is measured in meters
     */
    int  (*inject_location)(double latitude, double longitude, float accuracy);

    /**
     * Specifies that the next call to start will not use the
     * information defined in the flags. GPS_DELETE_ALL is passed for
     * a cold start.
     */
    void  (*delete_aiding_data)(GpsAidingData flags);

    /**
     * min_interval represents the time between fixes in milliseconds.
     * preferred_accuracy represents the requested fix accuracy in meters.
     * preferred_time represents the requested time to first fix in milliseconds.
     */
    int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
            uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);

    /** Get a pointer to extension information. */
    const void* (*get_extension)(const char* name);

    /* set criterias of location requests */
    int (*update_criteria) (UlpLocationCriteria criteria );
} GpsInterface;

/** Extended interface for raw GPS command support. */
typedef struct {
    /** set to sizeof(ExtraCmdInterface) */
    size_t          size;
    /** Injects Android extra cmd into the ulp. Clarify if they are blocking calls */
    bool  (*inject_raw_cmd)(char* bundle, int bundle_length );

} InjectRawCmdInterface;

/** ULP Network Interface */
/** Request for network position status   */
#define ULP_NETWORK_POS_STATUS_REQUEST                      (0x01)
/** Request for periodic network positions */
#define ULP_NETWORK_POS_START_PERIODIC_REQUEST              (0x02)
/** Request last known location   */
#define ULP_NETWORK_POS_GET_LAST_KNOWN_LOCATION_REQUEST     (0x03)
/** Cancel request */
#define ULP_NETWORK_POS_STOP_REQUEST                        (0x04)

/** Position was obtained using Wifi Network  */
#define ULP_NETWORK_POSITION_SRC_WIFI      (0x01)
/** Position was obtained using Cell Network  */
#define ULP_NETWORK_POSITION_SRC_CELL      (0x02)
/** Position was obtained using an Unknown Network */
#define ULP_NETWORK_POSITION_SRC_UNKNOWN   (0x00)

/** Represents the ULP network request */
typedef struct {
    /** type of request */
    uint16_t  request_type;
    /** Desired time between network positions/measurements in ms.
    *   Shall be set to 0 if only one position is requested */
    int       interval_ms;
    /** network position source to be used */
    uint16_t  desired_position_source;
}UlpNetworkRequestPos;

/** Callback with network position request. */
typedef void (*ulp_network_location_request)(UlpNetworkRequestPos *req);

/** ULP Network callback structure. */
typedef struct {
        ulp_network_location_request ulp_network_location_request_cb;
} UlpNetworkLocationCallbacks;

/** represent a network position */
typedef struct  {
    /** source of the position (Wifi, Cell) */
    uint16_t pos_source;
    /** latitude in degrees */
    double latitude;
    /** longitude in degrees */
    double longitude;
    /** Horzizontal error estimate in meters */
    uint16_t HEPE;
} UlpNetworkPosition;

/** Represents access point information */
typedef struct {
    /** Mac adderess */
    char mac_addr[6];
    /** signal strength in dbM */
    int32_t rssi;
    /** Beacon channel for access point */
    uint16_t channel;

    /** Bit 0 = AP is used by WiFi positioning system
     *  Bit 1 = AP doesn't broadcast SSID Bit 2 = AP has encrption
     *  turned on Bit 3 = AP is in infrastructure mode and not in
     *  ad-hoc/unknown mode  */
    uint8_t ap_qualifier;
} UlpNetworkAccessPointInfo;

/** Represents Wifi information */
typedef struct {
      /** Number of APs in the calculated position (-1 means
      *  unknown) */
      uint8_t num_aps_in_pos;
      /** Information of the scanned ap's used in the position estimation*/
      UlpNetworkAccessPointInfo *ap_info;
} UlpNetworkWifiInfo;


/** Represent network landscape information */
typedef struct {
    /** network type Cell/Wifi */
    uint8_t network_type;
    /** network information */
    union {
        UlpNetworkWifiInfo wifi_info;
        uint32_t cell_info;
    } u;
} UlpNetworkLandscape;

/** network report valid flags */
/** fix time is valid */
#define ULP_NETWORK_POSITION_REPORT_HAS_FIX_TIME  (0x01)
/** position is valid */
#define ULP_NETWORK_POSITION_REPORT_HAS_POSITION  (0x02)
/** landscape is valid */
#define ULP_NETWORK_POSITION_REPORT_HAS_LANDSCAPE (0x04)

/** Represents the network position report */
typedef struct
{
    /** validity flags */
    uint16_t valid_flag;
    /** time fo network fix */
    GpsUtcTime fix_time;
    /** network position */
    UlpNetworkPosition position;
    /** network landscape */
    UlpNetworkLandscape landscape_info;
}UlpNetworkPositionReport;

/** represents ULP network interface extension */
typedef struct
{
    /** set to sizeof(UlpNetworkInterface) */
    size_t          size;
    /** initialize network interface */
    int ( *init)(UlpNetworkLocationCallbacks *callback);
    /** send network position */
    int ( *ulp_send_network_position)(UlpNetworkPositionReport *position_report);
}UlpNetworkInterface;

/** Information for the ULP Phone context interface */

/** the Location settings context supports only ON_CHANGE
 *  request type */
#define ULP_PHONE_CONTEXT_GPS_SETTING                 (0x01)
#define ULP_PHONE_CONTEXT_NETWORK_POSITION_SETTING    (0x02)
#define ULP_PHONE_CONTEXT_WIFI_SETTING                (0x04)
/** The battery charging state context supports only
 * ON_CHANGE request type */
#define ULP_PHONE_CONTEXT_BATTERY_CHARGING_STATE          (0x08)
#define ULP_PHONE_CONTEXT_AGPS_SETTING                    (0x010)
#define ULP_PHONE_CONTEXT_ENH_LOCATION_SERVICES_SETTING   (0x020)

/** return phone context only once */
#define ULP_PHONE_CONTEXT_REQUEST_TYPE_SINGLE         (0x01)
/** return phone context periodcially */
#define ULP_PHONE_CONTEXT_REQUEST_TYPE_PERIODIC       (0x02)
/** return phone context when it changes */
#define ULP_PHONE_CONTEXT_REQUEST_TYPE_ON_CHANGE      (0x03)


/** Represents ULP phone context request   */
typedef struct {
    /** context type requested */
    uint16_t    context_type;
    /** request type  */
    uint16_t    request_type;
    /** interval in ms if request type is periodic */
    int            interval_ms;
}UlpPhoneContextRequest;

/** Callback for phone context request. */
typedef void (*ulp_request_phone_context)(UlpPhoneContextRequest *req);

/** ULP Phone Context callback structure. */
typedef struct {
        ulp_request_phone_context ulp_request_phone_context_cb;
}UlpPhoneContextCallbacks;

/** Represents the phone context settings */
typedef struct {
    /** Phone context information type */
    uint16_t context_type;

    /** network information */
    /** gps setting */
    bool    is_gps_enabled;
    /** is network positioning enabled */
    bool    is_network_position_available;
    /** is wifi turned on */
    bool    is_wifi_setting_enabled;
    /** is battery being currently charged */
    bool    is_battery_charging;
    /* is agps enabled for single shot */
    bool    is_agps_enabled;
    /* is Enhanced Location Services enabled by user*/
    bool    is_enh_location_services_enabled;
} UlpPhoneContextSettings;

/** Represent the phone contxt interface */
typedef struct
{
    /** set to sizeof(UlpPhoneContextInterface) */
    size_t          size;
    /** Initialize, register callback */
    int (*init)(UlpPhoneContextCallbacks *callback);
    /** send the phone context settings */
    int (*ulp_phone_context_settings_update) (UlpPhoneContextSettings *settings );
}UlpPhoneContextInterface;

/** Callback to request the client to download XTRA data.
 *  The client should download XTRA data and inject it by calling inject_xtra_data().
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* gps_xtra_download_request)();

/** Callback structure for the XTRA interface. */
typedef struct {
    gps_xtra_download_request download_request_cb;
    gps_create_thread create_thread_cb;
} GpsXtraCallbacks;

/** Extended interface for XTRA support. */
typedef struct {
    /** set to sizeof(GpsXtraInterface) */
    size_t          size;
    /**
     * Opens the XTRA interface and provides the callback routines
     * to the implemenation of this interface.
     */
    int  (*init)( GpsXtraCallbacks* callbacks );
    /** Injects XTRA data into the GPS. */
    int  (*inject_xtra_data)( char* data, int length );
} GpsXtraInterface;

/** Extended interface for DEBUG support. */
typedef struct {
    /** set to sizeof(GpsDebugInterface) */
    size_t          size;

    /**
     * This function should return any information that the native
     * implementation wishes to include in a bugreport.
     */
    size_t (*get_internal_state)(char* buffer, size_t bufferSize);
} GpsDebugInterface;

/** Represents the status of AGPS. */
typedef struct {
    /** set to sizeof(AGpsStatus) */
    size_t          size;

    AGpsType        type;
    AGpsStatusValue status;
    int             ipv4_addr;
    char            ipv6_addr[16];
    char            ssid[SSID_BUF_SIZE];
    char            password[SSID_BUF_SIZE];
} AGpsStatus;

/** Callback with AGPS status information.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (* agps_status_callback)(AGpsStatus* status);

/** Callback structure for the AGPS interface. */
typedef struct {
    agps_status_callback status_cb;
    gps_create_thread create_thread_cb;
} AGpsCallbacks;


/** Extended interface for AGPS support. */
typedef struct {
    /** set to sizeof(AGpsInterface) */
    size_t          size;

    /**
     * Opens the AGPS interface and provides the callback routines
     * to the implemenation of this interface.
     */
    void  (*init)( AGpsCallbacks* callbacks );
    /**
     * Notifies that a data connection is available and sets
     * the name of the APN to be used for SUPL.
     */
    int  (*data_conn_open)( AGpsType agpsType,
                            const char* apn, AGpsBearerType bearerType );
    /**
     * Notifies that the AGPS data connection has been closed.
     */
    int  (*data_conn_closed)( AGpsType agpsType );
    /**
     * Notifies that a data connection is not available for AGPS.
     */
    int  (*data_conn_failed)(AGpsType  agpsType );
    /**
     * Sets the hostname and port for the AGPS server.
     */
    int  (*set_server)( AGpsType type, const char* hostname, int port );
} AGpsInterface;


/** Represents an NI request */
typedef struct {
    /** set to sizeof(GpsNiNotification) */
    size_t          size;

    /**
     * An ID generated by HAL to associate NI notifications and UI
     * responses
     */
    int             notification_id;

    /**
     * An NI type used to distinguish different categories of NI
     * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
     */
    GpsNiType       ni_type;

    /**
     * Notification/verification options, combinations of GpsNiNotifyFlags constants
     */
    GpsNiNotifyFlags notify_flags;

    /**
     * Timeout period to wait for user response.
     * Set to 0 for no time out limit.
     */
    int             timeout;

    /**
     * Default response when time out.
     */
    GpsUserResponseType default_response;

    /**
     * Requestor ID
     */
    char            requestor_id[GPS_NI_SHORT_STRING_MAXLEN];

    /**
     * Notification message. It can also be used to store client_id in some cases
     */
    char            text[GPS_NI_LONG_STRING_MAXLEN];

    /**
     * Client name decoding scheme
     */
    GpsNiEncodingType requestor_id_encoding;

    /**
     * Client name decoding scheme
     */
    GpsNiEncodingType text_encoding;

    /**
     * A pointer to extra data. Format:
     * key_1 = value_1
     * key_2 = value_2
     */
    char           extras[GPS_NI_LONG_STRING_MAXLEN];

} GpsNiNotification;

/** Callback with NI notification.
 *  Can only be called from a thread created by create_thread_cb.
 */
typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);

/** GPS NI callback structure. */
typedef struct
{
    /**
     * Sends the notification request from HAL to GPSLocationProvider.
     */
    gps_ni_notify_callback notify_cb;
    gps_create_thread create_thread_cb;
} GpsNiCallbacks;

/**
 * Extended interface for Network-initiated (NI) support.
 */
typedef struct
{
    /** set to sizeof(GpsNiInterface) */
    size_t          size;

   /** Registers the callbacks for HAL to use. */
   void (*init) (GpsNiCallbacks *callbacks);

   /** Sends a response to HAL. */
   void (*respond) (int notif_id, GpsUserResponseType user_response);
} GpsNiInterface;

struct gps_device_t {
    struct hw_device_t common;

    /**
     * Set the provided lights to the provided values.
     *
     * Returns: 0 on succes, error code on failure.
     */
    const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
};

#define AGPS_RIL_REQUEST_SETID_IMSI     (1<<0L)
#define AGPS_RIL_REQUEST_SETID_MSISDN   (1<<1L)

#define AGPS_RIL_REQUEST_REFLOC_CELLID  (1<<0L)
#define AGPS_RIL_REQUEST_REFLOC_MAC     (1<<1L)

typedef void (*agps_ril_request_set_id)(uint32_t flags);
typedef void (*agps_ril_request_ref_loc)(uint32_t flags);

typedef struct {
    agps_ril_request_set_id request_setid;
    agps_ril_request_ref_loc request_refloc;
    gps_create_thread create_thread_cb;
} AGpsRilCallbacks;

/** Extended interface for AGPS_RIL support. */
typedef struct {
    /** set to sizeof(AGpsRilInterface) */
    size_t          size;
    /**
     * Opens the AGPS interface and provides the callback routines
     * to the implemenation of this interface.
     */
    void  (*init)( AGpsRilCallbacks* callbacks );

    /**
     * Sets the reference location.
     */
    void (*set_ref_location) (const AGpsRefLocation *agps_reflocation, size_t sz_struct);
    /**
     * Sets the set ID.
     */
    void (*set_set_id) (AGpsSetIDType type, const char* setid);

    /**
     * Send network initiated message.
     */
    void (*ni_message) (uint8_t *msg, size_t len);

    /**
     * Notify GPS of network status changes.
     * These parameters match values in the android.net.NetworkInfo class.
     */
    void (*update_network_state) (int connected, int type, int roaming, const char* extra_info);

    /**
     * Notify GPS of network status changes.
     * These parameters match values in the android.net.NetworkInfo class.
     */
    void (*update_network_availability) (int avaiable, const char* apn);
} AGpsRilInterface;
/**
 * GPS Geofence.
 *      There are 3 states associated with a Geofence: Inside, Outside, Unknown.
 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
 *
 * An example state diagram with confidence level: 95% and Unknown time limit
 * set as 30 secs is shown below. (confidence level and Unknown time limit are
 * explained latter)
 *                         ____________________________
 *                        |       Unknown (30 secs)   |
 *                         """"""""""""""""""""""""""""
 *                            ^ |                  |  ^
 *                   UNCERTAIN| |ENTERED     EXITED|  |UNCERTAIN
 *                            | v                  v  |
 *                        ________    EXITED     _________
 *                       | Inside | -----------> | Outside |
 *                       |        | <----------- |         |
 *                        """"""""    ENTERED    """""""""
 *
 * Inside state: We are 95% confident that the user is inside the geofence.
 * Outside state: We are 95% confident that the user is outside the geofence
 * Unknown state: Rest of the time.
 *
 * The Unknown state is better explained with an example:
 *
 *                            __________
 *                           |         c|
 *                           |  ___     |    _______
 *                           |  |a|     |   |   b   |
 *                           |  """     |    """""""
 *                           |          |
 *                            """"""""""
 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
 * circle reported by the GPS subsystem. Now with regard to "b", the system is
 * confident that the user is outside. But with regard to "a" is not confident
 * whether it is inside or outside the geofence. If the accuracy remains the
 * same for a sufficient period of time, the UNCERTAIN transition would be
 * triggered with the state set to Unknown. If the accuracy improves later, an
 * appropriate transition should be triggered.  This "sufficient period of time"
 * is defined by the parameter in the add_geofence_area API.
 *     In other words, Unknown state can be interpreted as a state in which the
 * GPS subsystem isn't confident enough that the user is either inside or
 * outside the Geofence. It moves to Unknown state only after the expiry of the
 * timeout.
 *
 * The geofence callback needs to be triggered for the ENTERED and EXITED
 * transitions, when the GPS system is confident that the user has entered
 * (Inside state) or exited (Outside state) the Geofence. An implementation
 * which uses a value of 95% as the confidence is recommended. The callback
 * should be triggered only for the transitions requested by the
 * add_geofence_area call.
 *
 * Even though the diagram and explanation talks about states and transitions,
 * the callee is only interested in the transistions. The states are mentioned
 * here for illustrative purposes.
 *
 * Startup Scenario: When the device boots up, if an application adds geofences,
 * and then we get an accurate GPS location fix, it needs to trigger the
 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
 * By default, all the Geofences will be in the Unknown state.
 *
 * When the GPS system is unavailable, gps_geofence_status_callback should be
 * called to inform the upper layers of the same. Similarly, when it becomes
 * available the callback should be called. This is a global state while the
 * UNKNOWN transition described above is per geofence.
 *
 * An important aspect to note is that users of this API (framework), will use
 * other subsystems like wifi, sensors, cell to handle Unknown case and
 * hopefully provide a definitive state transition to the third party
 * application. GPS Geofence will just be a signal indicating what the GPS
 * subsystem knows about the Geofence.
 *
 */
#define GPS_GEOFENCE_ENTERED     (1<<0L)
#define GPS_GEOFENCE_EXITED      (1<<1L)
#define GPS_GEOFENCE_UNCERTAIN   (1<<2L)

#define GPS_GEOFENCE_UNAVAILABLE (1<<0L)
#define GPS_GEOFENCE_AVAILABLE   (1<<1L)

#define GPS_GEOFENCE_OPERATION_SUCCESS           0
#define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
#define GPS_GEOFENCE_ERROR_ID_EXISTS          -101
#define GPS_GEOFENCE_ERROR_ID_UNKNOWN         -102
#define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
#define GPS_GEOFENCE_ERROR_GENERIC            -149
/**
* The callback associated with the geofence.
* Parameters:
*      geofence_id - The id associated with the add_geofence_area.
*      location    - The current GPS location.
*      transition  - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
*                    GPS_GEOFENCE_UNCERTAIN.
*      timestamp   - Timestamp when the transition was detected.
*
* The callback should only be called when the caller is interested in that
* particular transition. For instance, if the caller is interested only in
* ENTERED transition, then the callback should NOT be called with the EXITED
* transition.
*
* IMPORTANT: If a transition is triggered resulting in this callback, the GPS
* subsystem will wake up the application processor, if its in suspend state.
*/
typedef void (*gps_geofence_transition_callback) (int32_t geofence_id,  GpsLocation* location,
int32_t transition, GpsUtcTime timestamp);

/**
 * The callback associated with the availablity of the GPS system for geofencing
 * monitoring. If the GPS system determines that it cannot monitor geofences
 * because of lack of reliability or unavailability of the GPS signals, it will
 * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
 *
 * Parameters:
 *  status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
 *  last_location - Last known location.
 */
typedef void (*gps_geofence_status_callback) (int32_t status, GpsLocation* last_location);

/**
 * The callback associated with the add_geofence call.
 *
 * Parameter:
 * geofence_id - Id of the geofence.
 * status - GPS_GEOFENCE_OPERATION_SUCCESS
 *          GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES  - geofence limit has been reached.
 *          GPS_GEOFENCE_ERROR_ID_EXISTS  - geofence with id already exists
 *          GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
 *              invalid transition
 *          GPS_GEOFENCE_ERROR_GENERIC - for other errors.
 */
typedef void (*gps_geofence_add_callback) (int32_t geofence_id, int32_t status);

/**
 * The callback associated with the remove_geofence call.
 *
 * Parameter:
 * geofence_id - Id of the geofence.
 * status - GPS_GEOFENCE_OPERATION_SUCCESS
 *          GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
 *          GPS_GEOFENCE_ERROR_GENERIC for others.
 */
typedef void (*gps_geofence_remove_callback) (int32_t geofence_id, int32_t status);


/**
 * The callback associated with the pause_geofence call.
 *
 * Parameter:
 * geofence_id - Id of the geofence.
 * status - GPS_GEOFENCE_OPERATION_SUCCESS
 *          GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
 *          GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
 *                    when monitor_transitions is invalid
 *          GPS_GEOFENCE_ERROR_GENERIC for others.
 */
typedef void (*gps_geofence_pause_callback) (int32_t geofence_id, int32_t status);

/**
 * The callback associated with the resume_geofence call.
 *
 * Parameter:
 * geofence_id - Id of the geofence.
 * status - GPS_GEOFENCE_OPERATION_SUCCESS
 *          GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
 *          GPS_GEOFENCE_ERROR_GENERIC for others.
 */
typedef void (*gps_geofence_resume_callback) (int32_t geofence_id, int32_t status);

typedef struct {
    gps_geofence_transition_callback geofence_transition_callback;
    gps_geofence_status_callback geofence_status_callback;
    gps_geofence_add_callback geofence_add_callback;
    gps_geofence_remove_callback geofence_remove_callback;
    gps_geofence_pause_callback geofence_pause_callback;
    gps_geofence_resume_callback geofence_resume_callback;
    gps_create_thread create_thread_cb;
} GpsGeofenceCallbacks;

/** Extended interface for GPS_Geofencing support */
typedef struct {
    /** set to sizeof(GpsGeofencingInterface) */
    size_t          size;

    /**
     * Opens the geofence interface and provides the callback routines
     * to the implemenation of this interface.
     */
    void  (*init)( GpsGeofenceCallbacks* callbacks );

    /**
     * Add a geofence area. This api currently supports circular geofences.
     * Parameters:
     *    geofence_id - The id for the geofence. If a geofence with this id
     *       already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
     *       should be returned.
     *    latitude, longtitude, radius_meters - The lat, long and radius
     *       (in meters) for the geofence
     *    last_transition - The current state of the geofence. For example, if
     *       the system already knows that the user is inside the geofence,
     *       this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
     *       will be GPS_GEOFENCE_UNCERTAIN.
     *    monitor_transition - Which transitions to monitor. Bitwise OR of
     *       GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
     *       GPS_GEOFENCE_UNCERTAIN.
     *    notification_responsiveness_ms - Defines the best-effort description
     *       of how soon should the callback be called when the transition
     *       associated with the Geofence is triggered. For instance, if set
     *       to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
     *       should be called 1000 milliseconds within entering the geofence.
     *       This parameter is defined in milliseconds.
     *       NOTE: This is not to be confused with the rate that the GPS is
     *       polled at. It is acceptable to dynamically vary the rate of
     *       sampling the GPS for power-saving reasons; thus the rate of
     *       sampling may be faster or slower than this.
     *    unknown_timer_ms - The time limit after which the UNCERTAIN transition
     *       should be triggered. This paramter is defined in milliseconds.
     *       See above for a detailed explanation.
     */
    void (*add_geofence_area) (int32_t geofence_id, double latitude,
                               double longitude, double radius_meters,
                               int last_transition, int monitor_transitions,
                               int notification_responsiveness_ms,
                               int unknown_timer_ms);

    /**
     * Pause monitoring a particular geofence.
     * Parameters:
     *   geofence_id - The id for the geofence.
     */
    void (*pause_geofence) (int32_t geofence_id);

    /**
     * Resume monitoring a particular geofence.
     * Parameters:
     *   geofence_id - The id for the geofence.
     *   monitor_transitions - Which transitions to monitor. Bitwise OR of
     *       GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
     *       GPS_GEOFENCE_UNCERTAIN.
     *       This supersedes the value associated provided in the
     *       add_geofence_area call.
     */
    void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);

    /**
     * Remove a geofence area. After the function returns, no notifications
     * should be sent.
     * Parameter:
     *   geofence_id - The id for the geofence.
     */
    void (*remove_geofence_area) (int32_t geofence_id);
} GpsGeofencingInterface;
__END_DECLS

#endif /* ANDROID_INCLUDE_HARDWARE_GPS_H */