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