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