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
48using namespace loc_core;
49
50//Globals defns
51static gps_location_callback gps_loc_cb = NULL;
52static gps_sv_status_callback gps_sv_cb = NULL;
53
54static void local_loc_cb(UlpLocation* location, void* locExt);
55static void local_sv_cb(GpsSvStatus* sv_status, void* svExt);
56
57static const GpsGeofencingInterface* get_geofence_interface(void);
58
59// Function declarations for sLocEngInterface
60static int  loc_init(GpsCallbacks* callbacks);
61static int  loc_start();
62static int  loc_stop();
63static void loc_cleanup();
64static int  loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty);
65static int  loc_inject_location(double latitude, double longitude, float accuracy);
66static void loc_delete_aiding_data(GpsAidingData f);
67static int  loc_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence,
68                                  uint32_t min_interval, uint32_t preferred_accuracy,
69                                  uint32_t preferred_time);
70static const void* loc_get_extension(const char* name);
71
72// Defines the GpsInterface in gps.h
73static 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
88static void loc_agps_init(AGpsCallbacks* callbacks);
89static int  loc_agps_open(const char* apn);
90static int  loc_agps_closed();
91static int  loc_agps_open_failed();
92static int  loc_agps_set_server(AGpsType type, const char *hostname, int port);
93
94static 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
104static int loc_xtra_init(GpsXtraCallbacks* callbacks);
105static int loc_xtra_inject_data(char* data, int length);
106
107static const GpsXtraInterface sLocEngXTRAInterface =
108{
109    sizeof(GpsXtraInterface),
110    loc_xtra_init,
111    loc_xtra_inject_data
112};
113
114static void loc_ni_init(GpsNiCallbacks *callbacks);
115static void loc_ni_respond(int notif_id, GpsUserResponseType user_response);
116
117const GpsNiInterface sLocEngNiInterface =
118{
119   sizeof(GpsNiInterface),
120   loc_ni_init,
121   loc_ni_respond,
122};
123
124static void loc_agps_ril_init( AGpsRilCallbacks* callbacks );
125static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct);
126static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid);
127static void loc_agps_ril_ni_message(uint8_t *msg, size_t len);
128static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info);
129static void loc_agps_ril_update_network_availability(int avaiable, const char* apn);
130
131static 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
142static loc_eng_data_s_type loc_afw_data;
143static int gss_fd = 0;
144
145/*===========================================================================
146FUNCTION    gps_get_hardware_interface
147
148DESCRIPTION
149   Returns the GPS hardware interaface based on LOC API
150   if GPS is enabled.
151
152DEPENDENCIES
153   None
154
155RETURN VALUE
156   0: success
157
158SIDE EFFECTS
159   N/A
160
161===========================================================================*/
162const 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
188extern "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/*===========================================================================
216FUNCTION    loc_init
217
218DESCRIPTION
219   Initialize the location engine, this include setting up global datas
220   and registers location engien with loc api service.
221
222DEPENDENCIES
223   None
224
225RETURN VALUE
226   0: success
227
228SIDE EFFECTS
229   N/Ax
230
231===========================================================================*/
232static 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/*===========================================================================
278FUNCTION    loc_cleanup
279
280DESCRIPTION
281   Cleans location engine. The location client handle will be released.
282
283DEPENDENCIES
284   None
285
286RETURN VALUE
287   None
288
289SIDE EFFECTS
290   N/A
291
292===========================================================================*/
293static 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/*===========================================================================
312FUNCTION    loc_start
313
314DESCRIPTION
315   Starts the tracking session
316
317DEPENDENCIES
318   None
319
320RETURN VALUE
321   0: success
322
323SIDE EFFECTS
324   N/A
325
326===========================================================================*/
327static 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/*===========================================================================
337FUNCTION    loc_stop
338
339DESCRIPTION
340   Stops the tracking session
341
342DEPENDENCIES
343   None
344
345RETURN VALUE
346   0: success
347
348SIDE EFFECTS
349   N/A
350
351===========================================================================*/
352static 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/*===========================================================================
363FUNCTION    loc_set_position_mode
364
365DESCRIPTION
366   Sets the mode and fix frequency for the tracking session.
367
368DEPENDENCIES
369   None
370
371RETURN VALUE
372   0: success
373
374SIDE EFFECTS
375   N/A
376
377===========================================================================*/
378static 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/*===========================================================================
408FUNCTION    loc_inject_time
409
410DESCRIPTION
411   This is used by Java native function to do time injection.
412
413DEPENDENCIES
414   None
415
416RETURN VALUE
417   0
418
419SIDE EFFECTS
420   N/A
421
422===========================================================================*/
423static 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/*===========================================================================
437FUNCTION    loc_inject_location
438
439DESCRIPTION
440   This is used by Java native function to do location injection.
441
442DEPENDENCIES
443   None
444
445RETURN VALUE
446   0          : Successful
447   error code : Failure
448
449SIDE EFFECTS
450   N/A
451===========================================================================*/
452static 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/*===========================================================================
486FUNCTION    loc_delete_aiding_data
487
488DESCRIPTION
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
494DEPENDENCIES
495   Assumes the aiding data type specified in GpsAidingData matches with
496   LOC API specification.
497
498RETURN VALUE
499   None
500
501SIDE EFFECTS
502   N/A
503
504===========================================================================*/
505static 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
513const 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
542exit:
543    EXIT_LOG(%d, geofence_interface == NULL);
544    return geofence_interface;
545}
546/*===========================================================================
547FUNCTION    loc_get_extension
548
549DESCRIPTION
550   Get the gps extension to support XTRA.
551
552DEPENDENCIES
553   N/A
554
555RETURN VALUE
556   The GPS extension interface.
557
558SIDE EFFECTS
559   N/A
560
561===========================================================================*/
562const 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/*===========================================================================
616FUNCTION    loc_agps_init
617
618DESCRIPTION
619   Initialize the AGps interface.
620
621DEPENDENCIES
622   NONE
623
624RETURN VALUE
625   0
626
627SIDE EFFECTS
628   N/A
629
630===========================================================================*/
631static 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/*===========================================================================
639FUNCTION    loc_agps_open
640
641DESCRIPTION
642   This function is called when on-demand data connection opening is successful.
643It should inform ARM 9 about the data open result.
644
645DEPENDENCIES
646   NONE
647
648RETURN VALUE
649   0
650
651SIDE EFFECTS
652   N/A
653
654===========================================================================*/
655static 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/*===========================================================================
667FUNCTION    loc_agps_closed
668
669DESCRIPTION
670   This function is called when on-demand data connection closing is done.
671It should inform ARM 9 about the data close result.
672
673DEPENDENCIES
674   NONE
675
676RETURN VALUE
677   0
678
679SIDE EFFECTS
680   N/A
681
682===========================================================================*/
683static 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/*===========================================================================
694FUNCTION    loc_agps_open_failed
695
696DESCRIPTION
697   This function is called when on-demand data connection opening has failed.
698It should inform ARM 9 about the data open result.
699
700DEPENDENCIES
701   NONE
702
703RETURN VALUE
704   0
705
706SIDE EFFECTS
707   N/A
708
709===========================================================================*/
710int 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/*===========================================================================
721FUNCTION    loc_agps_set_server
722
723DESCRIPTION
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
728DEPENDENCIES
729   NONE
730
731RETURN VALUE
732   0
733
734SIDE EFFECTS
735   N/A
736
737===========================================================================*/
738static 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/*===========================================================================
759FUNCTIONf571
760    loc_xtra_init
761
762DESCRIPTION
763   Initialize XTRA module.
764
765DEPENDENCIES
766   None
767
768RETURN VALUE
769   0: success
770
771SIDE EFFECTS
772   N/A
773
774===========================================================================*/
775static 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/*===========================================================================
786FUNCTION    loc_xtra_inject_data
787
788DESCRIPTION
789   Initialize XTRA module.
790
791DEPENDENCIES
792   None
793
794RETURN VALUE
795   0: success
796
797SIDE EFFECTS
798   N/A
799
800===========================================================================*/
801static int loc_xtra_inject_data(char* data, int length)
802{
803    ENTRY_LOG();
804    int ret_val = -1;
805    if( (data != NULL) && ((unsigned int)length <= XTRA_DATA_MAX_SIZE))
806        ret_val = loc_eng_xtra_inject_data(loc_afw_data, data, length);
807    else
808        LOC_LOGE("%s, Could not inject XTRA data. Buffer address: %p, length: %d",
809                __func__, data, length);
810    EXIT_LOG(%d, ret_val);
811    return ret_val;
812}
813
814/*===========================================================================
815FUNCTION    loc_ni_init
816
817DESCRIPTION
818   This function initializes the NI interface
819
820DEPENDENCIES
821   NONE
822
823RETURN VALUE
824   None
825
826SIDE EFFECTS
827   N/A
828
829===========================================================================*/
830void loc_ni_init(GpsNiCallbacks *callbacks)
831{
832    ENTRY_LOG();
833    loc_eng_ni_init(loc_afw_data,(GpsNiExtCallbacks*) callbacks);
834    EXIT_LOG(%s, VOID_RET);
835}
836
837/*===========================================================================
838FUNCTION    loc_ni_respond
839
840DESCRIPTION
841   This function sends an NI respond to the modem processor
842
843DEPENDENCIES
844   NONE
845
846RETURN VALUE
847   None
848
849SIDE EFFECTS
850   N/A
851
852===========================================================================*/
853void loc_ni_respond(int notif_id, GpsUserResponseType user_response)
854{
855    ENTRY_LOG();
856    loc_eng_ni_respond(loc_afw_data, notif_id, user_response);
857    EXIT_LOG(%s, VOID_RET);
858}
859
860// Below stub functions are members of sLocEngAGpsRilInterface
861static void loc_agps_ril_init( AGpsRilCallbacks* callbacks ) {}
862static void loc_agps_ril_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) {}
863static void loc_agps_ril_set_set_id(AGpsSetIDType type, const char* setid) {}
864static void loc_agps_ril_ni_message(uint8_t *msg, size_t len) {}
865static void loc_agps_ril_update_network_state(int connected, int type, int roaming, const char* extra_info) {}
866
867/*===========================================================================
868FUNCTION    loc_agps_ril_update_network_availability
869
870DESCRIPTION
871   Sets data call allow vs disallow flag to modem
872   This is the only member of sLocEngAGpsRilInterface implemented.
873
874DEPENDENCIES
875   None
876
877RETURN VALUE
878   0: success
879
880SIDE EFFECTS
881   N/A
882
883===========================================================================*/
884static void loc_agps_ril_update_network_availability(int available, const char* apn)
885{
886    ENTRY_LOG();
887    loc_eng_agps_ril_update_network_availability(loc_afw_data, available, apn);
888    EXIT_LOG(%s, VOID_RET);
889}
890
891static void local_loc_cb(UlpLocation* location, void* locExt)
892{
893    ENTRY_LOG();
894    if (NULL != location) {
895        CALLBACK_LOG_CALLFLOW("location_cb - from", %d, location->position_source);
896
897        if (NULL != gps_loc_cb) {
898            gps_loc_cb(&location->gpsLocation);
899        }
900    }
901    EXIT_LOG(%s, VOID_RET);
902}
903
904static void local_sv_cb(GpsSvStatus* sv_status, void* svExt)
905{
906    ENTRY_LOG();
907    if (NULL != gps_sv_cb) {
908        CALLBACK_LOG_CALLFLOW("sv_status_cb -", %d, sv_status->num_svs);
909        gps_sv_cb(sv_status);
910    }
911    EXIT_LOG(%s, VOID_RET);
912}
913