1/* Copyright (c) 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#define LOG_NDDEBUG 0
31#define LOG_TAG "LocSvc_eng"
32
33#include "hardware/gps.h"
34#include "loc.h"
35#include "loc_log.h"
36#include "loc_eng_log.h"
37#include "loc_eng_msg_id.h"
38
39/* GPS status names */
40static loc_name_val_s_type gps_status_name[] =
41{
42    NAME_VAL( GPS_STATUS_NONE ),
43    NAME_VAL( GPS_STATUS_SESSION_BEGIN ),
44    NAME_VAL( GPS_STATUS_SESSION_END ),
45    NAME_VAL( GPS_STATUS_ENGINE_ON ),
46    NAME_VAL( GPS_STATUS_ENGINE_OFF ),
47};
48static int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type);
49
50/* Find Android GPS status name */
51const char* loc_get_gps_status_name(GpsStatusValue gps_status)
52{
53   return loc_get_name_from_val(gps_status_name, gps_status_num,
54         (long) gps_status);
55}
56
57
58
59static loc_name_val_s_type loc_eng_msgs[] =
60{
61    NAME_VAL( LOC_ENG_MSG_QUIT ),
62    NAME_VAL( LOC_ENG_MSG_ENGINE_DOWN ),
63    NAME_VAL( LOC_ENG_MSG_ENGINE_UP ),
64    NAME_VAL( LOC_ENG_MSG_START_FIX ),
65    NAME_VAL( LOC_ENG_MSG_STOP_FIX ),
66    NAME_VAL( LOC_ENG_MSG_SET_POSITION_MODE ),
67    NAME_VAL( LOC_ENG_MSG_SET_TIME ),
68    NAME_VAL( LOC_ENG_MSG_INJECT_XTRA_DATA ),
69    NAME_VAL( LOC_ENG_MSG_INJECT_LOCATION ),
70    NAME_VAL( LOC_ENG_MSG_DELETE_AIDING_DATA ),
71    NAME_VAL( LOC_ENG_MSG_SET_APN ),
72    NAME_VAL( LOC_ENG_MSG_SET_SERVER_URL ),
73    NAME_VAL( LOC_ENG_MSG_SET_SERVER_IPV4 ),
74    NAME_VAL( LOC_ENG_MSG_ENABLE_DATA ),
75    NAME_VAL( LOC_ENG_MSG_SUPL_VERSION ),
76    NAME_VAL( LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG ),
77    NAME_VAL( LOC_ENG_MSG_SET_SENSOR_PROPERTIES ),
78    NAME_VAL( LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG ),
79    NAME_VAL( LOC_ENG_MSG_MUTE_SESSION ),
80    NAME_VAL( LOC_ENG_MSG_ATL_OPEN_SUCCESS ),
81    NAME_VAL( LOC_ENG_MSG_ATL_CLOSED ),
82    NAME_VAL( LOC_ENG_MSG_ATL_OPEN_FAILED ),
83    NAME_VAL( LOC_ENG_MSG_REPORT_POSITION ),
84    NAME_VAL( LOC_ENG_MSG_REPORT_SV ),
85    NAME_VAL( LOC_ENG_MSG_REPORT_STATUS ),
86    NAME_VAL( LOC_ENG_MSG_REPORT_NMEA ),
87    NAME_VAL( LOC_ENG_MSG_REQUEST_ATL ),
88    NAME_VAL( LOC_ENG_MSG_RELEASE_ATL ),
89    NAME_VAL( LOC_ENG_MSG_REQUEST_BIT ),
90    NAME_VAL( LOC_ENG_MSG_RELEASE_BIT ),
91    NAME_VAL( LOC_ENG_MSG_REQUEST_NI ),
92    NAME_VAL( LOC_ENG_MSG_INFORM_NI_RESPONSE ),
93    NAME_VAL( LOC_ENG_MSG_REQUEST_XTRA_DATA ),
94    NAME_VAL( LOC_ENG_MSG_REQUEST_TIME )
95};
96static int loc_eng_msgs_num = sizeof(loc_eng_msgs) / sizeof(loc_name_val_s_type);
97
98/* Find Android GPS status name */
99const char* loc_get_msg_name(int id)
100{
101   return loc_get_name_from_val(loc_eng_msgs, loc_eng_msgs_num, (long) id);
102}
103
104
105
106static loc_name_val_s_type loc_eng_position_modes[] =
107{
108    NAME_VAL( LOC_POSITION_MODE_STANDALONE ),
109    NAME_VAL( LOC_POSITION_MODE_MS_BASED ),
110    NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ),
111    NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ),
112    NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ),
113    NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ),
114    NAME_VAL( LOC_POSITION_MODE_RESERVED_4 )
115};
116static int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type);
117
118const char* loc_get_position_mode_name(GpsPositionMode mode)
119{
120    return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode);
121}
122
123
124
125static loc_name_val_s_type loc_eng_position_recurrences[] =
126{
127    NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ),
128    NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE )
129};
130static int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type);
131
132const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
133{
134    return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur);
135}
136
137
138
139static loc_name_val_s_type loc_eng_aiding_data_bits[] =
140{
141    NAME_VAL( GPS_DELETE_EPHEMERIS ),
142    NAME_VAL( GPS_DELETE_ALMANAC ),
143    NAME_VAL( GPS_DELETE_POSITION ),
144    NAME_VAL( GPS_DELETE_TIME ),
145    NAME_VAL( GPS_DELETE_IONO ),
146    NAME_VAL( GPS_DELETE_UTC ),
147    NAME_VAL( GPS_DELETE_HEALTH ),
148    NAME_VAL( GPS_DELETE_SVDIR ),
149    NAME_VAL( GPS_DELETE_SVSTEER ),
150    NAME_VAL( GPS_DELETE_SADATA ),
151    NAME_VAL( GPS_DELETE_RTI ),
152    NAME_VAL( GPS_DELETE_CELLDB_INFO )
153#ifdef QCOM_FEATURE_DELEXT
154    ,NAME_VAL( GPS_DELETE_ALMANAC_CORR ),
155    NAME_VAL( GPS_DELETE_FREQ_BIAS_EST ),
156    NAME_VAL( GPS_DELETE_EPHEMERIS_GLO ),
157    NAME_VAL( GPS_DELETE_ALMANAC_GLO ),
158    NAME_VAL( GPS_DELETE_SVDIR_GLO ),
159    NAME_VAL( GPS_DELETE_SVSTEER_GLO ),
160    NAME_VAL( GPS_DELETE_ALMANAC_CORR_GLO ),
161    NAME_VAL( GPS_DELETE_TIME_GPS ),
162    NAME_VAL( GPS_DELETE_TIME_GLO )
163#endif
164};
165static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type);
166
167const char* loc_get_aiding_data_mask_names(GpsAidingData data)
168{
169    return NULL;
170}
171
172
173static loc_name_val_s_type loc_eng_agps_types[] =
174{
175#ifdef QCOM_FEATURE_IPV6
176    NAME_VAL( AGPS_TYPE_INVALID ),
177    NAME_VAL( AGPS_TYPE_ANY ),
178#endif
179    NAME_VAL( AGPS_TYPE_SUPL ),
180    NAME_VAL( AGPS_TYPE_C2K )
181#ifdef QCOM_FEATURE_IPV6
182    ,NAME_VAL( AGPS_TYPE_WWAN_ANY )
183#endif
184};
185static int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type);
186
187const char* loc_get_agps_type_name(AGpsType type)
188{
189    return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type);
190}
191
192
193static loc_name_val_s_type loc_eng_ni_types[] =
194{
195    NAME_VAL( GPS_NI_TYPE_VOICE ),
196    NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ),
197    NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE )
198};
199static int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type);
200
201const char* loc_get_ni_type_name(GpsNiType type)
202{
203    return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type);
204}
205
206
207static loc_name_val_s_type loc_eng_ni_responses[] =
208{
209    NAME_VAL( GPS_NI_RESPONSE_ACCEPT ),
210    NAME_VAL( GPS_NI_RESPONSE_DENY ),
211    NAME_VAL( GPS_NI_RESPONSE_DENY )
212};
213static int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type);
214
215const char* loc_get_ni_response_name(GpsUserResponseType response)
216{
217    return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response);
218}
219
220
221static loc_name_val_s_type loc_eng_ni_encodings[] =
222{
223    NAME_VAL( GPS_ENC_NONE ),
224    NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ),
225    NAME_VAL( GPS_ENC_SUPL_UTF8 ),
226    NAME_VAL( GPS_ENC_SUPL_UCS2 ),
227    NAME_VAL( GPS_ENC_UNKNOWN )
228};
229static int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type);
230
231const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding)
232{
233    return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding);
234}
235
236#ifdef QCOM_FEATURE_IPV6
237static loc_name_val_s_type loc_eng_agps_bears[] =
238{
239    NAME_VAL( AGPS_APN_BEARER_INVALID ),
240    NAME_VAL( AGPS_APN_BEARER_IPV4 ),
241    NAME_VAL( AGPS_APN_BEARER_IPV4 ),
242    NAME_VAL( AGPS_APN_BEARER_IPV4V6 )
243};
244static int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type);
245
246const char* loc_get_agps_bear_name(AGpsBearerType bearer)
247{
248    return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer);
249}
250#endif
251
252static loc_name_val_s_type loc_eng_server_types[] =
253{
254    NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ),
255    NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ),
256    NAME_VAL( LOC_AGPS_MPC_SERVER ),
257    NAME_VAL( LOC_AGPS_SUPL_SERVER )
258};
259static int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type);
260
261const char* loc_get_server_type_name(LocServerType type)
262{
263    return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type);
264}
265
266static loc_name_val_s_type loc_eng_position_sess_status_types[] =
267{
268    NAME_VAL( LOC_SESS_SUCCESS ),
269    NAME_VAL( LOC_SESS_INTERMEDIATE ),
270    NAME_VAL( LOC_SESS_FAILURE )
271};
272static int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type);
273
274const char* loc_get_position_sess_status_name(enum loc_sess_status status)
275{
276    return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status);
277}
278
279static loc_name_val_s_type loc_eng_agps_status_names[] =
280{
281    NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ),
282    NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ),
283    NAME_VAL( GPS_AGPS_DATA_CONNECTED ),
284    NAME_VAL( GPS_AGPS_DATA_CONN_DONE ),
285    NAME_VAL( GPS_AGPS_DATA_CONN_FAILED )
286};
287static int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type);
288
289const char* loc_get_agps_status_name(AGpsStatusValue status)
290{
291    return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status);
292}
293