1 /* Copyright (c) 2009-2014, 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_eng"
32
33 #include <stdint.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <dlfcn.h>
38 #include <ctype.h>
39 #include <math.h>
40 #include <pthread.h>
41 #include <arpa/inet.h>
42 #include <netinet/in.h> /* struct sockaddr_in */
43 #include <sys/socket.h>
44 #include <sys/time.h>
45 #include <netdb.h>
46 #include <time.h>
47 #include <new>
48 #include <LocEngAdapter.h>
49
50 #include <cutils/sched_policy.h>
51 #ifndef USE_GLIB
52 #include <utils/SystemClock.h>
53 #include <utils/Log.h>
54 #endif /* USE_GLIB */
55
56 #ifdef USE_GLIB
57 #include <glib.h>
58 #include <sys/syscall.h>
59 #endif /* USE_GLIB */
60
61 #include <string.h>
62
63 #include <loc_eng.h>
64 #include <loc_eng_ni.h>
65 #include <loc_eng_dmn_conn.h>
66 #include <loc_eng_dmn_conn_handler.h>
67 #include <loc_eng_msg.h>
68 #include <loc_eng_nmea.h>
69 #include <msg_q.h>
70 #include <loc.h>
71 #include "log_util.h"
72 #include "platform_lib_includes.h"
73 #include "loc_core_log.h"
74 #include "loc_eng_log.h"
75
76 #define SUCCESS TRUE
77 #define FAILURE FALSE
78
79 #ifndef GPS_CONF_FILE
80 #define GPS_CONF_FILE "/etc/gps.conf" //??? platform independent
81 #endif
82
83 #ifndef SAP_CONF_FILE
84 #define SAP_CONF_FILE "/etc/sap.conf"
85 #endif
86
87 #define XTRA1_GPSONEXTRA "xtra1.gpsonextra.net"
88
89 using namespace loc_core;
90
91 boolean configAlreadyRead = false;
92 unsigned int agpsStatus = 0;
93 loc_gps_cfg_s_type gps_conf;
94 loc_sap_cfg_s_type sap_conf;
95
96 /* Parameter spec table */
97 static loc_param_s_type gps_conf_table[] =
98 {
99 {"GPS_LOCK", &gps_conf.GPS_LOCK, NULL, 'n'},
100 {"SUPL_VER", &gps_conf.SUPL_VER, NULL, 'n'},
101 {"LPP_PROFILE", &gps_conf.LPP_PROFILE, NULL, 'n'},
102 {"A_GLONASS_POS_PROTOCOL_SELECT", &gps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'},
103 {"AGPS_CERT_WRITABLE_MASK", &gps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'},
104 {"INTERMEDIATE_POS", &gps_conf.INTERMEDIATE_POS, NULL, 'n'},
105 {"ACCURACY_THRES", &gps_conf.ACCURACY_THRES, NULL, 'n'},
106 {"NMEA_PROVIDER", &gps_conf.NMEA_PROVIDER, NULL, 'n'},
107 {"CAPABILITIES", &gps_conf.CAPABILITIES, NULL, 'n'},
108 };
109
110 static loc_param_s_type sap_conf_table[] =
111 {
112 {"GYRO_BIAS_RANDOM_WALK", &sap_conf.GYRO_BIAS_RANDOM_WALK, &sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'},
113 {"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
114 {"ANGLE_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
115 {"RATE_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
116 {"VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
117 {"SENSOR_ACCEL_BATCHES_PER_SEC", &sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, NULL, 'n'},
118 {"SENSOR_ACCEL_SAMPLES_PER_BATCH", &sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, NULL, 'n'},
119 {"SENSOR_GYRO_BATCHES_PER_SEC", &sap_conf.SENSOR_GYRO_BATCHES_PER_SEC, NULL, 'n'},
120 {"SENSOR_GYRO_SAMPLES_PER_BATCH", &sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, NULL, 'n'},
121 {"SENSOR_ACCEL_BATCHES_PER_SEC_HIGH", &sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, NULL, 'n'},
122 {"SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH", &sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, NULL, 'n'},
123 {"SENSOR_GYRO_BATCHES_PER_SEC_HIGH", &sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, NULL, 'n'},
124 {"SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH", &sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, NULL, 'n'},
125 {"SENSOR_CONTROL_MODE", &sap_conf.SENSOR_CONTROL_MODE, NULL, 'n'},
126 {"SENSOR_USAGE", &sap_conf.SENSOR_USAGE, NULL, 'n'},
127 {"SENSOR_ALGORITHM_CONFIG_MASK", &sap_conf.SENSOR_ALGORITHM_CONFIG_MASK, NULL, 'n'},
128 {"SENSOR_PROVIDER", &sap_conf.SENSOR_PROVIDER, NULL, 'n'},
129 {"XTRA_SERVER_1", &gps_conf.XTRA_SERVER_1, NULL, 's'},
130 {"XTRA_SERVER_2", &gps_conf.XTRA_SERVER_2, NULL, 's'},
131 {"XTRA_SERVER_3", &gps_conf.XTRA_SERVER_3, NULL, 's'}
132 };
133
loc_default_parameters(void)134 static void loc_default_parameters(void)
135 {
136 /* defaults */
137 gps_conf.INTERMEDIATE_POS = 0;
138 gps_conf.ACCURACY_THRES = 0;
139 gps_conf.NMEA_PROVIDER = 0;
140 gps_conf.GPS_LOCK = 0;
141 gps_conf.SUPL_VER = 0x10000;
142 gps_conf.CAPABILITIES = 0x7;
143
144 sap_conf.GYRO_BIAS_RANDOM_WALK = 0;
145 sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2;
146 sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5;
147 sap_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2;
148 sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5;
149 sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH = 4;
150 sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH = 25;
151 sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH = 4;
152 sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH = 25;
153 sap_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */
154 sap_conf.SENSOR_USAGE = 0; /* Enabled */
155 sap_conf.SENSOR_ALGORITHM_CONFIG_MASK = 0; /* INS Disabled = FALSE*/
156
157 /* Values MUST be set by OEMs in configuration for sensor-assisted
158 navigation to work. There are NO default values */
159 sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY = 0;
160 sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
161 sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
162 sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY = 0;
163
164 sap_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0;
165 sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
166 sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
167 sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
168 sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
169
170 /* LTE Positioning Profile configuration is disable by default*/
171 gps_conf.LPP_PROFILE = 0;
172
173 /*By default no positioning protocol is selected on A-GLONASS system*/
174 gps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0;
175
176 /* default provider is SSC */
177 sap_conf.SENSOR_PROVIDER = 1;
178
179 /* None of the 10 slots for agps certificates are writable by default */
180 gps_conf.AGPS_CERT_WRITABLE_MASK = 0;
181 }
182
183 // 2nd half of init(), singled out for
184 // modem restart to use.
185 static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data);
186 static void loc_eng_agps_reinit(loc_eng_data_s_type &loc_eng_data);
187
188 static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data,
189 LocServerType type, const char *hostname, int port);
190 // Internal functions
191 static void loc_inform_gps_status(loc_eng_data_s_type &loc_eng_data,
192 GpsStatusValue status);
193 static void loc_eng_report_status(loc_eng_data_s_type &loc_eng_data,
194 GpsStatusValue status);
195 static void loc_eng_process_conn_request(loc_eng_data_s_type &loc_eng_data,
196 int connHandle, AGpsType agps_type);
197 static void loc_eng_agps_close_status(loc_eng_data_s_type &loc_eng_data, int is_succ);
198 static void loc_eng_handle_engine_down(loc_eng_data_s_type &loc_eng_data) ;
199 static void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data) ;
200
201 static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data);
202 static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data);
203 static int loc_eng_get_zpp_handler(loc_eng_data_s_type &loc_eng_data);
204 static void loc_eng_handle_shutdown(loc_eng_data_s_type &loc_eng_data);
205 static void deleteAidingData(loc_eng_data_s_type &logEng);
206 static AgpsStateMachine*
207 getAgpsStateMachine(loc_eng_data_s_type& logEng, AGpsExtType agpsType);
208 static int dataCallCb(void *cb_data);
update_aiding_data_for_deletion(loc_eng_data_s_type & loc_eng_data)209 static void update_aiding_data_for_deletion(loc_eng_data_s_type& loc_eng_data) {
210 if (loc_eng_data.engine_status != GPS_STATUS_ENGINE_ON &&
211 loc_eng_data.aiding_data_for_deletion != 0)
212 {
213 loc_eng_data.adapter->deleteAidingData(loc_eng_data.aiding_data_for_deletion);
214 loc_eng_data.aiding_data_for_deletion = 0;
215 }
216 }
217
noProc(void * data)218 static void* noProc(void* data)
219 {
220 return NULL;
221 }
222
223
224 /*********************************************************************
225 * definitions of the static messages used in the file
226 *********************************************************************/
227 // case LOC_ENG_MSG_REQUEST_NI:
LocEngRequestNi(void * locEng,GpsNiNotification & notif,const void * data)228 LocEngRequestNi::LocEngRequestNi(void* locEng,
229 GpsNiNotification ¬if,
230 const void* data) :
231 LocMsg(), mLocEng(locEng), mNotify(notif), mPayload(data) {
232 locallog();
233 }
proc() const234 void LocEngRequestNi::proc() const {
235 loc_eng_ni_request_handler(*((loc_eng_data_s_type*)mLocEng),
236 &mNotify, mPayload);
237 }
locallog() const238 void LocEngRequestNi::locallog() const
239 {
240 LOC_LOGV("id: %d\n type: %s\n flags: %d\n time out: %d\n "
241 "default response: %s\n requestor id encoding: %s\n"
242 " text encoding: %s\n passThroughData: %p",
243 mNotify.notification_id,
244 loc_get_ni_type_name(mNotify.ni_type),
245 mNotify.notify_flags,
246 mNotify.timeout,
247 loc_get_ni_response_name(mNotify.default_response),
248 loc_get_ni_encoding_name(mNotify.requestor_id_encoding),
249 loc_get_ni_encoding_name(mNotify.text_encoding),
250 mPayload);
251 }
log() const252 inline void LocEngRequestNi::log() const {
253 locallog();
254 }
255
256 // case LOC_ENG_MSG_INFORM_NI_RESPONSE:
257 // in loc_eng_ni.cpp
258
259 // case LOC_ENG_MSG_START_FIX:
LocEngStartFix(LocEngAdapter * adapter)260 LocEngStartFix::LocEngStartFix(LocEngAdapter* adapter) :
261 LocMsg(), mAdapter(adapter)
262 {
263 locallog();
264 }
proc() const265 inline void LocEngStartFix::proc() const
266 {
267 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner();
268 loc_eng_start_handler(*locEng);
269 }
locallog() const270 inline void LocEngStartFix::locallog() const
271 {
272 LOC_LOGV("LocEngStartFix");
273 }
log() const274 inline void LocEngStartFix::log() const
275 {
276 locallog();
277 }
send() const278 void LocEngStartFix::send() const {
279 mAdapter->sendMsg(this);
280 }
281
282 // case LOC_ENG_MSG_STOP_FIX:
LocEngStopFix(LocEngAdapter * adapter)283 LocEngStopFix::LocEngStopFix(LocEngAdapter* adapter) :
284 LocMsg(), mAdapter(adapter)
285 {
286 locallog();
287 }
proc() const288 inline void LocEngStopFix::proc() const
289 {
290 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner();
291 loc_eng_stop_handler(*locEng);
292 }
locallog() const293 inline void LocEngStopFix::locallog() const
294 {
295 LOC_LOGV("LocEngStopFix");
296 }
log() const297 inline void LocEngStopFix::log() const
298 {
299 locallog();
300 }
send() const301 void LocEngStopFix::send() const {
302 mAdapter->sendMsg(this);
303 }
304
305 // case LOC_ENG_MSG_SET_POSITION_MODE:
LocEngPositionMode(LocEngAdapter * adapter,LocPosMode & mode)306 LocEngPositionMode::LocEngPositionMode(LocEngAdapter* adapter,
307 LocPosMode &mode) :
308 LocMsg(), mAdapter(adapter), mPosMode(mode)
309 {
310 mPosMode.logv();
311 }
proc() const312 inline void LocEngPositionMode::proc() const {
313 mAdapter->setPositionMode(&mPosMode);
314 }
log() const315 inline void LocEngPositionMode::log() const {
316 mPosMode.logv();
317 }
send() const318 void LocEngPositionMode::send() const {
319 mAdapter->sendMsg(this);
320 }
321
LocEngGetZpp(LocEngAdapter * adapter)322 LocEngGetZpp::LocEngGetZpp(LocEngAdapter* adapter) :
323 LocMsg(), mAdapter(adapter)
324 {
325 locallog();
326 }
proc() const327 inline void LocEngGetZpp::proc() const
328 {
329 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner();
330 loc_eng_get_zpp_handler(*locEng);
331 }
locallog() const332 inline void LocEngGetZpp::locallog() const
333 {
334 LOC_LOGV("LocEngGetZpp");
335 }
log() const336 inline void LocEngGetZpp::log() const
337 {
338 locallog();
339 }
send() const340 void LocEngGetZpp::send() const {
341 mAdapter->sendMsg(this);
342 }
343
344
LocEngShutdown(LocEngAdapter * adapter)345 LocEngShutdown::LocEngShutdown(LocEngAdapter* adapter) :
346 LocMsg(), mAdapter(adapter)
347 {
348 locallog();
349 }
proc() const350 inline void LocEngShutdown::proc() const
351 {
352 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mAdapter->getOwner();
353 LOC_LOGD("%s:%d]: Calling loc_eng_handle_shutdown", __func__, __LINE__);
354 loc_eng_handle_shutdown(*locEng);
355 }
locallog() const356 inline void LocEngShutdown::locallog() const
357 {
358 LOC_LOGV("LocEngShutdown");
359 }
log() const360 inline void LocEngShutdown::log() const
361 {
362 locallog();
363 }
364
365 // case LOC_ENG_MSG_SET_TIME:
366 struct LocEngSetTime : public LocMsg {
367 LocEngAdapter* mAdapter;
368 const GpsUtcTime mTime;
369 const int64_t mTimeReference;
370 const int mUncertainty;
LocEngSetTimeLocEngSetTime371 inline LocEngSetTime(LocEngAdapter* adapter,
372 GpsUtcTime t, int64_t tf, int unc) :
373 LocMsg(), mAdapter(adapter),
374 mTime(t), mTimeReference(tf), mUncertainty(unc)
375 {
376 locallog();
377 }
procLocEngSetTime378 inline virtual void proc() const {
379 mAdapter->setTime(mTime, mTimeReference, mUncertainty);
380 }
locallogLocEngSetTime381 inline void locallog() const {
382 LOC_LOGV("time: %lld\n timeReference: %lld\n uncertainty: %d",
383 mTime, mTimeReference, mUncertainty);
384 }
logLocEngSetTime385 inline virtual void log() const {
386 locallog();
387 }
388 };
389
390 // case LOC_ENG_MSG_INJECT_LOCATION:
391 struct LocEngInjectLocation : public LocMsg {
392 LocEngAdapter* mAdapter;
393 const double mLatitude;
394 const double mLongitude;
395 const float mAccuracy;
LocEngInjectLocationLocEngInjectLocation396 inline LocEngInjectLocation(LocEngAdapter* adapter,
397 double lat, double lon, float accur) :
398 LocMsg(), mAdapter(adapter),
399 mLatitude(lat), mLongitude(lon), mAccuracy(accur)
400 {
401 locallog();
402 }
procLocEngInjectLocation403 inline virtual void proc() const {
404 mAdapter->injectPosition(mLatitude, mLongitude, mAccuracy);
405 }
locallogLocEngInjectLocation406 inline void locallog() const {
407 LOC_LOGV("latitude: %f\n longitude: %f\n accuracy: %f",
408 mLatitude, mLongitude, mAccuracy);
409 }
logLocEngInjectLocation410 inline virtual void log() const {
411 locallog();
412 }
413 };
414
415 // case LOC_ENG_MSG_SET_SERVER_IPV4:
416 struct LocEngSetServerIpv4 : public LocMsg {
417 LocEngAdapter* mAdapter;
418 const unsigned int mNlAddr;
419 const int mPort;
420 const LocServerType mServerType;
LocEngSetServerIpv4LocEngSetServerIpv4421 inline LocEngSetServerIpv4(LocEngAdapter* adapter,
422 unsigned int ip,
423 int port,
424 LocServerType type) :
425 LocMsg(), mAdapter(adapter),
426 mNlAddr(ip), mPort(port), mServerType(type)
427 {
428 locallog();
429 }
procLocEngSetServerIpv4430 inline virtual void proc() const {
431 mAdapter->setServer(mNlAddr, mPort, mServerType);
432 }
locallogLocEngSetServerIpv4433 inline void locallog() const {
434 LOC_LOGV("LocEngSetServerIpv4 - addr: %x, port: %d, type: %s",
435 mNlAddr, mPort, loc_get_server_type_name(mServerType));
436 }
logLocEngSetServerIpv4437 inline virtual void log() const {
438 locallog();
439 }
440 };
441
442 // case LOC_ENG_MSG_SET_SERVER_URL:
443 struct LocEngSetServerUrl : public LocMsg {
444 LocEngAdapter* mAdapter;
445 const int mLen;
446 char* mUrl;
LocEngSetServerUrlLocEngSetServerUrl447 inline LocEngSetServerUrl(LocEngAdapter* adapter,
448 char* urlString,
449 int url_len) :
450 LocMsg(), mAdapter(adapter),
451 mLen(url_len), mUrl(new char[mLen+1])
452 {
453 memcpy((void*)mUrl, (void*)urlString, url_len);
454 mUrl[mLen] = 0;
455 locallog();
456 }
~LocEngSetServerUrlLocEngSetServerUrl457 inline ~LocEngSetServerUrl()
458 {
459 delete[] mUrl;
460 }
procLocEngSetServerUrl461 inline virtual void proc() const {
462 mAdapter->setServer(mUrl, mLen);
463 }
locallogLocEngSetServerUrl464 inline void locallog() const {
465 LOC_LOGV("LocEngSetServerUrl - url: %s", mUrl);
466 }
logLocEngSetServerUrl467 inline virtual void log() const {
468 locallog();
469 }
470 };
471
472 // case LOC_ENG_MSG_A_GLONASS_PROTOCOL:
473 struct LocEngAGlonassProtocol : public LocMsg {
474 LocEngAdapter* mAdapter;
475 const unsigned long mAGlonassProtocl;
LocEngAGlonassProtocolLocEngAGlonassProtocol476 inline LocEngAGlonassProtocol(LocEngAdapter* adapter,
477 unsigned long protocol) :
478 LocMsg(), mAdapter(adapter), mAGlonassProtocl(protocol)
479 {
480 locallog();
481 }
procLocEngAGlonassProtocol482 inline virtual void proc() const {
483 mAdapter->setAGLONASSProtocol(mAGlonassProtocl);
484 }
locallogLocEngAGlonassProtocol485 inline void locallog() const {
486 LOC_LOGV("A-GLONASS protocol: 0x%lx", mAGlonassProtocl);
487 }
logLocEngAGlonassProtocol488 inline virtual void log() const {
489 locallog();
490 }
491 };
492
493 // case LOC_ENG_MSG_SUPL_VERSION:
494 struct LocEngSuplVer : public LocMsg {
495 LocEngAdapter* mAdapter;
496 const int mSuplVer;
LocEngSuplVerLocEngSuplVer497 inline LocEngSuplVer(LocEngAdapter* adapter,
498 int suplVer) :
499 LocMsg(), mAdapter(adapter), mSuplVer(suplVer)
500 {
501 locallog();
502 }
procLocEngSuplVer503 inline virtual void proc() const {
504 mAdapter->setSUPLVersion(mSuplVer);
505 }
locallogLocEngSuplVer506 inline void locallog() const {
507 LOC_LOGV("SUPL Version: %d", mSuplVer);
508 }
logLocEngSuplVer509 inline virtual void log() const {
510 locallog();
511 }
512 };
513
514 // case LOC_ENG_MSG_LPP_CONFIG:
515 struct LocEngLppConfig : public LocMsg {
516 LocEngAdapter* mAdapter;
517 const int mLppConfig;
LocEngLppConfigLocEngLppConfig518 inline LocEngLppConfig(LocEngAdapter* adapter,
519 int lppConfig) :
520 LocMsg(), mAdapter(adapter), mLppConfig(lppConfig)
521 {
522 locallog();
523 }
procLocEngLppConfig524 inline virtual void proc() const {
525 mAdapter->setLPPConfig(mLppConfig);
526 }
locallogLocEngLppConfig527 inline void locallog() const {
528 LOC_LOGV("LocEngLppConfig - profile: %d", mLppConfig);
529 }
logLocEngLppConfig530 inline virtual void log() const {
531 locallog();
532 }
533 };
534
535 // case LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG:
536 struct LocEngSensorControlConfig : public LocMsg {
537 LocEngAdapter* mAdapter;
538 const int mSensorsDisabled;
539 const int mSensorProvider;
LocEngSensorControlConfigLocEngSensorControlConfig540 inline LocEngSensorControlConfig(LocEngAdapter* adapter,
541 int sensorsDisabled, int sensorProvider) :
542 LocMsg(), mAdapter(adapter), mSensorsDisabled(sensorsDisabled),
543 mSensorProvider(sensorProvider)
544 {
545 locallog();
546 }
procLocEngSensorControlConfig547 inline virtual void proc() const {
548 mAdapter->setSensorControlConfig(mSensorsDisabled, mSensorProvider);
549 }
locallogLocEngSensorControlConfig550 inline void locallog() const {
551 LOC_LOGV("LocEngSensorControlConfig - Sensors Disabled: %d, Sensor Provider: %d",
552 mSensorsDisabled, mSensorProvider);
553 }
logLocEngSensorControlConfig554 inline virtual void log() const {
555 locallog();
556 }
557 };
558
559 // case LOC_ENG_MSG_SET_SENSOR_PROPERTIES:
560 struct LocEngSensorProperties : public LocMsg {
561 LocEngAdapter* mAdapter;
562 const bool mGyroBiasVarianceRandomWalkValid;
563 const float mGyroBiasVarianceRandomWalk;
564 const bool mAccelRandomWalkValid;
565 const float mAccelRandomWalk;
566 const bool mAngleRandomWalkValid;
567 const float mAngleRandomWalk;
568 const bool mRateRandomWalkValid;
569 const float mRateRandomWalk;
570 const bool mVelocityRandomWalkValid;
571 const float mVelocityRandomWalk;
LocEngSensorPropertiesLocEngSensorProperties572 inline LocEngSensorProperties(LocEngAdapter* adapter,
573 bool gyroBiasRandomWalk_valid,
574 float gyroBiasRandomWalk,
575 bool accelRandomWalk_valid,
576 float accelRandomWalk,
577 bool angleRandomWalk_valid,
578 float angleRandomWalk,
579 bool rateRandomWalk_valid,
580 float rateRandomWalk,
581 bool velocityRandomWalk_valid,
582 float velocityRandomWalk) :
583 LocMsg(), mAdapter(adapter),
584 mGyroBiasVarianceRandomWalkValid(gyroBiasRandomWalk_valid),
585 mGyroBiasVarianceRandomWalk(gyroBiasRandomWalk),
586 mAccelRandomWalkValid(accelRandomWalk_valid),
587 mAccelRandomWalk(accelRandomWalk),
588 mAngleRandomWalkValid(angleRandomWalk_valid),
589 mAngleRandomWalk(angleRandomWalk),
590 mRateRandomWalkValid(rateRandomWalk_valid),
591 mRateRandomWalk(rateRandomWalk),
592 mVelocityRandomWalkValid(velocityRandomWalk_valid),
593 mVelocityRandomWalk(velocityRandomWalk)
594 {
595 locallog();
596 }
procLocEngSensorProperties597 inline virtual void proc() const {
598 mAdapter->setSensorProperties(mGyroBiasVarianceRandomWalkValid,
599 mGyroBiasVarianceRandomWalk,
600 mAccelRandomWalkValid,
601 mAccelRandomWalk,
602 mAngleRandomWalkValid,
603 mAngleRandomWalk,
604 mRateRandomWalkValid,
605 mRateRandomWalk,
606 mVelocityRandomWalkValid,
607 mVelocityRandomWalk);
608 }
locallogLocEngSensorProperties609 inline void locallog() const {
610 LOC_LOGV("Sensor properties validity, Gyro Random walk: %d "
611 "Accel Random Walk: %d "
612 "Angle Random Walk: %d Rate Random Walk: %d "
613 "Velocity Random Walk: %d\n"
614 "Sensor properties, Gyro Random walk: %f "
615 "Accel Random Walk: %f "
616 "Angle Random Walk: %f Rate Random Walk: %f "
617 "Velocity Random Walk: %f",
618 mGyroBiasVarianceRandomWalkValid,
619 mAccelRandomWalkValid,
620 mAngleRandomWalkValid,
621 mRateRandomWalkValid,
622 mVelocityRandomWalkValid,
623 mGyroBiasVarianceRandomWalk,
624 mAccelRandomWalk,
625 mAngleRandomWalk,
626 mRateRandomWalk,
627 mVelocityRandomWalk
628 );
629 }
logLocEngSensorProperties630 inline virtual void log() const {
631 locallog();
632 }
633 };
634
635 // case LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG:
636 struct LocEngSensorPerfControlConfig : public LocMsg {
637 LocEngAdapter* mAdapter;
638 const int mControlMode;
639 const int mAccelSamplesPerBatch;
640 const int mAccelBatchesPerSec;
641 const int mGyroSamplesPerBatch;
642 const int mGyroBatchesPerSec;
643 const int mAccelSamplesPerBatchHigh;
644 const int mAccelBatchesPerSecHigh;
645 const int mGyroSamplesPerBatchHigh;
646 const int mGyroBatchesPerSecHigh;
647 const int mAlgorithmConfig;
LocEngSensorPerfControlConfigLocEngSensorPerfControlConfig648 inline LocEngSensorPerfControlConfig(LocEngAdapter* adapter,
649 int controlMode,
650 int accelSamplesPerBatch,
651 int accelBatchesPerSec,
652 int gyroSamplesPerBatch,
653 int gyroBatchesPerSec,
654 int accelSamplesPerBatchHigh,
655 int accelBatchesPerSecHigh,
656 int gyroSamplesPerBatchHigh,
657 int gyroBatchesPerSecHigh,
658 int algorithmConfig) :
659 LocMsg(), mAdapter(adapter),
660 mControlMode(controlMode),
661 mAccelSamplesPerBatch(accelSamplesPerBatch),
662 mAccelBatchesPerSec(accelBatchesPerSec),
663 mGyroSamplesPerBatch(gyroSamplesPerBatch),
664 mGyroBatchesPerSec(gyroBatchesPerSec),
665 mAccelSamplesPerBatchHigh(accelSamplesPerBatchHigh),
666 mAccelBatchesPerSecHigh(accelBatchesPerSecHigh),
667 mGyroSamplesPerBatchHigh(gyroSamplesPerBatchHigh),
668 mGyroBatchesPerSecHigh(gyroBatchesPerSecHigh),
669 mAlgorithmConfig(algorithmConfig)
670 {
671 locallog();
672 }
procLocEngSensorPerfControlConfig673 inline virtual void proc() const {
674 mAdapter->setSensorPerfControlConfig(mControlMode,
675 mAccelSamplesPerBatch,
676 mAccelBatchesPerSec,
677 mGyroSamplesPerBatch,
678 mGyroBatchesPerSec,
679 mAccelSamplesPerBatchHigh,
680 mAccelBatchesPerSecHigh,
681 mGyroSamplesPerBatchHigh,
682 mGyroBatchesPerSecHigh,
683 mAlgorithmConfig);
684 }
locallogLocEngSensorPerfControlConfig685 inline void locallog() const {
686 LOC_LOGV("Sensor Perf Control Config (performanceControlMode)(%u) "
687 "accel(#smp,#batches) (%u,%u) "
688 "gyro(#smp,#batches) (%u,%u), "
689 "accel_high(#smp,#batches) (%u,%u) "
690 "gyro_high(#smp,#batches) (%u,%u), "
691 "algorithmConfig(%u)\n",
692 mControlMode,
693 mAccelSamplesPerBatch, mAccelBatchesPerSec,
694 mGyroSamplesPerBatch, mGyroBatchesPerSec,
695 mAccelSamplesPerBatchHigh, mAccelBatchesPerSecHigh,
696 mGyroSamplesPerBatchHigh, mGyroBatchesPerSecHigh,
697 mAlgorithmConfig);
698 }
logLocEngSensorPerfControlConfig699 inline virtual void log() const {
700 locallog();
701 }
702 };
703
704 // case LOC_ENG_MSG_EXT_POWER_CONFIG:
705 struct LocEngExtPowerConfig : public LocMsg {
706 LocEngAdapter* mAdapter;
707 const int mIsBatteryCharging;
LocEngExtPowerConfigLocEngExtPowerConfig708 inline LocEngExtPowerConfig(LocEngAdapter* adapter,
709 int isBatteryCharging) :
710 LocMsg(), mAdapter(adapter),
711 mIsBatteryCharging(isBatteryCharging)
712 {
713 locallog();
714 }
procLocEngExtPowerConfig715 inline virtual void proc() const {
716 mAdapter->setExtPowerConfig(mIsBatteryCharging);
717 }
locallogLocEngExtPowerConfig718 inline void locallog() const {
719 LOC_LOGV("LocEngExtPowerConfig - isBatteryCharging: %d",
720 mIsBatteryCharging);
721 }
logLocEngExtPowerConfig722 inline virtual void log() const {
723 locallog();
724 }
725 };
726
727 // case LOC_ENG_MSG_REPORT_POSITION:
LocEngReportPosition(LocAdapterBase * adapter,UlpLocation & loc,GpsLocationExtended & locExtended,void * locExt,enum loc_sess_status st,LocPosTechMask technology)728 LocEngReportPosition::LocEngReportPosition(LocAdapterBase* adapter,
729 UlpLocation &loc,
730 GpsLocationExtended &locExtended,
731 void* locExt,
732 enum loc_sess_status st,
733 LocPosTechMask technology) :
734 LocMsg(), mAdapter(adapter), mLocation(loc),
735 mLocationExtended(locExtended),
736 mLocationExt(((loc_eng_data_s_type*)
737 ((LocEngAdapter*)
738 (mAdapter))->getOwner())->location_ext_parser(locExt)),
739 mStatus(st), mTechMask(technology)
740 {
741 locallog();
742 }
proc() const743 void LocEngReportPosition::proc() const {
744 LocEngAdapter* adapter = (LocEngAdapter*)mAdapter;
745 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner();
746
747 if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) {
748 bool reported = false;
749 if (locEng->location_cb != NULL) {
750 if (LOC_SESS_FAILURE == mStatus) {
751 // in case we want to handle the failure case
752 locEng->location_cb(NULL, NULL);
753 reported = true;
754 }
755 // what's in the else if is... (line by line)
756 // 1. this is a final fix; and
757 // 1.1 it is a Satellite fix; or
758 // 1.2 it is a sensor fix
759 // 2. (must be intermediate fix... implicit)
760 // 2.1 we accepte intermediate; and
761 // 2.2 it is NOT the case that
762 // 2.2.1 there is inaccuracy; and
763 // 2.2.2 we care about inaccuracy; and
764 // 2.2.3 the inaccuracy exceeds our tolerance
765 else if ((LOC_SESS_SUCCESS == mStatus &&
766 ((LOC_POS_TECH_MASK_SATELLITE |
767 LOC_POS_TECH_MASK_SENSORS |
768 LOC_POS_TECH_MASK_HYBRID) &
769 mTechMask)) ||
770 (LOC_SESS_INTERMEDIATE == locEng->intermediateFix &&
771 !((mLocation.gpsLocation.flags &
772 GPS_LOCATION_HAS_ACCURACY) &&
773 (gps_conf.ACCURACY_THRES != 0) &&
774 (mLocation.gpsLocation.accuracy >
775 gps_conf.ACCURACY_THRES)))) {
776 locEng->location_cb((UlpLocation*)&(mLocation),
777 (void*)mLocationExt);
778 reported = true;
779 }
780 }
781
782 // if we have reported this fix
783 if (reported &&
784 // and if this is a singleshot
785 GPS_POSITION_RECURRENCE_SINGLE ==
786 locEng->adapter->getPositionMode().recurrence) {
787 if (LOC_SESS_INTERMEDIATE == mStatus) {
788 // modem could be still working for a final fix,
789 // although we no longer need it. So stopFix().
790 locEng->adapter->stopFix();
791 }
792 // turn off the session flag.
793 locEng->adapter->setInSession(false);
794 }
795
796 if (locEng->generateNmea &&
797 mLocation.position_source == ULP_LOCATION_IS_FROM_GNSS &&
798 mTechMask & (LOC_POS_TECH_MASK_SATELLITE |
799 LOC_POS_TECH_MASK_SENSORS |
800 LOC_POS_TECH_MASK_HYBRID))
801 {
802 unsigned char generate_nmea = reported &&
803 (mStatus != LOC_SESS_FAILURE);
804 loc_eng_nmea_generate_pos(locEng, mLocation, mLocationExtended,
805 generate_nmea);
806 }
807
808 // Free the allocated memory for rawData
809 UlpLocation* gp = (UlpLocation*)&(mLocation);
810 if (gp != NULL && gp->rawData != NULL)
811 {
812 delete (char*)gp->rawData;
813 gp->rawData = NULL;
814 gp->rawDataSize = 0;
815 }
816 }
817 }
locallog() const818 void LocEngReportPosition::locallog() const {
819 LOC_LOGV("flags: %d\n source: %d\n latitude: %f\n longitude: %f\n "
820 "altitude: %f\n speed: %f\n bearing: %f\n accuracy: %f\n "
821 "timestamp: %lld\n rawDataSize: %d\n rawData: %p\n Session"
822 " status: %d\n Technology mask: %u",
823 mLocation.gpsLocation.flags, mLocation.position_source,
824 mLocation.gpsLocation.latitude, mLocation.gpsLocation.longitude,
825 mLocation.gpsLocation.altitude, mLocation.gpsLocation.speed,
826 mLocation.gpsLocation.bearing, mLocation.gpsLocation.accuracy,
827 mLocation.gpsLocation.timestamp, mLocation.rawDataSize,
828 mLocation.rawData, mStatus, mTechMask);
829 }
log() const830 void LocEngReportPosition::log() const {
831 locallog();
832 }
send() const833 void LocEngReportPosition::send() const {
834 mAdapter->sendMsg(this);
835 }
836
837
838 // case LOC_ENG_MSG_REPORT_SV:
LocEngReportSv(LocAdapterBase * adapter,GpsSvStatus & sv,GpsLocationExtended & locExtended,void * svExt)839 LocEngReportSv::LocEngReportSv(LocAdapterBase* adapter,
840 GpsSvStatus &sv,
841 GpsLocationExtended &locExtended,
842 void* svExt) :
843 LocMsg(), mAdapter(adapter), mSvStatus(sv),
844 mLocationExtended(locExtended),
845 mSvExt(((loc_eng_data_s_type*)
846 ((LocEngAdapter*)
847 (mAdapter))->getOwner())->sv_ext_parser(svExt))
848 {
849 locallog();
850 }
proc() const851 void LocEngReportSv::proc() const {
852 LocEngAdapter* adapter = (LocEngAdapter*)mAdapter;
853 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner();
854
855 if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION)
856 {
857 if (locEng->sv_status_cb != NULL) {
858 locEng->sv_status_cb((GpsSvStatus*)&(mSvStatus),
859 (void*)mSvExt);
860 }
861
862 if (locEng->generateNmea)
863 {
864 loc_eng_nmea_generate_sv(locEng, mSvStatus, mLocationExtended);
865 }
866 }
867 }
locallog() const868 void LocEngReportSv::locallog() const {
869 LOC_LOGV("num sv: %d\n ephemeris mask: %dxn almanac mask: %x\n "
870 "used in fix mask: %x\n sv: prn snr "
871 "elevation azimuth",
872 mSvStatus.num_svs, mSvStatus.ephemeris_mask,
873 mSvStatus.almanac_mask, mSvStatus.used_in_fix_mask);
874 for (int i = 0; i < mSvStatus.num_svs && i < GPS_MAX_SVS; i++) {
875 LOC_LOGV(" %d: %d %f %f %f\n ",
876 i,
877 mSvStatus.sv_list[i].prn,
878 mSvStatus.sv_list[i].snr,
879 mSvStatus.sv_list[i].elevation,
880 mSvStatus.sv_list[i].azimuth);
881 }
882 }
log() const883 inline void LocEngReportSv::log() const {
884 locallog();
885 }
send() const886 void LocEngReportSv::send() const {
887 mAdapter->sendMsg(this);
888 }
889
890 // case LOC_ENG_MSG_REPORT_STATUS:
LocEngReportStatus(LocAdapterBase * adapter,GpsStatusValue engineStatus)891 LocEngReportStatus::LocEngReportStatus(LocAdapterBase* adapter,
892 GpsStatusValue engineStatus) :
893 LocMsg(), mAdapter(adapter), mStatus(engineStatus)
894 {
895 locallog();
896 }
proc() const897 inline void LocEngReportStatus::proc() const
898 {
899 LocEngAdapter* adapter = (LocEngAdapter*)mAdapter;
900 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)adapter->getOwner();
901
902 loc_eng_report_status(*locEng, mStatus);
903 update_aiding_data_for_deletion(*locEng);
904 }
locallog() const905 inline void LocEngReportStatus::locallog() const {
906 LOC_LOGV("LocEngReportStatus");
907 }
log() const908 inline void LocEngReportStatus::log() const {
909 locallog();
910 }
911
912 // case LOC_ENG_MSG_REPORT_NMEA:
LocEngReportNmea(void * locEng,const char * data,int len)913 LocEngReportNmea::LocEngReportNmea(void* locEng,
914 const char* data, int len) :
915 LocMsg(), mLocEng(locEng), mNmea(new char[len]), mLen(len)
916 {
917 memcpy((void*)mNmea, (void*)data, len);
918 locallog();
919 }
proc() const920 void LocEngReportNmea::proc() const {
921 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng;
922
923 struct timeval tv;
924 gettimeofday(&tv, (struct timezone *) NULL);
925 int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000;
926
927 if (locEng->nmea_cb != NULL)
928 locEng->nmea_cb(now, mNmea, mLen);
929 }
locallog() const930 inline void LocEngReportNmea::locallog() const {
931 LOC_LOGV("LocEngReportNmea");
932 }
log() const933 inline void LocEngReportNmea::log() const {
934 locallog();
935 }
936
937 // case LOC_ENG_MSG_REPORT_XTRA_SERVER:
LocEngReportXtraServer(void * locEng,const char * url1,const char * url2,const char * url3,const int maxlength)938 LocEngReportXtraServer::LocEngReportXtraServer(void* locEng,
939 const char *url1,
940 const char *url2,
941 const char *url3,
942 const int maxlength) :
943 LocMsg(), mLocEng(locEng), mMaxLen(maxlength),
944 mServers(new char[3*(mMaxLen+1)])
945 {
946 char * cptr = mServers;
947 memset(mServers, 0, 3*(mMaxLen+1));
948
949 // Override modem URLs with uncommented gps.conf urls
950 if( gps_conf.XTRA_SERVER_1[0] != '\0' ) {
951 url1 = &gps_conf.XTRA_SERVER_1[0];
952 }
953 if( gps_conf.XTRA_SERVER_2[0] != '\0' ) {
954 url2 = &gps_conf.XTRA_SERVER_2[0];
955 }
956 if( gps_conf.XTRA_SERVER_3[0] != '\0' ) {
957 url3 = &gps_conf.XTRA_SERVER_3[0];
958 }
959 // copy non xtra1.gpsonextra.net URLs into the forwarding buffer.
960 if( NULL == strcasestr(url1, XTRA1_GPSONEXTRA) ) {
961 strlcpy(cptr, url1, mMaxLen + 1);
962 cptr += mMaxLen + 1;
963 }
964 if( NULL == strcasestr(url2, XTRA1_GPSONEXTRA) ) {
965 strlcpy(cptr, url2, mMaxLen + 1);
966 cptr += mMaxLen + 1;
967 }
968 if( NULL == strcasestr(url3, XTRA1_GPSONEXTRA) ) {
969 strlcpy(cptr, url3, mMaxLen + 1);
970 }
971 locallog();
972 }
proc() const973 void LocEngReportXtraServer::proc() const {
974 loc_eng_xtra_data_s_type* locEngXtra =
975 &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data);
976
977 if (locEngXtra->report_xtra_server_cb != NULL) {
978 CALLBACK_LOG_CALLFLOW("report_xtra_server_cb", %s, mServers);
979 locEngXtra->report_xtra_server_cb(mServers,
980 &(mServers[mMaxLen+1]),
981 &(mServers[(mMaxLen+1)<<1]));
982 } else {
983 LOC_LOGE("Callback function for request xtra is NULL");
984 }
985 }
locallog() const986 inline void LocEngReportXtraServer::locallog() const {
987 LOC_LOGV("LocEngReportXtraServers: server1: %s\n server2: %s\n"
988 " server3: %s\n",
989 mServers, &mServers[mMaxLen+1], &mServers[(mMaxLen+1)<<1]);
990 }
log() const991 inline void LocEngReportXtraServer::log() const {
992 locallog();
993 }
994
995 // case LOC_ENG_MSG_REQUEST_BIT:
996 // case LOC_ENG_MSG_RELEASE_BIT:
LocEngReqRelBIT(void * locEng,AGpsExtType type,int ipv4,char * ipv6,bool isReq)997 LocEngReqRelBIT::LocEngReqRelBIT(void* locEng, AGpsExtType type,
998 int ipv4, char* ipv6, bool isReq) :
999 LocMsg(), mLocEng(locEng), mType(type), mIPv4Addr(ipv4),
1000 mIPv6Addr(ipv6 ? new char[16] : NULL), mIsReq(isReq) {
1001 if (NULL != ipv6)
1002 memcpy(mIPv6Addr, ipv6, 16);
1003 locallog();
1004 }
~LocEngReqRelBIT()1005 inline LocEngReqRelBIT::~LocEngReqRelBIT() {
1006 if (mIPv6Addr) {
1007 delete[] mIPv6Addr;
1008 }
1009 }
proc() const1010 void LocEngReqRelBIT::proc() const {
1011 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1012 BITSubscriber s(getAgpsStateMachine(*locEng, mType),
1013 mIPv4Addr, mIPv6Addr);
1014 AgpsStateMachine* sm = (AgpsStateMachine*)s.mStateMachine;
1015
1016 if (mIsReq) {
1017 sm->subscribeRsrc((Subscriber*)&s);
1018 } else {
1019 sm->unsubscribeRsrc((Subscriber*)&s);
1020 }
1021 }
locallog() const1022 inline void LocEngReqRelBIT::locallog() const {
1023 LOC_LOGV("LocEngRequestBIT - ipv4: %d.%d.%d.%d, ipv6: %s",
1024 (unsigned char)mIPv4Addr,
1025 (unsigned char)(mIPv4Addr>>8),
1026 (unsigned char)(mIPv4Addr>>16),
1027 (unsigned char)(mIPv4Addr>>24),
1028 NULL != mIPv6Addr ? mIPv6Addr : "");
1029 }
log() const1030 inline void LocEngReqRelBIT::log() const {
1031 locallog();
1032 }
send() const1033 void LocEngReqRelBIT::send() const {
1034 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1035 locEng->adapter->sendMsg(this);
1036 }
1037
1038 // case LOC_ENG_MSG_RELEASE_BIT:
1039 struct LocEngReleaseBIT : public LocMsg {
1040 const BITSubscriber mSubscriber;
LocEngReleaseBITLocEngReleaseBIT1041 inline LocEngReleaseBIT(const AgpsStateMachine* stateMachine,
1042 unsigned int ipv4, char* ipv6) :
1043 LocMsg(),
1044 mSubscriber(stateMachine, ipv4, ipv6)
1045 {
1046 locallog();
1047 }
procLocEngReleaseBIT1048 inline virtual void proc() const
1049 {
1050 AgpsStateMachine* sm = (AgpsStateMachine*)mSubscriber.mStateMachine;
1051 sm->unsubscribeRsrc((Subscriber*)&mSubscriber);
1052 }
locallogLocEngReleaseBIT1053 inline void locallog() const {
1054 LOC_LOGV("LocEngReleaseBIT - ipv4: %d.%d.%d.%d, ipv6: %s",
1055 (unsigned char)(mSubscriber.ID>>24),
1056 (unsigned char)(mSubscriber.ID>>16),
1057 (unsigned char)(mSubscriber.ID>>8),
1058 (unsigned char)mSubscriber.ID,
1059 NULL != mSubscriber.mIPv6Addr ? mSubscriber.mIPv6Addr : "");
1060 }
logLocEngReleaseBIT1061 virtual void log() const {
1062 locallog();
1063 }
1064 };
1065
1066 // LocEngSuplEsOpened
LocEngSuplEsOpened(void * locEng)1067 LocEngSuplEsOpened::LocEngSuplEsOpened(void* locEng) :
1068 LocMsg(), mLocEng(locEng) {
1069 locallog();
1070 }
proc() const1071 void LocEngSuplEsOpened::proc() const {
1072 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1073 if (locEng->ds_nif) {
1074 AgpsStateMachine* sm = locEng->ds_nif;
1075 sm->onRsrcEvent(RSRC_GRANTED);
1076 }
1077 }
locallog() const1078 void LocEngSuplEsOpened::locallog() const {
1079 LOC_LOGV("LocEngSuplEsOpened");
1080 }
log() const1081 void LocEngSuplEsOpened::log() const {
1082 locallog();
1083 }
1084
1085 // LocEngSuplEsClosed
LocEngSuplEsClosed(void * locEng)1086 LocEngSuplEsClosed::LocEngSuplEsClosed(void* locEng) :
1087 LocMsg(), mLocEng(locEng) {
1088 locallog();
1089 }
proc() const1090 void LocEngSuplEsClosed::proc() const {
1091 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1092 if (locEng->ds_nif) {
1093 AgpsStateMachine* sm = locEng->ds_nif;
1094 sm->onRsrcEvent(RSRC_RELEASED);
1095 }
1096 }
locallog() const1097 void LocEngSuplEsClosed::locallog() const {
1098 LOC_LOGV("LocEngSuplEsClosed");
1099 }
log() const1100 void LocEngSuplEsClosed::log() const {
1101 locallog();
1102 }
1103
1104
1105 // case LOC_ENG_MSG_REQUEST_SUPL_ES:
LocEngRequestSuplEs(void * locEng,int id)1106 LocEngRequestSuplEs::LocEngRequestSuplEs(void* locEng, int id) :
1107 LocMsg(), mLocEng(locEng), mID(id) {
1108 locallog();
1109 }
proc() const1110 void LocEngRequestSuplEs::proc() const {
1111 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1112 if (locEng->ds_nif) {
1113 AgpsStateMachine* sm = locEng->ds_nif;
1114 DSSubscriber s(sm, mID);
1115 sm->subscribeRsrc((Subscriber*)&s);
1116 } else {
1117 locEng->adapter->atlOpenStatus(mID, 0, NULL, -1, -1);
1118 }
1119 }
locallog() const1120 inline void LocEngRequestSuplEs::locallog() const {
1121 LOC_LOGV("LocEngRequestSuplEs");
1122 }
log() const1123 inline void LocEngRequestSuplEs::log() const {
1124 locallog();
1125 }
1126
1127 // case LOC_ENG_MSG_REQUEST_ATL:
LocEngRequestATL(void * locEng,int id,AGpsExtType agps_type)1128 LocEngRequestATL::LocEngRequestATL(void* locEng, int id,
1129 AGpsExtType agps_type) :
1130 LocMsg(), mLocEng(locEng), mID(id), mType(agps_type) {
1131 locallog();
1132 }
proc() const1133 void LocEngRequestATL::proc() const {
1134 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1135 AgpsStateMachine* sm = (AgpsStateMachine*)
1136 getAgpsStateMachine(*locEng, mType);
1137 if (sm) {
1138 ATLSubscriber s(mID,
1139 sm,
1140 locEng->adapter,
1141 AGPS_TYPE_INVALID == mType);
1142 sm->subscribeRsrc((Subscriber*)&s);
1143 } else {
1144 locEng->adapter->atlOpenStatus(mID, 0, NULL, -1, mType);
1145 }
1146 }
locallog() const1147 inline void LocEngRequestATL::locallog() const {
1148 LOC_LOGV("LocEngRequestATL");
1149 }
log() const1150 inline void LocEngRequestATL::log() const {
1151 locallog();
1152 }
1153
1154 // case LOC_ENG_MSG_RELEASE_ATL:
LocEngReleaseATL(void * locEng,int id)1155 LocEngReleaseATL::LocEngReleaseATL(void* locEng, int id) :
1156 LocMsg(), mLocEng(locEng), mID(id) {
1157 locallog();
1158 }
proc() const1159 void LocEngReleaseATL::proc() const {
1160 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1161
1162 if (locEng->agnss_nif) {
1163 ATLSubscriber s1(mID, locEng->agnss_nif, locEng->adapter, false);
1164 if (locEng->agnss_nif->unsubscribeRsrc((Subscriber*)&s1)) {
1165 LOC_LOGD("%s:%d]: Unsubscribed from agnss_nif",
1166 __func__, __LINE__);
1167 return;
1168 }
1169 }
1170
1171 if (locEng->internet_nif) {
1172 ATLSubscriber s2(mID, locEng->internet_nif, locEng->adapter, false);
1173 if (locEng->internet_nif->unsubscribeRsrc((Subscriber*)&s2)) {
1174 LOC_LOGD("%s:%d]: Unsubscribed from internet_nif",
1175 __func__, __LINE__);
1176 return;
1177 }
1178 }
1179
1180 if (locEng->ds_nif) {
1181 DSSubscriber s3(locEng->ds_nif, mID);
1182 if (locEng->ds_nif->unsubscribeRsrc((Subscriber*)&s3)) {
1183 LOC_LOGD("%s:%d]: Unsubscribed from ds_nif",
1184 __func__, __LINE__);
1185 return;
1186 }
1187 }
1188
1189 LOC_LOGW("%s:%d]: Could not release ATL. "
1190 "No subscribers found\n",
1191 __func__, __LINE__);
1192 locEng->adapter->atlCloseStatus(mID, 0);
1193 }
locallog() const1194 inline void LocEngReleaseATL::locallog() const {
1195 LOC_LOGV("LocEngReleaseATL");
1196 }
log() const1197 inline void LocEngReleaseATL::log() const {
1198 locallog();
1199 }
1200
1201 // case LOC_ENG_MSG_REQUEST_WIFI:
1202 // case LOC_ENG_MSG_RELEASE_WIFI:
LocEngReqRelWifi(void * locEng,AGpsExtType type,loc_if_req_sender_id_e_type sender_id,char * s,char * p,bool isReq)1203 LocEngReqRelWifi::LocEngReqRelWifi(void* locEng, AGpsExtType type,
1204 loc_if_req_sender_id_e_type sender_id,
1205 char* s, char* p, bool isReq) :
1206 LocMsg(), mLocEng(locEng), mType(type), mSenderId(sender_id),
1207 mSSID(NULL == s ? NULL : new char[SSID_BUF_SIZE]),
1208 mPassword(NULL == p ? NULL : new char[SSID_BUF_SIZE]),
1209 mIsReq(isReq) {
1210 if (NULL != s)
1211 strlcpy(mSSID, s, SSID_BUF_SIZE);
1212 if (NULL != p)
1213 strlcpy(mPassword, p, SSID_BUF_SIZE);
1214 locallog();
1215 }
~LocEngReqRelWifi()1216 LocEngReqRelWifi::~LocEngReqRelWifi() {
1217 if (NULL != mSSID) {
1218 delete[] mSSID;
1219 }
1220 if (NULL != mPassword) {
1221 delete[] mPassword;
1222 }
1223 }
proc() const1224 void LocEngReqRelWifi::proc() const {
1225 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1226 if (locEng->wifi_nif) {
1227 WIFISubscriber s(locEng->wifi_nif, mSSID, mPassword, mSenderId);
1228 if (mIsReq) {
1229 locEng->wifi_nif->subscribeRsrc((Subscriber*)&s);
1230 } else {
1231 locEng->wifi_nif->unsubscribeRsrc((Subscriber*)&s);
1232 }
1233 } else {
1234 locEng->adapter->atlOpenStatus(mSenderId, 0, NULL, -1, mType);
1235 }
1236 }
locallog() const1237 inline void LocEngReqRelWifi::locallog() const {
1238 LOC_LOGV("%s - senderId: %d, ssid: %s, password: %s",
1239 mIsReq ? "LocEngRequestWifi" : "LocEngReleaseWifi",
1240 mSenderId,
1241 NULL != mSSID ? mSSID : "",
1242 NULL != mPassword ? mPassword : "");
1243 }
log() const1244 inline void LocEngReqRelWifi::log() const {
1245 locallog();
1246 }
send() const1247 void LocEngReqRelWifi::send() const {
1248 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1249 locEng->adapter->sendMsg(this);
1250 }
1251
1252 // case LOC_ENG_MSG_REQUEST_XTRA_DATA:
LocEngRequestXtra(void * locEng)1253 LocEngRequestXtra::LocEngRequestXtra(void* locEng) :
1254 mLocEng(locEng) {
1255 locallog();
1256 }
proc() const1257 void LocEngRequestXtra::proc() const
1258 {
1259 loc_eng_xtra_data_s_type* locEngXtra =
1260 &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data);
1261
1262 if (locEngXtra->download_request_cb != NULL) {
1263 CALLBACK_LOG_CALLFLOW("download_request_cb", %p, mLocEng);
1264 locEngXtra->download_request_cb();
1265 } else {
1266 LOC_LOGE("Callback function for request xtra is NULL");
1267 }
1268 }
locallog() const1269 inline void LocEngRequestXtra::locallog() const {
1270 LOC_LOGV("LocEngReqXtra");
1271 }
log() const1272 inline void LocEngRequestXtra::log() const {
1273 locallog();
1274 }
1275
1276 // case LOC_ENG_MSG_REQUEST_TIME:
LocEngRequestTime(void * locEng)1277 LocEngRequestTime::LocEngRequestTime(void* locEng) :
1278 LocMsg(), mLocEng(locEng)
1279 {
1280 locallog();
1281 }
proc() const1282 void LocEngRequestTime::proc() const {
1283 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1284 if (gps_conf.CAPABILITIES & GPS_CAPABILITY_ON_DEMAND_TIME) {
1285 if (locEng->request_utc_time_cb != NULL) {
1286 locEng->request_utc_time_cb();
1287 } else {
1288 LOC_LOGE("Callback function for request time is NULL");
1289 }
1290 }
1291 }
locallog() const1292 inline void LocEngRequestTime::locallog() const {
1293 LOC_LOGV("LocEngReqTime");
1294 }
log() const1295 inline void LocEngRequestTime::log() const {
1296 locallog();
1297 }
1298
1299 // case LOC_ENG_MSG_DELETE_AIDING_DATA:
1300 struct LocEngDelAidData : public LocMsg {
1301 loc_eng_data_s_type* mLocEng;
1302 const GpsAidingData mType;
LocEngDelAidDataLocEngDelAidData1303 inline LocEngDelAidData(loc_eng_data_s_type* locEng,
1304 GpsAidingData f) :
1305 LocMsg(), mLocEng(locEng), mType(f)
1306 {
1307 locallog();
1308 }
procLocEngDelAidData1309 inline virtual void proc() const {
1310 mLocEng->aiding_data_for_deletion = mType;
1311 update_aiding_data_for_deletion(*mLocEng);
1312 }
locallogLocEngDelAidData1313 inline void locallog() const {
1314 LOC_LOGV("aiding data msak %d", mType);
1315 }
logLocEngDelAidData1316 virtual void log() const {
1317 locallog();
1318 }
1319 };
1320
1321 // case LOC_ENG_MSG_ENABLE_DATA:
1322 struct LocEngEnableData : public LocMsg {
1323 LocEngAdapter* mAdapter;
1324 const int mEnable;
1325 char* mAPN;
1326 const int mLen;
LocEngEnableDataLocEngEnableData1327 inline LocEngEnableData(LocEngAdapter* adapter,
1328 const char* name, int len, int enable) :
1329 LocMsg(), mAdapter(adapter),
1330 mEnable(enable), mAPN(NULL), mLen(len)
1331 {
1332 if (NULL != name) {
1333 mAPN = new char[len+1];
1334 memcpy((void*)mAPN, (void*)name, len);
1335 mAPN[len] = 0;
1336 }
1337 locallog();
1338 }
~LocEngEnableDataLocEngEnableData1339 inline ~LocEngEnableData() {
1340 if (NULL != mAPN) {
1341 delete[] mAPN;
1342 }
1343 }
procLocEngEnableData1344 inline virtual void proc() const {
1345 mAdapter->enableData(mEnable);
1346 if (NULL != mAPN) {
1347 mAdapter->setAPN(mAPN, mLen);
1348 }
1349 }
locallogLocEngEnableData1350 inline void locallog() const {
1351 LOC_LOGV("apn: %s\n enable: %d",
1352 (NULL == mAPN) ? "NULL" : mAPN, mEnable);
1353 }
logLocEngEnableData1354 inline virtual void log() const {
1355 locallog();
1356 }
1357 };
1358
1359 // case LOC_ENG_MSG_INJECT_XTRA_DATA:
1360 // loc_eng_xtra.cpp
1361
1362 // case LOC_ENG_MSG_SET_CAPABILITIES:
1363 struct LocEngSetCapabilities : public LocMsg {
1364 loc_eng_data_s_type* mLocEng;
LocEngSetCapabilitiesLocEngSetCapabilities1365 inline LocEngSetCapabilities(loc_eng_data_s_type* locEng) :
1366 LocMsg(), mLocEng(locEng)
1367 {
1368 locallog();
1369 }
procLocEngSetCapabilities1370 inline virtual void proc() const {
1371 if (NULL != mLocEng->set_capabilities_cb) {
1372 LOC_LOGV("calling set_capabilities_cb 0x%x",
1373 gps_conf.CAPABILITIES);
1374 mLocEng->set_capabilities_cb(gps_conf.CAPABILITIES);
1375 } else {
1376 LOC_LOGV("set_capabilities_cb is NULL.\n");
1377 }
1378 }
locallogLocEngSetCapabilities1379 inline void locallog() const
1380 {
1381 LOC_LOGV("LocEngSetCapabilities");
1382 }
logLocEngSetCapabilities1383 inline virtual void log() const
1384 {
1385 locallog();
1386 }
1387 };
1388
1389 // case LOC_ENG_MSG_LOC_INIT:
1390 struct LocEngInit : public LocMsg {
1391 loc_eng_data_s_type* mLocEng;
LocEngInitLocEngInit1392 inline LocEngInit(loc_eng_data_s_type* locEng) :
1393 LocMsg(), mLocEng(locEng)
1394 {
1395 locallog();
1396 }
procLocEngInit1397 inline virtual void proc() const {
1398 loc_eng_reinit(*mLocEng);
1399 // set the capabilities
1400 mLocEng->adapter->sendMsg(new LocEngSetCapabilities(mLocEng));
1401 }
locallogLocEngInit1402 inline void locallog() const
1403 {
1404 LOC_LOGV("LocEngInit");
1405 }
logLocEngInit1406 inline virtual void log() const
1407 {
1408 locallog();
1409 }
1410 };
1411
1412 // case LOC_ENG_MSG_REQUEST_XTRA_SERVER:
1413 // loc_eng_xtra.cpp
1414
1415 // case LOC_ENG_MSG_ATL_OPEN_SUCCESS:
1416 struct LocEngAtlOpenSuccess : public LocMsg {
1417 AgpsStateMachine* mStateMachine;
1418 const int mLen;
1419 char* mAPN;
1420 const AGpsBearerType mBearerType;
LocEngAtlOpenSuccessLocEngAtlOpenSuccess1421 inline LocEngAtlOpenSuccess(AgpsStateMachine* statemachine,
1422 const char* name,
1423 int len,
1424 AGpsBearerType btype) :
1425 LocMsg(),
1426 mStateMachine(statemachine), mLen(len),
1427 mAPN(new char[len+1]), mBearerType(btype)
1428 {
1429 memcpy((void*)mAPN, (void*)name, len);
1430 mAPN[len] = 0;
1431 locallog();
1432 }
~LocEngAtlOpenSuccessLocEngAtlOpenSuccess1433 inline ~LocEngAtlOpenSuccess()
1434 {
1435 delete[] mAPN;
1436 }
procLocEngAtlOpenSuccess1437 inline virtual void proc() const {
1438 mStateMachine->setBearer(mBearerType);
1439 mStateMachine->setAPN(mAPN, mLen);
1440 mStateMachine->onRsrcEvent(RSRC_GRANTED);
1441 }
locallogLocEngAtlOpenSuccess1442 inline void locallog() const {
1443 LOC_LOGV("LocEngAtlOpenSuccess agps type: %s\n apn: %s\n"
1444 " bearer type: %s",
1445 loc_get_agps_type_name(mStateMachine->getType()),
1446 mAPN,
1447 loc_get_agps_bear_name(mBearerType));
1448 }
logLocEngAtlOpenSuccess1449 inline virtual void log() const {
1450 locallog();
1451 }
1452 };
1453
1454 // case LOC_ENG_MSG_ATL_CLOSED:
1455 struct LocEngAtlClosed : public LocMsg {
1456 AgpsStateMachine* mStateMachine;
LocEngAtlClosedLocEngAtlClosed1457 inline LocEngAtlClosed(AgpsStateMachine* statemachine) :
1458 LocMsg(), mStateMachine(statemachine) {
1459 locallog();
1460 }
procLocEngAtlClosed1461 inline virtual void proc() const {
1462 mStateMachine->onRsrcEvent(RSRC_RELEASED);
1463 }
locallogLocEngAtlClosed1464 inline void locallog() const {
1465 LOC_LOGV("LocEngAtlClosed");
1466 }
logLocEngAtlClosed1467 inline virtual void log() const {
1468 locallog();
1469 }
1470 };
1471
1472 // case LOC_ENG_MSG_ATL_OPEN_FAILED:
1473 struct LocEngAtlOpenFailed : public LocMsg {
1474 AgpsStateMachine* mStateMachine;
LocEngAtlOpenFailedLocEngAtlOpenFailed1475 inline LocEngAtlOpenFailed(AgpsStateMachine* statemachine) :
1476 LocMsg(), mStateMachine(statemachine) {
1477 locallog();
1478 }
procLocEngAtlOpenFailed1479 inline virtual void proc() const {
1480 mStateMachine->onRsrcEvent(RSRC_DENIED);
1481 }
locallogLocEngAtlOpenFailed1482 inline void locallog() const {
1483 LOC_LOGV("LocEngAtlOpenFailed");
1484 }
logLocEngAtlOpenFailed1485 inline virtual void log() const {
1486 locallog();
1487 }
1488 };
1489
1490 // case LOC_ENG_MSG_ENGINE_DOWN:
LocEngDown(void * locEng)1491 LocEngDown::LocEngDown(void* locEng) :
1492 LocMsg(), mLocEng(locEng) {
1493 locallog();
1494 }
proc() const1495 inline void LocEngDown::proc() const {
1496 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1497 loc_eng_handle_engine_down(*locEng);
1498 }
locallog() const1499 inline void LocEngDown::locallog() const {
1500 LOC_LOGV("LocEngDown");
1501 }
log() const1502 inline void LocEngDown::log() const {
1503 locallog();
1504 }
1505
1506 // case LOC_ENG_MSG_ENGINE_UP:
LocEngUp(void * locEng)1507 LocEngUp::LocEngUp(void* locEng) :
1508 LocMsg(), mLocEng(locEng) {
1509 locallog();
1510 }
proc() const1511 inline void LocEngUp::proc() const {
1512 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng;
1513 loc_eng_handle_engine_up(*locEng);
1514 }
locallog() const1515 inline void LocEngUp::locallog() const {
1516 LOC_LOGV("LocEngUp");
1517 }
log() const1518 inline void LocEngUp::log() const {
1519 locallog();
1520 }
1521
1522 struct LocEngDataClientInit : public LocMsg {
1523 loc_eng_data_s_type* mLocEng;
LocEngDataClientInitLocEngDataClientInit1524 inline LocEngDataClientInit(loc_eng_data_s_type* locEng) :
1525 LocMsg(), mLocEng(locEng) {
1526 locallog();
1527 }
procLocEngDataClientInit1528 virtual void proc() const {
1529 loc_eng_data_s_type *locEng = (loc_eng_data_s_type *)mLocEng;
1530 if(!locEng->adapter->initDataServiceClient()) {
1531 locEng->ds_nif = new DSStateMachine(servicerTypeExt,
1532 (void *)dataCallCb,
1533 locEng->adapter);
1534 }
1535 }
locallogLocEngDataClientInit1536 void locallog() const {
1537 LOC_LOGV("LocEngDataClientInit\n");
1538 }
logLocEngDataClientInit1539 virtual void log() const {
1540 locallog();
1541 }
1542 };
1543
1544 struct LocEngInstallAGpsCert : public LocMsg {
1545 LocEngAdapter* mpAdapter;
1546 const size_t mNumberOfCerts;
1547 const uint32_t mSlotBitMask;
1548 DerEncodedCertificate* mpData;
LocEngInstallAGpsCertLocEngInstallAGpsCert1549 inline LocEngInstallAGpsCert(LocEngAdapter* adapter,
1550 const DerEncodedCertificate* pData,
1551 size_t numberOfCerts,
1552 uint32_t slotBitMask) :
1553 LocMsg(), mpAdapter(adapter),
1554 mNumberOfCerts(numberOfCerts), mSlotBitMask(slotBitMask),
1555 mpData(new DerEncodedCertificate[mNumberOfCerts])
1556 {
1557 for (int i=0; i < mNumberOfCerts; i++) {
1558 mpData[i].data = new u_char[pData[i].length];
1559 if (mpData[i].data) {
1560 memcpy(mpData[i].data, (void*)pData[i].data, pData[i].length);
1561 mpData[i].length = pData[i].length;
1562 } else {
1563 LOC_LOGE("malloc failed for cert#%d", i);
1564 break;
1565 }
1566 }
1567 locallog();
1568 }
~LocEngInstallAGpsCertLocEngInstallAGpsCert1569 inline ~LocEngInstallAGpsCert()
1570 {
1571 for (int i=0; i < mNumberOfCerts; i++) {
1572 if (mpData[i].data) {
1573 delete[] mpData[i].data;
1574 }
1575 }
1576 delete[] mpData;
1577 }
procLocEngInstallAGpsCert1578 inline virtual void proc() const {
1579 mpAdapter->installAGpsCert(mpData, mNumberOfCerts, mSlotBitMask);
1580 }
locallogLocEngInstallAGpsCert1581 inline void locallog() const {
1582 LOC_LOGV("LocEngInstallAGpsCert - certs=%u mask=%u",
1583 mNumberOfCerts, mSlotBitMask);
1584 }
logLocEngInstallAGpsCert1585 inline virtual void log() const {
1586 locallog();
1587 }
1588 };
1589
1590 struct LocEngUpdateRegistrationMask : public LocMsg {
1591 loc_eng_data_s_type* mLocEng;
1592 LOC_API_ADAPTER_EVENT_MASK_T mMask;
1593 loc_registration_mask_status mIsEnabled;
LocEngUpdateRegistrationMaskLocEngUpdateRegistrationMask1594 inline LocEngUpdateRegistrationMask(loc_eng_data_s_type* locEng,
1595 LOC_API_ADAPTER_EVENT_MASK_T mask,
1596 loc_registration_mask_status isEnabled) :
1597 LocMsg(), mLocEng(locEng), mMask(mask), mIsEnabled(isEnabled) {
1598 locallog();
1599 }
procLocEngUpdateRegistrationMask1600 inline virtual void proc() const {
1601 loc_eng_data_s_type *locEng = (loc_eng_data_s_type *)mLocEng;
1602 locEng->adapter->updateRegistrationMask(mMask,
1603 mIsEnabled);
1604 }
locallogLocEngUpdateRegistrationMask1605 void locallog() const {
1606 LOC_LOGV("LocEngUpdateRegistrationMask\n");
1607 }
logLocEngUpdateRegistrationMask1608 virtual void log() const {
1609 locallog();
1610 }
1611 };
1612
1613 struct LocEngGnssConstellationConfig : public LocMsg {
1614 LocEngAdapter* mAdapter;
LocEngGnssConstellationConfigLocEngGnssConstellationConfig1615 inline LocEngGnssConstellationConfig(LocEngAdapter* adapter) :
1616 LocMsg(), mAdapter(adapter) {
1617 locallog();
1618 }
procLocEngGnssConstellationConfig1619 inline virtual void proc() const {
1620 if (mAdapter->gnssConstellationConfig()) {
1621 LOC_LOGV("Modem supports GNSS measurements\n");
1622 gps_conf.CAPABILITIES |= GPS_CAPABILITY_MEASUREMENTS;
1623 } else {
1624 LOC_LOGV("Modem does not support GNSS measurements\n");
1625 }
1626 }
locallogLocEngGnssConstellationConfig1627 void locallog() const {
1628 LOC_LOGV("LocEngGnssConstellationConfig\n");
1629 }
logLocEngGnssConstellationConfig1630 virtual void log() const {
1631 locallog();
1632 }
1633 };
1634
1635 // case LOC_ENG_MSG_REPORT_GNSS_MEASUREMENT:
LocEngReportGpsMeasurement(void * locEng,GpsData & gpsData)1636 LocEngReportGpsMeasurement::LocEngReportGpsMeasurement(void* locEng,
1637 GpsData &gpsData) :
1638 LocMsg(), mLocEng(locEng), mGpsData(gpsData)
1639 {
1640 locallog();
1641 }
proc() const1642 void LocEngReportGpsMeasurement::proc() const {
1643 loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng;
1644 if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION)
1645 {
1646 if (locEng->gps_measurement_cb != NULL) {
1647 locEng->gps_measurement_cb((GpsData*)&(mGpsData));
1648 }
1649 }
1650 }
locallog() const1651 void LocEngReportGpsMeasurement::locallog() const {
1652 IF_LOC_LOGV {
1653 LOC_LOGV("%s:%d]: Received in GPS HAL."
1654 "GNSS Measurements count: %d \n",
1655 __func__, __LINE__, mGpsData.measurement_count);
1656 for (int i =0; i< mGpsData.measurement_count && i < GPS_MAX_SVS; i++) {
1657 LOC_LOGV(" GNSS measurement data in GPS HAL: \n"
1658 " GPS_HAL => Measurement ID | prn | time_offset_ns | state |"
1659 " received_gps_tow_ns| c_n0_dbhz | pseudorange_rate_mps |"
1660 " pseudorange_rate_uncertainty_mps |"
1661 " accumulated_delta_range_state | flags \n"
1662 " GPS_HAL => %d | %d | %f | %d | %lld | %f | %f | %f | %d | %d \n",
1663 i,
1664 mGpsData.measurements[i].prn,
1665 mGpsData.measurements[i].time_offset_ns,
1666 mGpsData.measurements[i].state,
1667 mGpsData.measurements[i].received_gps_tow_ns,
1668 mGpsData.measurements[i].c_n0_dbhz,
1669 mGpsData.measurements[i].pseudorange_rate_mps,
1670 mGpsData.measurements[i].pseudorange_rate_uncertainty_mps,
1671 mGpsData.measurements[i].accumulated_delta_range_state,
1672 mGpsData.measurements[i].flags);
1673 }
1674 LOC_LOGV(" GPS_HAL => Clocks Info: type | time_ns \n"
1675 " GPS_HAL => Clocks Info: %d | %lld", mGpsData.clock.type,
1676 mGpsData.clock.time_ns);
1677 }
1678 }
log() const1679 inline void LocEngReportGpsMeasurement::log() const {
1680 locallog();
1681 }
1682
1683 /*********************************************************************
1684 * Initialization checking macros
1685 *********************************************************************/
1686 #define STATE_CHECK(ctx, x, ret) \
1687 if (!(ctx)) \
1688 { \
1689 /* Not intialized, abort */\
1690 LOC_LOGE("%s: log_eng state error: %s", __func__, x); \
1691 EXIT_LOG(%s, x); \
1692 ret; \
1693 }
1694 #define INIT_CHECK(ctx, ret) STATE_CHECK(ctx, "instance not initialized", ret)
1695
1696 /*===========================================================================
1697 FUNCTION loc_eng_init
1698
1699 DESCRIPTION
1700 Initialize the location engine, this include setting up global datas
1701 and registers location engien with loc api service.
1702
1703 DEPENDENCIES
1704 None
1705
1706 RETURN VALUE
1707 0: success
1708
1709 SIDE EFFECTS
1710 N/A
1711
1712 ===========================================================================*/
loc_eng_init(loc_eng_data_s_type & loc_eng_data,LocCallbacks * callbacks,LOC_API_ADAPTER_EVENT_MASK_T event,ContextBase * context)1713 int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks,
1714 LOC_API_ADAPTER_EVENT_MASK_T event, ContextBase* context)
1715
1716 {
1717 int ret_val = 0;
1718
1719 ENTRY_LOG_CALLFLOW();
1720 if (NULL == callbacks || 0 == event) {
1721 LOC_LOGE("loc_eng_init: bad parameters cb %p eMask %d", callbacks, event);
1722 ret_val = -1;
1723 EXIT_LOG(%d, ret_val);
1724 return ret_val;
1725 }
1726
1727 STATE_CHECK((NULL == loc_eng_data.adapter),
1728 "instance already initialized", return 0);
1729
1730 memset(&loc_eng_data, 0, sizeof (loc_eng_data));
1731
1732 // Save callbacks
1733 loc_eng_data.location_cb = callbacks->location_cb;
1734 loc_eng_data.sv_status_cb = callbacks->sv_status_cb;
1735 loc_eng_data.status_cb = callbacks->status_cb;
1736 loc_eng_data.nmea_cb = callbacks->nmea_cb;
1737 loc_eng_data.set_capabilities_cb = callbacks->set_capabilities_cb;
1738 loc_eng_data.acquire_wakelock_cb = callbacks->acquire_wakelock_cb;
1739 loc_eng_data.release_wakelock_cb = callbacks->release_wakelock_cb;
1740 loc_eng_data.request_utc_time_cb = callbacks->request_utc_time_cb;
1741 loc_eng_data.location_ext_parser = callbacks->location_ext_parser ?
1742 callbacks->location_ext_parser : noProc;
1743 loc_eng_data.sv_ext_parser = callbacks->sv_ext_parser ?
1744 callbacks->sv_ext_parser : noProc;
1745 loc_eng_data.intermediateFix = gps_conf.INTERMEDIATE_POS;
1746 loc_eng_data.shutdown_cb = callbacks->shutdown_cb;
1747 // initial states taken care of by the memset above
1748 // loc_eng_data.engine_status -- GPS_STATUS_NONE;
1749 // loc_eng_data.fix_session_status -- GPS_STATUS_NONE;
1750 // loc_eng_data.mute_session_state -- LOC_MUTE_SESS_NONE;
1751
1752 if ((event & LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT) && (gps_conf.NMEA_PROVIDER == NMEA_PROVIDER_AP))
1753 {
1754 event = event ^ LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; // unregister for modem NMEA report
1755 loc_eng_data.generateNmea = true;
1756 }
1757 else
1758 {
1759 loc_eng_data.generateNmea = false;
1760 }
1761
1762 loc_eng_data.adapter =
1763 new LocEngAdapter(event, &loc_eng_data, context,
1764 (MsgTask::tCreate)callbacks->create_thread_cb);
1765
1766 LOC_LOGD("loc_eng_init created client, id = %p\n",
1767 loc_eng_data.adapter);
1768 loc_eng_data.adapter->sendMsg(new LocEngInit(&loc_eng_data));
1769
1770 EXIT_LOG(%d, ret_val);
1771 return ret_val;
1772 }
1773
loc_eng_reinit(loc_eng_data_s_type & loc_eng_data)1774 static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data)
1775 {
1776 ENTRY_LOG();
1777 int ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
1778
1779 if (LOC_API_ADAPTER_ERR_SUCCESS == ret_val) {
1780 LOC_LOGD("loc_eng_reinit reinit() successful");
1781
1782 LocEngAdapter* adapter = loc_eng_data.adapter;
1783 adapter->sendMsg(new LocEngGnssConstellationConfig(adapter));
1784 adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER));
1785 adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE));
1786 adapter->sendMsg(new LocEngSensorControlConfig(adapter, sap_conf.SENSOR_USAGE,
1787 sap_conf.SENSOR_PROVIDER));
1788 adapter->sendMsg(new LocEngAGlonassProtocol(adapter, gps_conf.A_GLONASS_POS_PROTOCOL_SELECT));
1789
1790 /* Make sure at least one of the sensor property is specified by the user in the gps.conf file. */
1791 if( sap_conf.GYRO_BIAS_RANDOM_WALK_VALID ||
1792 sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
1793 sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
1794 sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
1795 sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID )
1796 {
1797 adapter->sendMsg(new LocEngSensorProperties(adapter,
1798 sap_conf.GYRO_BIAS_RANDOM_WALK_VALID,
1799 sap_conf.GYRO_BIAS_RANDOM_WALK,
1800 sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
1801 sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY,
1802 sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
1803 sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY,
1804 sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
1805 sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY,
1806 sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
1807 sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY));
1808 }
1809
1810 adapter->sendMsg(new LocEngSensorPerfControlConfig(adapter,
1811 sap_conf.SENSOR_CONTROL_MODE,
1812 sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH,
1813 sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC,
1814 sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH,
1815 sap_conf.SENSOR_GYRO_BATCHES_PER_SEC,
1816 sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH,
1817 sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH,
1818 sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH,
1819 sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH,
1820 sap_conf.SENSOR_ALGORITHM_CONFIG_MASK));
1821
1822 adapter->sendMsg(new LocEngEnableData(adapter, NULL, 0, (agpsStatus ? 1:0)));
1823 }
1824
1825 EXIT_LOG(%d, ret_val);
1826 return ret_val;
1827 }
1828
1829 /*===========================================================================
1830 FUNCTION loc_eng_cleanup
1831
1832 DESCRIPTION
1833 Cleans location engine. The location client handle will be released.
1834
1835 DEPENDENCIES
1836 None
1837
1838 RETURN VALUE
1839 None
1840
1841 SIDE EFFECTS
1842 N/A
1843
1844 ===========================================================================*/
loc_eng_cleanup(loc_eng_data_s_type & loc_eng_data)1845 void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data)
1846 {
1847 ENTRY_LOG_CALLFLOW();
1848 INIT_CHECK(loc_eng_data.adapter, return);
1849
1850 // XTRA has no state, so we are fine with it.
1851
1852 // we need to check and clear NI
1853 #if 0
1854 // we need to check and clear ATL
1855 if (NULL != loc_eng_data.agnss_nif) {
1856 delete loc_eng_data.agnss_nif;
1857 loc_eng_data.agnss_nif = NULL;
1858 }
1859 if (NULL != loc_eng_data.internet_nif) {
1860 delete loc_eng_data.internet_nif;
1861 loc_eng_data.internet_nif = NULL;
1862 }
1863 #endif
1864 if (loc_eng_data.adapter->isInSession())
1865 {
1866 LOC_LOGD("loc_eng_cleanup: fix not stopped. stop it now.");
1867 loc_eng_stop(loc_eng_data);
1868 }
1869
1870 #if 0 // can't afford to actually clean up, for many reason.
1871
1872 LOC_LOGD("loc_eng_init: client opened. close it now.");
1873 delete loc_eng_data.adapter;
1874 loc_eng_data.adapter = NULL;
1875
1876 loc_eng_dmn_conn_loc_api_server_unblock();
1877 loc_eng_dmn_conn_loc_api_server_join();
1878
1879 #endif
1880
1881 EXIT_LOG(%s, VOID_RET);
1882 }
1883
1884
1885 /*===========================================================================
1886 FUNCTION loc_eng_start
1887
1888 DESCRIPTION
1889 Starts the tracking session
1890
1891 DEPENDENCIES
1892 None
1893
1894 RETURN VALUE
1895 0: success
1896
1897 SIDE EFFECTS
1898 N/A
1899
1900 ===========================================================================*/
loc_eng_start(loc_eng_data_s_type & loc_eng_data)1901 int loc_eng_start(loc_eng_data_s_type &loc_eng_data)
1902 {
1903 ENTRY_LOG_CALLFLOW();
1904 INIT_CHECK(loc_eng_data.adapter, return -1);
1905
1906 if(! loc_eng_data.adapter->getUlpProxy()->sendStartFix())
1907 {
1908 loc_eng_data.adapter->sendMsg(new LocEngStartFix(loc_eng_data.adapter));
1909 }
1910
1911 EXIT_LOG(%d, 0);
1912 return 0;
1913 }
1914
loc_eng_start_handler(loc_eng_data_s_type & loc_eng_data)1915 static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data)
1916 {
1917 ENTRY_LOG();
1918 int ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
1919
1920 if (!loc_eng_data.adapter->isInSession()) {
1921 ret_val = loc_eng_data.adapter->startFix();
1922
1923 if (ret_val == LOC_API_ADAPTER_ERR_SUCCESS ||
1924 ret_val == LOC_API_ADAPTER_ERR_ENGINE_DOWN)
1925 {
1926 loc_eng_data.adapter->setInSession(TRUE);
1927 loc_inform_gps_status(loc_eng_data, GPS_STATUS_SESSION_BEGIN);
1928 }
1929 }
1930
1931 EXIT_LOG(%d, ret_val);
1932 return ret_val;
1933 }
1934
1935 /*===========================================================================
1936 FUNCTION loc_eng_stop_wrapper
1937
1938 DESCRIPTION
1939 Stops the tracking session
1940
1941 DEPENDENCIES
1942 None
1943
1944 RETURN VALUE
1945 0: success
1946
1947 SIDE EFFECTS
1948 N/A
1949
1950 ===========================================================================*/
loc_eng_stop(loc_eng_data_s_type & loc_eng_data)1951 int loc_eng_stop(loc_eng_data_s_type &loc_eng_data)
1952 {
1953 ENTRY_LOG_CALLFLOW();
1954 INIT_CHECK(loc_eng_data.adapter, return -1);
1955
1956 if(! loc_eng_data.adapter->getUlpProxy()->sendStopFix())
1957 {
1958 loc_eng_data.adapter->sendMsg(new LocEngStopFix(loc_eng_data.adapter));
1959 }
1960
1961 EXIT_LOG(%d, 0);
1962 return 0;
1963 }
1964
loc_eng_stop_handler(loc_eng_data_s_type & loc_eng_data)1965 static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data)
1966 {
1967 ENTRY_LOG();
1968 int ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
1969
1970 if (loc_eng_data.adapter->isInSession()) {
1971
1972 ret_val = loc_eng_data.adapter->stopFix();
1973 if (ret_val == LOC_API_ADAPTER_ERR_SUCCESS)
1974 {
1975 loc_inform_gps_status(loc_eng_data, GPS_STATUS_SESSION_END);
1976 }
1977
1978 loc_eng_data.adapter->setInSession(FALSE);
1979 }
1980
1981 EXIT_LOG(%d, ret_val);
1982 return ret_val;
1983 }
1984
1985 /*===========================================================================
1986 FUNCTION loc_eng_mute_one_session
1987
1988 DESCRIPTION
1989 Mutes one session
1990
1991 DEPENDENCIES
1992 None
1993
1994 RETURN VALUE
1995 0: Success
1996
1997 SIDE EFFECTS
1998 N/A
1999
2000 ===========================================================================*/
loc_eng_mute_one_session(loc_eng_data_s_type & loc_eng_data)2001 void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data)
2002 {
2003 ENTRY_LOG();
2004 loc_eng_data.mute_session_state = LOC_MUTE_SESS_WAIT;
2005 EXIT_LOG(%s, VOID_RET);
2006 }
2007
2008 /*===========================================================================
2009 FUNCTION loc_eng_set_position_mode
2010
2011 DESCRIPTION
2012 Sets the mode and fix frequency for the tracking session.
2013
2014 DEPENDENCIES
2015 None
2016
2017 RETURN VALUE
2018 0: success
2019
2020 SIDE EFFECTS
2021 N/A
2022
2023 ===========================================================================*/
loc_eng_set_position_mode(loc_eng_data_s_type & loc_eng_data,LocPosMode & params)2024 int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data,
2025 LocPosMode ¶ms)
2026 {
2027 ENTRY_LOG_CALLFLOW();
2028 INIT_CHECK(loc_eng_data.adapter, return -1);
2029
2030 int gnssType = getTargetGnssType(loc_get_target());
2031
2032 // The position mode for GSS/QCA1530 can only be standalone
2033 bool is1530 = gnssType == GNSS_QCA1530;
2034 bool isAPQ = gnssType == GNSS_GSS;
2035 if ((isAPQ || is1530) && params.mode != LOC_POSITION_MODE_STANDALONE) {
2036 params.mode = LOC_POSITION_MODE_STANDALONE;
2037 LOC_LOGD("Position mode changed to standalone for target with GSS/qca1530.");
2038 }
2039
2040 if(! loc_eng_data.adapter->getUlpProxy()->sendFixMode(params))
2041 {
2042 LocEngAdapter* adapter = loc_eng_data.adapter;
2043 adapter->sendMsg(new LocEngPositionMode(adapter, params));
2044 }
2045
2046 EXIT_LOG(%d, 0);
2047 return 0;
2048 }
2049
2050 /*===========================================================================
2051 FUNCTION loc_eng_inject_time
2052
2053 DESCRIPTION
2054 This is used by Java native function to do time injection.
2055
2056 DEPENDENCIES
2057 None
2058
2059 RETURN VALUE
2060 0
2061
2062 SIDE EFFECTS
2063 N/A
2064
2065 ===========================================================================*/
loc_eng_inject_time(loc_eng_data_s_type & loc_eng_data,GpsUtcTime time,int64_t timeReference,int uncertainty)2066 int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data, GpsUtcTime time,
2067 int64_t timeReference, int uncertainty)
2068 {
2069 ENTRY_LOG_CALLFLOW();
2070 INIT_CHECK(loc_eng_data.adapter, return -1);
2071 LocEngAdapter* adapter = loc_eng_data.adapter;
2072
2073 adapter->sendMsg(new LocEngSetTime(adapter, time, timeReference,
2074 uncertainty));
2075
2076 EXIT_LOG(%d, 0);
2077 return 0;
2078 }
2079
2080
2081 /*===========================================================================
2082 FUNCTION loc_eng_inject_location
2083
2084 DESCRIPTION
2085 This is used by Java native function to do location injection.
2086
2087 DEPENDENCIES
2088 None
2089
2090 RETURN VALUE
2091 0 : Successful
2092 error code : Failure
2093
2094 SIDE EFFECTS
2095 N/A
2096 ===========================================================================*/
loc_eng_inject_location(loc_eng_data_s_type & loc_eng_data,double latitude,double longitude,float accuracy)2097 int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data, double latitude,
2098 double longitude, float accuracy)
2099 {
2100 ENTRY_LOG_CALLFLOW();
2101 INIT_CHECK(loc_eng_data.adapter, return -1);
2102 LocEngAdapter* adapter = loc_eng_data.adapter;
2103 if(adapter->mSupportsPositionInjection)
2104 {
2105 adapter->sendMsg(new LocEngInjectLocation(adapter, latitude, longitude,
2106 accuracy));
2107 }
2108
2109 EXIT_LOG(%d, 0);
2110 return 0;
2111 }
2112
2113
2114 /*===========================================================================
2115 FUNCTION loc_eng_delete_aiding_data
2116
2117 DESCRIPTION
2118 This is used by Java native function to delete the aiding data. The function
2119 updates the global variable for the aiding data to be deleted. If the GPS
2120 engine is off, the aiding data will be deleted. Otherwise, the actual action
2121 will happen when gps engine is turned off.
2122
2123 DEPENDENCIES
2124 Assumes the aiding data type specified in GpsAidingData matches with
2125 LOC API specification.
2126
2127 RETURN VALUE
2128 None
2129
2130 SIDE EFFECTS
2131 N/A
2132
2133 ===========================================================================*/
loc_eng_delete_aiding_data(loc_eng_data_s_type & loc_eng_data,GpsAidingData f)2134 void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data, GpsAidingData f)
2135 {
2136 ENTRY_LOG_CALLFLOW();
2137 INIT_CHECK(loc_eng_data.adapter, return);
2138
2139 loc_eng_data.adapter->sendMsg(new LocEngDelAidData(&loc_eng_data, f));
2140
2141 EXIT_LOG(%s, VOID_RET);
2142 }
2143
2144 /*===========================================================================
2145
2146 FUNCTION loc_inform_gps_state
2147
2148 DESCRIPTION
2149 Informs the GPS Provider about the GPS status
2150
2151 DEPENDENCIES
2152 None
2153
2154 RETURN VALUE
2155 None
2156
2157 SIDE EFFECTS
2158 N/A
2159
2160 ===========================================================================*/
loc_inform_gps_status(loc_eng_data_s_type & loc_eng_data,GpsStatusValue status)2161 static void loc_inform_gps_status(loc_eng_data_s_type &loc_eng_data, GpsStatusValue status)
2162 {
2163 ENTRY_LOG();
2164
2165 if (loc_eng_data.status_cb)
2166 {
2167 GpsStatus gs = { sizeof(gs),status };
2168 CALLBACK_LOG_CALLFLOW("status_cb", %s,
2169 loc_get_gps_status_name(gs.status));
2170 loc_eng_data.status_cb(&gs);
2171 }
2172
2173 EXIT_LOG(%s, VOID_RET);
2174 }
2175
loc_eng_get_zpp_handler(loc_eng_data_s_type & loc_eng_data)2176 static int loc_eng_get_zpp_handler(loc_eng_data_s_type &loc_eng_data)
2177 {
2178 ENTRY_LOG();
2179 int ret_val = LOC_API_ADAPTER_ERR_SUCCESS;
2180 UlpLocation location;
2181 LocPosTechMask tech_mask = LOC_POS_TECH_MASK_DEFAULT;
2182 GpsLocationExtended locationExtended;
2183 memset(&locationExtended, 0, sizeof (GpsLocationExtended));
2184 locationExtended.size = sizeof(locationExtended);
2185 memset(&location, 0, sizeof location);
2186
2187 ret_val = loc_eng_data.adapter->getZpp(location.gpsLocation, tech_mask);
2188 //Mark the location source as from ZPP
2189 location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
2190 location.position_source = ULP_LOCATION_IS_FROM_ZPP;
2191
2192 loc_eng_data.adapter->getUlpProxy()->reportPosition(location,
2193 locationExtended,
2194 NULL,
2195 LOC_SESS_SUCCESS,
2196 tech_mask);
2197
2198 EXIT_LOG(%d, ret_val);
2199 return ret_val;
2200 }
2201
2202 /*
2203 Callback function passed to Data Services State Machine
2204 This becomes part of the state machine's servicer and
2205 is used to send requests to the data services client
2206 */
dataCallCb(void * cb_data)2207 static int dataCallCb(void *cb_data)
2208 {
2209 LOC_LOGD("Enter dataCallCb\n");
2210 int ret=0;
2211 if(cb_data != NULL) {
2212 dsCbData *cbData = (dsCbData *)cb_data;
2213 LocEngAdapter *locAdapter = (LocEngAdapter *)cbData->mAdapter;
2214 if(cbData->action == GPS_REQUEST_AGPS_DATA_CONN) {
2215 LOC_LOGD("dataCallCb GPS_REQUEST_AGPS_DATA_CONN\n");
2216 ret = locAdapter->openAndStartDataCall();
2217 }
2218 else if(cbData->action == GPS_RELEASE_AGPS_DATA_CONN) {
2219 LOC_LOGD("dataCallCb GPS_RELEASE_AGPS_DATA_CONN\n");
2220 locAdapter->stopDataCall();
2221 }
2222 }
2223 else {
2224 LOC_LOGE("NULL argument received. Failing.\n");
2225 ret = -1;
2226 goto err;
2227 }
2228
2229 err:
2230 LOC_LOGD("Exit dataCallCb ret = %d\n", ret);
2231 return ret;
2232 }
2233
2234 /*===========================================================================
2235 FUNCTION loc_eng_agps_reinit
2236
2237 DESCRIPTION
2238 2nd half of loc_eng_agps_init(), singled out for modem restart to use.
2239
2240 DEPENDENCIES
2241 NONE
2242
2243 RETURN VALUE
2244 0
2245
2246 SIDE EFFECTS
2247 N/A
2248
2249 ===========================================================================*/
loc_eng_agps_reinit(loc_eng_data_s_type & loc_eng_data)2250 static void loc_eng_agps_reinit(loc_eng_data_s_type &loc_eng_data)
2251 {
2252 ENTRY_LOG();
2253
2254 // Set server addresses which came before init
2255 if (loc_eng_data.supl_host_set)
2256 {
2257 loc_eng_set_server(loc_eng_data, LOC_AGPS_SUPL_SERVER,
2258 loc_eng_data.supl_host_buf,
2259 loc_eng_data.supl_port_buf);
2260 }
2261
2262 if (loc_eng_data.c2k_host_set)
2263 {
2264 loc_eng_set_server(loc_eng_data, LOC_AGPS_CDMA_PDE_SERVER,
2265 loc_eng_data.c2k_host_buf,
2266 loc_eng_data.c2k_port_buf);
2267 }
2268 EXIT_LOG(%s, VOID_RET);
2269 }
2270 /*===========================================================================
2271 FUNCTION loc_eng_agps_init
2272
2273 DESCRIPTION
2274 Initialize the AGps interface.
2275
2276 DEPENDENCIES
2277 NONE
2278
2279 RETURN VALUE
2280 0
2281
2282 SIDE EFFECTS
2283 N/A
2284
2285 ===========================================================================*/
loc_eng_agps_init(loc_eng_data_s_type & loc_eng_data,AGpsExtCallbacks * callbacks)2286 void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* callbacks)
2287 {
2288 ENTRY_LOG_CALLFLOW();
2289 INIT_CHECK(loc_eng_data.adapter, return);
2290 STATE_CHECK((NULL == loc_eng_data.agps_status_cb),
2291 "agps instance already initialized",
2292 return);
2293 if (callbacks == NULL) {
2294 LOC_LOGE("loc_eng_agps_init: bad parameters cb %p", callbacks);
2295 EXIT_LOG(%s, VOID_RET);
2296 return;
2297 }
2298 LocEngAdapter* adapter = loc_eng_data.adapter;
2299 loc_eng_data.agps_status_cb = callbacks->status_cb;
2300
2301 loc_eng_data.internet_nif = new AgpsStateMachine(servicerTypeAgps,
2302 (void *)loc_eng_data.agps_status_cb,
2303 AGPS_TYPE_WWAN_ANY,
2304 false);
2305 loc_eng_data.wifi_nif = new AgpsStateMachine(servicerTypeAgps,
2306 (void *)loc_eng_data.agps_status_cb,
2307 AGPS_TYPE_WIFI,
2308 true);
2309
2310 int gnssType = getTargetGnssType(loc_get_target());
2311 bool isAPQ = (gnssType == GNSS_GSS);
2312 bool is1530 = (gnssType == GNSS_QCA1530);
2313 if (!isAPQ && !is1530) {
2314 loc_eng_data.agnss_nif = new AgpsStateMachine(servicerTypeAgps,
2315 (void *)loc_eng_data.agps_status_cb,
2316 AGPS_TYPE_SUPL,
2317 false);
2318
2319 if (adapter->mSupportsAgpsRequests) {
2320 loc_eng_data.adapter->sendMsg(new LocEngDataClientInit(&loc_eng_data));
2321
2322 loc_eng_dmn_conn_loc_api_server_launch(callbacks->create_thread_cb,
2323 NULL, NULL, &loc_eng_data);
2324 }
2325 loc_eng_agps_reinit(loc_eng_data);
2326 }
2327
2328 EXIT_LOG(%s, VOID_RET);
2329 }
2330
deleteAidingData(loc_eng_data_s_type & logEng)2331 static void deleteAidingData(loc_eng_data_s_type &logEng) {
2332 if (logEng.engine_status != GPS_STATUS_ENGINE_ON &&
2333 logEng.aiding_data_for_deletion != 0) {
2334 logEng.adapter->deleteAidingData(logEng.aiding_data_for_deletion);
2335 logEng.aiding_data_for_deletion = 0;
2336 }
2337 }
2338
2339 static AgpsStateMachine*
getAgpsStateMachine(loc_eng_data_s_type & locEng,AGpsExtType agpsType)2340 getAgpsStateMachine(loc_eng_data_s_type &locEng, AGpsExtType agpsType) {
2341 AgpsStateMachine* stateMachine;
2342 switch (agpsType) {
2343 case AGPS_TYPE_WIFI: {
2344 stateMachine = locEng.wifi_nif;
2345 break;
2346 }
2347 case AGPS_TYPE_INVALID:
2348 case AGPS_TYPE_SUPL: {
2349 stateMachine = locEng.agnss_nif;
2350 break;
2351 }
2352 case AGPS_TYPE_SUPL_ES: {
2353 stateMachine = locEng.ds_nif;
2354 break;
2355 }
2356 default:
2357 stateMachine = locEng.internet_nif;
2358 }
2359 return stateMachine;
2360 }
2361
2362 /*===========================================================================
2363 FUNCTION loc_eng_agps_open
2364
2365 DESCRIPTION
2366 This function is called when on-demand data connection opening is successful.
2367 It should inform engine about the data open result.
2368
2369 DEPENDENCIES
2370 NONE
2371
2372 RETURN VALUE
2373 0
2374
2375 SIDE EFFECTS
2376 N/A
2377
2378 ===========================================================================*/
loc_eng_agps_open(loc_eng_data_s_type & loc_eng_data,AGpsExtType agpsType,const char * apn,AGpsBearerType bearerType)2379 int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType,
2380 const char* apn, AGpsBearerType bearerType)
2381 {
2382 ENTRY_LOG_CALLFLOW();
2383 INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb,
2384 return -1);
2385
2386 if (apn == NULL)
2387 {
2388 LOC_LOGE("APN Name NULL\n");
2389 return 0;
2390 }
2391
2392 LOC_LOGD("loc_eng_agps_open APN name = [%s]", apn);
2393
2394 int apn_len = smaller_of(strlen (apn), MAX_APN_LEN);
2395 AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType);
2396
2397 loc_eng_data.adapter->sendMsg(
2398 new LocEngAtlOpenSuccess(sm, apn, apn_len, bearerType));
2399
2400 EXIT_LOG(%d, 0);
2401 return 0;
2402 }
2403
2404 /*===========================================================================
2405 FUNCTION loc_eng_agps_closed
2406
2407 DESCRIPTION
2408 This function is called when on-demand data connection closing is done.
2409 It should inform engine about the data close result.
2410
2411 DEPENDENCIES
2412 NONE
2413
2414 RETURN VALUE
2415 0
2416
2417 SIDE EFFECTS
2418 N/A
2419
2420 ===========================================================================*/
loc_eng_agps_closed(loc_eng_data_s_type & loc_eng_data,AGpsExtType agpsType)2421 int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType)
2422 {
2423 ENTRY_LOG_CALLFLOW();
2424 INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb,
2425 return -1);
2426
2427 AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType);
2428 loc_eng_data.adapter->sendMsg(new LocEngAtlClosed(sm));
2429
2430 EXIT_LOG(%d, 0);
2431 return 0;
2432 }
2433
2434 /*===========================================================================
2435 FUNCTION loc_eng_agps_open_failed
2436
2437 DESCRIPTION
2438 This function is called when on-demand data connection opening has failed.
2439 It should inform engine about the data open result.
2440
2441 DEPENDENCIES
2442 NONE
2443
2444 RETURN VALUE
2445 0
2446
2447 SIDE EFFECTS
2448 N/A
2449
2450 ===========================================================================*/
loc_eng_agps_open_failed(loc_eng_data_s_type & loc_eng_data,AGpsExtType agpsType)2451 int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType)
2452 {
2453 ENTRY_LOG_CALLFLOW();
2454 INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb,
2455 return -1);
2456
2457 AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType);
2458 loc_eng_data.adapter->sendMsg(new LocEngAtlOpenFailed(sm));
2459
2460 EXIT_LOG(%d, 0);
2461 return 0;
2462 }
2463
2464 /*===========================================================================
2465
2466 FUNCTION resolve_in_addr
2467
2468 DESCRIPTION
2469 Translates a hostname to in_addr struct
2470
2471 DEPENDENCIES
2472 n/a
2473
2474 RETURN VALUE
2475 TRUE if successful
2476
2477 SIDE EFFECTS
2478 n/a
2479
2480 ===========================================================================*/
resolve_in_addr(const char * host_addr,struct in_addr * in_addr_ptr)2481 static boolean resolve_in_addr(const char *host_addr, struct in_addr *in_addr_ptr)
2482 {
2483 ENTRY_LOG();
2484 boolean ret_val = TRUE;
2485
2486 struct hostent *hp;
2487 hp = gethostbyname(host_addr);
2488 if (hp != NULL) /* DNS OK */
2489 {
2490 memcpy(in_addr_ptr, hp->h_addr_list[0], hp->h_length);
2491 }
2492 else
2493 {
2494 /* Try IP representation */
2495 if (inet_aton(host_addr, in_addr_ptr) == 0)
2496 {
2497 /* IP not valid */
2498 LOC_LOGE("DNS query on '%s' failed\n", host_addr);
2499 ret_val = FALSE;
2500 }
2501 }
2502
2503 EXIT_LOG(%s, loc_logger_boolStr[ret_val!=0]);
2504 return ret_val;
2505 }
2506
2507 /*===========================================================================
2508 FUNCTION loc_eng_set_server
2509
2510 DESCRIPTION
2511 This is used to set the default AGPS server. Server address is obtained
2512 from gps.conf.
2513
2514 DEPENDENCIES
2515 NONE
2516
2517 RETURN VALUE
2518 0
2519
2520 SIDE EFFECTS
2521 N/A
2522
2523 ===========================================================================*/
loc_eng_set_server(loc_eng_data_s_type & loc_eng_data,LocServerType type,const char * hostname,int port)2524 static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data,
2525 LocServerType type, const char* hostname, int port)
2526 {
2527 ENTRY_LOG();
2528 int ret = 0;
2529 LocEngAdapter* adapter = loc_eng_data.adapter;
2530
2531 if (LOC_AGPS_SUPL_SERVER == type) {
2532 char url[MAX_URL_LEN];
2533 unsigned int len = 0;
2534 const char nohost[] = "NONE";
2535 if (hostname == NULL ||
2536 strncasecmp(nohost, hostname, sizeof(nohost)) == 0) {
2537 url[0] = NULL;
2538 } else {
2539 len = snprintf(url, sizeof(url), "%s:%u", hostname, (unsigned) port);
2540 }
2541
2542 if (sizeof(url) > len) {
2543 adapter->sendMsg(new LocEngSetServerUrl(adapter, url, len));
2544 }
2545 } else if (LOC_AGPS_CDMA_PDE_SERVER == type ||
2546 LOC_AGPS_CUSTOM_PDE_SERVER == type ||
2547 LOC_AGPS_MPC_SERVER == type) {
2548 struct in_addr addr;
2549 if (!resolve_in_addr(hostname, &addr))
2550 {
2551 LOC_LOGE("loc_eng_set_server, hostname %s cannot be resolved.\n", hostname);
2552 ret = -2;
2553 } else {
2554 unsigned int ip = htonl(addr.s_addr);
2555 adapter->sendMsg(new LocEngSetServerIpv4(adapter, ip, port, type));
2556 }
2557 } else {
2558 LOC_LOGE("loc_eng_set_server, type %d cannot be resolved.\n", type);
2559 }
2560
2561 EXIT_LOG(%d, ret);
2562 return ret;
2563 }
2564
2565 /*===========================================================================
2566 FUNCTION loc_eng_set_server_proxy
2567
2568 DESCRIPTION
2569 If loc_eng_set_server is called before loc_eng_init, it doesn't work. This
2570 proxy buffers server settings and calls loc_eng_set_server when the client is
2571 open.
2572
2573 DEPENDENCIES
2574 NONE
2575
2576 RETURN VALUE
2577 0
2578
2579 SIDE EFFECTS
2580 N/A
2581
2582 ===========================================================================*/
loc_eng_set_server_proxy(loc_eng_data_s_type & loc_eng_data,LocServerType type,const char * hostname,int port)2583 int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data,
2584 LocServerType type,
2585 const char* hostname, int port)
2586 {
2587 ENTRY_LOG_CALLFLOW();
2588 int ret_val = 0;
2589
2590 LOC_LOGV("save the address, type: %d, hostname: %s, port: %d",
2591 (int) type, hostname, port);
2592 switch (type)
2593 {
2594 case LOC_AGPS_SUPL_SERVER:
2595 strlcpy(loc_eng_data.supl_host_buf, hostname,
2596 sizeof(loc_eng_data.supl_host_buf));
2597 loc_eng_data.supl_port_buf = port;
2598 loc_eng_data.supl_host_set = 1;
2599 break;
2600 case LOC_AGPS_CDMA_PDE_SERVER:
2601 strlcpy(loc_eng_data.c2k_host_buf, hostname,
2602 sizeof(loc_eng_data.c2k_host_buf));
2603 loc_eng_data.c2k_port_buf = port;
2604 loc_eng_data.c2k_host_set = 1;
2605 break;
2606 default:
2607 LOC_LOGE("loc_eng_set_server_proxy, unknown server type = %d", (int) type);
2608 }
2609
2610 if (NULL != loc_eng_data.adapter)
2611 {
2612 ret_val = loc_eng_set_server(loc_eng_data, type, hostname, port);
2613 }
2614
2615 EXIT_LOG(%d, ret_val);
2616 return ret_val;
2617 }
2618
2619 /*===========================================================================
2620 FUNCTION loc_eng_agps_ril_update_network_availability
2621
2622 DESCRIPTION
2623 Sets data call allow vs disallow flag to modem
2624 This is the only member of sLocEngAGpsRilInterface implemented.
2625
2626 DEPENDENCIES
2627 None
2628
2629 RETURN VALUE
2630 0: success
2631
2632 SIDE EFFECTS
2633 N/A
2634
2635 ===========================================================================*/
loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type & loc_eng_data,int available,const char * apn)2636 void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data,
2637 int available, const char* apn)
2638 {
2639 ENTRY_LOG_CALLFLOW();
2640
2641 //This is to store the status of data availability over the network.
2642 //If GPS is not enabled, the INIT_CHECK will fail and the modem will
2643 //not be updated with the network's availability. Since the data status
2644 //can change before GPS is enabled the, storing the status will enable
2645 //us to inform the modem after GPS is enabled
2646 agpsStatus = available;
2647
2648 INIT_CHECK(loc_eng_data.adapter, return);
2649 if (apn != NULL)
2650 {
2651 LOC_LOGD("loc_eng_agps_ril_update_network_availability: APN Name = [%s]\n", apn);
2652 int apn_len = smaller_of(strlen (apn), MAX_APN_LEN);
2653 LocEngAdapter* adapter = loc_eng_data.adapter;
2654 adapter->sendMsg(new LocEngEnableData(adapter, apn, apn_len, available));
2655 }
2656 EXIT_LOG(%s, VOID_RET);
2657 }
2658
loc_eng_agps_install_certificates(loc_eng_data_s_type & loc_eng_data,const DerEncodedCertificate * certificates,size_t numberOfCerts)2659 int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data,
2660 const DerEncodedCertificate* certificates,
2661 size_t numberOfCerts)
2662 {
2663 ENTRY_LOG_CALLFLOW();
2664 int ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS;
2665
2666 uint32_t slotBitMask = gps_conf.AGPS_CERT_WRITABLE_MASK;
2667 uint32_t slotCount = 0;
2668 for (uint32_t slotBitMaskCounter=slotBitMask; slotBitMaskCounter; slotCount++) {
2669 slotBitMaskCounter &= slotBitMaskCounter - 1;
2670 }
2671 LOC_LOGD("SlotBitMask=%u SlotCount=%u NumberOfCerts=%u",
2672 slotBitMask, slotCount, numberOfCerts);
2673
2674 LocEngAdapter* adapter = loc_eng_data.adapter;
2675
2676 if (numberOfCerts == 0) {
2677 LOC_LOGE("No certs to install, since numberOfCerts is zero");
2678 ret_val = AGPS_CERTIFICATE_OPERATION_SUCCESS;
2679 } else if (!adapter) {
2680 LOC_LOGE("adapter is null!");
2681 ret_val = AGPS_CERTIFICATE_ERROR_GENERIC;
2682 } else if (slotCount < numberOfCerts) {
2683 LOC_LOGE("Not enough cert slots (%u) to install %u certs!",
2684 slotCount, numberOfCerts);
2685 ret_val = AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES;
2686 } else {
2687 for (int i=0; i < numberOfCerts; ++i)
2688 {
2689 if (certificates[i].length > AGPS_CERTIFICATE_MAX_LENGTH) {
2690 LOC_LOGE("cert#(%u) length of %u is too big! greater than %u",
2691 certificates[i].length, AGPS_CERTIFICATE_MAX_LENGTH);
2692 ret_val = AGPS_CERTIFICATE_ERROR_GENERIC;
2693 break;
2694 }
2695 }
2696
2697 if (ret_val == AGPS_CERTIFICATE_OPERATION_SUCCESS) {
2698 adapter->sendMsg(new LocEngInstallAGpsCert(adapter,
2699 certificates,
2700 numberOfCerts,
2701 slotBitMask));
2702 }
2703 }
2704
2705 EXIT_LOG(%d, ret_val);
2706 return ret_val;
2707 }
2708
loc_eng_configuration_update(loc_eng_data_s_type & loc_eng_data,const char * config_data,int32_t length)2709 void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data,
2710 const char* config_data, int32_t length)
2711 {
2712 ENTRY_LOG_CALLFLOW();
2713
2714 if (config_data && length > 0) {
2715 loc_gps_cfg_s_type gps_conf_tmp = gps_conf;
2716 UTIL_UPDATE_CONF(config_data, length, gps_conf_table);
2717 LocEngAdapter* adapter = loc_eng_data.adapter;
2718
2719 // it is possible that HAL is not init'ed at this time
2720 if (adapter) {
2721 if (gps_conf_tmp.SUPL_VER != gps_conf.SUPL_VER) {
2722 adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER));
2723 }
2724 if (gps_conf_tmp.LPP_PROFILE != gps_conf.LPP_PROFILE) {
2725 adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE));
2726 }
2727 if (gps_conf_tmp.A_GLONASS_POS_PROTOCOL_SELECT != gps_conf.A_GLONASS_POS_PROTOCOL_SELECT) {
2728 adapter->sendMsg(new LocEngAGlonassProtocol(adapter,
2729 gps_conf.A_GLONASS_POS_PROTOCOL_SELECT));
2730 }
2731 }
2732
2733 gps_conf_tmp.SUPL_VER = gps_conf.SUPL_VER;
2734 gps_conf_tmp.LPP_PROFILE = gps_conf.LPP_PROFILE;
2735 gps_conf_tmp.A_GLONASS_POS_PROTOCOL_SELECT = gps_conf.A_GLONASS_POS_PROTOCOL_SELECT;
2736 gps_conf_tmp.GPS_LOCK = gps_conf.GPS_LOCK;
2737 gps_conf = gps_conf_tmp;
2738 }
2739
2740 EXIT_LOG(%s, VOID_RET);
2741 }
2742
2743 /*===========================================================================
2744 FUNCTION loc_eng_report_status
2745
2746 DESCRIPTION
2747 Reports GPS engine state to Java layer.
2748
2749 DEPENDENCIES
2750 N/A
2751
2752 RETURN VALUE
2753 N/A
2754
2755 SIDE EFFECTS
2756 N/A
2757
2758 ===========================================================================*/
loc_eng_report_status(loc_eng_data_s_type & loc_eng_data,GpsStatusValue status)2759 static void loc_eng_report_status (loc_eng_data_s_type &loc_eng_data, GpsStatusValue status)
2760 {
2761 ENTRY_LOG();
2762 // Switch from WAIT to MUTE, for "engine on" or "session begin" event
2763 if (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_ENGINE_ON)
2764 {
2765 if (loc_eng_data.mute_session_state == LOC_MUTE_SESS_WAIT)
2766 {
2767 LOC_LOGD("loc_eng_report_status: mute_session_state changed from WAIT to IN SESSION");
2768 loc_eng_data.mute_session_state = LOC_MUTE_SESS_IN_SESSION;
2769 }
2770 }
2771
2772 // Switch off MUTE session
2773 if (loc_eng_data.mute_session_state == LOC_MUTE_SESS_IN_SESSION &&
2774 (status == GPS_STATUS_SESSION_END || status == GPS_STATUS_ENGINE_OFF))
2775 {
2776 LOC_LOGD("loc_eng_report_status: mute_session_state changed from IN SESSION to NONE");
2777 loc_eng_data.mute_session_state = LOC_MUTE_SESS_NONE;
2778 }
2779
2780 // Session End is not reported during Android navigating state
2781 boolean navigating = loc_eng_data.adapter->isInSession();
2782 if (status != GPS_STATUS_NONE &&
2783 !(status == GPS_STATUS_SESSION_END && navigating) &&
2784 !(status == GPS_STATUS_SESSION_BEGIN && !navigating))
2785 {
2786 if (loc_eng_data.mute_session_state != LOC_MUTE_SESS_IN_SESSION)
2787 {
2788 // Inform GpsLocationProvider about mNavigating status
2789 loc_inform_gps_status(loc_eng_data, status);
2790 }
2791 else {
2792 LOC_LOGD("loc_eng_report_status: muting the status report.");
2793 }
2794 }
2795
2796 // Only keeps ENGINE ON/OFF in engine_status
2797 if (status == GPS_STATUS_ENGINE_ON || status == GPS_STATUS_ENGINE_OFF)
2798 {
2799 loc_eng_data.engine_status = status;
2800 }
2801
2802 // Only keeps SESSION BEGIN/END in fix_session_status
2803 if (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_SESSION_END)
2804 {
2805 loc_eng_data.fix_session_status = status;
2806 }
2807 EXIT_LOG(%s, VOID_RET);
2808 }
2809
2810 /*===========================================================================
2811 FUNCTION loc_eng_handle_engine_down
2812 loc_eng_handle_engine_up
2813
2814 DESCRIPTION
2815 Calls this function when it is detected that modem restart is happening.
2816 Either we detected the modem is down or received modem up event.
2817 This must be called from the deferred thread to avoid race condition.
2818
2819 DEPENDENCIES
2820 None
2821
2822 RETURN VALUE
2823 None
2824
2825 SIDE EFFECTS
2826 N/A
2827
2828 ===========================================================================*/
loc_eng_handle_engine_down(loc_eng_data_s_type & loc_eng_data)2829 void loc_eng_handle_engine_down(loc_eng_data_s_type &loc_eng_data)
2830 {
2831 ENTRY_LOG();
2832 loc_eng_ni_reset_on_engine_restart(loc_eng_data);
2833 loc_eng_report_status(loc_eng_data, GPS_STATUS_ENGINE_OFF);
2834 EXIT_LOG(%s, VOID_RET);
2835 }
2836
loc_eng_handle_engine_up(loc_eng_data_s_type & loc_eng_data)2837 void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data)
2838 {
2839 ENTRY_LOG();
2840 loc_eng_reinit(loc_eng_data);
2841
2842 loc_eng_data.adapter->requestPowerVote();
2843
2844 if (loc_eng_data.agps_status_cb != NULL) {
2845 if (loc_eng_data.agnss_nif)
2846 loc_eng_data.agnss_nif->dropAllSubscribers();
2847 if (loc_eng_data.internet_nif)
2848 loc_eng_data.internet_nif->dropAllSubscribers();
2849
2850 loc_eng_agps_reinit(loc_eng_data);
2851 }
2852
2853 loc_eng_report_status(loc_eng_data, GPS_STATUS_ENGINE_ON);
2854
2855 // modem is back up. If we crashed in the middle of navigating, we restart.
2856 if (loc_eng_data.adapter->isInSession()) {
2857 // This sets the copy in adapter to modem
2858 loc_eng_data.adapter->setPositionMode(NULL);
2859 loc_eng_data.adapter->setInSession(false);
2860 loc_eng_start_handler(loc_eng_data);
2861 }
2862 EXIT_LOG(%s, VOID_RET);
2863 }
2864
2865 #ifdef USE_GLIB
2866 /*===========================================================================
2867 FUNCTION set_sched_policy
2868
2869 DESCRIPTION
2870 Local copy of this function which bypasses android set_sched_policy
2871
2872 DEPENDENCIES
2873 None
2874
2875 RETURN VALUE
2876 0
2877
2878 SIDE EFFECTS
2879 N/A
2880
2881 ===========================================================================*/
set_sched_policy(int tid,SchedPolicy policy)2882 static int set_sched_policy(int tid, SchedPolicy policy)
2883 {
2884 return 0;
2885 }
2886 #endif /* USE_GLIB */
2887
2888 /*===========================================================================
2889 FUNCTION loc_eng_read_config
2890
2891 DESCRIPTION
2892 Initiates the reading of the gps config file stored in /etc dir
2893
2894 DEPENDENCIES
2895 None
2896
2897 RETURN VALUE
2898 0: success
2899
2900 SIDE EFFECTS
2901 N/A
2902
2903 ===========================================================================*/
loc_eng_read_config(void)2904 int loc_eng_read_config(void)
2905 {
2906 ENTRY_LOG_CALLFLOW();
2907 if(configAlreadyRead == false)
2908 {
2909 // Initialize our defaults before reading of configuration file overwrites them.
2910 loc_default_parameters();
2911 // We only want to parse the conf file once. This is a good place to ensure that.
2912 // In fact one day the conf file should go into context.
2913 UTIL_READ_CONF(GPS_CONF_FILE, gps_conf_table);
2914 UTIL_READ_CONF(SAP_CONF_FILE, sap_conf_table);
2915 configAlreadyRead = true;
2916 } else {
2917 LOC_LOGV("GPS Config file has already been read\n");
2918 }
2919
2920 EXIT_LOG(%d, 0);
2921 return 0;
2922 }
2923
2924 /*===========================================================================
2925 FUNCTION loc_eng_handle_shutdown
2926
2927 DESCRIPTION
2928 Calls the shutdown callback function in the loc interface to close
2929 the modem node
2930
2931 DEPENDENCIES
2932 None
2933
2934 RETURN VALUE
2935 0: success
2936
2937 SIDE EFFECTS
2938 N/A
2939
2940 ===========================================================================*/
loc_eng_handle_shutdown(loc_eng_data_s_type & locEng)2941 void loc_eng_handle_shutdown(loc_eng_data_s_type &locEng)
2942 {
2943 ENTRY_LOG();
2944 locEng.shutdown_cb();
2945 EXIT_LOG(%d, 0);
2946 }
2947
2948 /*===========================================================================
2949 FUNCTION loc_eng_gps_measurement_init
2950
2951 DESCRIPTION
2952 Initialize gps measurement module.
2953
2954 DEPENDENCIES
2955 N/A
2956
2957 RETURN VALUE
2958 0: success
2959
2960 SIDE EFFECTS
2961 N/A
2962
2963 ===========================================================================*/
loc_eng_gps_measurement_init(loc_eng_data_s_type & loc_eng_data,GpsMeasurementCallbacks * callbacks)2964 int loc_eng_gps_measurement_init(loc_eng_data_s_type &loc_eng_data,
2965 GpsMeasurementCallbacks* callbacks)
2966 {
2967 ENTRY_LOG_CALLFLOW();
2968
2969 STATE_CHECK((NULL == loc_eng_data.gps_measurement_cb),
2970 "gps measurement already initialized",
2971 return GPS_MEASUREMENT_ERROR_ALREADY_INIT);
2972 STATE_CHECK((callbacks != NULL),
2973 "callbacks can not be NULL",
2974 return GPS_MEASUREMENT_ERROR_GENERIC);
2975 STATE_CHECK(loc_eng_data.adapter,
2976 "GpsInterface must be initialized first",
2977 return GPS_MEASUREMENT_ERROR_GENERIC);
2978
2979 // updated the mask
2980 LOC_API_ADAPTER_EVENT_MASK_T event = LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT;
2981 loc_eng_data.adapter->sendMsg(new LocEngUpdateRegistrationMask(
2982 &loc_eng_data,
2983 event,
2984 LOC_REGISTRATION_MASK_ENABLED));
2985 // set up the callback
2986 loc_eng_data.gps_measurement_cb = callbacks->measurement_callback;
2987 LOC_LOGD ("%s, event masks updated successfully", __func__);
2988
2989 return GPS_MEASUREMENT_OPERATION_SUCCESS;
2990 }
2991
2992 /*===========================================================================
2993 FUNCTION loc_eng_gps_measurement_close
2994
2995 DESCRIPTION
2996 Close gps measurement module.
2997
2998 DEPENDENCIES
2999 N/A
3000
3001 RETURN VALUE
3002 N/A
3003
3004 SIDE EFFECTS
3005 N/A
3006
3007 ===========================================================================*/
loc_eng_gps_measurement_close(loc_eng_data_s_type & loc_eng_data)3008 void loc_eng_gps_measurement_close(loc_eng_data_s_type &loc_eng_data)
3009 {
3010 ENTRY_LOG_CALLFLOW();
3011
3012 INIT_CHECK(loc_eng_data.adapter, return);
3013
3014 // updated the mask
3015 LOC_API_ADAPTER_EVENT_MASK_T event = LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT;
3016 loc_eng_data.adapter->sendMsg(new LocEngUpdateRegistrationMask(
3017 &loc_eng_data,
3018 event,
3019 LOC_REGISTRATION_MASK_DISABLED));
3020 // set up the callback
3021 loc_eng_data.gps_measurement_cb = NULL;
3022 EXIT_LOG(%d, 0);
3023 }
3024