• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2009,2011 Code Aurora Forum. 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 Code Aurora Forum, Inc. 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 
30 #ifndef LOC_ENG_H
31 #define LOC_ENG_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 
37 // Uncomment to keep all LOG messages (LOGD, LOGI, LOGV, etc.)
38 #define MAX_NUM_ATL_CONNECTIONS  2
39 // Define boolean type to be used by libgps on loc api module
40 typedef unsigned char boolean;
41 
42 #ifndef TRUE
43 #define TRUE 1
44 #endif
45 
46 #ifndef FALSE
47 #define FALSE 0
48 #endif
49 
50 #include <loc.h>
51 #include <loc_eng_xtra.h>
52 #include <loc_eng_ni.h>
53 #include <loc_eng_agps.h>
54 #include <loc_cfg.h>
55 #include <loc_log.h>
56 #include <log_util.h>
57 #include <loc_eng_msg.h>
58 #include <loc_eng_agps.h>
59 #include <LocApiAdapter.h>
60 
61 // The data connection minimal open time
62 #define DATA_OPEN_MIN_TIME        1  /* sec */
63 
64 // The system sees GPS engine turns off after inactive for this period of time
65 #define GPS_AUTO_OFF_TIME         2  /* secs */
66 #define SUCCESS              TRUE
67 #define FAILURE                 FALSE
68 #define INVALID_ATL_CONNECTION_HANDLE -1
69 
70 #define MAX_APN_LEN 100
71 #define MAX_URL_LEN 256
72 #define smaller_of(a, b) (((a) > (b)) ? (b) : (a))
73 
74 enum loc_mute_session_e_type {
75    LOC_MUTE_SESS_NONE = 0,
76    LOC_MUTE_SESS_WAIT,
77    LOC_MUTE_SESS_IN_SESSION
78 };
79 
80 // Module data
81 typedef struct
82 {
83     LocApiAdapter                 *client_handle;
84     loc_location_cb_ext            location_cb;
85     gps_status_callback            status_cb;
86     loc_sv_status_cb_ext           sv_status_cb;
87     agps_status_callback           agps_status_cb;
88     gps_nmea_callback              nmea_cb;
89     gps_ni_notify_callback         ni_notify_cb;
90     gps_acquire_wakelock           acquire_wakelock_cb;
91     gps_release_wakelock           release_wakelock_cb;
92     boolean                        intermediateFix;
93     AGpsStatusValue                agps_status;
94     // used to defer stopping the GPS engine until AGPS data calls are done
95     boolean                        agps_request_pending;
96     boolean                        stop_request_pending;
97     loc_eng_xtra_data_s_type       xtra_module_data;
98     loc_eng_ni_data_s_type         loc_eng_ni_data;
99 
100     boolean                        navigating;
101 
102     // AGPS state machines
103     AgpsStateMachine*              agnss_nif;
104     AgpsStateMachine*              internet_nif;
105 
106     // GPS engine status
107     GpsStatusValue                 engine_status;
108     GpsStatusValue                 fix_session_status;
109 
110     // Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off
111     GpsAidingData                  aiding_data_for_deletion;
112 
113     void*                          context;
114 
115     loc_eng_msg_position_mode      position_mode;
116 
117     // For muting session broadcast
118     loc_mute_session_e_type        mute_session_state;
119 
120     // Address buffers, for addressing setting before init
121     int    supl_host_set;
122     char   supl_host_buf[101];
123     int    supl_port_buf;
124     int    c2k_host_set;
125     char   c2k_host_buf[101];
126     int    c2k_port_buf;
127     int    mpc_host_set;
128     char   mpc_host_buf[101];
129     int    mpc_port_buf;
130 } loc_eng_data_s_type;
131 
132 
133 int  loc_eng_init(loc_eng_data_s_type &loc_eng_data,
134                   LocCallbacks* callbacks,
135                   LOC_API_ADAPTER_EVENT_MASK_T event);
136 int  loc_eng_start(loc_eng_data_s_type &loc_eng_data);
137 int  loc_eng_stop(loc_eng_data_s_type &loc_eng_data);
138 void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data);
139 int  loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data,
140                          GpsUtcTime time, int64_t timeReference,
141                          int uncertainty);
142 int  loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data,
143                              double latitude, double longitude,
144                              float accuracy);
145 void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data,
146                                 GpsAidingData f);
147 int  loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data,
148                                LocPositionMode mode, GpsPositionRecurrence recurrence,
149                                uint32_t min_interval, uint32_t preferred_accuracy,
150                                uint32_t preferred_time);
151 const void* loc_eng_get_extension(loc_eng_data_s_type &loc_eng_data,
152                                   const char* name);
153 #ifdef QCOM_FEATURE_ULP
154 int  loc_eng_update_criteria(loc_eng_data_s_type &loc_eng_data,
155                              UlpLocationCriteria criteria);
156 #endif
157 
158 void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data,
159                        AGpsCallbacks* callbacks);
160 #ifdef QCOM_FEATURE_IPV6
161 int  loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsType agpsType,
162                       const char* apn, AGpsBearerType bearerType);
163 int  loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsType agpsType);
164 int  loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsType agpsType);
165 #else
166 int  loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, const char* apn);
167 int  loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data);
168 int  loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data);
169 #endif
170 
171 int  loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data,
172                               LocServerType type, const char *hostname, int port);
173 
174 
175 void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data,
176                                                   int avaiable, const char* apn);
177 
178 
179 bool loc_eng_inject_raw_command(loc_eng_data_s_type &loc_eng_data,
180                                 char* command, int length);
181 
182 
183 void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data);
184 
185 int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data,
186                        GpsXtraCallbacks* callbacks);
187 
188 int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data,
189                              char* data, int length);
190 
191 extern void loc_eng_ni_init(loc_eng_data_s_type &loc_eng_data,
192                             GpsNiCallbacks *callbacks);
193 extern void loc_eng_ni_respond(loc_eng_data_s_type &loc_eng_data,
194                                int notif_id, GpsUserResponseType user_response);
195 extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data,
196                                    const GpsNiNotification *notif,
197                                    const void* passThrough);
198 extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data);
199 
200 #ifdef __cplusplus
201 }
202 #endif /* __cplusplus */
203 
204 #endif // LOC_ENG_H
205