1/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef GPS_EXTENDED_C_H
30#define GPS_EXTENDED_C_H
31
32#ifdef __cplusplus
33extern "C" {
34#endif /* __cplusplus */
35
36#include <ctype.h>
37#include <stdbool.h>
38#include <stdlib.h>
39#include <string.h>
40#include <hardware/gps.h>
41
42/** Location has valid source information. */
43#define LOCATION_HAS_SOURCE_INFO   0x0020
44/** GpsLocation has valid "is indoor?" flag */
45#define GPS_LOCATION_HAS_IS_INDOOR   0x0040
46/** GpsLocation has valid floor number */
47#define GPS_LOCATION_HAS_FLOOR_NUMBER   0x0080
48/** GpsLocation has valid map URL*/
49#define GPS_LOCATION_HAS_MAP_URL   0x0100
50/** GpsLocation has valid map index */
51#define GPS_LOCATION_HAS_MAP_INDEX   0x0200
52
53/** Sizes for indoor fields */
54#define GPS_LOCATION_MAP_URL_SIZE 400
55#define GPS_LOCATION_MAP_INDEX_SIZE 16
56
57/** Position source is ULP */
58#define ULP_LOCATION_IS_FROM_HYBRID   0x0001
59/** Position source is GNSS only */
60#define ULP_LOCATION_IS_FROM_GNSS   0x0002
61
62#define ULP_MIN_INTERVAL_INVALID 0xffffffff
63
64
65typedef struct {
66    /** set to sizeof(UlpLocation) */
67    size_t          size;
68    GpsLocation     gpsLocation;
69    /* Provider indicator for HYBRID or GPS */
70    uint16_t        position_source;
71    /*allows HAL to pass additional information related to the location */
72    int             rawDataSize;         /* in # of bytes */
73    void            * rawData;
74    bool            is_indoor;
75    float           floor_number;
76    char            map_url[GPS_LOCATION_MAP_URL_SIZE];
77    unsigned char   map_index[GPS_LOCATION_MAP_INDEX_SIZE];
78} UlpLocation;
79
80/** AGPS type */
81typedef int16_t AGpsExtType;
82#define AGPS_TYPE_INVALID       -1
83#define AGPS_TYPE_ANY           0
84#define AGPS_TYPE_SUPL          1
85#define AGPS_TYPE_C2K           2
86#define AGPS_TYPE_WWAN_ANY      3
87#define AGPS_TYPE_WIFI          4
88#define AGPS_TYPE_SUPL_ES       5
89
90/** SSID length */
91#define SSID_BUF_SIZE (32+1)
92
93typedef int16_t AGpsBearerType;
94#define AGPS_APN_BEARER_INVALID    -1
95#define AGPS_APN_BEARER_IPV4        0
96#define AGPS_APN_BEARER_IPV6        1
97#define AGPS_APN_BEARER_IPV4V6      2
98
99#define GPS_DELETE_ALMANAC_CORR     0x00001000
100#define GPS_DELETE_FREQ_BIAS_EST    0x00002000
101#define GPS_DELETE_EPHEMERIS_GLO    0x00004000
102#define GPS_DELETE_ALMANAC_GLO      0x00008000
103#define GPS_DELETE_SVDIR_GLO        0x00010000
104#define GPS_DELETE_SVSTEER_GLO      0x00020000
105#define GPS_DELETE_ALMANAC_CORR_GLO 0x00040000
106#define GPS_DELETE_TIME_GPS         0x00080000
107#define GPS_DELETE_TIME_GLO         0x00100000
108
109/** GPS extended callback structure. */
110typedef struct {
111    /** set to sizeof(GpsCallbacks) */
112    size_t      size;
113    gps_set_capabilities set_capabilities_cb;
114    gps_acquire_wakelock acquire_wakelock_cb;
115    gps_release_wakelock release_wakelock_cb;
116    gps_create_thread create_thread_cb;
117    gps_request_utc_time request_utc_time_cb;
118} GpsExtCallbacks;
119
120/** Callback to report the xtra server url to the client.
121 *  The client should use this url when downloading xtra unless overwritten
122 *  in the gps.conf file
123 */
124typedef void (* report_xtra_server)(const char*, const char*, const char*);
125
126/** Callback structure for the XTRA interface. */
127typedef struct {
128    gps_xtra_download_request download_request_cb;
129    gps_create_thread create_thread_cb;
130    report_xtra_server report_xtra_server_cb;
131} GpsXtraExtCallbacks;
132
133/** Represents the status of AGPS. */
134typedef struct {
135    /** set to sizeof(AGpsExtStatus) */
136    size_t          size;
137
138    AGpsExtType type;
139    AGpsStatusValue status;
140    uint32_t        ipv4_addr;
141    char            ipv6_addr[16];
142    char            ssid[SSID_BUF_SIZE];
143    char            password[SSID_BUF_SIZE];
144} AGpsExtStatus;
145
146/** Callback with AGPS status information.
147 *  Can only be called from a thread created by create_thread_cb.
148 */
149typedef void (* agps_status_extended)(AGpsExtStatus* status);
150
151/** Callback structure for the AGPS interface. */
152typedef struct {
153    agps_status_extended status_cb;
154    gps_create_thread create_thread_cb;
155} AGpsExtCallbacks;
156
157
158/** GPS NI callback structure. */
159typedef struct
160{
161    /**
162     * Sends the notification request from HAL to GPSLocationProvider.
163     */
164    gps_ni_notify_callback notify_cb;
165    gps_create_thread create_thread_cb;
166} GpsNiExtCallbacks;
167
168typedef enum loc_server_type {
169    LOC_AGPS_CDMA_PDE_SERVER,
170    LOC_AGPS_CUSTOM_PDE_SERVER,
171    LOC_AGPS_MPC_SERVER,
172    LOC_AGPS_SUPL_SERVER
173} LocServerType;
174
175typedef enum loc_position_mode_type {
176    LOC_POSITION_MODE_STANDALONE,
177    LOC_POSITION_MODE_MS_BASED,
178    LOC_POSITION_MODE_MS_ASSISTED,
179    LOC_POSITION_MODE_RESERVED_1,
180    LOC_POSITION_MODE_RESERVED_2,
181    LOC_POSITION_MODE_RESERVED_3,
182    LOC_POSITION_MODE_RESERVED_4,
183    LOC_POSITION_MODE_RESERVED_5
184} LocPositionMode;
185
186#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */
187
188/** Flags to indicate which values are valid in a GpsLocationExtended. */
189typedef uint16_t GpsLocationExtendedFlags;
190/** GpsLocationExtended has valid pdop, hdop, vdop. */
191#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001
192/** GpsLocationExtended has valid altitude mean sea level. */
193#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002
194/** UlpLocation has valid magnetic deviation. */
195#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004
196/** UlpLocation has valid mode indicator. */
197#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008
198/** GpsLocationExtended has valid vertical uncertainty */
199#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010
200/** GpsLocationExtended has valid speed uncertainty */
201#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020
202
203/** Represents gps location extended. */
204typedef struct {
205    /** set to sizeof(GpsLocationExtended) */
206    size_t          size;
207    /** Contains GpsLocationExtendedFlags bits. */
208    uint16_t        flags;
209    /** Contains the Altitude wrt mean sea level */
210    float           altitudeMeanSeaLevel;
211    /** Contains Position Dilusion of Precision. */
212    float           pdop;
213    /** Contains Horizontal Dilusion of Precision. */
214    float           hdop;
215    /** Contains Vertical Dilusion of Precision. */
216    float           vdop;
217    /** Contains Magnetic Deviation. */
218    float           magneticDeviation;
219    /** vertical uncertainty in meters */
220    float           vert_unc;
221    /** speed uncertainty in m/s */
222    float           speed_unc;
223} GpsLocationExtended;
224
225enum loc_sess_status {
226    LOC_SESS_SUCCESS,
227    LOC_SESS_INTERMEDIATE,
228    LOC_SESS_FAILURE
229};
230
231typedef uint32_t LocPosTechMask;
232#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000)
233#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001)
234#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002)
235#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004)
236#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008)
237#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010)
238#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020)
239#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040)
240#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080)
241
242typedef enum {
243  LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0,
244  LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM,
245  LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU,
246  LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
247  LOC_ENG_IF_REQUEST_SENDER_ID_MODEM,
248  LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN
249} loc_if_req_sender_id_e_type;
250
251
252#define smaller_of(a, b) (((a) > (b)) ? (b) : (a))
253#define MAX_APN_LEN 100
254
255// This will be overridden by the individual adapters
256// if necessary.
257#define DEFAULT_IMPL(rtv)                                     \
258{                                                             \
259    LOC_LOGD("%s: default implementation invoked", __func__); \
260    return rtv;                                               \
261}
262
263enum loc_api_adapter_err {
264    LOC_API_ADAPTER_ERR_SUCCESS             = 0,
265    LOC_API_ADAPTER_ERR_GENERAL_FAILURE     = 1,
266    LOC_API_ADAPTER_ERR_UNSUPPORTED         = 2,
267    LOC_API_ADAPTER_ERR_INVALID_HANDLE      = 4,
268    LOC_API_ADAPTER_ERR_INVALID_PARAMETER   = 5,
269    LOC_API_ADAPTER_ERR_ENGINE_BUSY         = 6,
270    LOC_API_ADAPTER_ERR_PHONE_OFFLINE       = 7,
271    LOC_API_ADAPTER_ERR_TIMEOUT             = 8,
272    LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9,
273
274    LOC_API_ADAPTER_ERR_ENGINE_DOWN         = 100,
275    LOC_API_ADAPTER_ERR_FAILURE,
276    LOC_API_ADAPTER_ERR_UNKNOWN
277};
278
279enum loc_api_adapter_event_index {
280    LOC_API_ADAPTER_REPORT_POSITION = 0,       // Position report comes in loc_parsed_position_s_type
281    LOC_API_ADAPTER_REPORT_SATELLITE,          // Satellite in view report
282    LOC_API_ADAPTER_REPORT_NMEA_1HZ,           // NMEA report at 1HZ rate
283    LOC_API_ADAPTER_REPORT_NMEA_POSITION,      // NMEA report at position report rate
284    LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY,  // NI notification/verification request
285    LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA,   // Assistance data, eg: time, predicted orbits request
286    LOC_API_ADAPTER_REQUEST_LOCATION_SERVER,   // Request for location server
287    LOC_API_ADAPTER_REPORT_IOCTL,              // Callback report for loc_ioctl
288    LOC_API_ADAPTER_REPORT_STATUS,             // Misc status report: eg, engine state
289    LOC_API_ADAPTER_REQUEST_WIFI,              //
290    LOC_API_ADAPTER_SENSOR_STATUS,             //
291    LOC_API_ADAPTER_REQUEST_TIME_SYNC,         //
292    LOC_API_ADAPTER_REPORT_SPI,                //
293    LOC_API_ADAPTER_REPORT_NI_GEOFENCE,        //
294    LOC_API_ADAPTER_GEOFENCE_GEN_ALERT,        //
295    LOC_API_ADAPTER_REPORT_GENFENCE_BREACH,    //
296    LOC_API_ADAPTER_PEDOMETER_CTRL,            //
297    LOC_API_ADAPTER_MOTION_CTRL,               //
298
299    LOC_API_ADAPTER_EVENT_MAX
300};
301
302#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT   (1<<LOC_API_ADAPTER_REPORT_POSITION)
303#define LOC_API_ADAPTER_BIT_SATELLITE_REPORT         (1<<LOC_API_ADAPTER_REPORT_SATELLITE)
304#define LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT          (1<<LOC_API_ADAPTER_REPORT_NMEA_1HZ)
305#define LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT     (1<<LOC_API_ADAPTER_REPORT_NMEA_POSITION)
306#define LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST (1<<LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY)
307#define LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST  (1<<LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA)
308#define LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST  (1<<LOC_API_ADAPTER_REQUEST_LOCATION_SERVER)
309#define LOC_API_ADAPTER_BIT_IOCTL_REPORT             (1<<LOC_API_ADAPTER_REPORT_IOCTL)
310#define LOC_API_ADAPTER_BIT_STATUS_REPORT            (1<<LOC_API_ADAPTER_REPORT_STATUS)
311#define LOC_API_ADAPTER_BIT_REQUEST_WIFI             (1<<LOC_API_ADAPTER_REQUEST_WIFI)
312#define LOC_API_ADAPTER_BIT_SENSOR_STATUS            (1<<LOC_API_ADAPTER_SENSOR_STATUS)
313#define LOC_API_ADAPTER_BIT_REQUEST_TIME_SYNC        (1<<LOC_API_ADAPTER_REQUEST_TIME_SYNC)
314#define LOC_API_ADAPTER_BIT_REPORT_SPI               (1<<LOC_API_ADAPTER_REPORT_SPI)
315#define LOC_API_ADAPTER_BIT_REPORT_NI_GEOFENCE       (1<<LOC_API_ADAPTER_REPORT_NI_GEOFENCE)
316#define LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT       (1<<LOC_API_ADAPTER_GEOFENCE_GEN_ALERT)
317#define LOC_API_ADAPTER_BIT_REPORT_GENFENCE_BREACH   (1<<LOC_API_ADAPTER_REPORT_GENFENCE_BREACH)
318#define LOC_API_ADAPTER_BIT_PEDOMETER_CTRL           (1<<LOC_API_ADAPTER_PEDOMETER_CTRL)
319#define LOC_API_ADAPTER_BIT_MOTION_CTRL              (1<<LOC_API_ADAPTER_MOTION_CTRL)
320
321typedef unsigned int LOC_API_ADAPTER_EVENT_MASK_T;
322
323
324#ifdef __cplusplus
325}
326#endif /* __cplusplus */
327
328#endif /* GPS_EXTENDED_C_H */
329
330