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