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