1/* Copyright (c) 2011-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_afw" 32 33#include <hardware/gps.h> 34#include <gps_extended.h> 35#include <loc_eng.h> 36#include <loc_target.h> 37#include <loc_log.h> 38#include <fcntl.h> 39#include <errno.h> 40#include <dlfcn.h> 41#include <sys/types.h> 42#include <sys/stat.h> 43#include <fcntl.h> 44#include <errno.h> 45#include <LocDualContext.h> 46#include <cutils/properties.h> 47 48using namespace loc_core; 49 50//Globals defns 51static gps_location_callback gps_loc_cb = NULL; 52static gps_sv_status_callback gps_sv_cb = NULL; 53static agps_status_callback agps_status_cb = NULL; 54 55static void local_loc_cb(UlpLocation* location, void* locExt); 56static void local_sv_cb(GpsSvStatus* sv_status, void* svExt); 57static void loc_agps_status_cb(AGpsStatus* status); 58 59static const GpsGeofencingInterface* get_geofence_interface(void); 60 61// Function declarations for sLocEngInterface 62static int loc_init(GpsCallbacks* callbacks); 63static int loc_start(); 64static int loc_stop(); 65static void loc_cleanup(); 66static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty); 67static int loc_inject_location(double latitude, double longitude, float accuracy); 68static void loc_delete_aiding_data(GpsAidingData f); 69static int loc_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence, 70 uint32_t min_interval, uint32_t preferred_accuracy, 71 uint32_t preferred_time); 72static const void* loc_get_extension(const char* name); 73static void loc_close_mdm_node(); 74// Defines the GpsInterface in gps.h 75static const GpsInterface sLocEngInterface = 76{ 77 sizeof(GpsInterface), 78 loc_init, 79 loc_start, 80 loc_stop, 81 loc_cleanup, 82 loc_inject_time, 83 loc_inject_location, 84 loc_delete_aiding_data, 85 loc_set_position_mode, 86 loc_get_extension 87}; 88 89// Function declarations for sLocEngAGpsInterface 90static void loc_agps_init(AGpsCallbacks* callbacks); 91static int loc_agps_open(const char* apn); 92static int loc_agps_closed(); 93static int loc_agps_open_failed(); 94static int loc_agps_set_server(AGpsType type, const char *hostname, int port); 95static int loc_agps_open_with_apniptype( const char* apn, ApnIpType apnIpType); 96 97static const AGpsInterface sLocEngAGpsInterface = 98{ 99 sizeof(AGpsInterface), 100 loc_agps_init, 101 loc_agps_open, 102 loc_agps_closed, 103 loc_agps_open_failed, 104 loc_agps_set_server, 105 loc_agps_open_with_apniptype 106}; 107 108static int loc_xtra_init(GpsXtraCallbacks* callbacks); 109static int loc_xtra_inject_data(char* data, int length); 110 111static const GpsXtraInterface sLocEngXTRAInterface = 112{ 113 sizeof(GpsXtraInterface), 114 loc_xtra_init, 115 loc_xtra_inject_data 116}; 117 118static void loc_ni_init(GpsNiCallbacks *callbacks); 119static void loc_ni_respond(int notif_id, GpsUserResponseType user_response); 120 121static const GpsNiInterface sLocEngNiInterface = 122{ 123 sizeof(GpsNiInterface), 124 loc_ni_init, 125 loc_ni_respond, 126}; 127 128// For shutting down MDM in fusion devices 129static int mdm_fd = -1; 130static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks); 131static void loc_gps_measurement_close(); 132 133static const GpsMeasurementInterface sLocEngGpsMeasurementInterface = 134{ 135 sizeof(GpsMeasurementInterface), 136 loc_gps_measurement_init, 137 loc_gps_measurement_close 138}; 139 140static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ); 141static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct); 142static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid); 143static void loc_agps_ril_ni_message(uint8_t *msg, size_t len); 144static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info); 145static void loc_agps_ril_update_network_availability(int avaiable, const char* apn); 146 147static const AGpsRilInterface sLocEngAGpsRilInterface = 148{ 149 sizeof(AGpsRilInterface), 150 loc_agps_ril_init, 151 loc_agps_ril_set_ref_location, 152 loc_agps_ril_set_set_id, 153 loc_agps_ril_ni_message, 154 loc_agps_ril_update_network_state, 155 loc_agps_ril_update_network_availability 156}; 157 158static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, 159 size_t length); 160static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, 161 size_t length); 162 163static const SuplCertificateInterface sLocEngAGpsCertInterface = 164{ 165 sizeof(SuplCertificateInterface), 166 loc_agps_install_certificates, 167 loc_agps_revoke_certificates 168}; 169 170static void loc_configuration_update(const char* config_data, int32_t length); 171 172static const GnssConfigurationInterface sLocEngConfigInterface = 173{ 174 sizeof(GnssConfigurationInterface), 175 loc_configuration_update 176}; 177 178static loc_eng_data_s_type loc_afw_data; 179static int gss_fd = -1; 180 181/*=========================================================================== 182FUNCTION gps_get_hardware_interface 183 184DESCRIPTION 185 Returns the GPS hardware interaface based on LOC API 186 if GPS is enabled. 187 188DEPENDENCIES 189 None 190 191RETURN VALUE 192 0: success 193 194SIDE EFFECTS 195 N/A 196 197===========================================================================*/ 198const GpsInterface* gps_get_hardware_interface () 199{ 200 ENTRY_LOG_CALLFLOW(); 201 const GpsInterface* ret_val; 202 203 char propBuf[PROPERTY_VALUE_MAX]; 204 205 loc_eng_read_config(); 206 207 // check to see if GPS should be disabled 208 property_get("gps.disable", propBuf, ""); 209 if (propBuf[0] == '1') 210 { 211 LOC_LOGD("gps_get_interface returning NULL because gps.disable=1\n"); 212 ret_val = NULL; 213 } else { 214 ret_val = &sLocEngInterface; 215 } 216 217 loc_eng_read_config(); 218 219 EXIT_LOG(%p, ret_val); 220 return ret_val; 221} 222 223// for gps.c 224extern "C" const GpsInterface* get_gps_interface() 225{ 226 unsigned int target = TARGET_DEFAULT; 227 loc_eng_read_config(); 228 229 target = loc_get_target(); 230 LOC_LOGD("Target name check returned %s", loc_get_target_name(target)); 231 232 int gnssType = getTargetGnssType(target); 233 switch (gnssType) 234 { 235 case GNSS_GSS: 236 //APQ8064 237 gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); 238 gss_fd = open("/dev/gss", O_RDONLY); 239 if (gss_fd < 0) { 240 LOC_LOGE("GSS open failed: %s\n", strerror(errno)); 241 } 242 else { 243 LOC_LOGD("GSS open success! CAPABILITIES %0lx\n", 244 gps_conf.CAPABILITIES); 245 } 246 break; 247 case GNSS_NONE: 248 //MPQ8064 249 LOC_LOGE("No GPS HW on this target. Not returning interface."); 250 return NULL; 251 case GNSS_QCA1530: 252 // qca1530 chip is present 253 gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB); 254 LOC_LOGD("qca1530 present: CAPABILITIES %0lx\n", gps_conf.CAPABILITIES); 255 break; 256 } 257 return &sLocEngInterface; 258} 259 260/*=========================================================================== 261FUNCTION loc_init 262 263DESCRIPTION 264 Initialize the location engine, this include setting up global datas 265 and registers location engien with loc api service. 266 267DEPENDENCIES 268 None 269 270RETURN VALUE 271 0: success 272 273SIDE EFFECTS 274 N/Ax 275 276===========================================================================*/ 277static int loc_init(GpsCallbacks* callbacks) 278{ 279 int retVal = -1; 280 int i = 0; 281 ENTRY_LOG(); 282 LOC_API_ADAPTER_EVENT_MASK_T event; 283 284 if (NULL == callbacks) { 285 LOC_LOGE("loc_init failed. cb = NULL\n"); 286 EXIT_LOG(%d, retVal); 287 return retVal; 288 } 289 290 event = LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | 291 LOC_API_ADAPTER_BIT_SATELLITE_REPORT | 292 LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST | 293 LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST | 294 LOC_API_ADAPTER_BIT_IOCTL_REPORT | 295 LOC_API_ADAPTER_BIT_STATUS_REPORT | 296 LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | 297 LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; 298 299 LocCallbacks clientCallbacks = {local_loc_cb, /* location_cb */ 300 callbacks->status_cb, /* status_cb */ 301 local_sv_cb, /* sv_status_cb */ 302 callbacks->nmea_cb, /* nmea_cb */ 303 callbacks->set_capabilities_cb, /* set_capabilities_cb */ 304 callbacks->acquire_wakelock_cb, /* acquire_wakelock_cb */ 305 callbacks->release_wakelock_cb, /* release_wakelock_cb */ 306 callbacks->create_thread_cb, /* create_thread_cb */ 307 NULL, /* location_ext_parser */ 308 NULL, /* sv_ext_parser */ 309 callbacks->request_utc_time_cb, /* request_utc_time_cb */ 310 loc_close_mdm_node /*loc_shutdown_cb*/}; 311 312 gps_loc_cb = callbacks->location_cb; 313 gps_sv_cb = callbacks->sv_status_cb; 314 315 retVal = loc_eng_init(loc_afw_data, &clientCallbacks, event, NULL); 316 loc_afw_data.adapter->mSupportsAgpsRequests = !loc_afw_data.adapter->hasAgpsExtendedCapabilities(); 317 loc_afw_data.adapter->mSupportsPositionInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities(); 318 loc_afw_data.adapter->setGpsLockMsg(0); 319 loc_afw_data.adapter->requestUlp(gps_conf.CAPABILITIES); 320 321 if(retVal) { 322 LOC_LOGE("loc_eng_init() fail!"); 323 goto err; 324 } 325 326 loc_afw_data.adapter->setPowerVoteRight(loc_get_target() == TARGET_QCA1530); 327 loc_afw_data.adapter->setPowerVote(true); 328 329 LOC_LOGD("loc_eng_init() success!"); 330 331#ifdef PLATFORM_MSM8084 332 if (mdm_fd < 0) { 333 int (*open_first_external_modem)(void); 334 const char *name = "libdetectmodem.so"; 335 const char *func = "open_first_external_modem"; 336 const char *error; 337 338 void *lib = ::dlopen(name, RTLD_NOW); 339 error = ::dlerror(); 340 if (!lib) { 341 LOC_LOGE("%s: could not find %s: %s", __func__, name, error); 342 goto err; 343 } 344 345 open_first_external_modem = NULL; 346 *(void **)(&open_first_external_modem) = ::dlsym(lib, func); 347 error = ::dlerror(); 348 349 if (!open_first_external_modem) { 350 LOC_LOGE("%s: could not find symbol %s in %s: %s", 351 __func__, func, name, error); 352 } 353 else { 354 errno = 0; 355 mdm_fd = open_first_external_modem(); 356 if (mdm_fd < 0) { 357 LOC_LOGE("%s: %s failed: %s\n", __func__, func, strerror(errno)); 358 } 359 else { 360 LOC_LOGD("%s: external power up modem opened successfully\n", __func__); 361 } 362 } 363 dlclose(lib); 364 } else { 365 LOC_LOGD("powerup_node has been opened before"); 366 } 367#endif //PLATFORM_MSM8084 368err: 369 EXIT_LOG(%d, retVal); 370 return retVal; 371} 372 373/*=========================================================================== 374FUNCTION loc_close_mdm_node 375 376DESCRIPTION 377 closes mdm_fd which is the modem powerup node obtained in loc_init 378 379DEPENDENCIES 380 None 381 382RETURN VALUE 383 None 384 385SIDE EFFECTS 386 N/A 387 388===========================================================================*/ 389static void loc_close_mdm_node() 390{ 391 ENTRY_LOG(); 392 if (mdm_fd >= 0) { 393 LOC_LOGD("closing the powerup node"); 394 close(mdm_fd); 395 mdm_fd = -1; 396 LOC_LOGD("finished closing the powerup node"); 397 } else { 398 LOC_LOGD("powerup node has not been opened yet."); 399 } 400 401 EXIT_LOG(%s, VOID_RET); 402} 403 404/*=========================================================================== 405FUNCTION loc_cleanup 406 407DESCRIPTION 408 Cleans location engine. The location client handle will be released. 409 410DEPENDENCIES 411 None 412 413RETURN VALUE 414 None 415 416SIDE EFFECTS 417 N/A 418 419===========================================================================*/ 420static void loc_cleanup() 421{ 422 ENTRY_LOG(); 423 424 loc_afw_data.adapter->setPowerVote(false); 425 loc_afw_data.adapter->setGpsLockMsg(gps_conf.GPS_LOCK); 426 427 loc_eng_cleanup(loc_afw_data); 428 loc_close_mdm_node(); 429 gps_loc_cb = NULL; 430 gps_sv_cb = NULL; 431 432 EXIT_LOG(%s, VOID_RET); 433} 434 435/*=========================================================================== 436FUNCTION loc_start 437 438DESCRIPTION 439 Starts the tracking session 440 441DEPENDENCIES 442 None 443 444RETURN VALUE 445 0: success 446 447SIDE EFFECTS 448 N/A 449 450===========================================================================*/ 451static int loc_start() 452{ 453 ENTRY_LOG(); 454 int ret_val = loc_eng_start(loc_afw_data); 455 456 EXIT_LOG(%d, ret_val); 457 return ret_val; 458} 459 460/*=========================================================================== 461FUNCTION loc_stop 462 463DESCRIPTION 464 Stops the tracking session 465 466DEPENDENCIES 467 None 468 469RETURN VALUE 470 0: success 471 472SIDE EFFECTS 473 N/A 474 475===========================================================================*/ 476static int loc_stop() 477{ 478 ENTRY_LOG(); 479 int ret_val = -1; 480 ret_val = loc_eng_stop(loc_afw_data); 481 482 EXIT_LOG(%d, ret_val); 483 return ret_val; 484} 485 486/*=========================================================================== 487FUNCTION loc_set_position_mode 488 489DESCRIPTION 490 Sets the mode and fix frequency for the tracking session. 491 492DEPENDENCIES 493 None 494 495RETURN VALUE 496 0: success 497 498SIDE EFFECTS 499 N/A 500 501===========================================================================*/ 502static int loc_set_position_mode(GpsPositionMode mode, 503 GpsPositionRecurrence recurrence, 504 uint32_t min_interval, 505 uint32_t preferred_accuracy, 506 uint32_t preferred_time) 507{ 508 ENTRY_LOG(); 509 int ret_val = -1; 510 LocPositionMode locMode; 511 switch (mode) { 512 case GPS_POSITION_MODE_MS_BASED: 513 locMode = LOC_POSITION_MODE_MS_BASED; 514 break; 515 case GPS_POSITION_MODE_MS_ASSISTED: 516 locMode = LOC_POSITION_MODE_MS_ASSISTED; 517 break; 518 default: 519 locMode = LOC_POSITION_MODE_STANDALONE; 520 break; 521 } 522 523 LocPosMode params(locMode, recurrence, min_interval, 524 preferred_accuracy, preferred_time, NULL, NULL); 525 ret_val = loc_eng_set_position_mode(loc_afw_data, params); 526 527 EXIT_LOG(%d, ret_val); 528 return ret_val; 529} 530 531/*=========================================================================== 532FUNCTION loc_inject_time 533 534DESCRIPTION 535 This is used by Java native function to do time injection. 536 537DEPENDENCIES 538 None 539 540RETURN VALUE 541 0 542 543SIDE EFFECTS 544 N/A 545 546===========================================================================*/ 547static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty) 548{ 549 ENTRY_LOG(); 550 int ret_val = 0; 551 552 ret_val = loc_eng_inject_time(loc_afw_data, time, 553 timeReference, uncertainty); 554 555 EXIT_LOG(%d, ret_val); 556 return ret_val; 557} 558 559 560/*=========================================================================== 561FUNCTION loc_inject_location 562 563DESCRIPTION 564 This is used by Java native function to do location injection. 565 566DEPENDENCIES 567 None 568 569RETURN VALUE 570 0 : Successful 571 error code : Failure 572 573SIDE EFFECTS 574 N/A 575===========================================================================*/ 576static int loc_inject_location(double latitude, double longitude, float accuracy) 577{ 578 static bool initialized = false; 579 static bool enable_cpi = true; 580 ENTRY_LOG(); 581 582 if (accuracy < 1000) 583 { 584 accuracy = 1000; 585 } 586 587 int ret_val = 0; 588 ret_val = loc_eng_inject_location(loc_afw_data, latitude, longitude, accuracy); 589 590 if(!initialized) 591 { 592 char value[PROPERTY_VALUE_MAX]; 593 memset(value, 0, sizeof(value)); 594 (void)property_get("persist.gps.qc_nlp_in_use", value, "0"); 595 if(0 == strcmp(value, "1")) 596 { 597 enable_cpi = false; 598 LOC_LOGI("GPS HAL coarse position injection disabled"); 599 } 600 else 601 { 602 LOC_LOGI("GPS HAL coarse position injection enabled"); 603 } 604 initialized = true; 605 } 606 607 if(enable_cpi) 608 { 609 ret_val = loc_eng_inject_location(loc_afw_data, latitude, longitude, accuracy); 610 } 611 EXIT_LOG(%d, ret_val); 612 return ret_val; 613} 614 615 616/*=========================================================================== 617FUNCTION loc_delete_aiding_data 618 619DESCRIPTION 620 This is used by Java native function to delete the aiding data. The function 621 updates the global variable for the aiding data to be deleted. If the GPS 622 engine is off, the aiding data will be deleted. Otherwise, the actual action 623 will happen when gps engine is turned off. 624 625DEPENDENCIES 626 Assumes the aiding data type specified in GpsAidingData matches with 627 LOC API specification. 628 629RETURN VALUE 630 None 631 632SIDE EFFECTS 633 N/A 634 635===========================================================================*/ 636static void loc_delete_aiding_data(GpsAidingData f) 637{ 638 ENTRY_LOG(); 639 loc_eng_delete_aiding_data(loc_afw_data, f); 640 641 EXIT_LOG(%s, VOID_RET); 642} 643 644const GpsGeofencingInterface* get_geofence_interface(void) 645{ 646 ENTRY_LOG(); 647 void *handle; 648 const char *error; 649 typedef const GpsGeofencingInterface* (*get_gps_geofence_interface_function) (void); 650 get_gps_geofence_interface_function get_gps_geofence_interface; 651 static const GpsGeofencingInterface* geofence_interface = NULL; 652 653 dlerror(); /* Clear any existing error */ 654 655 handle = dlopen ("libgeofence.so", RTLD_NOW); 656 657 if (!handle) 658 { 659 if ((error = dlerror()) != NULL) { 660 LOC_LOGE ("%s, dlopen for libgeofence.so failed, error = %s\n", __func__, error); 661 } 662 goto exit; 663 } 664 dlerror(); /* Clear any existing error */ 665 get_gps_geofence_interface = (get_gps_geofence_interface_function)dlsym(handle, "gps_geofence_get_interface"); 666 if ((error = dlerror()) != NULL) { 667 LOC_LOGE ("%s, dlsym for get_gps_geofence_interface failed, error = %s\n", __func__, error); 668 goto exit; 669 } 670 671 geofence_interface = get_gps_geofence_interface(); 672 673exit: 674 EXIT_LOG(%d, geofence_interface == NULL); 675 return geofence_interface; 676} 677/*=========================================================================== 678FUNCTION loc_get_extension 679 680DESCRIPTION 681 Get the gps extension to support XTRA. 682 683DEPENDENCIES 684 N/A 685 686RETURN VALUE 687 The GPS extension interface. 688 689SIDE EFFECTS 690 N/A 691 692===========================================================================*/ 693const void* loc_get_extension(const char* name) 694{ 695 ENTRY_LOG(); 696 const void* ret_val = NULL; 697 698 LOC_LOGD("%s:%d] For Interface = %s\n",__func__, __LINE__, name); 699 if (strcmp(name, GPS_XTRA_INTERFACE) == 0) 700 { 701 ret_val = &sLocEngXTRAInterface; 702 } 703 else if (strcmp(name, AGPS_INTERFACE) == 0) 704 { 705 ret_val = &sLocEngAGpsInterface; 706 } 707 else if (strcmp(name, GPS_NI_INTERFACE) == 0) 708 { 709 ret_val = &sLocEngNiInterface; 710 } 711 else if (strcmp(name, AGPS_RIL_INTERFACE) == 0) 712 { 713 char baseband[PROPERTY_VALUE_MAX]; 714 property_get("ro.baseband", baseband, "msm"); 715 if (strcmp(baseband, "csfb") == 0) 716 { 717 ret_val = &sLocEngAGpsRilInterface; 718 } 719 } 720 else if (strcmp(name, GPS_GEOFENCING_INTERFACE) == 0) 721 { 722 if ((gps_conf.CAPABILITIES | GPS_CAPABILITY_GEOFENCING) == gps_conf.CAPABILITIES ){ 723 ret_val = get_geofence_interface(); 724 } 725 } 726 else if (strcmp(name, SUPL_CERTIFICATE_INTERFACE) == 0) 727 { 728 ret_val = &sLocEngAGpsCertInterface; 729 } 730 else if (strcmp(name, GNSS_CONFIGURATION_INTERFACE) == 0) 731 { 732 ret_val = &sLocEngConfigInterface; 733 } 734 else if (strcmp(name, GPS_MEASUREMENT_INTERFACE) == 0) 735 { 736 ret_val = &sLocEngGpsMeasurementInterface; 737 } 738 else 739 { 740 LOC_LOGE ("get_extension: Invalid interface passed in\n"); 741 } 742 EXIT_LOG(%p, ret_val); 743 return ret_val; 744} 745 746/*=========================================================================== 747FUNCTION loc_agps_init 748 749DESCRIPTION 750 Initialize the AGps interface. 751 752DEPENDENCIES 753 NONE 754 755RETURN VALUE 756 0 757 758SIDE EFFECTS 759 N/A 760 761===========================================================================*/ 762static void loc_agps_init(AGpsCallbacks* callbacks) 763{ 764 ENTRY_LOG(); 765 if (agps_status_cb == NULL) { 766 agps_status_cb = callbacks->status_cb; 767 callbacks->status_cb = loc_agps_status_cb; 768 } 769 loc_eng_agps_init(loc_afw_data, (AGpsExtCallbacks*)callbacks); 770 EXIT_LOG(%s, VOID_RET); 771} 772 773/*=========================================================================== 774FUNCTION loc_agps_open 775 776DESCRIPTION 777 This function is called when on-demand data connection opening is successful. 778It should inform ARM 9 about the data open result. 779 780DEPENDENCIES 781 NONE 782 783RETURN VALUE 784 0 785 786SIDE EFFECTS 787 N/A 788 789===========================================================================*/ 790static int loc_agps_open(const char* apn) 791{ 792 ENTRY_LOG(); 793 AGpsType agpsType = AGPS_TYPE_SUPL; 794 AGpsBearerType bearerType = AGPS_APN_BEARER_IPV4; 795 int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType); 796 797 EXIT_LOG(%d, ret_val); 798 return ret_val; 799} 800 801/*=========================================================================== 802FUNCTION loc_agps_open_with_apniptype 803 804DESCRIPTION 805 This function is called when on-demand data connection opening is successful. 806It should inform ARM 9 about the data open result. 807 808DEPENDENCIES 809 NONE 810 811RETURN VALUE 812 0 813 814SIDE EFFECTS 815 N/A 816 817===========================================================================*/ 818static int loc_agps_open_with_apniptype(const char* apn, ApnIpType apnIpType) 819{ 820 ENTRY_LOG(); 821 AGpsType agpsType = AGPS_TYPE_SUPL; 822 AGpsBearerType bearerType; 823 824 switch (apnIpType) { 825 case APN_IP_IPV4: 826 bearerType = AGPS_APN_BEARER_IPV4; 827 break; 828 case APN_IP_IPV6: 829 bearerType = AGPS_APN_BEARER_IPV6; 830 break; 831 case APN_IP_IPV4V6: 832 bearerType = AGPS_APN_BEARER_IPV4V6; 833 break; 834 default: 835 bearerType = AGPS_APN_BEARER_INVALID; 836 break; 837 } 838 839 int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType); 840 841 EXIT_LOG(%d, ret_val); 842 return ret_val; 843} 844 845/*=========================================================================== 846FUNCTION loc_agps_closed 847 848DESCRIPTION 849 This function is called when on-demand data connection closing is done. 850It should inform ARM 9 about the data close result. 851 852DEPENDENCIES 853 NONE 854 855RETURN VALUE 856 0 857 858SIDE EFFECTS 859 N/A 860 861===========================================================================*/ 862static int loc_agps_closed() 863{ 864 ENTRY_LOG(); 865 AGpsType agpsType = AGPS_TYPE_SUPL; 866 int ret_val = loc_eng_agps_closed(loc_afw_data, agpsType); 867 868 EXIT_LOG(%d, ret_val); 869 return ret_val; 870} 871 872/*=========================================================================== 873FUNCTION loc_agps_open_failed 874 875DESCRIPTION 876 This function is called when on-demand data connection opening has failed. 877It should inform ARM 9 about the data open result. 878 879DEPENDENCIES 880 NONE 881 882RETURN VALUE 883 0 884 885SIDE EFFECTS 886 N/A 887 888===========================================================================*/ 889int loc_agps_open_failed() 890{ 891 ENTRY_LOG(); 892 AGpsType agpsType = AGPS_TYPE_SUPL; 893 int ret_val = loc_eng_agps_open_failed(loc_afw_data, agpsType); 894 895 EXIT_LOG(%d, ret_val); 896 return ret_val; 897} 898 899/*=========================================================================== 900FUNCTION loc_agps_set_server 901 902DESCRIPTION 903 If loc_eng_set_server is called before loc_eng_init, it doesn't work. This 904 proxy buffers server settings and calls loc_eng_set_server when the client is 905 open. 906 907DEPENDENCIES 908 NONE 909 910RETURN VALUE 911 0 912 913SIDE EFFECTS 914 N/A 915 916===========================================================================*/ 917static int loc_agps_set_server(AGpsType type, const char* hostname, int port) 918{ 919 ENTRY_LOG(); 920 LocServerType serverType; 921 switch (type) { 922 case AGPS_TYPE_SUPL: 923 serverType = LOC_AGPS_SUPL_SERVER; 924 break; 925 case AGPS_TYPE_C2K: 926 serverType = LOC_AGPS_CDMA_PDE_SERVER; 927 break; 928 default: 929 serverType = LOC_AGPS_SUPL_SERVER; 930 } 931 int ret_val = loc_eng_set_server_proxy(loc_afw_data, serverType, hostname, port); 932 933 EXIT_LOG(%d, ret_val); 934 return ret_val; 935} 936 937/*=========================================================================== 938FUNCTIONf571 939 loc_xtra_init 940 941DESCRIPTION 942 Initialize XTRA module. 943 944DEPENDENCIES 945 None 946 947RETURN VALUE 948 0: success 949 950SIDE EFFECTS 951 N/A 952 953===========================================================================*/ 954static int loc_xtra_init(GpsXtraCallbacks* callbacks) 955{ 956 ENTRY_LOG(); 957 int ret_val = loc_eng_xtra_init(loc_afw_data, (GpsXtraExtCallbacks*)callbacks); 958 959 EXIT_LOG(%d, ret_val); 960 return ret_val; 961} 962 963 964/*=========================================================================== 965FUNCTION loc_xtra_inject_data 966 967DESCRIPTION 968 Initialize XTRA module. 969 970DEPENDENCIES 971 None 972 973RETURN VALUE 974 0: success 975 976SIDE EFFECTS 977 N/A 978 979===========================================================================*/ 980static int loc_xtra_inject_data(char* data, int length) 981{ 982 ENTRY_LOG(); 983 int ret_val = loc_eng_xtra_inject_data(loc_afw_data, data, length); 984 985 EXIT_LOG(%d, ret_val); 986 return ret_val; 987} 988 989/*=========================================================================== 990FUNCTION loc_gps_measurement_init 991 992DESCRIPTION 993 This function initializes the gps measurement interface 994 995DEPENDENCIES 996 NONE 997 998RETURN VALUE 999 None 1000 1001SIDE EFFECTS 1002 N/A 1003 1004===========================================================================*/ 1005static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks) 1006{ 1007 ENTRY_LOG(); 1008 int ret_val = loc_eng_gps_measurement_init(loc_afw_data, 1009 callbacks); 1010 1011 EXIT_LOG(%d, ret_val); 1012 return ret_val; 1013} 1014 1015/*=========================================================================== 1016FUNCTION loc_gps_measurement_close 1017 1018DESCRIPTION 1019 This function closes the gps measurement interface 1020 1021DEPENDENCIES 1022 NONE 1023 1024RETURN VALUE 1025 None 1026 1027SIDE EFFECTS 1028 N/A 1029 1030===========================================================================*/ 1031static void loc_gps_measurement_close() 1032{ 1033 ENTRY_LOG(); 1034 loc_eng_gps_measurement_close(loc_afw_data); 1035 1036 EXIT_LOG(%s, VOID_RET); 1037} 1038 1039/*=========================================================================== 1040FUNCTION loc_ni_init 1041 1042DESCRIPTION 1043 This function initializes the NI interface 1044 1045DEPENDENCIES 1046 NONE 1047 1048RETURN VALUE 1049 None 1050 1051SIDE EFFECTS 1052 N/A 1053 1054===========================================================================*/ 1055void loc_ni_init(GpsNiCallbacks *callbacks) 1056{ 1057 ENTRY_LOG(); 1058 loc_eng_ni_init(loc_afw_data,(GpsNiExtCallbacks*) callbacks); 1059 EXIT_LOG(%s, VOID_RET); 1060} 1061 1062/*=========================================================================== 1063FUNCTION loc_ni_respond 1064 1065DESCRIPTION 1066 This function sends an NI respond to the modem processor 1067 1068DEPENDENCIES 1069 NONE 1070 1071RETURN VALUE 1072 None 1073 1074SIDE EFFECTS 1075 N/A 1076 1077===========================================================================*/ 1078void loc_ni_respond(int notif_id, GpsUserResponseType user_response) 1079{ 1080 ENTRY_LOG(); 1081 loc_eng_ni_respond(loc_afw_data, notif_id, user_response); 1082 EXIT_LOG(%s, VOID_RET); 1083} 1084 1085// Below stub functions are members of sLocEngAGpsRilInterface 1086static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ) {} 1087static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) {} 1088static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid) {} 1089static void loc_agps_ril_ni_message(uint8_t *msg, size_t len) {} 1090static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info) {} 1091 1092/*=========================================================================== 1093FUNCTION loc_agps_ril_update_network_availability 1094 1095DESCRIPTION 1096 Sets data call allow vs disallow flag to modem 1097 This is the only member of sLocEngAGpsRilInterface implemented. 1098 1099DEPENDENCIES 1100 None 1101 1102RETURN VALUE 1103 0: success 1104 1105SIDE EFFECTS 1106 N/A 1107 1108===========================================================================*/ 1109static void loc_agps_ril_update_network_availability(int available, const char* apn) 1110{ 1111 ENTRY_LOG(); 1112 loc_eng_agps_ril_update_network_availability(loc_afw_data, available, apn); 1113 EXIT_LOG(%s, VOID_RET); 1114} 1115 1116static int loc_agps_install_certificates(const DerEncodedCertificate* certificates, 1117 size_t length) 1118{ 1119 ENTRY_LOG(); 1120 int ret_val = loc_eng_agps_install_certificates(loc_afw_data, certificates, length); 1121 EXIT_LOG(%d, ret_val); 1122 return ret_val; 1123} 1124static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints, 1125 size_t length) 1126{ 1127 ENTRY_LOG(); 1128 LOC_LOGE("agps_revoke_certificates not supported"); 1129 int ret_val = AGPS_CERTIFICATE_ERROR_GENERIC; 1130 EXIT_LOG(%d, ret_val); 1131 return ret_val; 1132} 1133 1134static void loc_configuration_update(const char* config_data, int32_t length) 1135{ 1136 ENTRY_LOG(); 1137 loc_eng_configuration_update(loc_afw_data, config_data, length); 1138 EXIT_LOG(%s, VOID_RET); 1139} 1140 1141static void local_loc_cb(UlpLocation* location, void* locExt) 1142{ 1143 ENTRY_LOG(); 1144 if (NULL != location) { 1145 CALLBACK_LOG_CALLFLOW("location_cb - from", %d, location->position_source); 1146 1147 if (NULL != gps_loc_cb) { 1148 gps_loc_cb(&location->gpsLocation); 1149 } 1150 } 1151 EXIT_LOG(%s, VOID_RET); 1152} 1153 1154static void local_sv_cb(GpsSvStatus* sv_status, void* svExt) 1155{ 1156 ENTRY_LOG(); 1157 if (NULL != gps_sv_cb) { 1158 CALLBACK_LOG_CALLFLOW("sv_status_cb -", %d, sv_status->num_svs); 1159 gps_sv_cb(sv_status); 1160 } 1161 EXIT_LOG(%s, VOID_RET); 1162} 1163 1164static void loc_agps_status_cb(AGpsStatus* status) 1165{ 1166 ENTRY_LOG(); 1167 1168 if (NULL != agps_status_cb) { 1169 size_t realSize = sizeof(AGpsStatus); 1170 LOC_LOGD("agps_status size=%d real-size=%d", status->size, realSize); 1171 status->size = realSize; 1172 agps_status_cb(status); 1173 } 1174 EXIT_LOG(%s, VOID_RET); 1175} 1176 1177