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