Home | History | Annotate | Download | only in libloc_api_50001
      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 
     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_SATELLITE_REPORT |
    289             LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST |
    290             LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST |
    291             LOC_API_ADAPTER_BIT_IOCTL_REPORT |
    292             LOC_API_ADAPTER_BIT_STATUS_REPORT |
    293             LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
    294             LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST;
    295 
    296     LocCallbacks clientCallbacks = {local_loc_cb, /* location_cb */
    297                                     callbacks->status_cb, /* status_cb */
    298                                     local_sv_cb, /* sv_status_cb */
    299                                     callbacks->nmea_cb, /* nmea_cb */
    300                                     callbacks->set_capabilities_cb, /* set_capabilities_cb */
    301                                     callbacks->acquire_wakelock_cb, /* acquire_wakelock_cb */
    302                                     callbacks->release_wakelock_cb, /* release_wakelock_cb */
    303                                     callbacks->create_thread_cb, /* create_thread_cb */
    304                                     NULL, /* location_ext_parser */
    305                                     NULL, /* sv_ext_parser */
    306                                     callbacks->request_utc_time_cb, /* request_utc_time_cb */
    307                                     };
    308 
    309     gps_loc_cb = callbacks->location_cb;
    310     gps_sv_cb = callbacks->sv_status_cb;
    311 
    312     retVal = loc_eng_init(loc_afw_data, &clientCallbacks, event, NULL);
    313     loc_afw_data.adapter->mSupportsAgpsRequests = !loc_afw_data.adapter->hasAgpsExtendedCapabilities();
    314     loc_afw_data.adapter->mSupportsPositionInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities();
    315     loc_afw_data.adapter->mSupportsTimeInjection = !loc_afw_data.adapter->hasCPIExtendedCapabilities();
    316     loc_afw_data.adapter->setGpsLockMsg(0);
    317     loc_afw_data.adapter->requestUlp(getCarrierCapabilities());
    318 
    319     if(retVal) {
    320         LOC_LOGE("loc_eng_init() fail!");
    321         goto err;
    322     }
    323 
    324     loc_afw_data.adapter->setPowerVoteRight(loc_get_target() == TARGET_QCA1530);
    325     loc_afw_data.adapter->setPowerVote(true);
    326 
    327     LOC_LOGD("loc_eng_init() success!");
    328 
    329 err:
    330     EXIT_LOG(%d, retVal);
    331     return retVal;
    332 }
    333 
    334 /*===========================================================================
    335 FUNCTION    loc_cleanup
    336 
    337 DESCRIPTION
    338    Cleans location engine. The location client handle will be released.
    339 
    340 DEPENDENCIES
    341    None
    342 
    343 RETURN VALUE
    344    None
    345 
    346 SIDE EFFECTS
    347    N/A
    348 
    349 ===========================================================================*/
    350 static void loc_cleanup()
    351 {
    352     ENTRY_LOG();
    353 
    354     loc_afw_data.adapter->setPowerVote(false);
    355     loc_afw_data.adapter->setGpsLockMsg(gps_conf.GPS_LOCK);
    356 
    357     loc_eng_cleanup(loc_afw_data);
    358     gps_loc_cb = NULL;
    359     gps_sv_cb = NULL;
    360 
    361     EXIT_LOG(%s, VOID_RET);
    362 }
    363 
    364 /*===========================================================================
    365 FUNCTION    loc_start
    366 
    367 DESCRIPTION
    368    Starts the tracking session
    369 
    370 DEPENDENCIES
    371    None
    372 
    373 RETURN VALUE
    374    0: success
    375 
    376 SIDE EFFECTS
    377    N/A
    378 
    379 ===========================================================================*/
    380 static int loc_start()
    381 {
    382     ENTRY_LOG();
    383     int ret_val = loc_eng_start(loc_afw_data);
    384 
    385     EXIT_LOG(%d, ret_val);
    386     return ret_val;
    387 }
    388 
    389 /*===========================================================================
    390 FUNCTION    loc_stop
    391 
    392 DESCRIPTION
    393    Stops the tracking session
    394 
    395 DEPENDENCIES
    396    None
    397 
    398 RETURN VALUE
    399    0: success
    400 
    401 SIDE EFFECTS
    402    N/A
    403 
    404 ===========================================================================*/
    405 static int loc_stop()
    406 {
    407     ENTRY_LOG();
    408     int ret_val = -1;
    409     ret_val = loc_eng_stop(loc_afw_data);
    410 
    411     EXIT_LOG(%d, ret_val);
    412     return ret_val;
    413 }
    414 
    415 /*===========================================================================
    416 FUNCTION    loc_set_position_mode
    417 
    418 DESCRIPTION
    419    Sets the mode and fix frequency for the tracking session.
    420 
    421 DEPENDENCIES
    422    None
    423 
    424 RETURN VALUE
    425    0: success
    426 
    427 SIDE EFFECTS
    428    N/A
    429 
    430 ===========================================================================*/
    431 static int  loc_set_position_mode(GpsPositionMode mode,
    432                                   GpsPositionRecurrence recurrence,
    433                                   uint32_t min_interval,
    434                                   uint32_t preferred_accuracy,
    435                                   uint32_t preferred_time)
    436 {
    437     ENTRY_LOG();
    438     int ret_val = -1;
    439     LocPositionMode locMode;
    440     switch (mode) {
    441     case GPS_POSITION_MODE_MS_BASED:
    442         locMode = LOC_POSITION_MODE_MS_BASED;
    443         break;
    444     case GPS_POSITION_MODE_MS_ASSISTED:
    445         locMode = LOC_POSITION_MODE_MS_ASSISTED;
    446         break;
    447     default:
    448         locMode = LOC_POSITION_MODE_STANDALONE;
    449         break;
    450     }
    451 
    452     LocPosMode params(locMode, recurrence, min_interval,
    453                       preferred_accuracy, preferred_time, NULL, NULL);
    454     ret_val = loc_eng_set_position_mode(loc_afw_data, params);
    455 
    456     EXIT_LOG(%d, ret_val);
    457     return ret_val;
    458 }
    459 
    460 /*===========================================================================
    461 FUNCTION    loc_inject_time
    462 
    463 DESCRIPTION
    464    This is used by Java native function to do time injection.
    465 
    466 DEPENDENCIES
    467    None
    468 
    469 RETURN VALUE
    470    0
    471 
    472 SIDE EFFECTS
    473    N/A
    474 
    475 ===========================================================================*/
    476 static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty)
    477 {
    478     ENTRY_LOG();
    479     int ret_val = 0;
    480 
    481     ret_val = loc_eng_inject_time(loc_afw_data, time,
    482                                   timeReference, uncertainty);
    483 
    484     EXIT_LOG(%d, ret_val);
    485     return ret_val;
    486 }
    487 
    488 
    489 /*===========================================================================
    490 FUNCTION    loc_inject_location
    491 
    492 DESCRIPTION
    493    This is used by Java native function to do location injection.
    494 
    495 DEPENDENCIES
    496    None
    497 
    498 RETURN VALUE
    499    0          : Successful
    500    error code : Failure
    501 
    502 SIDE EFFECTS
    503    N/A
    504 ===========================================================================*/
    505 static int loc_inject_location(double latitude, double longitude, float accuracy)
    506 {
    507     ENTRY_LOG();
    508 
    509     int ret_val = 0;
    510     ret_val = loc_eng_inject_location(loc_afw_data, latitude, longitude, accuracy);
    511 
    512     EXIT_LOG(%d, ret_val);
    513     return ret_val;
    514 }
    515 
    516 
    517 /*===========================================================================
    518 FUNCTION    loc_delete_aiding_data
    519 
    520 DESCRIPTION
    521    This is used by Java native function to delete the aiding data. The function
    522    updates the global variable for the aiding data to be deleted. If the GPS
    523    engine is off, the aiding data will be deleted. Otherwise, the actual action
    524    will happen when gps engine is turned off.
    525 
    526 DEPENDENCIES
    527    Assumes the aiding data type specified in GpsAidingData matches with
    528    LOC API specification.
    529 
    530 RETURN VALUE
    531    None
    532 
    533 SIDE EFFECTS
    534    N/A
    535 
    536 ===========================================================================*/
    537 static void loc_delete_aiding_data(GpsAidingData f)
    538 {
    539     ENTRY_LOG();
    540     loc_eng_delete_aiding_data(loc_afw_data, f);
    541 
    542     EXIT_LOG(%s, VOID_RET);
    543 }
    544 
    545 const GpsGeofencingInterface* get_geofence_interface(void)
    546 {
    547     ENTRY_LOG();
    548     void *handle;
    549     const char *error;
    550     typedef const GpsGeofencingInterface* (*get_gps_geofence_interface_function) (void);
    551     get_gps_geofence_interface_function get_gps_geofence_interface;
    552     static const GpsGeofencingInterface* geofence_interface = NULL;
    553 
    554     dlerror();    /* Clear any existing error */
    555 
    556     handle = dlopen ("libgeofence.so", RTLD_NOW);
    557 
    558     if (!handle)
    559     {
    560         if ((error = dlerror()) != NULL)  {
    561             LOC_LOGE ("%s, dlopen for libgeofence.so failed, error = %s\n", __func__, error);
    562            }
    563         goto exit;
    564     }
    565     dlerror();    /* Clear any existing error */
    566     get_gps_geofence_interface = (get_gps_geofence_interface_function)dlsym(handle, "gps_geofence_get_interface");
    567     if ((error = dlerror()) != NULL && NULL != get_gps_geofence_interface)  {
    568         LOC_LOGE ("%s, dlsym for get_gps_geofence_interface failed, error = %s\n", __func__, error);
    569         goto exit;
    570      }
    571 
    572     geofence_interface = get_gps_geofence_interface();
    573 
    574 exit:
    575     EXIT_LOG(%d, geofence_interface == NULL);
    576     return geofence_interface;
    577 }
    578 /*===========================================================================
    579 FUNCTION    loc_get_extension
    580 
    581 DESCRIPTION
    582    Get the gps extension to support XTRA.
    583 
    584 DEPENDENCIES
    585    N/A
    586 
    587 RETURN VALUE
    588    The GPS extension interface.
    589 
    590 SIDE EFFECTS
    591    N/A
    592 
    593 ===========================================================================*/
    594 const void* loc_get_extension(const char* name)
    595 {
    596     ENTRY_LOG();
    597     const void* ret_val = NULL;
    598 
    599    LOC_LOGD("%s:%d] For Interface = %s\n",__func__, __LINE__, name);
    600    if (strcmp(name, GPS_XTRA_INTERFACE) == 0)
    601    {
    602        ret_val = &sLocEngXTRAInterface;
    603    }
    604    else if (strcmp(name, AGPS_INTERFACE) == 0)
    605    {
    606        ret_val = &sLocEngAGpsInterface;
    607    }
    608    else if (strcmp(name, GPS_NI_INTERFACE) == 0)
    609    {
    610        ret_val = &sLocEngNiInterface;
    611    }
    612    else if (strcmp(name, AGPS_RIL_INTERFACE) == 0)
    613    {
    614        char baseband[PROPERTY_VALUE_MAX];
    615        property_get("ro.baseband", baseband, "msm");
    616        if (strcmp(baseband, "csfb") == 0)
    617        {
    618            ret_val = &sLocEngAGpsRilInterface;
    619        }
    620    }
    621    else if (strcmp(name, GPS_GEOFENCING_INTERFACE) == 0)
    622    {
    623        if ((gps_conf.CAPABILITIES | GPS_CAPABILITY_GEOFENCING) == gps_conf.CAPABILITIES ){
    624            ret_val = get_geofence_interface();
    625        }
    626    }
    627    else if (strcmp(name, SUPL_CERTIFICATE_INTERFACE) == 0)
    628    {
    629        ret_val = &sLocEngAGpsCertInterface;
    630    }
    631    else if (strcmp(name, GNSS_CONFIGURATION_INTERFACE) == 0)
    632    {
    633        ret_val = &sLocEngConfigInterface;
    634    }
    635    else if (strcmp(name, GPS_MEASUREMENT_INTERFACE) == 0)
    636    {
    637        ret_val = &sLocEngGpsMeasurementInterface;
    638    }
    639    else
    640    {
    641       LOC_LOGE ("get_extension: Invalid interface passed in\n");
    642    }
    643     EXIT_LOG(%p, ret_val);
    644     return ret_val;
    645 }
    646 
    647 /*===========================================================================
    648 FUNCTION    loc_agps_init
    649 
    650 DESCRIPTION
    651    Initialize the AGps interface.
    652 
    653 DEPENDENCIES
    654    NONE
    655 
    656 RETURN VALUE
    657    0
    658 
    659 SIDE EFFECTS
    660    N/A
    661 
    662 ===========================================================================*/
    663 static void loc_agps_init(AGpsCallbacks* callbacks)
    664 {
    665     ENTRY_LOG();
    666     loc_eng_agps_init(loc_afw_data, (AGpsExtCallbacks*)callbacks);
    667     EXIT_LOG(%s, VOID_RET);
    668 }
    669 
    670 /*===========================================================================
    671 FUNCTION    loc_agps_open
    672 
    673 DESCRIPTION
    674    This function is called when on-demand data connection opening is successful.
    675 It should inform ARM 9 about the data open result.
    676 
    677 DEPENDENCIES
    678    NONE
    679 
    680 RETURN VALUE
    681    0
    682 
    683 SIDE EFFECTS
    684    N/A
    685 
    686 ===========================================================================*/
    687 static int loc_agps_open(const char* apn)
    688 {
    689     ENTRY_LOG();
    690     AGpsType agpsType = AGPS_TYPE_SUPL;
    691     AGpsBearerType bearerType = AGPS_APN_BEARER_IPV4;
    692     int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType);
    693 
    694     EXIT_LOG(%d, ret_val);
    695     return ret_val;
    696 }
    697 
    698 /*===========================================================================
    699 FUNCTION    loc_agps_open_with_apniptype
    700 
    701 DESCRIPTION
    702    This function is called when on-demand data connection opening is successful.
    703 It should inform ARM 9 about the data open result.
    704 
    705 DEPENDENCIES
    706    NONE
    707 
    708 RETURN VALUE
    709    0
    710 
    711 SIDE EFFECTS
    712    N/A
    713 
    714 ===========================================================================*/
    715 static int  loc_agps_open_with_apniptype(const char* apn, ApnIpType apnIpType)
    716 {
    717     ENTRY_LOG();
    718     AGpsType agpsType = AGPS_TYPE_SUPL;
    719     AGpsBearerType bearerType;
    720 
    721     switch (apnIpType) {
    722         case APN_IP_IPV4:
    723             bearerType = AGPS_APN_BEARER_IPV4;
    724             break;
    725         case APN_IP_IPV6:
    726             bearerType = AGPS_APN_BEARER_IPV6;
    727             break;
    728         case APN_IP_IPV4V6:
    729             bearerType = AGPS_APN_BEARER_IPV4V6;
    730             break;
    731         default:
    732             bearerType = AGPS_APN_BEARER_IPV4;
    733             break;
    734     }
    735 
    736     int ret_val = loc_eng_agps_open(loc_afw_data, agpsType, apn, bearerType);
    737 
    738     EXIT_LOG(%d, ret_val);
    739     return ret_val;
    740 }
    741 
    742 /*===========================================================================
    743 FUNCTION    loc_agps_closed
    744 
    745 DESCRIPTION
    746    This function is called when on-demand data connection closing is done.
    747 It should inform ARM 9 about the data close result.
    748 
    749 DEPENDENCIES
    750    NONE
    751 
    752 RETURN VALUE
    753    0
    754 
    755 SIDE EFFECTS
    756    N/A
    757 
    758 ===========================================================================*/
    759 static int loc_agps_closed()
    760 {
    761     ENTRY_LOG();
    762     AGpsType agpsType = AGPS_TYPE_SUPL;
    763     int ret_val = loc_eng_agps_closed(loc_afw_data, agpsType);
    764 
    765     EXIT_LOG(%d, ret_val);
    766     return ret_val;
    767 }
    768 
    769 /*===========================================================================
    770 FUNCTION    loc_agps_open_failed
    771 
    772 DESCRIPTION
    773    This function is called when on-demand data connection opening has failed.
    774 It should inform ARM 9 about the data open result.
    775 
    776 DEPENDENCIES
    777    NONE
    778 
    779 RETURN VALUE
    780    0
    781 
    782 SIDE EFFECTS
    783    N/A
    784 
    785 ===========================================================================*/
    786 int loc_agps_open_failed()
    787 {
    788     ENTRY_LOG();
    789     AGpsType agpsType = AGPS_TYPE_SUPL;
    790     int ret_val = loc_eng_agps_open_failed(loc_afw_data, agpsType);
    791 
    792     EXIT_LOG(%d, ret_val);
    793     return ret_val;
    794 }
    795 
    796 /*===========================================================================
    797 FUNCTION    loc_agps_set_server
    798 
    799 DESCRIPTION
    800    If loc_eng_set_server is called before loc_eng_init, it doesn't work. This
    801    proxy buffers server settings and calls loc_eng_set_server when the client is
    802    open.
    803 
    804 DEPENDENCIES
    805    NONE
    806 
    807 RETURN VALUE
    808    0
    809 
    810 SIDE EFFECTS
    811    N/A
    812 
    813 ===========================================================================*/
    814 static int loc_agps_set_server(AGpsType type, const char* hostname, int port)
    815 {
    816     ENTRY_LOG();
    817     LocServerType serverType;
    818     switch (type) {
    819     case AGPS_TYPE_SUPL:
    820         serverType = LOC_AGPS_SUPL_SERVER;
    821         break;
    822     case AGPS_TYPE_C2K:
    823         serverType = LOC_AGPS_CDMA_PDE_SERVER;
    824         break;
    825     default:
    826         serverType = LOC_AGPS_SUPL_SERVER;
    827     }
    828     int ret_val = loc_eng_set_server_proxy(loc_afw_data, serverType, hostname, port);
    829 
    830     EXIT_LOG(%d, ret_val);
    831     return ret_val;
    832 }
    833 
    834 /*===========================================================================
    835 FUNCTIONf571
    836     loc_xtra_init
    837 
    838 DESCRIPTION
    839    Initialize XTRA module.
    840 
    841 DEPENDENCIES
    842    None
    843 
    844 RETURN VALUE
    845    0: success
    846 
    847 SIDE EFFECTS
    848    N/A
    849 
    850 ===========================================================================*/
    851 static int loc_xtra_init(GpsXtraCallbacks* callbacks)
    852 {
    853     ENTRY_LOG();
    854     GpsXtraExtCallbacks extCallbacks;
    855     memset(&extCallbacks, 0, sizeof(extCallbacks));
    856     extCallbacks.download_request_cb = callbacks->download_request_cb;
    857     int ret_val = loc_eng_xtra_init(loc_afw_data, &extCallbacks);
    858 
    859     EXIT_LOG(%d, ret_val);
    860     return ret_val;
    861 }
    862 
    863 
    864 /*===========================================================================
    865 FUNCTION    loc_xtra_inject_data
    866 
    867 DESCRIPTION
    868    Initialize XTRA module.
    869 
    870 DEPENDENCIES
    871    None
    872 
    873 RETURN VALUE
    874    0: success
    875 
    876 SIDE EFFECTS
    877    N/A
    878 
    879 ===========================================================================*/
    880 static int loc_xtra_inject_data(char* data, int length)
    881 {
    882     ENTRY_LOG();
    883     int ret_val = -1;
    884     if( (data != NULL) && ((unsigned int)length <= XTRA_DATA_MAX_SIZE))
    885         ret_val = loc_eng_xtra_inject_data(loc_afw_data, data, length);
    886     else
    887         LOC_LOGE("%s, Could not inject XTRA data. Buffer address: %p, length: %d",
    888                  __func__, data, length);
    889     EXIT_LOG(%d, ret_val);
    890     return ret_val;
    891 }
    892 
    893 /*===========================================================================
    894 FUNCTION    loc_gps_measurement_init
    895 
    896 DESCRIPTION
    897    This function initializes the gps measurement interface
    898 
    899 DEPENDENCIES
    900    NONE
    901 
    902 RETURN VALUE
    903    None
    904 
    905 SIDE EFFECTS
    906    N/A
    907 
    908 ===========================================================================*/
    909 static int loc_gps_measurement_init(GpsMeasurementCallbacks* callbacks)
    910 {
    911     ENTRY_LOG();
    912     int ret_val = loc_eng_gps_measurement_init(loc_afw_data,
    913                                                callbacks);
    914 
    915     EXIT_LOG(%d, ret_val);
    916     return ret_val;
    917 }
    918 
    919 /*===========================================================================
    920 FUNCTION    loc_gps_measurement_close
    921 
    922 DESCRIPTION
    923    This function closes the gps measurement interface
    924 
    925 DEPENDENCIES
    926    NONE
    927 
    928 RETURN VALUE
    929    None
    930 
    931 SIDE EFFECTS
    932    N/A
    933 
    934 ===========================================================================*/
    935 static void loc_gps_measurement_close()
    936 {
    937     ENTRY_LOG();
    938     loc_eng_gps_measurement_close(loc_afw_data);
    939 
    940     EXIT_LOG(%s, VOID_RET);
    941 }
    942 
    943 /*===========================================================================
    944 FUNCTION    loc_ni_init
    945 
    946 DESCRIPTION
    947    This function initializes the NI interface
    948 
    949 DEPENDENCIES
    950    NONE
    951 
    952 RETURN VALUE
    953    None
    954 
    955 SIDE EFFECTS
    956    N/A
    957 
    958 ===========================================================================*/
    959 void loc_ni_init(GpsNiCallbacks *callbacks)
    960 {
    961     ENTRY_LOG();
    962     loc_eng_ni_init(loc_afw_data,(GpsNiExtCallbacks*) callbacks);
    963     EXIT_LOG(%s, VOID_RET);
    964 }
    965 
    966 /*===========================================================================
    967 FUNCTION    loc_ni_respond
    968 
    969 DESCRIPTION
    970    This function sends an NI respond to the modem processor
    971 
    972 DEPENDENCIES
    973    NONE
    974 
    975 RETURN VALUE
    976    None
    977 
    978 SIDE EFFECTS
    979    N/A
    980 
    981 ===========================================================================*/
    982 void loc_ni_respond(int notif_id, GpsUserResponseType user_response)
    983 {
    984     ENTRY_LOG();
    985     loc_eng_ni_respond(loc_afw_data, notif_id, user_response);
    986     EXIT_LOG(%s, VOID_RET);
    987 }
    988 
    989 // Below stub functions are members of sLocEngAGpsRilInterface
    990 static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ) {}
    991 static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) {}
    992 static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid) {}
    993 static void loc_agps_ril_ni_message(uint8_t *msg, size_t len) {}
    994 static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info) {}
    995 
    996 /*===========================================================================
    997 FUNCTION    loc_agps_ril_update_network_availability
    998 
    999 DESCRIPTION
   1000    Sets data call allow vs disallow flag to modem
   1001    This is the only member of sLocEngAGpsRilInterface implemented.
   1002 
   1003 DEPENDENCIES
   1004    None
   1005 
   1006 RETURN VALUE
   1007    0: success
   1008 
   1009 SIDE EFFECTS
   1010    N/A
   1011 
   1012 ===========================================================================*/
   1013 static void loc_agps_ril_update_network_availability(int available, const char* apn)
   1014 {
   1015     ENTRY_LOG();
   1016     loc_eng_agps_ril_update_network_availability(loc_afw_data, available, apn);
   1017     EXIT_LOG(%s, VOID_RET);
   1018 }
   1019 
   1020 static int loc_agps_install_certificates(const DerEncodedCertificate* certificates,
   1021                                          size_t length)
   1022 {
   1023     ENTRY_LOG();
   1024     int ret_val = loc_eng_agps_install_certificates(loc_afw_data, certificates, length);
   1025     EXIT_LOG(%d, ret_val);
   1026     return ret_val;
   1027 }
   1028 static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* fingerprints,
   1029                                         size_t length)
   1030 {
   1031     ENTRY_LOG();
   1032     LOC_LOGE("%s:%d]: agps_revoke_certificates not supported");
   1033     int ret_val = AGPS_CERTIFICATE_ERROR_GENERIC;
   1034     EXIT_LOG(%d, ret_val);
   1035     return ret_val;
   1036 }
   1037 
   1038 static void loc_configuration_update(const char* config_data, int32_t length)
   1039 {
   1040     ENTRY_LOG();
   1041     loc_eng_configuration_update(loc_afw_data, config_data, length);
   1042     switch (sGnssType)
   1043     {
   1044     case GNSS_GSS:
   1045     case GNSS_AUTO:
   1046     case GNSS_QCA1530:
   1047         //APQ
   1048         gps_conf.CAPABILITIES &= ~(GPS_CAPABILITY_MSA | GPS_CAPABILITY_MSB);
   1049         break;
   1050     }
   1051     EXIT_LOG(%s, VOID_RET);
   1052 }
   1053 
   1054 static void local_loc_cb(UlpLocation* location, void* locExt)
   1055 {
   1056     ENTRY_LOG();
   1057     if (NULL != location) {
   1058         CALLBACK_LOG_CALLFLOW("location_cb - from", %d, location->position_source);
   1059 
   1060         if (NULL != gps_loc_cb) {
   1061             gps_loc_cb(&location->gpsLocation);
   1062         }
   1063     }
   1064     EXIT_LOG(%s, VOID_RET);
   1065 }
   1066 
   1067 static void local_sv_cb(GpsSvStatus* sv_status, void* svExt)
   1068 {
   1069     ENTRY_LOG();
   1070     if (NULL != gps_sv_cb) {
   1071         CALLBACK_LOG_CALLFLOW("sv_status_cb -", %d, sv_status->num_svs);
   1072         gps_sv_cb(sv_status);
   1073     }
   1074     EXIT_LOG(%s, VOID_RET);
   1075 }
   1076 
   1077