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