1 /* Copyright (c) 2011 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
30 #define LOG_NDDEBUG 0
31 #define LOG_TAG "LocSvc_api_rpc_glue"
32
33 #include "loc_api_log.h"
34 #include "loc_log.h"
35 #include "log_util.h"
36 #include "platform_lib_includes.h"
37 #include "rpc/rpc.h"
38 #include "loc_api_fixup.h"
39
40 /* Event names */
41 loc_name_val_s_type loc_event_name[] =
42 {
43 NAME_VAL( RPC_LOC_EVENT_PARSED_POSITION_REPORT ),
44 NAME_VAL( RPC_LOC_EVENT_SATELLITE_REPORT ),
45 NAME_VAL( RPC_LOC_EVENT_NMEA_1HZ_REPORT ),
46 NAME_VAL( RPC_LOC_EVENT_NMEA_POSITION_REPORT ),
47 NAME_VAL( RPC_LOC_EVENT_NI_NOTIFY_VERIFY_REQUEST ),
48 NAME_VAL( RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST ),
49 NAME_VAL( RPC_LOC_EVENT_LOCATION_SERVER_REQUEST ),
50 NAME_VAL( RPC_LOC_EVENT_IOCTL_REPORT ),
51 NAME_VAL( RPC_LOC_EVENT_STATUS_REPORT ),
52 NAME_VAL( RPC_LOC_EVENT_WPS_NEEDED_REQUEST ),
53 };
54 int loc_event_num = sizeof loc_event_name / sizeof(loc_name_val_s_type);
55
56 /* Event names */
57 loc_name_val_s_type loc_event_atl_open_name[] =
58 {
59 NAME_VAL( RPC_LOC_SERVER_REQUEST_OPEN ),
60 NAME_VAL( RPC_LOC_SERVER_REQUEST_CLOSE ),
61 NAME_VAL( RPC_LOC_SERVER_REQUEST_MULTI_OPEN )
62 };
63 int loc_event_atl_open_num = sizeof loc_event_atl_open_name / sizeof(loc_name_val_s_type);
64
65 /* Finds the first event found in the mask */
loc_get_event_atl_open_name(rpc_loc_server_request_e_type loc_event_atl_open)66 const char* loc_get_event_atl_open_name(rpc_loc_server_request_e_type loc_event_atl_open)
67 {
68 return loc_get_name_from_val(loc_event_atl_open_name, loc_event_atl_open_num,
69 (long) loc_event_atl_open);
70 }
71
72 /* IOCTL Type names */
73 loc_name_val_s_type loc_ioctl_type_name[] =
74 {
75 NAME_VAL( RPC_LOC_IOCTL_GET_API_VERSION ),
76 NAME_VAL( RPC_LOC_IOCTL_SET_FIX_CRITERIA ),
77 NAME_VAL( RPC_LOC_IOCTL_GET_FIX_CRITERIA ),
78 NAME_VAL( RPC_LOC_IOCTL_INFORM_NI_USER_RESPONSE ),
79 NAME_VAL( RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA ),
80 NAME_VAL( RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_VALIDITY ),
81 NAME_VAL( RPC_LOC_IOCTL_QUERY_PREDICTED_ORBITS_DATA_SOURCE ),
82 NAME_VAL( RPC_LOC_IOCTL_SET_PREDICTED_ORBITS_DATA_AUTO_DOWNLOAD ),
83 NAME_VAL( RPC_LOC_IOCTL_INJECT_UTC_TIME ),
84 NAME_VAL( RPC_LOC_IOCTL_INJECT_RTC_VALUE ),
85 NAME_VAL( RPC_LOC_IOCTL_INJECT_POSITION ),
86 NAME_VAL( RPC_LOC_IOCTL_QUERY_ENGINE_STATE ),
87 NAME_VAL( RPC_LOC_IOCTL_ERROR_ESTIMATE_CONFIG),
88 NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_MULTI_OPEN_STATUS ),
89 NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_OPEN_STATUS ),
90 NAME_VAL( RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS ),
91 NAME_VAL( RPC_LOC_IOCTL_SEND_WIPER_POSITION_REPORT ),
92 NAME_VAL( RPC_LOC_IOCTL_NOTIFY_WIPER_STATUS ),
93 NAME_VAL( RPC_LOC_IOCTL_SET_ENGINE_LOCK ),
94 NAME_VAL( RPC_LOC_IOCTL_GET_ENGINE_LOCK ),
95 NAME_VAL( RPC_LOC_IOCTL_SET_SBAS_CONFIG ),
96 NAME_VAL( RPC_LOC_IOCTL_GET_SBAS_CONFIG ),
97 NAME_VAL( RPC_LOC_IOCTL_SET_NMEA_TYPES ),
98 NAME_VAL( RPC_LOC_IOCTL_GET_NMEA_TYPES ),
99 NAME_VAL( RPC_LOC_IOCTL_SET_CDMA_PDE_SERVER_ADDR ),
100 NAME_VAL( RPC_LOC_IOCTL_GET_CDMA_PDE_SERVER_ADDR ),
101 NAME_VAL( RPC_LOC_IOCTL_SET_CDMA_MPC_SERVER_ADDR ),
102 NAME_VAL( RPC_LOC_IOCTL_GET_CDMA_MPC_SERVER_ADDR ),
103 NAME_VAL( RPC_LOC_IOCTL_SET_UMTS_SLP_SERVER_ADDR ),
104 NAME_VAL( RPC_LOC_IOCTL_GET_UMTS_SLP_SERVER_ADDR ),
105 NAME_VAL( RPC_LOC_IOCTL_SET_ON_DEMAND_LPM ),
106 NAME_VAL( RPC_LOC_IOCTL_GET_ON_DEMAND_LPM ),
107 NAME_VAL( RPC_LOC_IOCTL_SET_XTRA_T_SESSION_CONTROL ),
108 NAME_VAL( RPC_LOC_IOCTL_GET_XTRA_T_SESSION_CONTROL ),
109 NAME_VAL( RPC_LOC_IOCTL_SET_LBS_APN_PROFILE ),
110 NAME_VAL( RPC_LOC_IOCTL_GET_LBS_APN_PROFILE ),
111 NAME_VAL( RPC_LOC_IOCTL_SET_XTRA_APN_PROFILE ),
112 NAME_VAL( RPC_LOC_IOCTL_GET_XTRA_APN_PROFILE ),
113 NAME_VAL( RPC_LOC_IOCTL_SET_DATA_ENABLE ),
114 NAME_VAL( RPC_LOC_IOCTL_SET_SUPL_VERSION ),
115 NAME_VAL( RPC_LOC_IOCTL_GET_SUPL_VERSION ),
116 NAME_VAL( RPC_LOC_IOCTL_DELETE_ASSIST_DATA ),
117 NAME_VAL( RPC_LOC_IOCTL_SET_CUSTOM_PDE_SERVER_ADDR ),
118 NAME_VAL( RPC_LOC_IOCTL_GET_CUSTOM_PDE_SERVER_ADDR ),
119 };
120 int loc_ioctl_type_num = sizeof loc_ioctl_type_name / sizeof(loc_name_val_s_type);
121
122 /* IOCTL Status names */
123 loc_name_val_s_type loc_ioctl_status_name[] =
124 {
125 NAME_VAL( RPC_LOC_API_SUCCESS ),
126 NAME_VAL( RPC_LOC_API_GENERAL_FAILURE ),
127 NAME_VAL( RPC_LOC_API_UNSUPPORTED ),
128 NAME_VAL( RPC_LOC_API_INVALID_HANDLE ),
129 NAME_VAL( RPC_LOC_API_INVALID_PARAMETER ),
130 NAME_VAL( RPC_LOC_API_ENGINE_BUSY ),
131 NAME_VAL( RPC_LOC_API_PHONE_OFFLINE ),
132 NAME_VAL( RPC_LOC_API_TIMEOUT ),
133 NAME_VAL( RPC_LOC_API_RPC_FAILURE ),
134 NAME_VAL( RPC_LOC_API_RPC_MODEM_RESTART )
135 };
136 int loc_ioctl_status_num = sizeof loc_ioctl_status_name / sizeof(loc_name_val_s_type);
137
138 /* Fix session status names */
139 loc_name_val_s_type loc_sess_status_name[] =
140 {
141 NAME_VAL( RPC_LOC_SESS_STATUS_SUCCESS ),
142 NAME_VAL( RPC_LOC_SESS_STATUS_IN_PROGESS ),
143 NAME_VAL( RPC_LOC_SESS_STATUS_GENERAL_FAILURE ),
144 NAME_VAL( RPC_LOC_SESS_STATUS_TIMEOUT ),
145 NAME_VAL( RPC_LOC_SESS_STATUS_USER_END ),
146 NAME_VAL( RPC_LOC_SESS_STATUS_BAD_PARAMETER ),
147 NAME_VAL( RPC_LOC_SESS_STATUS_PHONE_OFFLINE ),
148 NAME_VAL( RPC_LOC_SESS_STATUS_USER_END ),
149 NAME_VAL( RPC_LOC_SESS_STATUS_ENGINE_LOCKED )
150 };
151 int loc_sess_status_num = sizeof loc_sess_status_name / sizeof(loc_name_val_s_type);
152
153 /* Engine state names */
154 loc_name_val_s_type loc_engine_state_name[] =
155 {
156 NAME_VAL( RPC_LOC_ENGINE_STATE_ON ),
157 NAME_VAL( RPC_LOC_ENGINE_STATE_OFF )
158 };
159 int loc_engine_state_num = sizeof loc_engine_state_name / sizeof(loc_name_val_s_type);
160
161 /* Fix session state names */
162 loc_name_val_s_type loc_fix_session_state_name[] =
163 {
164 NAME_VAL( RPC_LOC_FIX_SESSION_STATE_BEGIN ),
165 NAME_VAL( RPC_LOC_FIX_SESSION_STATE_END )
166 };
167 int loc_fix_session_state_num = sizeof loc_fix_session_state_name / sizeof(loc_name_val_s_type);
168
169
log_final_interm_string(int is_final)170 static const char* log_final_interm_string(int is_final)
171 {
172 return is_final ? "final" : "intermediate";
173 }
174
175 /* Logs parsed report */
log_parsed_report(const rpc_loc_parsed_position_s_type * parsed_report)176 static void log_parsed_report(const rpc_loc_parsed_position_s_type *parsed_report)
177 {
178 rpc_loc_session_status_e_type status = parsed_report->session_status;
179 LOC_LOGD("Session status: %s Valid mask: 0x%X\n",
180 loc_get_sess_status_name(status),
181 (uint) parsed_report->valid_mask);
182 LOC_LOGD("Latitude: %.7f (%s)\n", parsed_report->latitude,
183 log_final_interm_string(
184 (parsed_report->valid_mask & RPC_LOC_POS_VALID_LATITUDE) &&
185 parsed_report->session_status == RPC_LOC_SESS_STATUS_SUCCESS));
186 LOC_LOGD("Longitude: %.7f\n", parsed_report->longitude);
187 LOC_LOGD("Accuracy: %.7f\n", parsed_report->hor_unc_circular);
188 }
189
190 /* Logs status report */
log_status_report(const rpc_loc_status_event_s_type * status_event)191 static void log_status_report(const rpc_loc_status_event_s_type *status_event)
192 {
193 rpc_loc_status_event_e_type event = status_event->event;
194 switch (event) {
195 case RPC_LOC_STATUS_EVENT_ENGINE_STATE:
196 LOC_LOGD("Engine state: %s\n",
197 loc_get_engine_state_name(
198 status_event->payload.rpc_loc_status_event_payload_u_type_u.engine_state));
199 break;
200 case RPC_LOC_STATUS_EVENT_FIX_SESSION_STATE:
201 LOC_LOGD("Fix session state: %s\n",
202 loc_get_fix_session_state_name(
203 status_event->payload.rpc_loc_status_event_payload_u_type_u.fix_session_state));
204 break;
205 default:
206 break;
207 }
208 }
209
210 /* Logs valid fields in the GNSS SV constellation report */
log_satellite_report(const rpc_loc_gnss_info_s_type * gnss)211 static void log_satellite_report(const rpc_loc_gnss_info_s_type *gnss)
212 {
213 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_POS_DOP)
214 {
215 LOC_LOGV("position dop: %.3f\n", (float) gnss->position_dop);
216 }
217 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_HOR_DOP)
218 {
219 LOC_LOGV("horizontal dop: %.3f\n", (float) gnss->horizontal_dop);
220 }
221 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_VERT_DOP)
222 {
223 LOC_LOGV("vertical dop: %.3f\n", (float) gnss->vertical_dop);
224 }
225 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_ALTITUDE_ASSUMED)
226 {
227 LOC_LOGV("altitude assumed: %d\n", (int) gnss->altitude_assumed);
228 }
229 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_COUNT)
230 {
231 LOC_LOGD("sv count: %d\n", (int) gnss->sv_count);
232 }
233 if (gnss->valid_mask & RPC_LOC_GNSS_INFO_VALID_SV_LIST)
234 {
235 LOC_LOGV("sv list: ");
236
237 if (gnss->sv_count)
238 {
239 LOC_LOGV("\n\tsys\tprn\thlth\tproc\teph\talm\telev\tazi\tsnr\n");
240 }
241 else {
242 LOC_LOGV("empty\n");
243 }
244
245 int i;
246 for (i = 0; i < gnss->sv_count; i++)
247 {
248 const rpc_loc_sv_info_s_type *sv = &gnss->sv_list.sv_list_val[i];
249 rpc_loc_sv_info_valid_mask_type mask = sv->valid_mask;
250 LOC_LOGV(" %d: \t%d\t%d\t%d\t%d\t%d\t%d\t%.3f\t%.3f\t%.3f\n", i,
251 CHECK_MASK(int, sv->system, mask, RPC_LOC_SV_INFO_VALID_SYSTEM),
252 CHECK_MASK(int, sv->prn, mask, RPC_LOC_SV_INFO_VALID_PRN),
253 CHECK_MASK(int, sv->health_status, mask, RPC_LOC_SV_INFO_VALID_HEALTH_STATUS),
254 CHECK_MASK(int, sv->process_status, mask, RPC_LOC_SV_INFO_VALID_PROCESS_STATUS),
255 CHECK_MASK(int, sv->has_eph, mask, RPC_LOC_SV_INFO_VALID_HAS_EPH),
256 CHECK_MASK(int, sv->has_alm, mask, RPC_LOC_SV_INFO_VALID_HAS_ALM),
257 CHECK_MASK(float, sv->elevation, mask, RPC_LOC_SV_INFO_VALID_ELEVATION),
258 CHECK_MASK(float, sv->azimuth, mask, RPC_LOC_SV_INFO_VALID_AZIMUTH),
259 CHECK_MASK(float, sv->snr, mask, RPC_LOC_SV_INFO_VALID_SNR)
260 );
261 }
262 }
263 }
264
265 /* Logs a callback event */
loc_callback_log(rpc_loc_event_mask_type loc_event,const rpc_loc_event_payload_u_type * loc_event_payload)266 int loc_callback_log(
267 rpc_loc_event_mask_type loc_event, /* event mask */
268 const rpc_loc_event_payload_u_type* loc_event_payload /* payload */
269 )
270 {
271 switch (loc_event)
272 {
273 case RPC_LOC_EVENT_SATELLITE_REPORT:
274 log_satellite_report(&loc_event_payload->
275 rpc_loc_event_payload_u_type_u.gnss_report);
276 break;
277 case RPC_LOC_EVENT_STATUS_REPORT:
278 log_status_report(&loc_event_payload->
279 rpc_loc_event_payload_u_type_u.status_report);
280 break;
281 case RPC_LOC_EVENT_PARSED_POSITION_REPORT:
282 log_parsed_report(&loc_event_payload->
283 rpc_loc_event_payload_u_type_u.parsed_location_report);
284 break;
285 default:
286 break;
287 }
288
289 return 0;
290 }
291
292 /* Finds the first event found in the mask */
loc_get_event_name(rpc_loc_event_mask_type loc_event_mask)293 const char* loc_get_event_name(rpc_loc_event_mask_type loc_event_mask)
294 {
295 return loc_get_name_from_mask(loc_event_name, loc_event_num,
296 (long) loc_event_mask);
297 }
298
299 /* Finds IOCTL type name */
loc_get_ioctl_type_name(rpc_loc_ioctl_e_type ioctl_type)300 const char* loc_get_ioctl_type_name(rpc_loc_ioctl_e_type ioctl_type)
301 {
302 return loc_get_name_from_val(loc_ioctl_type_name, loc_ioctl_type_num,
303 (long) ioctl_type);
304 }
305
306 /* Finds IOCTL status name */
loc_get_ioctl_status_name(uint32 status)307 const char* loc_get_ioctl_status_name(uint32 status)
308 {
309 return loc_get_name_from_val(loc_ioctl_status_name, loc_ioctl_status_num,
310 (long) status);
311 }
312
313 /* Finds session status name */
loc_get_sess_status_name(rpc_loc_session_status_e_type status)314 const char* loc_get_sess_status_name(rpc_loc_session_status_e_type status)
315 {
316 return loc_get_name_from_val(loc_sess_status_name, loc_sess_status_num,
317 (long) status);
318 }
319
320 /* Find engine state name */
loc_get_engine_state_name(rpc_loc_engine_state_e_type state)321 const char* loc_get_engine_state_name(rpc_loc_engine_state_e_type state)
322 {
323 return loc_get_name_from_val(loc_engine_state_name, loc_engine_state_num,
324 (long) state);
325 }
326
327 /* Find engine state name */
loc_get_fix_session_state_name(rpc_loc_fix_session_state_e_type state)328 const char* loc_get_fix_session_state_name(rpc_loc_fix_session_state_e_type state)
329 {
330 return loc_get_name_from_val(loc_fix_session_state_name, loc_fix_session_state_num,
331 (long) state);
332 }
333
334 /* Event names */
335 loc_name_val_s_type rpc_reset_event_name[] =
336 {
337 NAME_VAL( RPC_SUBSYSTEM_RESTART_BEGIN ),
338 NAME_VAL( RPC_SUBSYSTEM_RESTART_END )
339 };
340 int rpc_reset_event_num = sizeof rpc_reset_event_name / sizeof(loc_name_val_s_type);
341
loc_get_rpc_reset_event_name(enum rpc_reset_event event)342 const char* loc_get_rpc_reset_event_name(enum rpc_reset_event event)
343 {
344 return loc_get_name_from_val(rpc_reset_event_name, rpc_reset_event_num, event);
345 }
346